summaryrefslogtreecommitdiffstats
path: root/GameField.cpp
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-02-17 19:02:29 +0000
committerJoursoir <chat@joursoir.net>2021-02-17 19:02:29 +0000
commit00fe0c43e7080a8d8af2566196a8540eee553ad2 (patch)
tree3e9c6af4a3af6cd68e89add8af09ef5fc832de0a /GameField.cpp
parent87d7320f84926c4d10734c773ecf3cf4eb47ddc4 (diff)
downloadlp-gomoku-00fe0c43e7080a8d8af2566196a8540eee553ad2.tar.gz
lp-gomoku-00fe0c43e7080a8d8af2566196a8540eee553ad2.tar.bz2
lp-gomoku-00fe0c43e7080a8d8af2566196a8540eee553ad2.zip
add command line user interface (clui); improve GameField class
Diffstat (limited to 'GameField.cpp')
-rw-r--r--GameField.cpp34
1 files changed, 30 insertions, 4 deletions
diff --git a/GameField.cpp b/GameField.cpp
index 381275e..51c0347 100644
--- a/GameField.cpp
+++ b/GameField.cpp
@@ -1,17 +1,43 @@
#include "GameField.hpp"
-bool GameField::CanMove(int x, int y)
+GameField::GameField(int a_cols, int a_rows, int a_lwin)
+ : cols(a_cols), rows(a_rows), 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;
+ }
+ }
+ free_fields = cols * rows;
+}
+
+GameField::~GameField()
+{
+ if(field) {
+ int c;
+ for(c = 0; c < cols; c++) {
+ delete[] field[c];
+ }
+ delete[] field;
+ }
+}
+
+bool GameField::CanMove(int y, int x)
{
if(field[y][x] != G_EMPTY)
return false;
return true;
}
-void GameField::Move(int x, int y)
+void GameField::Move(int y, int x)
{
field[y][x] = who_move;
who_move = -who_move; // change player
- free--;
+ free_fields--;
UpdateState();
}
@@ -20,7 +46,7 @@ void GameField::UpdateState()
{
int tmp;
- if(!free) {
+ if(!free_fields) {
state = G_DRAW;
return;
}