Permalink
Browse files

Cosmetics

  • Loading branch information...
Keruspe committed Jun 27, 2010
1 parent c4e7087 commit 5acceff29a9a9012b0a8866517d11f429f99af21
@@ -25,22 +25,22 @@ using namespace bombherman;
using namespace bombherman::bomb;
// Initialize statics
std::vector<std::vector<Bomb *> > AtomicCenter::bombs;
std::vector< std::vector< Bomb * > > AtomicCenter::bombs;
int AtomicCenter::numberOfBombs = 0;
void
AtomicCenter::boum()
{
// Make all bombs explode
for ( std::vector<std::vector<Bomb *> >::iterator i = bombs.begin(),
for ( std::vector< std::vector< Bomb * > >::iterator i = bombs.begin(),
iEnd = bombs.end() ; i != iEnd ; ++i )
for ( std::vector<Bomb *>::iterator j = i->begin(),
jEnd = i->end(); j != jEnd; ++j )
if ( *j )
Bomb::doExplode(*j);
// We wait until all bombs have exploded (custom "waitThreads")
while (AtomicCenter::numberOfBombs > 0)
while ( AtomicCenter::numberOfBombs > 0 )
SDL_Delay(250);
Bomb::newGame();
}
@@ -50,9 +50,9 @@ AtomicCenter::plantBomb(int player, map::Coords & c, Uint32 range)
{
if ( bombs.empty() )
{
int size = Config::getInt("mapSize");
const int size = Config::getInt("mapSize");
bombs.resize(size);
for (int i(0) ; i < size ; ++i)
for ( int i(0) ; i < size ; ++i )
bombs[i].resize(size);
}
if ( ! map::Map::plantBomb(c) )
@@ -70,7 +70,7 @@ namespace bombherman
/// Decrease the number of bombs still alive
static void bombExploded() { --AtomicCenter::numberOfBombs; }
private:
static std::vector<std::vector<Bomb *> > bombs;
static std::vector< std::vector< Bomb * > > bombs;
static int numberOfBombs;
};
}
View
@@ -31,19 +31,19 @@ using namespace bombherman::bomb;
SDL_mutex * Bomb::mutex = SDL_CreateMutex ();
bool Bomb::gameOver = false;
Bomb::Bomb (int player, map::Coords c, Uint32 _range) :
Bomb::Bomb(int player, map::Coords c, Uint32 _range) :
explosion(SDL_CreateSemaphore(0)),
player(player),
range(_range),
coords(c),
explodedCells(std::vector<map::Coords>()),
chain(std::vector<map::Coords>())
explodedCells(std::vector< map::Coords >()),
chain(std::vector< map::Coords >())
{
if ( SDL_CreateThread(waitExplode, this) == NULL )
bherr << "Unable to create thread to manage a bomb : " << SDL_GetError();
bherr << "Unable to create thread to manage a bomb: " << SDL_GetError();
}
Bomb::Bomb (const Bomb & other) :
Bomb::Bomb(const Bomb & other) :
explosion(other.explosion),
player(other.player),
range(other.range),
@@ -66,10 +66,10 @@ Bomb::operator=(const Bomb & other)
}
int
Bomb::waitExplode(void *p)
Bomb::waitExplode(void * p)
{
// Delay the explosion
Bomb *b = static_cast<Bomb * >(p);
Bomb * b = static_cast< Bomb * >(p);
SDL_SemWaitTimeout(b->explosion, Config::getInt("timeBeforeExplosion") * 1000);
b->explode();
AtomicCenter::bombExploded();
@@ -78,7 +78,7 @@ Bomb::waitExplode(void *p)
}
void
Bomb::doExplode(Bomb *b)
Bomb::doExplode(Bomb * b)
{
// Force explosion
if ( b )
@@ -108,7 +108,7 @@ Bomb::explode()
right = check(coords.x - i, coords.y);
if ( left )
left = check(coords.x + i, coords.y);
if ( ( ! up ) && ( ! down ) && ( ! right ) && ( ! left ) )
if ( ! up && ! down && ! right && ! left )
break;
}
@@ -138,7 +138,7 @@ bool
Bomb::check(Uint32 x, Uint32 y)
{
map::Coords c(x, y);
if ( ( ! c.validate() ) || Bomb::gameOver )
if ( ! c.validate() || Bomb::gameOver )
return false;
// Get element on cell
@@ -77,13 +77,13 @@ namespace bombherman
Uint32 getRange() { return this->range; }
/// Destructor
virtual ~Bomb () { SDL_DestroySemaphore(explosion); }
virtual ~Bomb() { SDL_DestroySemaphore(explosion); }
private:
static int waitExplode(void *);
void explode();
bool check(Uint32, Uint32);
static SDL_mutex * mutex;
SDL_sem *explosion;
SDL_sem * explosion;
int player;
Uint32 range;
map::Coords coords;
View
@@ -31,7 +31,7 @@ extern "C"
int
#ifdef __MINGW32__
SDL_main(int argc, char **argv)
SDL_main(int argc, char ** argv)
#else
main()
#endif // __MINGW32__
@@ -59,7 +59,7 @@ main()
catch ( std::exception & e )
{
// We should never go there
bherr << "Ouch, an unknown exception was thrown, please report this as a bug : "
bherr << "Ouch, an unknown exception was thrown, please report this as a bug: "
<< bhendl << e.what() << bhendl;
}
return 0;
View
@@ -23,15 +23,17 @@
// TODO DYNAMIC FILE FOR WINDOWS
#ifdef __MINGW32__
#include <direct.h>
#define CONFIG_DIR (std::string(getenv("AppData")) + std::string("\\bomb-her-man\\"))
#define CONFIG_FILE (CONFIG_DIR + std::string("config.init")).c_str()
#define CONFIG_DIR_BASE (std::string(getenv("AppData")) + std::string("\\bomb-her-man\\"))
#define CONFIG_FILE (CONFIG_DIR_BASE + std::string("config.init")).c_str()
#else
#include <cstdlib>
#include <sys/stat.h>
#define CONFIG_DIR (std::string(getenv("HOME")) + std::string("/.config/bomb-her-man/"))
#define CONFIG_FILE (CONFIG_DIR + std::string("config")).c_str()
#define CONFIG_DIR_BASE (std::string(getenv("HOME")) + std::string("/.config/bomb-her-man/"))
#define CONFIG_FILE (CONFIG_DIR_BASE + std::string("config")).c_str()
#endif // __MINGW32__
#define CONFIG_DIR CONFIG_DIR_BASE.c_str()
using namespace bombherman;
/*
@@ -87,7 +89,7 @@ Config::stringValue()
*/
// Initialize statics
std::map<std::string, Config> Config::config;
std::map< std::string, Config > Config::config;
bool Config::isInit = false;
void
@@ -192,9 +194,9 @@ Config::write()
{
// Create the directory
#ifdef __MINGW32__
_mkdir(CONFIG_DIR.c_str());
_mkdir(CONFIG_DIR);
#else
mkdir(CONFIG_DIR.c_str(), 0700);
mkdir(CONFIG_DIR, 0700);
#endif // __MINGW32__
// Open the file
@@ -220,7 +222,7 @@ Config::get(std::string key)
}
int
Config::getInt (std::string key)
Config::getInt(std::string key)
{
Config::init();
return (config[key]).iValue;
View
@@ -89,13 +89,11 @@ namespace bombherman
static void read();
/// The configuration map
static std::map<std::string, Config> config;
static std::map< std::string, Config > config;
static bool isInit;
};
}
#endif // _CONFIG_HPP_
View
@@ -102,7 +102,7 @@ Display::init()
throw exceptions::display::NoSDLException("No modes available!");
if ( modes == reinterpret_cast<SDL_Rect**>(-1) )
throw exceptions::display::NoSDLException("Can't choice the resolution");
throw exceptions::display::NoSDLException("Can't choose the resolution");
widthMax = modes[0]->w;
heightMax = modes[0]->h;
@@ -38,7 +38,7 @@ namespace bombherman
* @param elem The bad element (std::string)
*/
BadElementException(const std::string & elem) throw() :
Exception("Bad element : " + elem) {}
Exception("Bad element: " + elem) {}
/// Destructor
virtual ~BadElementException() throw () {}
@@ -38,7 +38,7 @@ namespace bombherman
* @param path The path of the malformed file (std::string)
*/
MalformedFileException(const std::string & path) throw() :
Exception("Malformed file : " + path) {}
Exception("Malformed file: " + path) {}
/// Destructor
virtual ~MalformedFileException() throw () {}
View
@@ -32,13 +32,13 @@ MapGenerator::generate(Grid & g)
MapGenerator::init();
// Stock config things to avoid multiple callings to Config
int insertionProbabilityBaseHorizontal = Config::getInt("mgInsertionProbabilityBaseHorizontal");
int insertionRegressionHorizontal = Config::getInt("mgInsertionRegressionHorizontal");
int insertionElementSizeMaxVertical = Config::getInt("mgInsertionElementSizeMaxVertical");
int insertionRegressionVertical = Config::getInt("mgInsertionRegressionVertical");
int insertionProbabilityBaseVertical = Config::getInt("mgInsertionProbabilityBaseVertical");
int insertionElementSizeMaxHorizontal = Config::getInt("mgInsertionElementSizeMaxHorizontal");
int insertionProbabilityBarrel = Config::getInt("mgInsertionProbabilityBarrel");
const int insertionProbabilityBaseHorizontal = Config::getInt("mgInsertionProbabilityBaseHorizontal");
const int insertionRegressionHorizontal = Config::getInt("mgInsertionRegressionHorizontal");
const int insertionElementSizeMaxVertical = Config::getInt("mgInsertionElementSizeMaxVertical");
const int insertionRegressionVertical = Config::getInt("mgInsertionRegressionVertical");
const int insertionProbabilityBaseVertical = Config::getInt("mgInsertionProbabilityBaseVertical");
const int insertionElementSizeMaxHorizontal = Config::getInt("mgInsertionElementSizeMaxHorizontal");
const int insertionProbabilityBarrel = Config::getInt("mgInsertionProbabilityBarrel");
// We'll need those local vars for various stocking
int currentHorizontalElementSize;
@@ -49,26 +49,26 @@ MapGenerator::generate(Grid & g)
// Resize the map to the right dimensions
g.grid.resize(g.size);
for (std::vector< std::vector< char > >::iterator i = g.grid.begin(),
i_end = g.grid.end() ; i != i_end ; ++i)
for ( std::vector< std::vector< char > >::iterator i = g.grid.begin(),
i_end = g.grid.end() ; i != i_end ; ++i )
{
// Fill each cell with NOTHING
i->resize(g.size, NOTHING);
}
// Go through the gris to fill it, col by col, line by line
for (c.x = 0; c.x < g.size; ++c.x)
for ( c.x = 0; c.x < g.size; ++c.x )
{
for (c.y = 0; c.y < g.size; ++c.y)
for ( c.y = 0; c.y < g.size; ++c.y )
{
currentHorizontalElementSize = horizontalScan(g, c);
currentHorizontalInsertionProbability = insertionProbabilityBaseHorizontal - currentHorizontalElementSize * insertionRegressionHorizontal;
if (currentVerticalElementSize != 0)
if ( currentVerticalElementSize != 0 )
{
// The upper element is INDESTRUCTIBLE
if (throwDice(currentVerticalInsertionProbability)
if ( throwDice(currentVerticalInsertionProbability)
&& currentVerticalElementSize < insertionElementSizeMaxVertical
&& testCellLimited(g, c))
&& testCellLimited(g, c) )
{
// If we didn't reach max vertical INDESTRUCTIBLE block size and we do not lock anything
// and the dice tells us to put INDESTRUCTIBLE, juste do it
@@ -84,14 +84,14 @@ MapGenerator::generate(Grid & g)
currentVerticalInsertionProbability = insertionProbabilityBaseVertical;
}
}
else if (currentHorizontalElementSize != 0
else if ( currentHorizontalElementSize != 0
&& currentHorizontalElementSize < insertionElementSizeMaxHorizontal
&& throwDice(currentHorizontalInsertionProbability)
&& c.x != (g.size - 1))
&& c.x != (g.size - 1) )
// INDESTRUCTIBLE on left, and can put another one without locking
g[c.y][c.x] = INDESTRUCTIBLE;
else if (throwDice(insertionProbabilityBaseVertical)
&& testCellFull(g, c))
else if ( throwDice(insertionProbabilityBaseVertical)
&& testCellFull(g, c) )
{
// Base INDESTRUCTIBLE insertion, none on left nor top
g[c.y][c.x] = INDESTRUCTIBLE;
@@ -102,10 +102,10 @@ MapGenerator::generate(Grid & g)
}
// Fill the gris with barrels
for (c.x = 0; c.x < g.size; ++c.x)
for (c.y = 0; c.y < g.size; ++c.y)
if (g[c.y][c.x] == NOTHING
&& throwDice (insertionProbabilityBarrel))
for ( c.x = 0; c.x < g.size; ++c.x )
for ( c.y = 0; c.y < g.size; ++c.y )
if ( g[c.y][c.x] == NOTHING
&& throwDice (insertionProbabilityBarrel) )
g[c.y][c.x] = BARREL;
}
@@ -130,14 +130,14 @@ MapGenerator::throwDice(int percentage)
bool
MapGenerator::testCellFull(Grid & grid, Coords & coords)
{
if (coords.x == 0)
if ( coords.x == 0 )
// Don't care about first column
return true;
bool result = grid[coords.y][coords.x - 1] != INDESTRUCTIBLE;
if (coords.y > 0)
if ( coords.y > 0 )
result = result && grid[coords.y - 1][coords.x - 1] != INDESTRUCTIBLE &&
grid[coords.y - 1][coords.x] != INDESTRUCTIBLE;
if (coords.y < grid.size - 1)
if ( coords.y < grid.size - 1 )
result = result && grid[coords.y+1][coords.x-1] != INDESTRUCTIBLE;
// We'll return false if a nearby cell is INDESTRUCTIBLE (strict north and all west)
return result;
@@ -155,8 +155,8 @@ int
MapGenerator::horizontalScan(Grid & grid, Coords & coords)
{
int i;
for (i = 0 ; coords.x - i != 0
&& grid[coords.y][coords.x - i - 1] == INDESTRUCTIBLE ; ++i);
for ( i = 0 ; coords.x - i != 0
&& grid[coords.y][coords.x - i - 1] == INDESTRUCTIBLE ; ++i );
// Return the number of cell before next not INDESTRUCTIBLE on the left
return i;
}
@@ -176,7 +176,7 @@ MapGenerator::getRandomCoords()
void
MapGenerator::init()
{
if (MapGenerator::isInit)
if ( MapGenerator::isInit )
// Don't init twice
return;
::srand(time(0));
Oops, something went wrong.

0 comments on commit 5acceff

Please sign in to comment.