diff options
Diffstat (limited to 'GameField.cpp')
-rw-r--r-- | GameField.cpp | 34 |
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; } |