diff --git a/game/board.cpp b/game/board.cpp index 54b4a95..35f62ad 100644 --- a/game/board.cpp +++ b/game/board.cpp @@ -1,7 +1,5 @@ #include "board.h" -#include // std::cout - // ---------------------------------------------- // Default constructor for the board @@ -10,29 +8,22 @@ CBoard::CBoard( unsigned int c, unsigned int r ) , rows ( r ) , total ( rows * cols ) { - board = new square_t[total]; - fill(square_invalid); + board.resize(total,square_empty); } -CBoard::~CBoard() -{ - delete[] board; -} -// Clear the board -void CBoard::clear() +// constructor +CBoard::CBoard( unsigned int c, unsigned int r, vunit_t&& b ) +: cols ( c ) +, rows ( r ) +, total ( rows * cols ) +, board ( std::move(b) ) { - fill(square_empty); -} - -// Fill the board -void CBoard::fill(square_t v) -{ - std::fill(board,board+total,v); + board.resize(total,square_empty); } // print get a slot on the board -square_t CBoard::get( unsigned int c, unsigned int r ) const +unit_t CBoard::get( const unsigned int c, const unsigned int r ) const { if ( (r >= rows) || (c >= cols) ) return square_invalid; @@ -40,29 +31,13 @@ square_t CBoard::get( unsigned int c, unsigned int r ) const return board[r*c]; } -// print a board -void CBoard::debug_print() const +// Get a square on the board +unit_t CBoard::set( const unsigned int c, const unsigned int r , const unit_t n ) { - for ( unsigned int r = 0; r < rows; r++ ) - { - for ( unsigned int c = 0; c < cols; c++ ) - { - std::cout<<(char)board[r*c]; - } - std::cout<= rows) || (c >= cols) ) + return square_invalid; -// Test the board data class -void tests::test_CBoard() -{ - CBoard board = CBoard(20,10); - - std::cout<<"Blank board"< // std::numeric_limits +#include // std::vector + +typedef std::vector< unit_t > vunit_t; + +// Invalid value for the board square +constexpr unit_t square_invalid = std::numeric_limits::max(); +constexpr unit_t square_empty = 32; // 32 is ascii empty // Class to store simple data about a board class CBoard { public: - // Invalid value for the board square - static const square_t square_invalid = std::numeric_limits::max(); - static const square_t square_empty = 32; // 32 is ascii empty - - // Default constructor - CBoard( unsigned int c, unsigned int r ); - ~CBoard(); - - // Print the board - void debug_print() const; - - // clear the board - void clear(); - - // fill the board - void fill(square_t v); - - // Get a square on the board - square_t get( unsigned int c, unsigned int r ) const; - -private: - const unsigned int cols; // Number of columns const unsigned int rows; // Number of rows const unsigned int total; // Total number of pieces - square_t* board; // Board data storage + // constructor + CBoard( unsigned int c, unsigned int r ); + + // constructor + CBoard( unsigned int c, unsigned int r, vunit_t&& b ); + + // Default destructor + ~CBoard() = default; + + // clear the board + inline void clear() { fill(square_empty); } + + // fill the board + inline void fill(unit_t v) { std::fill(board.begin(),board.end(),v); }; + + // Get a square on the board + unit_t get( const unsigned int c, const unsigned int r ) const; + + // Get the full board + inline const vunit_t& get() const { return board; }; + + // Get a square on the board + unit_t set( const unsigned int c, const unsigned int r , const unit_t n ); + +private: + + vunit_t board; // Board data storage }; -// Namespace for testing functions -namespace tests -{ - void test_CBoard(); -}; - #endif //_BOARD_H_ \ No newline at end of file diff --git a/game/game.h b/game/game.h index fd6dbf3..8a4e184 100644 --- a/game/game.h +++ b/game/game.h @@ -1,4 +1,17 @@ #ifndef _GAME_H_ #define _GAME_H_ +#include "board.h" + +class CTTRTSGame +{ +public: + + CTTRTSGame(); + ~CTTRTSGame() = default; + +private: + +}; + #endif //_GAME_H_ \ No newline at end of file diff --git a/game/unit.h b/game/unit.h new file mode 100644 index 0000000..dca188d --- /dev/null +++ b/game/unit.h @@ -0,0 +1,26 @@ +#ifndef _UNIT_H_ +#define _UNIT_H_ + +#include + +#include "vector2.h" + +// Type for the unit type-id +typedef char unit_t; + +// Base unit type +template < unit_t unit_type > +class CUnit +{ +public: + + CUnit() = default; + virtual ~CUnit() = default; + +private: + + // All units must have position + uvector2 pos; +}; + +#endif //_UNIT_H_ \ No newline at end of file diff --git a/game/unitv.cpp b/game/unitv.cpp new file mode 100644 index 0000000..0a84da0 --- /dev/null +++ b/game/unitv.cpp @@ -0,0 +1,15 @@ +#include "unitv.h" + +// V unit +class CUnitV +: public CUnit<'V'> +{ +public: + CUnitV() = default; + virtual ~CUnitV() = default; + +private: + + // V also has a direction + char dir; +}; \ No newline at end of file diff --git a/game/unitv.h b/game/unitv.h new file mode 100644 index 0000000..65e3607 --- /dev/null +++ b/game/unitv.h @@ -0,0 +1,20 @@ +#ifndef _UNITV_H_ +#define _UNITV_H_ + +// V unit +class CUnitV +: public CUnit<'V'> +{ +public: + CUnitV() = default; + virtual ~CUnitV() = default; + + virtual std::string&& getDescriptor(); + +private: + + // V also has a direction + char dir; +}; + +#endif \ No newline at end of file diff --git a/maths/basetypes.h b/maths/basetypes.h index bacfeb1..004400b 100644 --- a/maths/basetypes.h +++ b/maths/basetypes.h @@ -1,7 +1,7 @@ #ifndef _BASETYPES_H_ #define _BASETYPES_H_ -// Type for the board square -typedef short square_t; +typedef short coord_t; +typedef unsigned short ucoord_t; #endif //_BASETYPES_H_ \ No newline at end of file diff --git a/maths/vector2.h b/maths/vector2.h index d375fee..446a68d 100644 --- a/maths/vector2.h +++ b/maths/vector2.h @@ -5,8 +5,14 @@ struct vector2 { - square_t x; - square_t y; + coord_t x; + coord_t y; +}; + +struct uvector2 +{ + ucoord_t x; + ucoord_t y; }; #endif //_VECTOR2_H_ \ No newline at end of file diff --git a/test/test.cpp b/test/test.cpp index e7b2a28..85142e8 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,5 +1,43 @@ #include "board.h" +#include // std::cout + + +// Namespace for testing functions +namespace tests +{ + // print a board + void debug_print( CBoard& b ) + { + for ( unsigned int r = 0; r < b.rows; r++ ) + { + for ( unsigned int c = 0; c < b.cols; c++ ) + { + std::cout<<(char)(b.get(c,r)); + } + std::cout<