Move the board code out to ui as it's only for board visualisation

This commit is contained in:
Marc Di Luzio 2014-12-16 13:12:58 +00:00
parent a17a9db2ad
commit 2abd4ad832
9 changed files with 39 additions and 13 deletions

View file

@ -13,7 +13,6 @@ set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11" )
# Add the sources
set( SOURCES
game.cpp
board.cpp
unitv.cpp
unit.cpp
orders.cpp

View file

@ -1,43 +0,0 @@
#include "board.h"
// ----------------------------------------------
// Default constructor for the board
CBoard::CBoard( unsigned int c, unsigned int r )
: cols ( c )
, rows ( r )
, total ( rows * cols )
{
board.resize(total,square_empty);
}
// constructor
CBoard::CBoard( unsigned int c, unsigned int r, vunitVis_c&& b )
: cols ( c )
, rows ( r )
, total ( rows * cols )
, board ( std::move(b) )
{
board.resize(total,square_empty);
}
// print get a slot on the board
unitVis_c CBoard::get( const unsigned int c, const unsigned int r ) const
{
if ( (r >= rows) || (c >= cols) )
return square_invalid;
return board[r*c];
}
// Get a square on the board
unitVis_c CBoard::set( const unsigned int c, const unsigned int r , const unitVis_c n )
{
if ( (r >= rows) || (c >= cols) )
return square_invalid;
unitVis_c old = board[r*c];
board[r*c] = n;
return old;
}

View file

@ -1,54 +0,0 @@
#ifndef _BOARD_H_
#define _BOARD_H_
#include "basetypes.h"
#include "unit.h"
#include <limits> // std::numeric_limits
#include <vector> // std::vector
typedef std::vector< unitVis_c > vunitVis_c;
// Invalid value for the board square
constexpr unitVis_c square_invalid = std::numeric_limits<unitVis_c>::max();
constexpr unitVis_c square_empty = ' ';
// Class to store simple data about a board
class CBoard
{
public:
const unsigned int cols; // Number of columns
const unsigned int rows; // Number of rows
const unsigned int total; // Total number of pieces
// constructor
CBoard( unsigned int c, unsigned int r );
// constructor
CBoard( unsigned int c, unsigned int r, vunitVis_c&& b );
// Default destructor
~CBoard() = default;
// clear the board
inline void clear() { fill(square_empty); }
// fill the board
inline void fill(unitVis_c v) { std::fill(board.begin(),board.end(),v); };
// Get a square on the board
unitVis_c get( const unsigned int c, const unsigned int r ) const;
// Get the full board
inline const vunitVis_c& get() const { return board; };
// Get a square on the board
unitVis_c set( const unsigned int c, const unsigned int r , const unitVis_c n );
private:
vunitVis_c board; // Board data storage
};
#endif //_BOARD_H_

View file

@ -1,7 +1,7 @@
#ifndef _GAME_H_
#define _GAME_H_
#include "board.h"
#include "unit.h"
#include "gametypes.h"
#include "orders.h"
@ -27,10 +27,16 @@ public:
bool NextTurn();
// Get the number of units
inline unsigned int GetNumUnits() const { return m_orders.size(); }
inline unsigned int GetNumUnits() const { return m_allUnits.size(); }
// Get unit by index as above (not unit ID)
inline const CUnit& GetUnitByIndex( unsigned int i ) const { return *m_orders[i]; }
inline const CUnit& GetUnitByIndex( unsigned int i ) const { return *m_allUnits[i]; }
// Get the number of order
inline unsigned int GetNumOrders() const { return m_orders.size(); }
// Get orders by index as above
inline const COrder& GetOrdersByIndex( unsigned int i ) const { return m_orders[i]; }
private:
@ -39,7 +45,7 @@ private:
// Simulate all actions
bool SimulateActions();
// Vector to store points to all units
sharedUnitVector_t m_allUnits;

View file

@ -10,4 +10,10 @@ typedef unsigned short player_id_t;
// Type for unit IDs
typedef unsigned short unit_id_t;
// Type for the unit type-id
typedef char unitType_c;
// Typedef for unit visual representations
typedef char unitVis_c;
#endif //_GAME_TYPES_H_

View file

@ -7,12 +7,6 @@
#include "gametypes.h"
#include "vector2.h"
// Type for the unit type-id
typedef char unitType_c;
// Typedef for unit visual representations
typedef char unitVis_c;
// Base unit type
class CUnit
{