git.ucc.asn.au
/
progcomp2012.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Revamped manager program and added manual page
[progcomp2012.git]
/
manager
/
stratego.cpp
diff --git
a/manager/stratego.cpp
b/manager/stratego.cpp
index
8ffad72
..
37df4d2
100644
(file)
--- a/
manager/stratego.cpp
+++ b/
manager/stratego.cpp
@@
-1,4
+1,4
@@
-#include "common.h"
+
#include "stratego.h"
#include "stratego.h"
@@
-7,19
+7,18
@@
using namespace std;
/**
* Static variables
*/
/**
* Static variables
*/
-Board Board::theBoard(14,14);
+
//nothing, boulder, flag, spy, scout, miner, sergeant, lietenant, captain, major, colonel, general, marshal, bomb, error
//nothing, boulder, flag, spy, scout, miner, sergeant, lietenant, captain, major, colonel, general, marshal, bomb, error
-char Piece::tokens[] = {'.','
+','F','y','s','n','S','L','c','m','C','G','M
','B','?'};
+char Piece::tokens[] = {'.','
*','F','s','9','8','7','6','5','4','3','2','1
','B','?'};
int Piece::maxUnits[] = {0,0,1,1,8,5,4,4,4,3,2,1,1,6,0};
int Piece::maxUnits[] = {0,0,1,1,8,5,4,4,4,3,2,1,1,6,0};
-#ifdef GRAPHICS
-
Piece::TextureManager Piece::textures;
-#endif //GRAPHICS
+
+Piece::TextureManager Piece::textures;
+
-#ifdef GRAPHICS
Piece::TextureManager::~TextureManager()
{
Piece::TextureManager::~TextureManager()
{
@@
-42,7
+41,7
@@
Texture & Piece::TextureManager::operator[](const LUint & at)
}
return *(Array<Texture*>::operator[](at));
}
}
return *(Array<Texture*>::operator[](at));
}
-#endif //GRAPHICS
+
/**
* Gets the type of a piece, based off a character token
/**
* Gets the type of a piece, based off a character token
@@
-135,7
+134,7
@@
void Board::Print(FILE * stream, const Piece::Colour & reveal)
}
}
-#ifdef GRAPHICS
+
/**
* Draw the board state to graphics
* @param reveal - Pieces matching this colour will be revealed. All others will be shown as blank coloured squares.
/**
* Draw the board state to graphics
* @param reveal - Pieces matching this colour will be revealed. All others will be shown as blank coloured squares.
@@
-144,7
+143,9
@@
void Board::Draw(const Piece::Colour & reveal)
{
if (!Graphics::Initialised())
{
{
if (!Graphics::Initialised())
{
- Graphics::Initialise("Stratego", width*32, height*32);
+ fprintf(stderr, "ERROR - Board::Draw called whilst graphics disabled!!!\n");
+ exit(EXIT_FAILURE);
+
}
Graphics::ClearScreen();
}
Graphics::ClearScreen();
@@
-170,10
+171,10
@@
void Board::Draw(const Piece::Colour & reveal)
switch (piece->colour)
{
case Piece::RED:
switch (piece->colour)
{
case Piece::RED:
- Piece::textures[(int)(Piece::
BOULDER
)].DrawColour(x*32,y*32,0,1, Piece::GetGraphicsColour(piece->colour));
+ Piece::textures[(int)(Piece::
NOTHING
)].DrawColour(x*32,y*32,0,1, Piece::GetGraphicsColour(piece->colour));
break;
case Piece::BLUE:
break;
case Piece::BLUE:
- Piece::textures[(int)(Piece::
BOULDER
)].DrawColour(x*32,y*32,0,1, Piece::GetGraphicsColour(piece->colour));
+ Piece::textures[(int)(Piece::
NOTHING
)].DrawColour(x*32,y*32,0,1, Piece::GetGraphicsColour(piece->colour));
break;
case Piece::NONE:
Piece::textures[(int)(Piece::BOULDER)].DrawColour(x*32,y*32,0,1, Piece::GetGraphicsColour(piece->colour));
break;
case Piece::NONE:
Piece::textures[(int)(Piece::BOULDER)].DrawColour(x*32,y*32,0,1, Piece::GetGraphicsColour(piece->colour));
@@
-189,7
+190,6
@@
void Board::Draw(const Piece::Colour & reveal)
Graphics::UpdateScreen();
}
Graphics::UpdateScreen();
}
-#endif //GRAPHICS
/**
* Adds a piece to the board
/**
* Adds a piece to the board
@@
-232,32
+232,32
@@
Piece * Board::GetPiece(int x, int y)
* @param colour - Colour which the piece must match for the move to be valid
* @returns A MovementResult which indicates the result of the move - OK is good, VICTORY means that a flag was captured, anything else is an error
*/
* @param colour - Colour which the piece must match for the move to be valid
* @returns A MovementResult which indicates the result of the move - OK is good, VICTORY means that a flag was captured, anything else is an error
*/
-
Board::
MovementResult Board::MovePiece(int x, int y, const Direction & direction, int multiplier,const Piece::Colour & colour)
+MovementResult Board::MovePiece(int x, int y, const Direction & direction, int multiplier,const Piece::Colour & colour)
{
if (board == NULL)
{
{
if (board == NULL)
{
- return
NO_BOARD
;
+ return
MovementResult(MovementResult::NO_BOARD)
;
}
if (!(x >= 0 && x < width && y >= 0 && y < height))
{
}
if (!(x >= 0 && x < width && y >= 0 && y < height))
{
- return
INVALID_POSITION
;
+ return
MovementResult(MovementResult::INVALID_POSITION)
;
}
Piece * target = board[x][y];
if (target == NULL)
{
}
Piece * target = board[x][y];
if (target == NULL)
{
- return
NO_SELECTION
;
+ return
MovementResult(MovementResult::NO_SELECTION)
;
}
if (!(colour == Piece::NONE || target->colour == colour))
{
}
if (!(colour == Piece::NONE || target->colour == colour))
{
- return
NOT_YOUR_UNIT
;
+ return
MovementResult(MovementResult::NOT_YOUR_UNIT)
;
}
if (target->type == Piece::FLAG || target->type == Piece::BOMB || target->type == Piece::BOULDER)
{
}
if (target->type == Piece::FLAG || target->type == Piece::BOMB || target->type == Piece::BOULDER)
{
- return
IMMOBILE_UNIT
;
+ return
MovementResult(MovementResult::IMMOBILE_UNIT)
;
}
if (multiplier > 1 && target->type != Piece::SCOUT)
{
}
if (multiplier > 1 && target->type != Piece::SCOUT)
{
- return
INVALID_DIRECTION
; //Can only move a scout multiple times.
+ return
MovementResult(MovementResult::INVALID_DIRECTION)
; //Can only move a scout multiple times.
}
int x2 = x; int y2 = y;
}
int x2 = x; int y2 = y;
@@
-280,11
+280,11
@@
Board::MovementResult Board::MovePiece(int x, int y, const Direction & direction
}
if (!(x2 >= 0 && x2 < width && y2 >= 0 && y2 < height))
{
}
if (!(x2 >= 0 && x2 < width && y2 >= 0 && y2 < height))
{
- return
INVALID_DIRECTION
;
+ return
MovementResult(MovementResult::INVALID_DIRECTION)
;
}
if (ii < multiplier-1 && board[x2][y2] != NULL)
{
}
if (ii < multiplier-1 && board[x2][y2] != NULL)
{
- return
POSITION_FULL
;
+ return
MovementResult(MovementResult::POSITION_FULL)
;
}
}
Piece * defender = board[x2][y2];
}
}
Piece * defender = board[x2][y2];
@@
-295,23
+295,27
@@
Board::MovementResult Board::MovePiece(int x, int y, const Direction & direction
}
else if (defender->colour != target->colour)
{
}
else if (defender->colour != target->colour)
{
+ Piece::Type defenderType = defender->type;
+ Piece::Type attackerType = target->type;
+
if (defender->colour == Piece::NONE)
{
if (defender->colour == Piece::NONE)
{
- return
POSITION_FULL
;
+ return
MovementResult(MovementResult::POSITION_FULL)
;
}
if (defender->type == Piece::FLAG)
{
winner = target->colour;
}
if (defender->type == Piece::FLAG)
{
winner = target->colour;
- return
VICTORY
;
+ return
MovementResult(MovementResult::VICTORY)
;
}
else if (defender->type == Piece::BOMB)
{
if (target->type == Piece::MINER)
{
}
else if (defender->type == Piece::BOMB)
{
if (target->type == Piece::MINER)
{
+
delete defender;
board[x][y] = NULL;
board[x2][y2] = target;
delete defender;
board[x][y] = NULL;
board[x2][y2] = target;
- return
KILLS
;
+ return
MovementResult(MovementResult::KILLS, attackerType, defenderType)
;
}
else
{
}
else
{
@@
-319,7
+323,7
@@
Board::MovementResult Board::MovePiece(int x, int y, const Direction & direction
delete target;
board[x][y] = NULL;
board[x2][y2] = NULL;
delete target;
board[x][y] = NULL;
board[x2][y2] = NULL;
- return
BOTH_DIE
;
+ return
MovementResult(MovementResult::BOTH_DIE, attackerType, defenderType)
;
}
}
else if (defender->type == Piece::MARSHAL && target->type == Piece::SPY)
}
}
else if (defender->type == Piece::MARSHAL && target->type == Piece::SPY)
@@
-327,34
+331,34
@@
Board::MovementResult Board::MovePiece(int x, int y, const Direction & direction
delete defender;
board[x][y] = NULL;
board[x2][y2] = target;
delete defender;
board[x][y] = NULL;
board[x2][y2] = target;
- return
KILLS
;
+ return
MovementResult(MovementResult::KILLS, attackerType, defenderType)
;
}
else if (target->operator > (*defender))
{
delete defender;
board[x][y] = NULL;
board[x2][y2] = target;
}
else if (target->operator > (*defender))
{
delete defender;
board[x][y] = NULL;
board[x2][y2] = target;
- return
KILLS
;
+ return
MovementResult(MovementResult::KILLS, attackerType, defenderType)
;
}
else if (target->operator==(*defender) && rand() % 2 == 0)
{
delete defender;
board[x][y] = NULL;
board[x2][y2] = target;
}
else if (target->operator==(*defender) && rand() % 2 == 0)
{
delete defender;
board[x][y] = NULL;
board[x2][y2] = target;
- return
KILLS
;
+ return
MovementResult(MovementResult::KILLS, attackerType, defenderType)
;
}
else
{
delete target;
board[x][y] = NULL;
}
else
{
delete target;
board[x][y] = NULL;
- return
DIES
;
+ return
MovementResult(MovementResult::DIES, attackerType, defenderType)
;
}
}
else
{
}
}
else
{
- return
POSITION_FULL
;
+ return
MovementResult(MovementResult::POSITION_FULL)
;
}
}
- return
OK
;
+ return
MovementResult(MovementResult::OK)
;
}
}
UCC
git Repository :: git.ucc.asn.au