//-------------------------------------------------------------------------------------------------------------------- // Creates the tasks and starts the game. The game simulates the old telephone message where a message is passed // around the circle. At the end of the game, the original message is compared to the final result to see how much // it changed. In our case, we just print the message as it travels the circle until the game is done. //-------------------------------------------------------------------------------------------------------------------- #include "player.h" #include using namespace std; int main() { Player *players[NUMPLAYERS]; // List of players. Player::Status StateInformation[NUMPLAYERS]; // Status of the players. int i; // Loop index. char message[15] = "abcdefghijkl\0"; // Test message to send around the chain. int numberOfPasses = 0; // Number of times the message is passed. If equals // NUMPLAYERS*TIMESAROUND+1, the game is over. srandom( (intptr_t)time(NULL) ); // Seed the random number generator. // Start up the players for the game. players[NUMPLAYERS - 1] = new Player( StateInformation, numberOfPasses, NULL, NUMPLAYERS - 1 ); for ( i = NUMPLAYERS - 2; i >= 0; i -= 1 ) { players[i] = new Player( StateInformation, numberOfPasses, players[i + 1], i ); } // for players[NUMPLAYERS - 1]->SetPlayer( players[0] ); players[0]->SendMessage( message ); // Start off the game. for ( i = 0; i < NUMPLAYERS; i += 1 ) { delete players[i]; } // for cout << "Final message was: '" << message << "'" << endl; } // main // Local Variables: // compile-command: "u++ -g -o telephone player.C driver.C" // End: