Я пытаюсь закончить программу для игры Connect Four. Единственными двумя оставшимися методами являются «Uphill Win ()» и «Hower The Win ()». Метод «Uphill win ()» направлен на определение того, основан ли диагональ в гору 4-дюймовый й-кадре на «задержках» движении и игроке (x или 0).
Метод 'Downhillwin ()' Целью определить, есть ли диагональ спуска 4-дюйма.
Не могли бы вы помочь мне с этими двумя методами? < /p>
Код: < /p>
#include
#include
using namespace std;
const int ROWS = 6;
const int COLS = 7;
class ConnectFour {
private:
char cells[ROWS][COLS]; //a ROWS x COLS board of one of three characters ('X', 'O', ' '). Initialize all ' '
int movesLeft[COLS]; //an array containing the number of spaces left (or available) in each column. Initialize all 6
int lastPlayed; //records the last column that was played 0, 1, 2, 3, 4, 5, 6. Initialize -1
bool tiedGame; //records true if the board is full and no winner is found, otherwise false. Initialize false
bool horizontalWin(); //returns true if there is at least a horizontal 4-in-a-row. Hint: use cells and lastPlayed
bool verticalWin(); //returns true if there is at least a vertical 4-in-a-row. Hint: use cells and lastPlayed
bool uphillWin(); //returns true if there is at least a diagonal uphill 4-in-a-row. Hint: use cells and lastPlayed
bool downhillWin(); //returns true if there is at least a diagonal downhill 4-in-a-row. Hint: use cells and lastPlayed
public:
ConnectFour(); //initializes the attributes of the game;
void drawBoard(); //prints the gameboard with updated moves;
bool gameOver(); //return true if there is a four in row or a fullboard, if there is a full board, set tiedGame to true
bool isTiedGame(); //returns tiedGame
bool validMove(int j); //input: an attempt to play on column j; output: returns true if that play is valid
void play(int j, char c); //input: a valid play of c ('X' or 'O') in column j. update cells, lastPlayed, and movesLeft
};
//initializes the attributes of the game; prints boardgame
ConnectFour::ConnectFour() {
lastPlayed = -1;
tiedGame = false;
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
cells[j] = ' ';
}
}
for (int j = 0; j < COLS; j++) {
movesLeft[j] = ROWS; //
}
}
//prints the gameboard with updated moves;
void ConnectFour::drawBoard() {
cout
Подробнее здесь: https://stackoverflow.com/questions/794 ... -four-game
Подключить четыре игры [закрыто] ⇐ C++
Программы на C++. Форум разработчиков
1739985026
Anonymous
Я пытаюсь закончить программу для игры Connect Four. Единственными двумя оставшимися методами являются «Uphill Win ()» и «Hower The Win ()». Метод «Uphill win ()» направлен на определение того, основан ли диагональ в гору 4-дюймовый й-кадре на «задержках» движении и игроке (x или 0).
Метод 'Downhillwin ()' Целью определить, есть ли диагональ спуска 4-дюйма.
Не могли бы вы помочь мне с этими двумя методами? < /p>
Код: < /p>
#include
#include
using namespace std;
const int ROWS = 6;
const int COLS = 7;
class ConnectFour {
private:
char cells[ROWS][COLS]; //a ROWS x COLS board of one of three characters ('X', 'O', ' '). Initialize all ' '
int movesLeft[COLS]; //an array containing the number of spaces left (or available) in each column. Initialize all 6
int lastPlayed; //records the last column that was played 0, 1, 2, 3, 4, 5, 6. Initialize -1
bool tiedGame; //records true if the board is full and no winner is found, otherwise false. Initialize false
bool horizontalWin(); //returns true if there is at least a horizontal 4-in-a-row. Hint: use cells and lastPlayed
bool verticalWin(); //returns true if there is at least a vertical 4-in-a-row. Hint: use cells and lastPlayed
bool uphillWin(); //returns true if there is at least a diagonal uphill 4-in-a-row. Hint: use cells and lastPlayed
bool downhillWin(); //returns true if there is at least a diagonal downhill 4-in-a-row. Hint: use cells and lastPlayed
public:
ConnectFour(); //initializes the attributes of the game;
void drawBoard(); //prints the gameboard with updated moves;
bool gameOver(); //return true if there is a four in row or a fullboard, if there is a full board, set tiedGame to true
bool isTiedGame(); //returns tiedGame
bool validMove(int j); //input: an attempt to play on column j; output: returns true if that play is valid
void play(int j, char c); //input: a valid play of c ('X' or 'O') in column j. update cells, lastPlayed, and movesLeft
};
//initializes the attributes of the game; prints boardgame
ConnectFour::ConnectFour() {
lastPlayed = -1;
tiedGame = false;
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
cells[i][j] = ' ';
}
}
for (int j = 0; j < COLS; j++) {
movesLeft[j] = ROWS; //
}
}
//prints the gameboard with updated moves;
void ConnectFour::drawBoard() {
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79452218/connect-four-game[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия