#include "game.h"
-
+#include <stdarg.h>
using namespace std;
signal(SIGPIPE, Game::HandleBrokenPipe);
+ #ifdef BUILD_GRAPHICS
if (graphicsEnabled && (!Graphics::Initialised()))
Graphics::Initialise("Stratego", theBoard.Width()*32, theBoard.Height()*32);
+ #endif //BUILD_GRAPHICS
if (strcmp(redPath, "human") == 0)
red = new Human_Controller(Piece::RED, graphicsEnabled);
Game::theGame = this;
signal(SIGPIPE, Game::HandleBrokenPipe);
-
+ #ifdef BUILD_GRAPHICS
if (graphicsEnabled && (!Graphics::Initialised()))
Graphics::Initialise("Stratego", theBoard.Width()*32, theBoard.Height()*32);
+ #endif //BUILD_GRAPHICS
input = fopen(fromFile, "r");
TimerThread timer(wait*1000000); //Wait in seconds
timer.Start();
+ #ifdef BUILD_GRAPHICS
if (!graphicsEnabled)
{
while (!timer.Finished());
timer.Stop();
return;
}
-
+ #endif //BUILD_GRAPHICS
while (!timer.Finished())
{
+ #ifdef BUILD_GRAPHICS
SDL_Event event;
while (SDL_PollEvent(&event))
{
break;
}
}
+ #endif //BUILD_GRAPHICS
}
timer.Stop();
if (Game::theGame->printBoard)
Game::theGame->theBoard.PrintPretty(stdout, Piece::BOTH);
+
+ #ifdef BUILD_GRAPHICS
if (Game::theGame->graphicsEnabled && theGame->log == stdout)
{
theGame->logMessage("CLOSE WINDOW TO EXIT\n");
}
}
else
+ #endif //BUILD_GRAPHICS
{
if (theGame->log == stdout)
{
theBoard.PrintPretty(stdout, Piece::BOTH);
fprintf(stdout, "\n");
}
+
+ #ifdef BUILD_GRAPHICS
if (graphicsEnabled && log == stdout)
{
logMessage("CLOSE WINDOW TO EXIT\n");
}
}
else
+ #endif //BUILD_GRAPHICS
{
if (log == stdout)
{
fprintf(stdout, "\n\n");
}
+ #ifdef BUILD_GRAPHICS
if (graphicsEnabled)
theBoard.Draw(toReveal);
+ #endif //BUILD_GRAPHICS
turn = Piece::RED;
logMessage( "%d RED: ", turnCount);
theBoard.PrintPretty(stdout, toReveal);
fprintf(stdout, "\n\n");
}
+
+ #ifdef BUILD_GRAPHICS
if (graphicsEnabled)
theBoard.Draw(toReveal);
+ #endif //BUILD_GRAPHICS
#include "stratego.h"
#include "ai_controller.h"
#include "human_controller.h"
-
+#include <cstring>
/**
#include <cassert>
#include <iostream>
+#ifdef BUILD_GRAPHICS
#undef DEBUG
//#define DEBUG
}
+
Font::Font(const char * filename, int newWidth, int newHeight) : Texture(filename), width(newWidth), height(newHeight)
{
return result;
}
+void Graphics::Wait(int n)
+{
+ SDL_Delay(n);
+}
-
-
-
-
+#endif //BUILD_GRAPHICS
+//#define BUILD_GRAPHICS
+#ifdef BUILD_GRAPHICS
+
#ifndef GRAPHICS_H
#define GRAPHICS_H
+
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
+typedef SDL_Surface Screen;
+typedef SDL_Rect Rectangle;
+typedef short unsigned int SUint;
+typedef unsigned char Uint8;
#include <vector>
#include <list>
-typedef SDL_Surface Screen;
-typedef SDL_Rect Rectangle;
-typedef short unsigned int SUint;
+
+
class Texture;
class Font;
static SDL_Surface * TextureFromColours(std::vector<SUint> * R, std::vector<SUint> * G, std::vector<SUint> * B, std::vector<SUint> * A = NULL);
static SDL_Surface * TextureFromColours(std::vector<std::vector<SUint> > * R, std::vector<std::vector<SUint> > * G, std::vector<std::vector<SUint> > * B, std::vector<std::vector<SUint> > * A = NULL);
-
- static void Wait(int n) {SDL_Delay(n);}
+
+ static void Wait(int n);
template <class T>
class TextureManager
int width() const {return surface->w;}
int height() const {return surface->h;}
+
protected:
SDL_Surface * surface;
GLuint texture;
#endif //GRAPHICS_H
+#endif //BUILD_GRAPHICS
+
//EOF
}
-
+ #ifdef BUILD_GRAPHICS
if (graphicsEnabled)
{
+
fprintf(stdout, "Click to move!\n");
SDL_Event event; int mouseClick = 0;
}
}
fprintf(stdout, "Move complete!\n");
+
}
else
+ #endif //BUILD_GRAPHICS
{
buffer.clear();
for (char in = fgetc(stdin); in != '\n'; in = fgetc(stdin))
#include "game.h"
+
using namespace std;
Piece::Colour SetupGame(int argc, char ** argv);
++ii;
break;
case 'g':
+ #ifdef BUILD_GRAPHICS
graphics = !graphics;
+ #else
+ fprintf(stderr, "ERROR: -g switch supplied, but the program was not built with graphics.\n Please do not use the -g switch.");
+ exit(EXIT_FAILURE);
+ #endif //BUILD_GRAPHICS
+
break;
case 'p':
printBoard = !printBoard;
-
+#ifdef BUILD_GRAPHICS
Piece::TextureManager Piece::textures;
-
-
-
Piece::TextureManager::~TextureManager()
{
Array<Texture*>::Iterator i(*this);
}
return *(Array<Texture*>::operator[](at));
}
-
+#endif //BUILD_GRAPHICS
/**
* Gets the type of a piece, based off a character token
}
-
+#ifdef BUILD_GRAPHICS
/**
* Draw the board state to graphics
* @param reveal - Pieces matching this colour will be revealed. If Piece::BOTH, all pieces will be revealed
*/
void Board::Draw(const Piece::Colour & reveal, bool showRevealed)
{
+
if (!Graphics::Initialised())
{
fprintf(stderr, "ERROR - Board::Draw called whilst graphics disabled!!!\n");
Graphics::UpdateScreen();
}
+#endif //BUILD_GRAPHICS
/**
* Adds a piece to the board
#include <assert.h>
-
- #include "graphics.h"
- #include "array.h"
+#include "graphics.h"
+#include "array.h"
#include <vector>
public:
+ #ifdef BUILD_GRAPHICS
class TextureManager : public Graphics::TextureManager<LUint>, private Array<Texture*>
{
public:
break;
}
}
-
+ #endif //BUILD_GRAPHICS
void Print(FILE * stream, const Piece::Colour & reveal=Piece::BOTH); //Print board
void PrintPretty(FILE * stream, const Piece::Colour & reveal=Piece::BOTH); //Print board using colour
+ #ifdef BUILD_GRAPHICS
void Draw(const Piece::Colour & reveal=Piece::BOTH, bool showRevealed = true); //Draw board
-
+ #endif //BUILD_GRAPHICS
bool AddPiece(int x, int y, const Piece::Type & newType, const Piece::Colour & newColour); //Add piece to board
OPTIONS
-g
+ NOTE: This switch only functions if stratego is built with graphics enabled. See BUILDING for more information.
+
By default, graphics are disabled. If the -g switch is present, stratego will draw the game as it is played using SDL/OpenGL
-p
If an error occurs within stratego itself, an error message will be printed to stderr and return exit code 1.
If possible, stratego will print the message "QUIT" to both AI programs, and they should exit as soon as possible.
+
+BUILDING
+ To build from source, simply run make in the source directory.
+
+ stratego can be built with or without graphics enabled. By default, graphics are disabled.
+
+ To enable graphics, ensure that the first line of the source file "graphics.h" reads:
+
+ #define BUILD_GRAPHICS
+
+ To disable graphics, comment out the first line of "graphics.h" i.e ensure that it reads:
+
+ //#define BUILD_GRAPHICS
+
+ If you intend to build with graphics enabled, you will need the SDL and OpenGL developement libraries installed first.
+ If you intend to use graphics, please ensure the "images" directory is located in the executable's run directory.
+
+
BUGS
irc://irc.ucc.asn.au #progcomp
THIS PAGE LAST UPDATED
- 20/12/11 by Sam Moore
+ 23/12/11 by Sam Moore