H.A.15.2 - game.cpp

Game.cpp

 

 

//  game.cpp

 

//  This program simulates a board game as described in the student outline of Lesson 15.

 

#include <iostream.h>

#include <iomanip.h>

#include <bool.h>

#include <token.h>

 

void playGame (int lenOfGame, int maxRoll);

 

main ()

{

       int maxRoll, lenOfGame;

 

       cout << "This is a simulation of a board game" << endl << endl;

       cout << "Enter number of winning square ---> ";

       cin >> lenOfGame;

       cout << "Enter maximum dice roll for a token ---> ";

       cin >> maxRoll;

       cout << endl << endl;

       playGame (lenOfGame, maxRoll);

       cout << endl << endl;

       return 0;

}

 

 

void playGame (int lenOfGame, int maxRoll)

{

       token p1('A',1, lenOfGame, maxRoll);

       token p2('B',1, lenOfGame, maxRoll);

       bool p1Turn=true, done=false;

 

       do

       {

             if (p1Turn)

             {

                   done = p1.move();

                   cout << p1.getName() << " - " << p1.getPos() << "      ";

             }

             else

             {

                   done = p2.move();

                   cout << p2.getName() << " - " << p2.getPos() << endl;

             }

             p1Turn = !p1Turn;

       }

       while (!done);

 

       cout << endl << endl;

       cout << p1.getName() << " - " << p1.getPos() << "     ";

       cout << p2.getName() << " - " << p2.getPos() << endl;

       cout << endl;

}