I need Help on my arcade game collection

I need help on this end of semester project. My project is to make a arcade video game collection. I need Help on making the Game Menu, putting in function form, and creating the Password Protected Game.
Game Menu:
******* *******
******* GAME-R-US *******
******* *******
I Have four Games:
-Guess the Number?
-Tic-Tat-Toe
-Jumble Words
-Roll a die
-Secret Game(Password Protected/Beat Computer on Tic-Tat-Toe)

-I need a Game Menu for the list of the Games I have?
-The whole code needs to be in functions form
-Secret Game need to be password protected

Guess a number:
// Guess My Number
// The classic number guessing game
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(static_cast<unsigned int>(time(0))); //seed random number generator
int secretNumber = rand() % 100 + 1; // random number between 1 and 100
int tries = 0;
int guess;
cout << "\tWelcome to Guess My Number\n\n";
do
{
cout << "Enter a guess: ";
cin >> guess;
++tries;
if (guess > secretNumber)
{
cout << "Too high!\n\n";
}
else if (guess < secretNumber)
{
cout << "Too low!\n\n";
}
else
{
cout << "\nThat’s it! You got it in " << tries << " guesses!\n";
}
} while (guess != secretNumber);
return 0;
}

Roll a Die:
// Die Roller
// Demonstrates generating random numbers
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(static_cast<unsigned int>(time(0))); //seed random number generator
int randomNumber = rand(); //generate random number
int die = (randomNumber % 6) + 1; // get a number between 1 and 6
cout << "You rolled a " << die << endl;
return 0;
}


Jumble Words:
// Word Jumble
// The classic word jumble game where the player can ask for a hint
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
enum fields {WORD, HINT, NUM_FIELDS};
const int NUM_WORDS = 5;
const string WORDS[NUM_WORDS][NUM_FIELDS] =
{
{"wall", "Do you feel you’re banging your head against something?"},
{"glasses", "These might help you see the answer."},
{"labored", "Going slowly, is it?"},
{"persistent", "Keep at it."},
{"jumble", "It’s what the game is all about."}
};
srand(static_cast<unsigned int>(time(0)));
int choice = (rand() % NUM_WORDS);
string theWord = WORDS[choice][WORD]; // word to guess
string theHint = WORDS[choice][HINT]; // hint for word
string jumble = theWord; // jumbled version of word
int length = jumble.size();
for (int i = 0; i < length; ++i)
{
int index1 = (rand() % length);
int index2 = (rand() % length);
char temp = jumble[index1];
jumble[index1] = jumble[index2];
jumble[index2] = temp;
}
cout << "\t\t\tWelcome to Word Jumble!\n\n";
cout << "Unscramble the letters to make a word.\n";
cout << "Enter ’hint’ for a hint.\n";
cout << "Enter ’quit’ to quit the game.\n\n";
cout << "The jumble is: " << jumble;
string guess;
cout << "\n\nYour guess: ";
cin >> guess;
while ((guess != theWord) && (guess != "quit"))

Secret game:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string username;
string password;
bool success;
cout << "\tSecret Game\n";
do
{
cout << "\nUsername: ";
cin >> username;
cout << "Password: ";
cin >> password;
if (username == "Blank" && password == "360")
{
cout << "\n Welcome to the Secret game";
success = true;
else
{
cout << "\nYour login failed.";
success = false;
}
} while (!success);
return 0;
}

Here the Code For the Secret Game, I want it when the user enter the password and username its runs this code :
#include <iostream>
using namespace std;


//The workings of Connect Four
class connectFour{
int player;
int score[2];
int board[6][7]; //6 = Rows, 7 = Columns
int move;
bool win;

public:
//Set the player number to one and the scores to zero
connectFour(){
player = 1;
score[0] = 0;
score[1] = 0;
win = false;

//Initialize board array
for (int i = 0; i < 6; i++){
for (int x = 0; x < 7; x++){
board[i][x] = 0;
}
}
}

//Setup the turn by first checking for a win
//If there is no win, continue by displaying the board
//and getting the player's move
void startTurn(){
checkWin();
if (win == true){
clearScreen();
display();
cout<< "Player #" << player << " has won!" <<endl <<endl;
}
else{
display();
gatherMove();
}
}

//Display the board
void display(){
clearScreen();
cout<< " 1 2 3 4 5 6 7 " <<endl;
for (int i = 0; i < 6; i++){
for (int x = 0; x < 7; x++){
cout<< "[" << board[i][x] << "]";
}
cout<< endl;
}
}

//Gather the player's move
void gatherMove(){
int emptySpots = 0;
cout<< endl << "Player #" << player << ": Move to which space? ";
cin>> move;

//If the player enters anything above 7, set it to 7
if (move > 7){move = 7;}
//If the player enters anything below 0, set it to 0
if (move < 0){move = 0;}

//Determine where the player's piece falls
//If something occupies the lowest point already, put it above
for (int i = 5; i >= 0; i--){
if (board[i][move - 1] == 0){
board[i][move - 1] = player;
break;
}
else{
emptySpots += 1;
}
}

//If there are no more rows in a column, tell the player to try again
if (emptySpots == 6){
cout<< endl << "There are no empty spots on #" << move << "! Try again!";
gatherMove();
}

//Set the next player to move
if (player == 1){player = 2;}
else {player = 1;}

//Call start of next turn
startTurn();
}

//Check for any winning combinations
void checkWin(){
int start = 0;

//Horizontal Win
for (int i = 0; i < 6; i ++){
for (start = 0; start <= 3; start++){
if ((board[i][start] == board[i][start+1] && board[i][start+1] == board[i][start+2] && board[i][start+2] == board[i][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}

//Vertical Win
for (int i = 0; i < 7; i ++){
for (start = 0; start <= 2; start++){
if ((board[start][i] == board[start+1][i] && board[start+1][i] == board[start+2][i] && board[start+2][i] == board[start+3][i]) && (board[start][i] != 0)){
win = true;
player = board[start][i];
break;
}
}
}

//Diagonal Win - "/"
for (int i = 3; i < 6; i ++){
for (start = 0; start <= 3; start++){
if ((board[i][start] == board[i-1][start+1] && board[i-1][start+1] == board[i-2][start+2] && board[i-2][start+2] == board[i-3][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}

//Diagonal Win - "\"
for (int i = 0; i < 3; i ++){
for (start = 0; start <= 4; start++){
if ((board[i][start] == board[i+1][start+1] && board[i+1][start+1] == board[i+2][start+2] && board[i+2][start+2] == board[i+3][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}
}

//Clear the screen
//Set for OSX currently - Change the inner system call for Windows or Linux
void clearScreen(){
system("clear");
}

};

//Main function - Nice and small just like I like it!
int main (int argc, char * const argv[]) {
connectFour play;
play.startTurn();

return 0;
}
Hi @jakesweater,

this is a
little menu
example for
your game program.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//Menu.cpp
//Simple menu.

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <string>
using std::string;
using std::getline;


void f_1(); //function prototypes
void f_2();
void f_3();
void f_4();

bool PasswordIsCorrect(string const& PasswordEnteredByTheUser,string const& SecretPassword);

int Menu(); 

int main(){

bool theUserWantToContinue=true;
string const SecretPassword="jakesweater";
int choice;
string passwordEnteredByTheUser;
char Continue;

while(theUserWantToContinue){
	choice=Menu();
	
	switch(choice){
		case 1:
			f_1();
		break;
		case 2:
			f_2();
		break;
		case 3:
			f_3();
		break;
		case 4:
			cin.ignore(100,'\n');
			cout<<"Enter password: ";
			getline(cin,passwordEnteredByTheUser);
			if(PasswordIsCorrect(passwordEnteredByTheUser,SecretPassword)){
				f_4();
			}else{
				cout<<"\nIncorrect password"<<endl;
			}//end if...else
			
		break;
	}//end switch
	cout<<"\nDo you want to cotinue? [y/n]: ";
	cin>>Continue;
	
	while(!(Continue=='y'||Continue=='Y'||Continue=='N'||Continue=='n')){
		cin.ignore(1000,'\n');
		cout<<"Enter y/Y or n/N \nContinue? [y/n]: ";
		cin>>Continue;
	}//end while
	if(Continue=='n'||Continue=='N'){
		theUserWantToContinue=false;
	}//end if	
}//end while


return 0; //indicates success
}//end main

int Menu(){
	int choice;
	cout<<"\nHello i have 4 functions\n"
	<<"(1)Function 1\n"
	<<"(2)Function 2\n"
	<<"(3)Function 3\n"
	<<"(4)Function 4(Password protected)\n"
	<<"Select: ";
	cin>>choice;
	
	while((choice<1||choice>4)||cin.fail()){
			
			if(cin.fail()){
				cin.clear();
			}//end if
			cin.ignore(100,'\n');
		
		cout<<"\nI do not have this function\n"
		<<"(1)Function 1\n"
        	<<"(2)Function 2\n"
        	<<"(3)Function 3\n"
        	<<"(4)Function 4(Password protected)\n"
        	<<"Select again: ";
        	cin>>choice;
	}//end while

return choice;	
}//end menu

bool PasswordIsCorrect(string const& PasswordEnteredByTheUser,string const& SecretPassword){
	if(PasswordEnteredByTheUser==SecretPassword)
		return true;

return false;
}//end function PasswordIsCorrect
	

void f_1(){
	cout<<"\nYou selected function 1"
	<<endl;
}//end function f_1

void f_2(){
        cout<<"\nYou selected function 2"
        <<endl;
}//end function f_2

void f_3(){
        cout<<"\nYou selected function 3"
        <<endl;
}//end function f_3

void f_4(){
        cout<<"\nYou selected function 4"
        <<endl;
}//end function f_4 
So function 1-4, I just replace it with my game codes. Thank You. How do I display this on the menu screen:
******* ******* *********
******* GAME-R-US *******
******* ****************
The secret game is in function form.
Last edited on
Just add:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
int Menu(){
	int choice;
        cout<<'\n';
        cout<<"*********************\n";
        cout<<"*****GAME-R-US*******\n";
        cout<<"*********************\n";
	cout<<"\nIhave 4 functions\n"
	<<"(1)Function 1\n"
	<<"(2)Function 2\n"
	<<"(3)Function 3\n"
	<<"(4)Function 4(Password protected)\n"
	<<"Select: ";
	cin>>choice;
	
	while((choice<1||choice>4)||cin.fail()){
			
			if(cin.fail()){
				cin.clear();
			}//end if
			cin.ignore(100,'\n');
		
		cout<<"\nI do not have this function\n"
		<<"(1)Function 1\n"
        	<<"(2)Function 2\n"
        	<<"(3)Function 3\n"
        	<<"(4)Function 4(Password protected)\n"
        	<<"Select again: ";
        	cin>>choice;
	}//end while

return choice;	
}//end menu 
I have errors on my tic-tat-toe and connect-4 game:

Have 27 errors Tic-Tat-Toe:
// Tic-Tac-Toe
// Plays the game of tic-tac-toe against a human opponent
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
// global constants
const char X = ’X’;
const char O = ’O’;
const char EMPTY = ’ ’;
const char TIE = ’T’;
const char NO_ONE = ’N’;
// function prototypes
void instructions();
char askYesNo(string question);
void instructions();
char askYesNo(string question);

int askNumber(string question, int
high, int low = 0);
char humanPiece();
char opponent(char piece);
void displayBoard(const
vector<char>& board);
char winner(const vector<char>&
board);
bool isLegal(const vector<char>&
board, int move);
(const vector<char>&
board, char human);
int computerMove(vector<char> board,
char computer);
void announceWinner(char winner,
char computer, char human);
// main function
int main()
{
int move;
const int NUM_SQUARES = 9;
vector<char> board(NUM_SQUARES, EMPTY);
instructions();
char human = humanPiece();
char computer = opponent(human);
char turn = X;
displayBoard(board);
while (winner(board) == NO_ONE)
{
if (turn == human)
{
move = humanMove(board, human);
board[move] = human;
}
else
{
move = computerMove(board, computer);
board[move] = computer;
}
displayBoard(board);
turn = opponent(turn);
}
announceWinner(winner(board), computer, human);
return 0;
}
void instructions()
{
cout << "Welcome to the ultimate man-machine showdown: Tic-Tac-Toe.\n";
cout << "--where human brain is pit against silicon processor\n\n";
cout << "Make your move known by entering a number, 0 - 8. The number\n";
cout << "corresponds to the desired board position, as illustrated:\n\n";
cout << " 0 | 1 | 2\n";
cout << " ——————— \n";
cout << " 3 | 4 | 5\n";
cout << " ——————— \n";
cout << " 6 | 7 | 8\n\n";
cout << "Prepare yourself, human. The battle is about to begin.\n\n";
}
char askYesNo(string question)
{
char response;
do
{
cout << question << " (y/n): ";
cin >> response;
} while (response != ’y’ && response != ’n’);
return response;
}
int askNumber(string question, int high, int low)
{
int number;
do
{
cout << question << " (" << low << " - " << high << "): ";
cin >> number;
} while (number > high || number < low);
return number;
}
char humanPiece()
{char go_first = askYesNo("Do you require the first move?");
if (go_first == ’y’)
{
cout << "\nThen take the first move. You will need it.\n";
return X;
}
else
{
cout << "\nYour bravery will be your undoing. . . I will go first.\n";
return O;
}
}
char opponent(char piece)
{
if (piece == X)
{
return O;
}
else
{
return X;
}
}
void displayBoard(const vector<char>& board)
{
cout << "\n\t" << board[0] << " | " << board[1] << " | " << board[2];
cout << "\n\t" << "———————";
cout << "\n\t" << board[3] << " | " << board[4] << " | " << board[5];
cout << "\n\t" << "———————";
cout << "\n\t" << board[6] << " | " << board[7] << " | " << board[8];
cout << "\n\n";
}
char winner(const vector<char>& board)
{
// all possible winning rows
const int WINNING_ROWS[8][3] = { {0, 1, 2},
{3, 4, 5},
{6, 7, 8},
{0, 3, 6},
{1, 4, 7},
{2, 5, 8},
{0, 4, 8},
{2, 4, 6} };
const int TOTAL_ROWS = 8;
// if any winning row has three values that are the same (and not EMPTY),
// then we have a winner
for(int row = 0; row < TOTAL_ROWS; ++row)
{
if ( (board[WINNING_ROWS[row][0]] != EMPTY) &&
(board[WINNING_ROWS[row][0]] == board[WINNING_ROWS[row][1]]) &&
(board[WINNING_ROWS[row][1]] == board[WINNING_ROWS[row][2]]) )
{
return board[WINNING_ROWS[row][0]];
}
}
// since nobody has won, check for a tie (no empty squares left)
if (count(board.begin(), board.end(), EMPTY) == 0)
return TIE;
// since nobody has won and it isn’t a tie, the game ain’t over
return NO_ONE;
}
// since nobody has won and it isn’t a tie, the game ain’t over
return NO_ONE;
}
int humanMove(const vector<char>& board, char human)
{
int move = askNumber("Where will you move?", (board.size() - 1));
while (!isLegal(move, board))
{
cout << "\nThat square is already occupied, foolish human.\n";
move = askNumber("Where will you move?", (board.size() - 1));
}
cout << "Fine. . .\n";
return move;
}
int computerMove(vector<char> board, char computer)
{
unsigned int move = 0;
bool found = false;
//if computer can win on next move, that’s the move to make
while (!found && move < board.size())
{
if (isLegal(move, board))
{
board[move] = computer;
found = winner(board) == computer;
board[move] = EMPTY;
}
if (!found)
{
++move;
}
}
//otherwise, if human can win on next move, that’s the move to make
if (!found)
{
move = 0;
char human = opponent(computer);
while (!found && move < board.size())
{
if (isLegal(move, board))
{
board[move] = human;
found = winner(board) == human;
board[move] = EMPTY;
}
if (!found)
{
++move;
}
}
}
//otherwise, moving to the best open square is the move to make
if (!found)
{
move = 0;
unsigned int i = 0;
const int BEST_MOVES[] = {4, 0, 2, 6, 8, 1, 3, 5, 7};
//pick best open square
while (!found && i < board.size())
{
move = BEST_MOVES[i];
if (isLegal(move, board))
{
found = true;
}
++i;
}
}
//otherwise, moving to the best open square is the move to make
if (!found)
{
move = 0;
unsigned int i = 0;
const int BEST_MOVES[] = {4, 0, 2, 6, 8, 1, 3, 5, 7};
//pick best open square
while (!found && i < board.size())
{
move = BEST_MOVES[i];
if (isLegal(move, board))
{
found = true;
}
++i;
}
}
void announceWinner(char winner, char computer, char human)
{
if (winner == computer)
{
cout << winner << "’s won!\n";
cout << "As I predicted, human, I am triumphant once more -- proof\n";
cout << "that computers are superior to humans in all regards.\n";
}
else if (winner == human)
{
cout << winner << "’s won!\n";
cout << "No, no! It cannot be! Somehow you tricked me, human.\n";
cout << "But never again! I, the computer, so swear it!\n";
}
else
{
cout << "It’s a tie.\n";
cout << "You were most lucky, human, and somehow managed to tie me.\n";
cout << "Celebrate. . . for this is the best you will ever achieve.\n";
}
Connect-4 have 5 errors:
#include <iostream>
using namespace std;


//The workings of Connect Four
class connectFour{
int player;
int score[2];
int board[6][7]; //6 = Rows, 7 = Columns
int move;
bool win;

public:
//Set the player number to one and the scores to zero
connectFour(){
player = 1;
score[0] = 0;
score[1] = 0;
win = false;

//Initialize board array
for (int i = 0; i < 6; i++){
for (int x = 0; x < 7; x++){
board[i][x] = 0;
}
}
}

//Setup the turn by first checking for a win
//If there is no win, continue by displaying the board
//and getting the player's move
void startTurn(){
checkWin();
if (win == true){
clearScreen();
display();
cout<< "Player #" << player << " has won!" <<endl <<endl;
}
else{
display();
gatherMove();
}
}

//Display the board
void display(){
clearScreen();
cout<< " 1 2 3 4 5 6 7 " <<endl;
for (int i = 0; i < 6; i++){
for (int x = 0; x < 7; x++){
cout<< "[" << board[i][x] << "]";
}
cout<< endl;
}
}

//Gather the player's move
void gatherMove(){
int emptySpots = 0;
cout<< endl << "Player #" << player << ": Move to which space? ";
cin>> move;

//If the player enters anything above 7, set it to 7
if (move > 7){move = 7;}
//If the player enters anything below 0, set it to 0
if (move < 0){move = 0;}

//Determine where the player's piece falls
//If something occupies the lowest point already, put it above
for (int i = 5; i >= 0; i--){
if (board[i][move - 1] == 0){
board[i][move - 1] = player;
break;
}
else{
emptySpots += 1;
}
}

//If there are no more rows in a column, tell the player to try again
if (emptySpots == 6){
cout<< endl << "There are no empty spots on #" << move << "! Try again!";
gatherMove();
}

//Set the next player to move
if (player == 1){player = 2;}
else {player = 1;}

//Call start of next turn
startTurn();
}

//Check for any winning combinations
void checkWin(){
int start = 0;

//Horizontal Win
for (int i = 0; i < 6; i ++){
for (start = 0; start <= 3; start++){
if ((board[i][start] == board[i][start+1] && board[i][start+1] == board[i][start+2] && board[i][start+2] == board[i][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}

//Vertical Win
for (int i = 0; i < 7; i ++){
for (start = 0; start <= 2; start++){
if ((board[start][i] == board[start+1][i] && board[start+1][i] == board[start+2][i] && board[start+2][i] == board[start+3][i]) && (board[start][i] != 0)){
win = true;
player = board[start][i];
break;
}
}
}

//Diagonal Win - "/"
for (int i = 3; i < 6; i ++){
for (start = 0; start <= 3; start++){
if ((board[i][start] == board[i-1][start+1] && board[i-1][start+1] == board[i-2][start+2] && board[i-2][start+2] == board[i-3][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}

//Diagonal Win - "\"
for (int i = 0; i < 3; i ++){
for (start = 0; start <= 4; start++){
if ((board[i][start] == board[i+1][start+1] && board[i+1][start+1] == board[i+2][start+2] && board[i+2][start+2] == board[i+3][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}
}

//Clear the screen
//Set for OSX currently - Change the inner system call for Windows or Linux
void clearScreen(){
system("clear");
}

};

//Main function - Nice and small just like I like it!
int main (int argc, char * const argv[]) {
connectFour play;
play.startTurn();

return 0;
}
Topic archived. No new replies allowed.