Commit 65cc3870 authored by Jason Riggs's avatar Jason Riggs
Browse files

change

parent e4064e30
......@@ -44,6 +44,183 @@ void displayBoard::printBoard() {
}
}
char displayBoard::chipCheck(int x, int y) {
return board[x][y];
}
\ No newline at end of file
char displayBoard::getChip(int x, int y) {
return board[x-1][y-1];
}
void displayBoard::verticalCheck(int x, char chip) {
int firstX = 0;
int secondX = 0;
x -= 1;
for (int i = firstX; i < 8; i++) {
if (board[x][i] == chip) {
firstX = i;
break;
}
}
for (int i = 7; i > firstX; i--) {
if (board[x][i] == chip) {
secondX = i;
break;
}
}
for (int i = firstX; i <= secondX; i++) {
board[x][i] = {chip};
}
}
void displayBoard::horizontalCheck(int y, char chip) {
int firstY = 0;
int secondY = 0;
y -= 1;
for (int i = firstY; i < 8; i++) {
if (board[i][y] == chip) {
firstY = i;
break;
}
}
for (int i = 7; i > firstY; i--) {
if (board[i][y] == chip) {
secondY = i;
break;
}
}
for (int i = firstY; i <= secondY; i++) {
board[i][y] = {chip};
}
}
void displayBoard::downleftCheck(int x,int y,char chip) {
x -= 1;
y -= 1;
int firstX = x;
int firstY = y;
int secondX;
int secondY;
bool addChip = false;
for (int i = 1; i < 8; i++) {
if (board[firstX - i][firstY + i] == chip) {
secondX = firstX - i;
secondY = firstY + i;
if (secondX < 8 && secondY < 8) {
addChip = true;
}
break;
}
}
if (addChip == true) {
int temp = firstX - secondX;
int i = 1;
while (temp > 0) {
board[firstX - i][firstY + i] = {chip};
temp --;
i++;
}
}
}
void displayBoard::upleftCheck(int x, int y, char chip) {
x -= 1;
y -= 1;
int firstX = x;
int firstY = y;
int secondX;
int secondY;
bool addChip = false;
for (int i = 1; i < 8; i++) {
if (board[firstX - i][firstY - i] == chip) {
secondX = firstX - i;
secondY = firstY - i;
if (secondX < 8 && secondY < 8) {
addChip = true;
}
break;
}
}
if (addChip == true) {
int temp = firstX - secondX;
int i = 1;
while (temp > 0) {
board[firstX - i][firstY - i] = {chip};
temp --;
i++;
}
}
}
void displayBoard::downrightCheck(int x, int y, char chip) {
x -= 1;
y -= 1;
int firstX = x;
int firstY = y;
int secondX;
int secondY;
bool addChip = false;
for (int i = 1; i < 8; i++) {
if (board[firstX + i][firstY + i] == chip) {
secondX = firstX + i;
secondY = firstY + i;
if (secondX < 8 && secondY < 8) {
addChip = true;
}
break;
}
}
if (addChip == true) {
int temp = secondX - firstX;
int i = 1;
while (temp > 0) {
board[firstX + i][firstY + i] = {chip};
temp --;
i++;
}
}
}
void displayBoard::uprightCheck(int x,int y,char chip) {
x -= 1;
y -= 1;
int firstX = x;
int firstY = y;
int secondX;
int secondY;
bool addChip = false;
for (int i = 1; i < 8; i++) {
if (board[firstX + i][firstY - i] == chip) {
secondX = firstX + i;
secondY = firstY - i;
if (secondX < 8 && secondY < 8) {
addChip = true;
}
break;
}
}
if (addChip == true) {
int temp = secondX - firstX;
int i = 1;
while (temp > 0) {
board[firstX + i][firstY - i] = {chip};
temp --;
i++;
}
}
}
#include <iostream>
#include <vector>
using namespace std;
class displayBoard {
public:
void start();
// mutators and other
void playerMove1(int x, int y);
void playerMove2(int x, int y);
void printBoard();
char chipCheck(int x, int y);
private:
char board[9][9] = {};
int x;
int y;
};
\ No newline at end of file
public:
void start();
void playerMove1(int x, int y);
void playerMove2(int x, int y);
void printBoard();
char getChip(int x, int y);
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);
private:
char board[8][8] = {};
int x;
int y;
};
......@@ -34,7 +34,7 @@ int main() {
displayBoard board;
board.start();
// loop until finish
do {
board.printBoard();
cout << "Enter the (X,Y) coordinates of where you would like to place a chip: " ;
......@@ -44,12 +44,26 @@ int main() {
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++;
} 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--;
}
} while (winner == false);
return 0;
......
Supports Markdown
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