File indexing completed on 2024-11-24 03:43:17
0001 /******************************************************************* 0002 * 0003 * Copyright 2007 Aron Boström <c02ab@efd.lth.se> 0004 * 0005 * Bovo is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation; either version 2, or (at your option) 0008 * any later version. 0009 * 0010 * Bovo is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with Bovo; see the file COPYING. If not, write to 0017 * the Free Software Foundation, 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 * 0020 ********************************************************************/ 0021 0022 #include "board.h" 0023 0024 #include "coord.h" 0025 #include "dimension.h" 0026 #include "move.h" 0027 #include "square.h" 0028 0029 /** 0030 * @file file implementing class Board, 0031 * which is really not a Board but an entire game. 0032 */ 0033 0034 /** namespace for game engine */ 0035 namespace bovo { 0036 0037 Board::Board(const Dimension& dimension) { 0038 m_dimension = new Dimension(dimension.width(), dimension.height()); 0039 m_board = new Square*[m_dimension->width()]; 0040 for (int x = 0; x < m_dimension->width(); ++x) { 0041 m_board[x] = new Square[m_dimension->height()]; 0042 } 0043 } 0044 0045 Board::~Board() { 0046 for (int x = 0; x < m_dimension->width(); ++x) { 0047 delete[] m_board[x]; 0048 } 0049 delete[] m_board; 0050 delete m_dimension; 0051 } 0052 0053 bool Board::empty(const Coord& coord) const { 0054 if (!ok(coord)) { 0055 return false; 0056 } 0057 return m_board[coord.x()][coord.y()].empty(); 0058 } 0059 0060 bool Board::ok(const Coord& coord) const { 0061 return m_dimension->ok(coord); 0062 } 0063 0064 Player Board::player(const Coord& c) const { 0065 if (!ok(c)) { 0066 return No; 0067 } 0068 return m_board[c.x()][c.y()].player(); 0069 } 0070 0071 void Board::setPlayer(const Move& move) { 0072 if (!ok(move.coord())) { 0073 return; 0074 } 0075 m_board[move.x()][move.y()].setPlayer(move.player()); 0076 } 0077 0078 } /* namespace bovo */