< Previous | Contents | Next >
Introducing the Designers Network
The Designers Network program simulates a computer network in which only a select group of game designers are members. Like real-world computer systems,
62 Chapter 2 n Truth, Branching, and the Game Loop: Guess My Number
each member must enter a username and a password to log in. With a successful login, the member is personally greeted. To log in as a guest, all a user needs to do is enter guest at either the username or password prompt. Figures 2.9 through 2.11 show the program.
Figure 2.9
If you’re not a member or a guest, you can’t get in.
Figure 2.10
You can log in as a guest.
Using Logical Operators 63
Figure 2.11
Looks like one of the elite logged in today.
You can download the code for this program from the Course Technology website (www.courseptr.com/downloads). The program is in the Chapter 2 folder; the filename is designers_network.cpp.
// Designers Network
// Demonstrates logical operators
#include <iostream> #include <string> using namespace std;
int main()
{
string username; string password; bool success;
cout << "\tGame Designer’s Network\n"; do
64 Chapter 2 n Truth, Branching, and the Game Loop: Guess My Number
{
cout << "\nUsername: "; cin >> username;
cout << "Password: "; cin >> password;
if (username == "S.Meier" && password == "civilization")
{
cout << "\nHey, Sid."; success = true;
}
else if (username == "S.Miyamoto" && password == "mariobros")
{
cout << "\nWhat’s up, Shigeru?"; success = true;
}
else if (username == "W.Wright" && password == "thesims")
{
cout << "\nHow goes it, Will?"; success = true;
}
else if (username == "guest" || password == "guest")
{
}
else
{
}
cout << "\nWelcome, guest."; success = true;
cout << "\nYour login failed."; success = false;
} while (!success);
return 0;
}