...
 
Commits (3)
......@@ -3,29 +3,23 @@
#include "classes.hpp"
namespace AapeliBlox {
Move::Move (int sx, int sy, int srotation, bool sjump) {
x = sx; y = sy; rotation = srotation; jump = sjump; lastMove = 0;
}
void Move::restart (void) {
lastMove = 0;
}
Vector::Vector (int sx, int sy) {
Vector::Vector(int sx, int sy) {
x = sx; y = sy;
}
Block::Block (sf::Color scolor, bool visible, bool sisUndoBlock) {
Block::Block(sf::Color scolor, bool visible, bool sisUndoBlock) {
color = scolor; isBlock = visible; isUndoBlock = sisUndoBlock;
}
ShapeBlock::ShapeBlock (sf::Color scolor, int sx, int sy) {
ShapeBlock::ShapeBlock(sf::Color scolor, int sx, int sy) {
x = sx; y = sy; color = scolor;
}
void Shape::updateExtrema (void) {
void Shape::updateExtrema(void) {
minx = 0; maxx = 0;
for (int i = 0; i < 4; i++) {
minx = std::min(minx, blocks[i].x);
maxx = std::max(maxx, blocks[i].x);
}
}
Shape::Shape (sf::Color scolor,
Shape::Shape(sf::Color scolor,
int x1, int y1,
int x2, int y2,
int x3, int y3,
......@@ -46,7 +40,7 @@ namespace AapeliBlox {
updateExtrema();
}
/** Rotate either 0, 90, 180, 270, etc degrees */
void Shape::rotate (int rotation) {
void Shape::rotate(int rotation) {
while (rotation < 0) {
rotation += 4;
}
......
......@@ -4,29 +4,21 @@
#include <SFML/Graphics.hpp>
namespace AapeliBlox {
// Small helper class for moves
struct Move {
int x, y, rotation;
bool jump;
double lastMove;
Move (int sx = 0, int sy = 0, int srotation = 0, bool sjump = false);
void restart (void);
};
const int blockSide = 30;
struct Vector {
int x, y;
Vector (int sx = 0, int sy = 0);
Vector(int sx = 0, int sy = 0);
};
struct Block {
sf::Color color;
bool isBlock;
bool isUndoBlock;
Block (sf::Color scolor = sf::Color::White, bool visible = false, bool sisUndoBlock = false);
Block(sf::Color scolor = sf::Color::White, bool visible = false, bool sisUndoBlock = false);
};
struct ShapeBlock {
sf::Color color;
int x, y;
ShapeBlock (sf::Color scolor = sf::Color::White, int sx = 0, int sy = 0);
ShapeBlock(sf::Color scolor = sf::Color::White, int sx = 0, int sy = 0);
};
struct Shape {
bool evenWide;
......@@ -35,7 +27,7 @@ namespace AapeliBlox {
int originx, originy;
sf::Color color;
Vector blocks[4];
Shape (sf::Color scolor = sf::Color(255,255,255,0),
Shape(sf::Color scolor = sf::Color(255,255,255,0),
int x1 = 0, int y1 = 0,
int x2 = 0, int y2 = 1,
int x3 = 0, int y3 = 2,
......@@ -44,9 +36,9 @@ namespace AapeliBlox {
bool soddThick = false,
int soriginx = 0,
int soriginy = 0);
void rotate (int rotation);
void rotate(int rotation);
private:
void updateExtrema (void);
void updateExtrema(void);
};
}
......
This diff is collapsed.
......@@ -15,6 +15,14 @@ namespace AapeliBlox {
timeTrial,
normal
};
enum moves {
left,
right,
down,
rotateLeft,
rotateRight,
jump
};
class Game {
enum endType {
undoNoBlocks,
......@@ -24,9 +32,11 @@ namespace AapeliBlox {
};
states& gameState;
std::map<moves, int> lastMoveTicks;
// Global game settings
int blockTowerWidth, blockTowerHeight, blockTowerVisibleHeight, blockSide, totalPoints, featureWidth;
int nextBlockHeight, textPaddingx, textPaddingy, featurePadding, undoHeight, gameTime, gameTimeMins, secsInMin;
int nextBlockHeight, textPaddingx, textPaddingy, featurePadding, undoHeight, gameTicks;
Vector min, max, features, featuresNextBlock, featuresYourScore, featuresTimer;
Vector featuresNextBlockDimensions, featuresYourScoreDimensions, featuresTimerDimensions;
bool drawGhost;
......@@ -37,10 +47,11 @@ namespace AapeliBlox {
Block emptyBlock, undoBlock;
// Time between each drop
double dropInterval, effectInterval;
double effectInterval;
int dropInterval;
// Timers
sf::Clock drop, effects, gameTimer;
sf::Clock effects, tickTimer;
std::string gameTimePretty;
......@@ -73,9 +84,8 @@ namespace AapeliBlox {
sf::VertexArray featureOutline, featureBoxes;
sf::Color featureOutlineColor, featureBoxColor;
Move left, right, down, jump, rotateLeft, rotateRight;
sf::Clock moveTimer;
double minMoveInterval;
int minMoveTicks, ticksPerSecond, ticks;
int lastDropTicks;
// Point calcuation
std::vector<int> points;
......@@ -97,26 +107,26 @@ namespace AapeliBlox {
MenuEntry &scoreEntry, &endEntry, &timeEntry;
void drawBlock (int x, int y, sf::Color& color);
void drawShape (Shape& sh, Vector& loc);
void drawNext (void);
void drawPoints (void);
void drawTimer (void);
void drawFeatureBox (int x, int y, int width, int height);
void placeGhost (void);
void checkRows (void);
bool canBlockGo (Shape shape, Vector location);
bool canBlockRotate (Shape shape, Vector location, int rotation);
void dissolveCurrentBlock (void);
void placeBlock (void);
void move (Move& doMove);
void centerText (sf::Text& text, int x, int y);
void doEffects (void);
void createUndoMap (void);
void calculatePoints (void);
void endGameLogic (endType type);
void drawBlock(int x, int y, sf::Color& color);
void drawShape(Shape& sh, Vector& loc);
void drawNext(void);
void drawPoints(void);
void drawTimer(void);
void drawFeatureBox(int x, int y, int width, int height);
void placeGhost(void);
void checkRows(void);
bool canBlockGo(Shape shape, Vector location);
bool canBlockRotate(Shape shape, Vector location, int rotation);
void dissolveCurrentBlock(void);
void placeBlock(void);
void move(moves move);
void centerText(sf::Text& text, int x, int y);
void doEffects(void);
void createUndoMap(void);
void calculatePoints(void);
void endGameLogic(endType type);
public:
Game (states& sgameState,
Game(states& sgameState,
RandomNumberGenerator& sRNG,
sf::Font& sdFont,
sf::Font& ssFont,
......@@ -131,23 +141,24 @@ namespace AapeliBlox {
int sfeaturewidth = 200,
int sfeaturepadding = 20,
bool sdrawGhost = true,
double sdropInterval = 0.5,
int sdropInterval = 15,
int blockColor = 254,
double sminMoveInterval = 0.1,
int sminMoveTicks = 3,
int sticksPerSecond = 30,
sf::Color empty = sf::Color(255, 0, 255, 150),
sf::Color undo = sf::Color(23, 47, 66, 255));
void newGame (gameType newGameType);
void spawnNewBlock (void);
void gameLogic (void);
void draw (sf::RenderWindow& window);
void inputLeft (void);
void inputRight (void);
void inputDown (void);
void inputRotateLeft (void);
void inputRotateRight (void);
void inputJump (void);
int getPoints (void);
void restart (void);
void newGame(gameType newGameType);
void spawnNewBlock(void);
void gameLogic(void);
void draw(sf::RenderWindow& window);
void inputLeft(void);
void inputRight(void);
void inputDown(void);
void inputRotateLeft(void);
void inputRotateRight(void);
void inputJump(void);
int getPoints(void);
void restart(void);
};
}
......
......@@ -19,124 +19,124 @@ using namespace AapeliBlox;
int main(void)
{
// Current state
states gameState = inMainMenu;
// Current state
states gameState = inMainMenu;
int gameWidth = 522;
int gameHeight = 603;
int padding = 20;
int gameWidth = 522;
int gameHeight = 603;
int padding = 20;
int width = gameWidth + 2 * padding;
int height = gameHeight + 2 * padding;
int width = gameWidth + 2 * padding;
int height = gameHeight + 2 * padding;
sf::ContextSettings settings;
settings.antialiasingLevel = 2;
sf::RenderWindow window(sf::VideoMode(width, height), "AapeliBlox", sf::Style::Close, settings);
sf::ContextSettings settings;
settings.antialiasingLevel = 2;
sf::RenderWindow window(sf::VideoMode(width, height), "AapeliBlox", sf::Style::Close, settings);
window.setIcon(bloxIcon.width, bloxIcon.height, bloxIcon.pixel_data);
window.setIcon(bloxIcon.width, bloxIcon.height, bloxIcon.pixel_data);
std::random_device rRandomDevice;
std::random_device rRandomDevice;
RandomNumberGenerator myRNG(rRandomDevice(), 10);
sf::Font scoreFont;
scoreFont.loadFromMemory(Inconsolata_ttf, Inconsolata_ttf_len);
sf::Font menuFont;
menuFont.loadFromMemory(Bangers_ttf, Bangers_ttf_len);
sf::Font chewy;
chewy.loadFromMemory(Chewy_ttf, Chewy_ttf_len);
sf::Font scoreFont;
scoreFont.loadFromMemory(Inconsolata_ttf, Inconsolata_ttf_len);
sf::Font menuFont;
menuFont.loadFromMemory(Bangers_ttf, Bangers_ttf_len);
sf::Font chewy;
chewy.loadFromMemory(Chewy_ttf, Chewy_ttf_len);
MenuHandler menus(gameState, menuFont, width, height);
MenuHandler menus(gameState, menuFont, width, height);
Game myGame(gameState, myRNG, menuFont, scoreFont, menus.getEndScoreEntry(), menus.getEndTextEntry(), menus.getEndTimeEntry(), 10, 22, 30, 20, 20,
200, 20, true, 0.5, 200, 0.1, sf::Color(255, 0, 255, 150),
sf::Color(23, 47, 66, 255));
gameState = inMainMenu;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type) {
case sf::Event::Closed:
window.close(); break;
case sf::Event::LostFocus:
if (gameState == inGame) {
gameState = inContinueMenu;
}
case sf::Event::MouseMoved:
if (gameState != inGame) {
menus.mouseMoved(event.mouseMove.x, event.mouseMove.y);
}
break;
case sf::Event::MouseButtonPressed:
if (event.mouseButton.button == sf::Mouse::Left && gameState != inGame) {
menus.mouseClicked(event.mouseButton.x, event.mouseButton.y);
}
break;
case sf::Event::KeyPressed:
if (gameState != inGame) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { menus.inputUp(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { menus.inputDown(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return)) { menus.inputEnter(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { menus.inputEsc(); }
} else {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { myGame.inputLeft(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { myGame.inputRight(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { myGame.inputDown(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { myGame.inputRotateRight(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::X)) { myGame.inputRotateRight(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) { myGame.inputRotateLeft(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { myGame.inputJump(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::P)) { gameState = inContinueMenu; }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { gameState = inContinueMenu; }
}
default: break;
}
}
if (gameState != inGame) {
switch (menus.processSelection()) {
case goToNewGameMenu:
gameState = inNewGameMenu; break;
case goToAboutBox:
gameState = inAboutBox; break;
case goToMainMenu:
gameState = inMainMenu; break;
case continueGame:
gameState = inGame; break;
case doQuit:
window.close(); break;
case newGameUndo:
myRNG.reSeed(rRandomDevice());
myGame.newGame(undoGame); break;
case newGameTimeTrial:
myRNG.reSeed(rRandomDevice());
myGame.newGame(timeTrial); break;
case newGameNormal:
myRNG.reSeed(rRandomDevice());
myGame.newGame(normal); break;
case newGameRestart:
myGame.restart(); break;
default: break;
}
}
// Clear the buffer
window.clear(sf::Color(255, 255, 255, 255));
myGame.gameLogic();
myGame.draw(window);
menus.draw(window);
200, 20, true, 15, 200, 3, 30, sf::Color(255, 0, 255, 150),
sf::Color(23, 47, 66, 255));
gameState = inMainMenu;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type) {
case sf::Event::Closed:
window.close(); break;
case sf::Event::LostFocus:
if (gameState == inGame) {
gameState = inContinueMenu;
}
case sf::Event::MouseMoved:
if (gameState != inGame) {
menus.mouseMoved(event.mouseMove.x, event.mouseMove.y);
}
break;
case sf::Event::MouseButtonPressed:
if (event.mouseButton.button == sf::Mouse::Left && gameState != inGame) {
menus.mouseClicked(event.mouseButton.x, event.mouseButton.y);
}
break;
case sf::Event::KeyPressed:
if (gameState != inGame) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { menus.inputUp(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { menus.inputDown(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return)) { menus.inputEnter(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { menus.inputEsc(); }
} else {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { myGame.inputLeft(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { myGame.inputRight(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { myGame.inputDown(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { myGame.inputRotateRight(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::X)) { myGame.inputRotateRight(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) { myGame.inputRotateLeft(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { myGame.inputJump(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::P)) { gameState = inContinueMenu; }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { gameState = inContinueMenu; }
}
default: break;
}
}
if (gameState != inGame) {
switch (menus.processSelection()) {
case goToNewGameMenu:
gameState = inNewGameMenu; break;
case goToAboutBox:
gameState = inAboutBox; break;
case goToMainMenu:
gameState = inMainMenu; break;
case continueGame:
gameState = inGame; break;
case doQuit:
window.close(); break;
case newGameUndo:
myRNG.reSeed(rRandomDevice());
myGame.newGame(undoGame); break;
case newGameTimeTrial:
myRNG.reSeed(rRandomDevice());
myGame.newGame(timeTrial); break;
case newGameNormal:
myRNG.reSeed(rRandomDevice());
myGame.newGame(normal); break;
case newGameRestart:
myGame.restart(); break;
default: break;
}
}
// Clear the buffer
window.clear(sf::Color(255, 255, 255, 255));
myGame.gameLogic();
myGame.draw(window);
menus.draw(window);
// Display everything
window.display();
}
window.display();
}
// All good. Quit.
return 0;
return 0;
}
......@@ -7,19 +7,19 @@
#include "menu.hpp"
namespace AapeliBlox {
MenuEntry::MenuEntry (std::string stext, bool sclickable) {
MenuEntry::MenuEntry(std::string stext, bool sclickable) {
text = stext; clickable = sclickable;
}
void MenuEntry::setText (std::string stext) {
void MenuEntry::setText(std::string stext) {
text = stext;
}
MenuScreen::MenuText::MenuText (sf::Text ssfText, MenuEntry* sentry) {
MenuScreen::MenuText::MenuText(sf::Text ssfText, MenuEntry* sentry) {
sfText = ssfText; entry = sentry;
}
MenuScreen::MenuScreen (void) {
MenuScreen::MenuScreen(void) {
// Do nothing
}
MenuScreen::MenuScreen (sf::Font& sfont,
MenuScreen::MenuScreen(sf::Font& sfont,
std::vector<MenuEntry*> menuEntries,
int scharSize,
int smaxx,
......@@ -49,7 +49,7 @@ namespace AapeliBlox {
sfText.setCharacterSize(scharSize);
sfText.setColor(textColor);
sfText.setString(menuEntries[i]->text);
lineHeight = std::max(int (lineHeight), int (sfText.getLocalBounds().height));
lineHeight = std::max(int(lineHeight), int(sfText.getLocalBounds().height));
entries.push_back(MenuText(sfText, menuEntries[i]));
}
......@@ -59,7 +59,7 @@ namespace AapeliBlox {
}
}
}
bool MenuScreen::checkHover (int x, int y) {
bool MenuScreen::checkHover(int x, int y) {
for (int i = 0; i < entries.size(); i++) {
if (entries[i].sfText.getGlobalBounds().contains(x, y) && entries[i].entry->clickable) {
selected = i;
......@@ -68,12 +68,12 @@ namespace AapeliBlox {
}
return false;
}
void MenuScreen::changeSelection (int dir) {
void MenuScreen::changeSelection(int dir) {
if (selected + dir >= 0 && selected + dir < entries.size() && entries[selected + dir].entry->clickable) {
selected += dir;
}
}
void MenuScreen::draw (sf::RenderWindow& window) {
void MenuScreen::draw(sf::RenderWindow& window) {
// Draw background
window.draw(bgStrip);
......@@ -89,7 +89,7 @@ namespace AapeliBlox {
drawAt += (lineHeight + padding);
}
}
MenuEntry* MenuScreen::getSelected (void) {
MenuEntry* MenuScreen::getSelected(void) {
return entries[selected].entry;
}
}
......@@ -10,14 +10,14 @@ namespace AapeliBlox {
struct MenuEntry {
std::string text;
bool clickable;
MenuEntry (std::string stext = "", bool sclickable = true);
void setText (std::string stext);
MenuEntry(std::string stext = "", bool sclickable = true);
void setText(std::string stext);
};
class MenuScreen {
struct MenuText {
sf::Text sfText;
MenuEntry* entry;
MenuText (sf::Text ssfText, MenuEntry* sentry);
MenuText(sf::Text ssfText, MenuEntry* sentry);
};
int maxx, maxy, centerx, centery;
int bgHeight, padding;
......@@ -27,16 +27,16 @@ namespace AapeliBlox {
std::vector<MenuText> entries;
sf::VertexArray bgStrip;
public:
MenuScreen (void);
MenuScreen (sf::Font& sfont,
MenuScreen(void);
MenuScreen(sf::Font& sfont,
std::vector<MenuEntry*> menuEntries,
int scharSize,
int smaxx,
int smaxy);
bool checkHover (int x, int y);
void draw (sf::RenderWindow& window);
void changeSelection (int dir);
MenuEntry* getSelected (void);
bool checkHover(int x, int y);
void draw(sf::RenderWindow& window);
void changeSelection(int dir);
MenuEntry* getSelected(void);
};
}
......
......@@ -9,7 +9,7 @@
#include "resources/bloxLogo.hpp"
namespace AapeliBlox {
MenuHandler::MenuHandler (states& sgameState, sf::Font& menuFont, int width, int height) : gameState(sgameState) {
MenuHandler::MenuHandler(states& sgameState, sf::Font& menuFont, int width, int height) : gameState(sgameState) {
selected = 0;
// Let's make some menus!
......@@ -95,7 +95,7 @@ namespace AapeliBlox {
logoSprite.setTexture(logoTexture);
logoSprite.setPosition(width / 2 - bloxLogo.width / 2, width / 2 - 100);
}
MenuScreen* MenuHandler::currentMenu (void) {
MenuScreen* MenuHandler::currentMenu(void) {
switch (gameState) {
case inMainMenu:
return &mainMenu;
......@@ -111,23 +111,23 @@ namespace AapeliBlox {
return 0;
}
}
void MenuHandler::mouseMoved (int x, int y) {
void MenuHandler::mouseMoved(int x, int y) {
currentMenu()->checkHover(x, y);
}
void MenuHandler::mouseClicked (int x, int y) {
void MenuHandler::mouseClicked(int x, int y) {
currentMenu()->checkHover(x, y);
selected = currentMenu()->getSelected();
}
void MenuHandler::inputUp (void) {
void MenuHandler::inputUp(void) {
currentMenu()->changeSelection(-1);
}
void MenuHandler::inputDown (void) {
void MenuHandler::inputDown(void) {
currentMenu()->changeSelection(1);
}
void MenuHandler::inputEnter (void) {
void MenuHandler::inputEnter(void) {
selected = currentMenu()->getSelected();
}
void MenuHandler::inputEsc (void) {
void MenuHandler::inputEsc(void) {
switch (gameState) {
case inContinueMenu:
selected = &Continue; break;
......@@ -137,7 +137,7 @@ namespace AapeliBlox {
selected = &Back; break;
}
}
selectionOutcome MenuHandler::processSelection (void) {
selectionOutcome MenuHandler::processSelection(void) {
MenuEntry* temp = selected;
selected = 0;
if (temp == &Singleplayer) { return goToNewGameMenu; }
......@@ -153,19 +153,19 @@ namespace AapeliBlox {
else if (temp == &Back) { return goToMainMenu; }
else { return doNothing; }
}
void MenuHandler::draw (sf::RenderWindow& window) {
void MenuHandler::draw(sf::RenderWindow& window) {
if (gameState != inGame) {
currentMenu()->draw(window);
window.draw(logoSprite);
}
}
MenuEntry& MenuHandler::getEndTextEntry (void) {
MenuEntry& MenuHandler::getEndTextEntry(void) {
return EndGameText;
}
MenuEntry& MenuHandler::getEndScoreEntry (void) {
MenuEntry& MenuHandler::getEndScoreEntry(void) {
return EndGameScore;
}
MenuEntry& MenuHandler::getEndTimeEntry (void) {
MenuEntry& MenuHandler::getEndTimeEntry(void) {
return EndGameTime;
}
}
......
......@@ -43,19 +43,19 @@ namespace AapeliBlox {
EndGameTime, EndGameScore;
MenuEntry About0, About1, About2, About3, About4, EmptyLine, Back;
public:
MenuHandler (states& sgameState, sf::Font& menuFont, int width, int height);
MenuScreen* currentMenu (void);
void mouseMoved (int x, int y);
void mouseClicked (int x, int y);
void inputUp (void);
void inputDown (void);
void inputEnter (void);
void inputEsc (void);
selectionOutcome processSelection (void);
void draw (sf::RenderWindow& window);
MenuEntry& getEndTextEntry (void);
MenuEntry& getEndScoreEntry (void);
MenuEntry& getEndTimeEntry (void);
MenuHandler(states& sgameState, sf::Font& menuFont, int width, int height);
MenuScreen* currentMenu(void);
void mouseMoved(int x, int y);
void mouseClicked(int x, int y);
void inputUp(void);
void inputDown(void);
void inputEnter(void);
void inputEsc(void);
selectionOutcome processSelection(void);
void draw(sf::RenderWindow& window);
MenuEntry& getEndTextEntry(void);
MenuEntry& getEndScoreEntry(void);
MenuEntry& getEndTimeEntry(void);
};
}
......
......@@ -3,7 +3,7 @@
#include "random.hpp"
namespace AapeliBlox {
RandomNumberGenerator::RandomNumberGenerator (int seed, int blockTowerWidth) {
RandomNumberGenerator::RandomNumberGenerator(int seed, int blockTowerWidth) {
currentSeed = seed;
// Seed the Mersenne Twister with a real random number
......@@ -22,23 +22,23 @@ namespace AapeliBlox {
// Randomly rotate the next block
rRotation = std::uniform_int_distribution<int>(0, 3);
}
void RandomNumberGenerator::reSeed (int seed) {
void RandomNumberGenerator::reSeed(int seed) {
currentSeed = seed;
rMersenneTwister = std::mt19937(currentSeed);
}
bool RandomNumberGenerator::createBlock (void) {
bool RandomNumberGenerator::createBlock(void) {
return rCreateBlock(rMersenneTwister);
}
int RandomNumberGenerator::blockDestroy (void) {
int RandomNumberGenerator::blockDestroy(void) {
return rBlockDestroy(rMersenneTwister);
}
int RandomNumberGenerator::block (void) {
int RandomNumberGenerator::block(void) {
return rBlock(rMersenneTwister);
}
int RandomNumberGenerator::rotation (void) {
int RandomNumberGenerator::rotation(void) {
return rRotation(rMersenneTwister);
}
int RandomNumberGenerator::getSeed (void) {
int RandomNumberGenerator::getSeed(void) {
return currentSeed;
}
}
......@@ -12,13 +12,13 @@ namespace AapeliBlox {
std::uniform_int_distribution<int> rRotation;
int currentSeed;
public:
RandomNumberGenerator (int seed, int blockTowerWidth = 1);
void reSeed (int seed);
bool createBlock (void);
int blockDestroy (void);
int block (void);
int rotation (void);
int getSeed (void);
RandomNumberGenerator(int seed, int blockTowerWidth = 1);
void reSeed(int seed);
bool createBlock(void);
int blockDestroy(void);
int block(void);
int rotation(void);
int getSeed(void);
};
}
......