summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-02-19 18:49:55 +0000
committerJoursoir <chat@joursoir.net>2021-02-19 18:49:55 +0000
commit0f2504aaa684d53bb30a6d3c152e35f9dfe6e47e (patch)
treeee3163ae1ec48b626a63eed50025c7de63196bc0
parentf8ef01b479ffac6e4432970ca4c471635dc2b120 (diff)
downloadlp-gomoku-0f2504aaa684d53bb30a6d3c152e35f9dfe6e47e.tar.gz
lp-gomoku-0f2504aaa684d53bb30a6d3c152e35f9dfe6e47e.tar.bz2
lp-gomoku-0f2504aaa684d53bb30a6d3c152e35f9dfe6e47e.zip
fix rows and cols typos
-rw-r--r--GameField.cpp48
-rw-r--r--GameField.hpp5
-rw-r--r--clui.cpp35
3 files changed, 45 insertions, 43 deletions
diff --git a/GameField.cpp b/GameField.cpp
index 18a3470..5340d7a 100644
--- a/GameField.cpp
+++ b/GameField.cpp
@@ -1,35 +1,35 @@
#include "GameField.hpp"
-GameField::GameField(int a_cols, int a_rows, int a_lwin)
- : cols(a_cols), rows(a_rows), win_length(a_lwin), state(G_NONE),
+GameField::GameField(int a_rows, int a_cols, int a_lwin)
+ : rows(a_rows), cols(a_cols), win_length(a_lwin), state(G_NONE),
who_move(G_XPLAYER)
{
- int c, r;
- field = new int*[cols];
- for(c = 0; c < cols; c++) {
- field[c] = new int[rows];
- for(r = 0; r < rows; r++) {
- field[c][r] = G_EMPTY;
+ int r, c;
+ field = new int*[rows];
+ for(r = 0; r < rows; r++) {
+ field[r] = new int[cols];
+ for(c = 0; c < cols; c++) {
+ field[r][c] = G_EMPTY;
}
}
- free_fields = cols * rows;
+ free_fields = rows * cols;
}
GameField::GameField(const GameField& a)
{
- int c, r;
- cols = a.cols;
+ int r, c;
rows = a.rows;
+ cols = a.cols;
free_fields = a.free_fields;
win_length = a.win_length;
state = a.state;
who_move = a.who_move;
- field = new int*[cols];
- for(c = 0; c < cols; c++) {
- field[c] = new int[rows];
- for(r = 0; r < rows; r++) {
- field[c][r] = a.field[c][r];
+ field = new int*[rows];
+ for(r = 0; r < rows; r++) {
+ field[r] = new int[cols];
+ for(c = 0; c < cols; c++) {
+ field[r][c] = a.field[r][c];
}
}
}
@@ -37,9 +37,9 @@ GameField::GameField(const GameField& a)
GameField::~GameField()
{
if(field) {
- int c;
- for(c = 0; c < cols; c++) {
- delete[] field[c];
+ int r;
+ for(r = 0; r < rows; r++) {
+ delete[] field[r];
}
delete[] field;
}
@@ -100,7 +100,7 @@ int GameField::ScanRowsAround(int y, int x)
}
// ray to right
- for(i = x, n -= 1; i < rows; i++) {
+ for(i = x, n -= 1; i < cols; i++) {
if(player == field[y][i]) {
n++;
if(n == win_length)
@@ -127,7 +127,7 @@ int GameField::ScanColsAround(int y, int x)
}
// ray to down
- for(i = y, n -= 1; i < cols; i++) {
+ for(i = y, n -= 1; i < rows; i++) {
if(player == field[i][x]) {
n++;
if(n == win_length)
@@ -154,7 +154,7 @@ int GameField::ScanDiagsAround(int y, int x)
}
// ray to right down corner
- for(i = x, j = y, n -= 1; i < rows && j < cols; i++, j++) {
+ for(i = x, j = y, n -= 1; i < cols && j < rows; i++, j++) {
if(player == field[j][i]) {
n++;
if(n == win_length)
@@ -166,7 +166,7 @@ int GameField::ScanDiagsAround(int y, int x)
/* change the diagonal */
// ray to right up corner
- for(i = x, j = y, n = 0; i < rows && j >= 0; i++, j--) {
+ for(i = x, j = y, n = 0; i < cols && j >= 0; i++, j--) {
if(player == field[j][i]) {
n++;
if(n == win_length)
@@ -176,7 +176,7 @@ int GameField::ScanDiagsAround(int y, int x)
}
// ray to left down cornet
- for(i = x, j = y, n -= 1; i >= 0 && j < cols; i--, j++) {
+ for(i = x, j = y, n -= 1; i >= 0 && j < rows; i--, j++) {
if(player == field[j][i]) {
n++;
if(n == win_length)
diff --git a/GameField.hpp b/GameField.hpp
index de5ccd1..00a2764 100644
--- a/GameField.hpp
+++ b/GameField.hpp
@@ -12,7 +12,7 @@ enum states {
class GameField {
// optional:
int **field;
- int cols, rows;
+ int rows, cols;
int free_fields;
int win_length;
@@ -24,8 +24,9 @@ public:
GameField(const GameField &a);
~GameField();
int GetState() { return state; }
- int GetCols() { return cols; }
int GetRows() { return rows; }
+ int GetCols() { return cols; }
+ int GetWhoMove() { return who_move; }
bool CanMove(int y, int x);
void Move(int y, int x);
diff --git a/clui.cpp b/clui.cpp
index 2816a52..0f43161 100644
--- a/clui.cpp
+++ b/clui.cpp
@@ -19,7 +19,7 @@ enum keys {
};
/* clui vars */
-int screen_cols = 0, screen_rows = 0;
+int screen_rows = 0, screen_cols = 0;
int min_y, max_y, min_x, max_x;
/* game vars */
@@ -56,53 +56,53 @@ void help_print(const char *msg, ...)
va_list args;
va_start(args, msg);
- char *str = new char[screen_rows+1];
+ char *str = new char[screen_cols+1];
vsprintf(str, msg, args);
va_end(args);
- mvprintw(max_y + 2, (screen_rows - strlen(str)) / 2, str);
+ mvprintw(max_y + 2, (screen_cols - strlen(str)) / 2, str);
updateCursor();
delete[] str;
}
-void drawGame(int cols, int rows, int symbol)
+void drawGame(int rows, int cols)
{
- getmaxyx(stdscr, screen_cols, screen_rows);
+ getmaxyx(stdscr, screen_rows, screen_cols);
- int len_col = cols * NC_MOVE_Y - 1;
- min_y = (screen_cols - len_col) / 2;
- max_y = min_y + len_col - 1;
+ int used_row = rows * NC_MOVE_Y - 1;
+ min_y = (screen_rows - used_row) / 2;
+ max_y = min_y + used_row - 1;
- int len_row = rows * NC_MOVE_X - 1;
- min_x = (screen_rows - len_row) / 2;
- max_x = min_x + len_row - 1;
+ int used_col = cols * NC_MOVE_X - 1;
+ min_x = (screen_cols - used_col) / 2;
+ max_x = min_x + used_col - 1;
int i, j, d;
for(j = min_y, d = 0; j <= max_y; j++, d++) {
move(j, min_x);
if(d % 2 == 0) {
addch('#');
- for(i = 1; i < rows; i++) {
+ for(i = 1; i < cols; i++) {
addch('|');
addch('#');
}
}
else {
addch('-');
- for(i = 1; i < rows; i++) {
+ for(i = 1; i < cols; i++) {
addch('|');
addch('-');
}
}
}
- mvprintw(min_y - 3, (screen_rows - strlen(app_name)) / 2, app_name);
- mvprintw(min_y - 2, (screen_rows - strlen(app_tips)) / 2, app_tips);
+ mvprintw(min_y - 3, (screen_cols - strlen(app_name)) / 2, app_name);
+ mvprintw(min_y - 2, (screen_cols - strlen(app_tips)) / 2, app_tips);
help_print("MOVE: %c", SYMBOL_PLAYERONE);
cursor_y = min_y; // + (max_y - min_y) / NC_MOVE_Y;
cursor_x = min_x; // + (max_x - min_x) / NC_MOVE_X;
- player_symbol = symbol;
+ print_symbol = SYMBOL_PLAYERONE;
updateCursor();
}
@@ -180,7 +180,7 @@ void handleButtons()
}
case key_restart: {
delete game_field;
- drawGame(gb_y, gb_x, gb_symbol);
+ drawGame(gb_y, gb_x);
game_field = new GameField(gb_y, gb_x, gb_lwin);
// no break
}
@@ -203,6 +203,7 @@ int main(int argc, char *argv[])
game_field = new GameField(gb_y, gb_x, gb_lwin);
drawGame(gb_y, gb_x, gb_symbol);
+ drawGame(gb_y, gb_x);
handleButtons();
if(game_field)