Commit ffc256ed authored by Jason Riggs's avatar Jason Riggs

change

parent 9702aeaa
......@@ -62,7 +62,9 @@ void displayBoard::verticalCheck(int x, char chip) {
}
for (int i = firstX; i <= secondX; i++) {
board[x][i] = {chip};
if (board[x][i] == 'X' || board[x][i] == 'O') {
board[x][i] = {chip};
}
}
}
......@@ -86,7 +88,9 @@ void displayBoard::horizontalCheck(int y, char chip) {
}
for (int i = firstY; i <= secondY; i++) {
board[i][y] = {chip};
if (board[i][y] == 'X' || board[i][y] == 'O') {
board[i][y] = {chip};
}
}
}
......@@ -115,7 +119,9 @@ void displayBoard::downleftCheck(int x,int y,char chip) {
int temp = firstX - secondX;
int i = 1;
while (temp > 0) {
board[firstX - i][firstY + i] = {chip};
if (board[firstX - i][firstY + i] == 'X' || board[firstX - i][firstY + i] == 'O') {
board[firstX - i][firstY + i] = {chip};
}
temp --;
i++;
}
......@@ -147,7 +153,9 @@ void displayBoard::upleftCheck(int x, int y, char chip) {
int temp = firstX - secondX;
int i = 1;
while (temp > 0) {
board[firstX - i][firstY - i] = {chip};
if (board[firstX - i][firstY - i] == 'X' || board[firstX - i][firstY - i] == 'O') {
board[firstX - i][firstY - i] = {chip};
}
temp --;
i++;
}
......@@ -179,7 +187,9 @@ void displayBoard::downrightCheck(int x, int y, char chip) {
int temp = secondX - firstX;
int i = 1;
while (temp > 0) {
board[firstX + i][firstY + i] = {chip};
if (board[firstX + i][firstY + i] == 'X' || board[firstX + i][firstY + i] == 'O') {
board[firstX + i][firstY + i] = {chip};
}
temp --;
i++;
}
......@@ -211,13 +221,18 @@ void displayBoard::uprightCheck(int x,int y,char chip) {
int temp = secondX - firstX;
int i = 1;
while (temp > 0) {
board[firstX + i][firstY - i] = {chip};
if (board[firstX + i][firstY - i] == 'X' || board[firstX + i][firstY - i] == 'O') {
board[firstX + i][firstY - i] = {chip};
}
temp --;
i++;
}
}
}
bool displayBoard::isValidAdjacent(int row, int col, char oppTurn) {
if (board[row + 1][col] == oppTurn) {
return true;
......
......@@ -43,7 +43,7 @@ int main() {
cin >> x >> y;
if (turn == 1) {
if(board.isValidAdjacent(x-1,y-1,'O')){
if(board.isValidAdjacent(x-1,y-1,'O') && board.isValidFlip(x-1, y-1, 'X')){
board.playerMove1(x,y);
board.verticalCheck(x, 'X');
board.horizontalCheck(y, 'X');
......@@ -59,7 +59,7 @@ int main() {
}
} else if (turn == 2) {
if(isValidAdjacent(x-1, y-1, 'X')){
if(board.isValidAdjacent(x-1, y-1, 'X') && board.isValidFlip(x-1, y-1, 'O')){
board.playerMove2(x,y);
board.verticalCheck(x, 'O');
board.horizontalCheck(y, 'O');
......
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