< Previous | Contents | Next >
The main() function displays the players in the lobby, presents the user with a menu of choices, and performs the requested action.
int main()
{
Lobby myLobby; int choice;
do
{
cout << myLobby;
cout << "\nGAME LOBBY\n";
cout << "0 - Exit the program.\n";
cout << "1 - Add a player to the lobby.\n";
cout << "2 - Remove a player from the lobby.\n"; cout << "3 - Clear the lobby.\n";
cout << endl << "Enter choice: "; cin >> choice;
switch (choice)
{
case 0: cout << "Good-bye.\n"; break; case 1: myLobby.AddPlayer(); break; case 2: myLobby.RemovePlayer(); break; case 3: myLobby.Clear(); break;
default: cout << "That was not a valid choice.\n";
}
}
while (choice != 0);
}
The function first instantiates a new Lobby object, and then it enters a loop that presents a menu and gets the user’s choice. Then it calls the corresponding Lobby object’s member function. If the user enters an invalid choice, he or she is told so. The loop continues until the user enters 0.