Clean some other things
This commit is contained in:
parent
e72ce20365
commit
f7610d669b
4 changed files with 30 additions and 74 deletions
|
@ -3,27 +3,32 @@
|
|||
|
||||
|
||||
|
||||
//==================== Constructor and Destructor ====================
|
||||
|
||||
|
||||
//Constructor
|
||||
SFMLController::SFMLController() : m_game(), m_MainWindow(600,800, "2P11"){
|
||||
}
|
||||
|
||||
|
||||
//Destructor
|
||||
SFMLController::~SFMLController(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Run controller
|
||||
void SFMLController::run(){
|
||||
|
||||
//Init keypress
|
||||
kbdh::Direction keyPress;
|
||||
|
||||
//First pop
|
||||
m_game.popRandomNumber();
|
||||
|
||||
|
||||
//Start game
|
||||
while(m_MainWindow.isOpen()){
|
||||
|
||||
|
||||
//Check event
|
||||
sf::Event event;
|
||||
while (m_MainWindow.pollEvent(event))
|
||||
{
|
||||
|
@ -54,71 +59,16 @@ void SFMLController::run(){
|
|||
}
|
||||
|
||||
|
||||
//Clear window
|
||||
m_MainWindow.clearBG();
|
||||
//m_game.swipe(kbdh::Direction::Left);
|
||||
std::vector<std::vector<int> > aaa=m_game.getGrid();
|
||||
m_MainWindow.drawGame(aaa,m_game.isOver(), m_game.getStats());
|
||||
|
||||
//Draw the game
|
||||
m_MainWindow.drawGame(m_game.getGrid(),m_game.isOver(), m_game.getStats());
|
||||
|
||||
//Display the changements
|
||||
m_MainWindow.display();
|
||||
|
||||
//keyPress=this->waitArrowKeyPress();
|
||||
m_game.swipe(keyPress);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//Wait for keypress and return the keyPress.
|
||||
kbdh::Direction SFMLController::waitArrowKeyPress()
|
||||
{
|
||||
//Initialise keyPress
|
||||
kbdh::Direction keyPress;
|
||||
|
||||
//White space to remove arrows print by the terminal
|
||||
std::string spaces=" ";
|
||||
|
||||
//Wait for keypress
|
||||
while(1){
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
||||
{
|
||||
keyPress=kbdh::Left;
|
||||
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
||||
{
|
||||
//Wait for release and try to remove arrow printed characters
|
||||
std::cout << "\r" << spaces;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
|
||||
{
|
||||
keyPress=kbdh::Right;
|
||||
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
|
||||
{
|
||||
//Wait for release and try to remove arrow printed characters
|
||||
std::cout << "\r" << spaces;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
||||
{
|
||||
keyPress=kbdh::Up;
|
||||
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
||||
{
|
||||
//Wait for release and try to remove arrow printed characters
|
||||
std::cout << "\r" << spaces;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
|
||||
{
|
||||
keyPress=kbdh::Down;
|
||||
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
|
||||
{
|
||||
//Wait for release and try to remove arrow printed characters
|
||||
std::cout << "\r" << spaces;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return keyPress;
|
||||
}
|
||||
|
|
|
@ -1,26 +1,30 @@
|
|||
|
||||
#ifndef __SFMLCONTROLLER__
|
||||
#define __SFMLCONTROLLER__
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/Window/Keyboard.hpp>
|
||||
|
||||
#include "../../View/MainWindow.hpp"
|
||||
#include "../../Model/Game.hpp"
|
||||
#include "../../Helpers/Keyboard.hpp"
|
||||
#include <SFML/Window/Keyboard.hpp>
|
||||
|
||||
|
||||
|
||||
class SFMLController{
|
||||
|
||||
private:
|
||||
MainWindow m_MainWindow;
|
||||
Game m_game;
|
||||
|
||||
|
||||
public:
|
||||
SFMLController();
|
||||
~SFMLController();
|
||||
|
||||
kbdh::Direction waitArrowKeyPress();
|
||||
void run();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -347,7 +347,7 @@ std::vector<int> Grid::getCol(int col){
|
|||
return colVect;
|
||||
}
|
||||
|
||||
|
||||
//Retrieve the grid for the view
|
||||
std::vector<std::vector<int> > Grid::getGrid(){
|
||||
return m_grid;
|
||||
}
|
||||
|
|
|
@ -21,8 +21,10 @@ int main()
|
|||
srand(time(NULL));
|
||||
|
||||
//Init controller
|
||||
//SFMLController controller;
|
||||
ConsoleController controller;
|
||||
SFMLController controller;
|
||||
|
||||
//ConsoleController controller;
|
||||
|
||||
//Run the game
|
||||
controller.run();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue