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