Fixed major issues, still not launching due to vectors
This commit is contained in:
parent
9082d7fdfd
commit
c4d40d152b
@ -11,11 +11,12 @@ public:
|
||||
sf::Vector2f gameBoundaries;
|
||||
DisplayInterface(void);
|
||||
bool IsOpen(void);
|
||||
protected:
|
||||
bool isWindowAlive;
|
||||
virtual void CheckContinue(void) = 0;
|
||||
virtual void DisplayGameState(std::vector< std::vector<char> >* gameBoard) = 0;
|
||||
virtual void DisplayEndScreen(void) = 0;
|
||||
virtual void StartGameWindow(void) = 0;
|
||||
protected:
|
||||
bool isWindowAlive;
|
||||
private:
|
||||
;
|
||||
};
|
||||
@ -24,6 +25,7 @@ class CommandLine : public DisplayInterface
|
||||
{
|
||||
public:
|
||||
CommandLine(void);
|
||||
void CheckContinue(void);
|
||||
void DisplayGameState(std::vector< std::vector<char> >* gameBoard);
|
||||
void DisplayEndScreen(void);
|
||||
void StartGameWindow(void);
|
||||
@ -37,6 +39,7 @@ class SFML : public DisplayInterface
|
||||
{
|
||||
public:
|
||||
SFML(void);
|
||||
void CheckContinue(void);
|
||||
void DisplayGameState(std::vector< std::vector<char> >* gameBoard);
|
||||
void DisplayEndScreen(void);
|
||||
void StartGameWindow(void);
|
||||
|
@ -23,14 +23,15 @@ private:
|
||||
Snake player;
|
||||
SnakeFood playerFood;
|
||||
bool useSFML = 1;
|
||||
bool isGameOver = 0;
|
||||
void ApplySettings(void);
|
||||
void DisplayEndScreen(void);
|
||||
void GetKeyboardInput(void);
|
||||
bool PlayerWantsToContinue(void);
|
||||
void PlaceNewSnakePart(sf::Vector2f location);
|
||||
void PlayerWantsToContinue(void);
|
||||
void RegenerateFood(void);
|
||||
void ResetGameBoard(void);
|
||||
void RunGameLoop(void);
|
||||
void RenderWindow(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -19,6 +19,14 @@ CommandLine::CommandLine(void)
|
||||
return;
|
||||
}
|
||||
|
||||
void CommandLine::CheckContinue(void)
|
||||
{
|
||||
int placeholder;
|
||||
std::cout << "Press enter to play again.";
|
||||
std::cin >> placeholder;
|
||||
return;
|
||||
}
|
||||
|
||||
void CommandLine::DisplayEndScreen(void)
|
||||
{
|
||||
std::cout << "Game Over!" << std::endl;
|
||||
@ -50,6 +58,24 @@ SFML::SFML(void)
|
||||
return;
|
||||
}
|
||||
|
||||
void SFML::CheckContinue(void)
|
||||
{
|
||||
sf::Event event;
|
||||
while (true)
|
||||
{
|
||||
while (gameWindow.pollEvent(event))
|
||||
{
|
||||
if ((event.type == sf::Event::Closed) ||
|
||||
(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
|
||||
gameWindow.close();
|
||||
return;
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Enter))
|
||||
return;
|
||||
sf::sleep(delay);
|
||||
}
|
||||
}
|
||||
|
||||
void SFML::DisplayEndScreen(void)
|
||||
{
|
||||
gameWindow.clear();
|
||||
|
@ -25,6 +25,7 @@ void GameState::StartGame()
|
||||
{
|
||||
ApplySettings();
|
||||
ResetGameBoard();
|
||||
graphics->StartGameWindow();
|
||||
RunGameLoop();
|
||||
return;
|
||||
}
|
||||
@ -35,12 +36,13 @@ void GameState::ApplySettings(void)
|
||||
graphics.reset(new SFML());
|
||||
else
|
||||
graphics.reset(new CommandLine());
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Reimplement for DisplayInterface
|
||||
void GameState::DisplayEndScreen(void)
|
||||
{
|
||||
// graphics->DisplayEndScreen();
|
||||
graphics->DisplayEndScreen();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -62,23 +64,16 @@ void GameState::GetKeyboardInput(void)
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Reimplement for DisplayInterface
|
||||
bool GameState::PlayerWantsToContinue(void)
|
||||
void GameState::PlaceNewSnakePart(sf::Vector2f location)
|
||||
{
|
||||
// sf::Event event;
|
||||
// while (true)
|
||||
// {
|
||||
// while (gameWindow.pollEvent(event))
|
||||
// {
|
||||
// if ((event.type == sf::Event::Closed) ||
|
||||
// (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
|
||||
// gameWindow.close();
|
||||
// return false;
|
||||
// }
|
||||
// if (sf::Keyboard::isKeyPressed(sf::Keyboard::Enter))
|
||||
// return true;
|
||||
// sf::sleep(delay);
|
||||
// }
|
||||
gameBoard.at(location.y).at(location.x) = 'o';
|
||||
return;
|
||||
}
|
||||
|
||||
void GameState::PlayerWantsToContinue(void)
|
||||
{
|
||||
graphics->CheckContinue();
|
||||
return;
|
||||
}
|
||||
|
||||
// Generates new food until not colliding with player
|
||||
@ -97,10 +92,9 @@ void GameState::ResetGameBoard(void)
|
||||
{
|
||||
gameBoard.clear();
|
||||
sf::Vector2f boardDimensions = GetGameBoundaries();
|
||||
gameBoard.resize(boardDimensions.y);
|
||||
for (int i = 0; i < boardDimensions.y; i++)
|
||||
for (int j = 0; j < boardDimensions.x; j++)
|
||||
gameBoard[i].push_back(' ');
|
||||
std::vector<char> tempBoard;
|
||||
tempBoard.resize(boardDimensions.x, ' ');
|
||||
gameBoard.resize(boardDimensions.y, tempBoard);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -109,21 +103,12 @@ void GameState::RunGameLoop(void)
|
||||
while (graphics->IsOpen())
|
||||
{
|
||||
GetKeyboardInput();
|
||||
player.MoveSnake();
|
||||
PlaceNewSnakePart(player.MoveSnake());
|
||||
RegenerateFood();
|
||||
RenderWindow();
|
||||
graphics->DisplayGameState(&gameBoard);
|
||||
if (isGameOver)
|
||||
PlayerWantsToContinue();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Reimplement for DisplayInterface
|
||||
void GameState::RenderWindow(void)
|
||||
{
|
||||
// gameWindow.clear();
|
||||
// player.DisplaySnake(gameWindow);
|
||||
// gameWindow.draw(playerFood.GetFoodObject());
|
||||
// gameWindow.display();
|
||||
// if (player.gameFinished)
|
||||
// DisplayEndScreen();
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user