Commit 9702aeaa authored by Jason Riggs's avatar Jason Riggs

change

parent ad8b15bd
......@@ -12,19 +12,13 @@ void displayBoard::start() {
}
void displayBoard::playerMove1(int x, int y) {
if (x > 8 || x < 0 || y > 8 || y < 0) {
cout << endl << "Invalid (X,Y) coordinates." << endl << endl;
} else {
board[x-1][y-1] = {'X'};
}
board[x-1][y-1] = {'X'};
}
void displayBoard::playerMove2(int x, int y) {
if (x > 8 || x < 0 || y > 8 || y < 0) {
cout << endl << "Invalid (X,Y) coordinates." << endl << endl;
} else {
board[x-1][y-1] = {'O'};
}
}
void displayBoard::printBoard() {
......@@ -224,3 +218,60 @@ void displayBoard::uprightCheck(int x,int y,char chip) {
}
}
bool displayBoard::isValidAdjacent(int row, int col, char oppTurn) {
if (board[row + 1][col] == oppTurn) {
return true;
}
else if (board[row - 1][col] == oppTurn) {
return true;
}
else if (board[row][col + 1] == oppTurn) {
return true;
}
else if (board[row][col - 1] == oppTurn) {
return true;
}
else if (board[row - 1][col - 1] == oppTurn) {
return true;
}
else if (board[row - 1][col + 1] == oppTurn) {
return true;
}
else if (board[row + 1][col - 1] == oppTurn) {
return true;
}
else if (board[row + 1][col + 1] == oppTurn) {
return true;
}
return false;
}
bool displayBoard::isValidFlip(int row, int col, char playerTurn) {
for (int i = 2; i < 8; i++) {
if (board[row][col + i] == playerTurn) {
return true;
}
else if (board[row][col - i] == playerTurn) {
return true;
}
else if (board[row + i][col] == playerTurn) {
return true;
}
else if (board[row - i][col] == playerTurn) {
return true;
}
else if (board[row + i][col + i] == playerTurn) {
return true;
}
else if (board[row + i][col - i] == playerTurn) {
return true;
}
else if (board[row - i][col + i] == playerTurn) {
return true;
}
else if (board[row - i][col - i] == playerTurn) {
return true;
}
}
return false;
}
\ No newline at end of file
......@@ -12,12 +12,17 @@ class displayBoard {
void playerMove2(int x, int y);
void printBoard();
char getChip(int x, int y);
// Checks to flip peices
void verticalCheck(int x, char chip);
void horizontalCheck(int y, char chip);
void upleftCheck(int x, int y, char chip);
void downleftCheck(int x, int y, char chip);
void uprightCheck(int x, int y, char chip);
void downrightCheck(int x, int y, char chip);
// Player movement error checking
bool isValidAdjacent(int row, int col, char oppTurn);
bool isValidFlip(int row, int col, char playerTurn);
private:
char board[8][8] = {};
int x;
......
......@@ -43,23 +43,36 @@ int main() {
cin >> x >> y;
if (turn == 1) {
board.playerMove1(x,y);
board.verticalCheck(x, 'X');
board.horizontalCheck(y, 'X');
board.uprightCheck(x,y,'X');
board.upleftCheck(x,y,'X');
board.downrightCheck(x,y,'X');
board.downleftCheck(x,y,'X');
turn++;
if(board.isValidAdjacent(x-1,y-1,'O')){
board.playerMove1(x,y);
board.verticalCheck(x, 'X');
board.horizontalCheck(y, 'X');
board.uprightCheck(x,y,'X');
board.upleftCheck(x,y,'X');
board.downrightCheck(x,y,'X');
board.downleftCheck(x,y,'X');
turn++;
}else{
cout << "Invalid Move!"<<endl;
}
} else if (turn == 2) {
board.playerMove2(x,y);
board.verticalCheck(x, 'O');
board.horizontalCheck(y, 'O');
board.uprightCheck(x,y,'O');
board.upleftCheck(x,y,'O');
board.downrightCheck(x,y,'O');
board.downleftCheck(x,y,'O');
turn--;
if(isValidAdjacent(x-1, y-1, 'X')){
board.playerMove2(x,y);
board.verticalCheck(x, 'O');
board.horizontalCheck(y, 'O');
board.uprightCheck(x,y,'O');
board.upleftCheck(x,y,'O');
board.downrightCheck(x,y,'O');
board.downleftCheck(x,y,'O');
turn--;
}else{
cout << "Invalid Move!"<<endl;
}
}
} while (winner == false);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment