FaltuTech.Club : Fane of Advanced Logical Thriving Utopian Technical Club

Snakes and Ladders (Saanp-Sidhi) Code in C++(C Plus Plus(cpp))


#include  // for standed input output
#include    // for console input output
#include   // for rand function
#include     // for time.(to get the seed of rand)
#include   // for string manupulation
#include  // for data manupulator(formatter)
  class SaanpSidhi {
    public: int Position;

    private: int ConditionNegaOrPlus(int current, int newrand); // condition for negation or plus
    public: void ptar(int Pos1, char User1[], int Pos2, char User2[]); // print the place of player and whole grid
    int RandomNum(int current); // adds random number
  };
int SaanpSidhi::ConditionNegaOrPlus(int current, int newrand) { // logic of condition for negation or plus
  int newval;
  newval = current + newrand;
  cout > player1;
  cout > player2;
  SaanpSidhi p1, p2; // creation of two objects for two players p1 and p2
  p1.Position = 0; // set position to 0 for both players
  p2.Position = 0;
  p1.ptar(p1.Position, player1, p2.Position, player2); // print initial grid 
  do {
    cout > r;
    if (r == 'r' || r == 'R') { // condition to check if player pressed r or R
      p1.Position = p1.RandomNum(p1.Position); // call the function RandomNum with args = Player 1 Position
      p1.ptar(p1.Position, player1, p2.Position, player2); // Printing the grid after player 1 has rolled the dice
      if (p1.Position >= 100) { // check if player reaches 100 or more if yes break the loop and declare him winner
        cout > r;
    if (r == 'r' || r == 'R') {
      p2.Position = p2.RandomNum(p2.Position);
      p1.ptar(p1.Position, player1, p2.Position, player2);
      if (p2.Position >= 100) {
        cout