diff options
Diffstat (limited to 'GameField.cpp')
-rw-r--r-- | GameField.cpp | 48 |
1 files changed, 24 insertions, 24 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) |