Hey there.
I have to submit an assignmnent today of an sos game in c++,i have made a code but i donot know how to add a function to count score of each player.any help will be greatly appreciated.
@Zibago and other programmers
here is the code;
#include <iostream>
using namespace std;
int currentPlayer = 0; // 0-> player 1. 1->player 2
int score[2]; // indexed by currentPlayer
char board[8][8] = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
};
void gameboard();
void getmove(int &row, int &col);
void gather_all();
void win1();
void
gameboard()
{
system("cls");
cout << "player1: " << score[0] << "\t" << "player2: " << score[1] << endl;
cout << "+===+===+===+===+===+===+===+===+" << endl;
for (int i = 0; i < 8; i++) {
cout << "! ";
for (int j = 0; j < 8; j++)
cout << board
[j] << " ! ";
cout << endl << "+===+===+===+===+===+===+===+===+" << endl;
}
}
// Get a move from the current player. Set the value in the board and return the row/column
// that they set.
void
getmove(int &row, int &col)
{
char letter;
while (true) {
if (currentPlayer == 0) {
cout << "Player 1 enter the row and column (NUMBERS ONLY!): ";
} else {
cout << "Player 2 enter the row and column (NUMBERS ONLY!): ";
}
if (!(cin >> row >> col)) {
cout << "I SAID NUMBERS ONLY!!!!\n";
cin.clear();
cin.ignore(1000, '\n');
continue; // go back to the start of the loop
}
row--; // immediately convert from 1-8 to 0-7
col--;
// Is the number valid?
if (row < 0 || col < 0 || row > 7 || col > 7) {
cout << "Row and column numbers must be 1-8\n";
continue;
}
if (board[row][col] != ' ') {
cout << "That square is already taken\n";
continue;
}
break; // success
}
// Get the value for the square
while (true) {
cout << "Enter S or O(USE CAPITALS ONLY!): ";
cin >> letter;
if (letter == 'S' || letter == 'O') {
break;
} else {
cout << "I SAID CAPITALS ONLY!!!!. ALSO USE S OR O.";
system("pause");
system("cls");
}
}
board[row][col] = letter;
}
void
win1()
{
}
int
main()
{
int row, col;
while (1) {
gameboard();
getmove(row, col);
currentPlayer = !currentPlayer; // switch players
}
return 0;
}