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

change

parent e4064e30
...@@ -44,6 +44,183 @@ void displayBoard::printBoard() { ...@@ -44,6 +44,183 @@ void displayBoard::printBoard() {
} }
} }
char displayBoard::chipCheck(int x, int y) { char displayBoard::getChip(int x, int y) {
return board[x][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 { class displayBoard {
public: public:
void start(); void start();
// mutators and other
void playerMove1(int x, int y); void playerMove1(int x, int y);
void playerMove2(int x, int y); void playerMove2(int x, int y);
void printBoard(); void printBoard();
char chipCheck(int x, int y); 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: private:
char board[9][9] = {}; char board[8][8] = {};
int x; int x;
int y; int y;
}; };
...@@ -34,7 +34,7 @@ int main() { ...@@ -34,7 +34,7 @@ int main() {
displayBoard board; displayBoard board;
board.start(); board.start();
// loop until finish
do { do {
board.printBoard(); board.printBoard();
cout << "Enter the (X,Y) coordinates of where you would like to place a chip: " ; cout << "Enter the (X,Y) coordinates of where you would like to place a chip: " ;
...@@ -44,13 +44,27 @@ int main() { ...@@ -44,13 +44,27 @@ int main() {
if (turn == 1) { if (turn == 1) {
board.playerMove1(x,y); 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++; turn++;
} else if (turn == 2) { } else if (turn == 2) {
board.playerMove2(x,y); 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--; turn--;
} }
} while (winner == false); } while (winner == false);
return 0; return 0;
} }
\ No newline at end of file
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