[HELP in S.O.S game win counts]
Sep 14, 2015 at 12:33pm UTC
Hello, my professor asked us to make an S.O.S game. My only problem is how can I check whether the p1 or p2 made an SOS. Can you give me a hint and also can you give me an advice to make my program more efficient and bug free. My friend told me to make void scorecheck1(int&player1score) and void scorecheck2(int&player2score). But I don't know what to put in that function. here are the codes.
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
#include <iostream>
#include <cstdlib>
#include <windows.h>
#include <cstring>
#include <ctime>
using namespace std;
void game_start();
void start_up();
void game_board();
void scorecheck1(int &player1score);
void scorecheck2(int &player2score);
string player1,player2;
int player1score = 0;
int player2score = 0;
int i, turn1,turn2, j = 0;
int player1choice, player2choice;
string letter;
string board[64];
int main()
{
start_up();
return 0;
}
void start_up()
{
system("color 0B" );
char choice;
cout<<"\t\t ===== ====== =====\t\t\n" ;Sleep(250);
cout<<"\t\t || || || || \t\t\n" ;Sleep(250);
cout<<"\t\t || || || || \t\t\n" ;Sleep(250);
cout<<"\t\t ===== || || =====\t\t\n" ;Sleep(250);
cout<<"\t\t || || || ||\t\t\n" ;Sleep(250);
cout<<"\t\t || || || ||\t\t\n" ;Sleep(250);
cout<<"\t\t ===== ====== ===== \t\t\n" ;Sleep(250);
cout<<"\t\t ====== ====== ====== ===== ===== ====== ====== ======\t\t\n" ;Sleep(250);
cout<<"\t\t || || || || || || || || || ||\t\t\n" ;Sleep(250);
cout<<"\t\t || || || ====== ==> || || ====== ==> ||==== ======\t\t\n" ;Sleep(250);
cout<<"\t\t || || || || || || || || || ||\t\t\n" ;Sleep(250);
cout<<"\t\t ====== ====== ====== ======= ====== ====== ====== ======\t\t\n" ;Sleep(250);
cout<<"\t\tWelcome to the game of S.O.S!\t\t\n\n" ;Sleep(250);
cout<<"\t\tThis game is brought to you BY:\t\t\n" ;Sleep(250);
cout<<"\t\tJasper Adrian S. Escala\t\t\n" ;Sleep(250);
cout<<"\t\tGelo M. Hubalde\t\t\n" ;Sleep(250);
cout<<"\t\tPress any key to continute..\n\n" ;
system("pause>0" );
system("cls" );
cout<<"Press Y if you like to start and N if you want to terminate.\n" ;
cin>>choice;
system ("cls" );
switch (choice)
{
case 'y' :
case 'Y' :
cout<<"Lets begin the Game!!!\n" ;
cout<<"Enter Player 1's name:" ;
cin>>player1;
cout<<"Enter Player 2's name:" ;
cin>>player2;
system("cls" );
game_start();
case 'n' :
case 'N' :
exit(1);
default :
cout<<"Wrong input. The program is terminating ...\n" ;
}
}
void game_board()
{
cout << player1 << " : " << player1score << "\t " << player2 << " : " << player2score << endl;
cout << " +---+---+---+---+---+---+---+---+" << endl;
cout << " | " << board[0] << " | " << board[1] << " | " << board[2] << " | " << board[3] << " | " << board[4] << " | " << board[5] << " | " << board[6] << " | " << board[7] << " |" <<"1-8" << endl;
cout << " +---+---+---+---+---+---+---+---+" << endl;
cout << " | " << board[8] << " | " << board[9] << " | " << board[10] << " | " << board[11] << " | " << board[12] << " | " << board[13] << " | " << board[14] << " | " << board[15] << " |" <<"9-16" << endl;
cout << " +---+---+---+---+---+---+---+---+" << endl;
cout << " | " << board[16] << " | " << board[17] << " | " << board[18] << " | " << board[19] << " | " << board[20] << " | " << board[21] << " | " << board[22] << " | " << board[23] << " |" << "17-24" <<endl;
cout << " +---+---+---+---+---+---+---+---+" << endl;
cout << " | " << board[24] << " | " << board[25] << " | " << board[26] << " | " << board[27] << " | " << board[28] << " | " << board[29] << " | " << board[30] << " | " << board[31] << " |" <<"25-32" << endl;
cout << " +---+---+---+---+---+---+---+---+" << endl;
cout << " | " << board[32] << " | " << board[33] << " | " << board[34] << " | " << board[35] << " | " << board[36] << " | " << board[37] << " | " << board[38] << " | " << board[39] << " |" << "33-40" <<endl;
cout << " +---+---+---+---+---+---+---+---+" << endl;
cout << " | " << board[40] << " | " << board[41] << " | " << board[42] << " | " << board[43] << " | " << board[44] << " | " << board[45] << " | " << board[46] << " | " << board[47] << " |" <<"41-48" << endl;
cout << " +---+---+---+---+---+---+---+---+" << endl;
cout << " | " << board[48] << " | " << board[49] << " | " << board[50] << " | " << board[51] << " | " << board[52] << " | " << board[53] << " | " << board[54] << " | " << board[55] << " |" <<"49-56" << endl;
cout << " +---+---+---+---+---+---+---+---+" << endl;
cout << " | " << board[56] << " | " << board[57] << " | " << board[58] << " | " << board[59] << " | " << board[60] << " | " << board[61] << " | " << board[62] << " | " << board[63] << " |" <<"57-64" << endl;
cout << " +---+---+---+---+---+---+---+---+" << endl;
}
void game_start()
{
int i, turn1, turn2, j = 0;
for (i = 0;i<65;i++)
{
turn1 = i;
}
if (turn1 = i)
{
game_board();
cout<<player1<<" 's turn\n" ;
cout<<"Enter your move. Look at the guide block numbers at the board.\n" ;
cin>>player1choice;
while (!(cin>>player1choice))
{
cout<<"Numbers only.\n" ;
}
cout<<"Enter S or O. (NOTE: Use capital letters ONLY!)\n" ;
cin>>letter;
if (letter == "S" || letter == "O" )
{
board[player1choice-1]=letter;
scorecheck1(player1score);
system("cls" );
}
else
{
cout<<"Invalid input!\n" ;
system("pause" );
system("cls" );
}
}
turn2 = j;
if (turn2 != i)
{
game_board();
cout<<player2<<" 's turn\n" ;
cout<<"Enter your move. Look at the guide block numbers at the board.\n" ;
while (!(cin>>player2choice))
{
cout<<"Numbers only.\n" ;
}
cout<<"Enter S or O. (NOTE: Use capital letters ONLY!)\n" ;
cin>>letter;
if (letter == "S" || letter == "O" )
{
board[player2choice-1]=letter;
scorecheck2(player2score);
system("cls" );
}
else
{
cout<<"Invalid input!\n" ;
system("pause" );
system("cls" );
}
}
}
Topic archived. No new replies allowed.