Add some newers things :
-Change helper ModelConstants to Keyboard -Now helpers is in folder Helpers -Change direction name to use CamelCase
This commit is contained in:
parent
672358a947
commit
048f1e17b7
9 changed files with 25 additions and 107 deletions
|
@ -15,4 +15,4 @@ include_directories(${SFML_INCLUDE_DIR})
|
||||||
target_link_libraries(2P11 ${SFML_LIBRARIES} Model ConsoleController)
|
target_link_libraries(2P11 ${SFML_LIBRARIES} Model ConsoleController)
|
||||||
|
|
||||||
add_subdirectory(./Model)
|
add_subdirectory(./Model)
|
||||||
add_subdirectory(./Controller/)
|
add_subdirectory(./Controllers/)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "./ConsoleController.hpp"
|
#include "./ConsoleController.hpp"
|
||||||
#include <SFML/Window/Keyboard.hpp>
|
#include <SFML/Window/Keyboard.hpp>
|
||||||
#include "../../Model/ModelConstants.hpp"
|
#include "../../Helpers/Keyboard.hpp"
|
||||||
|
|
||||||
ConsoleController::ConsoleController()
|
ConsoleController::ConsoleController()
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,7 @@ void ConsoleController::play()
|
||||||
std::cout << "Use arrows to play !" << std::endl;
|
std::cout << "Use arrows to play !" << std::endl;
|
||||||
|
|
||||||
//Init keyPress
|
//Init keyPress
|
||||||
Direction keyPress;
|
kbdh::Direction keyPress;
|
||||||
|
|
||||||
//Display the first grid
|
//Display the first grid
|
||||||
m_game->showGrid();
|
m_game->showGrid();
|
||||||
|
@ -35,16 +35,16 @@ void ConsoleController::play()
|
||||||
|
|
||||||
//Print keyPress
|
//Print keyPress
|
||||||
switch(keyPress){
|
switch(keyPress){
|
||||||
case UP:
|
case kbdh::Up:
|
||||||
std::cout << "Keypress : Up" << std::endl;
|
std::cout << "Keypress : Up" << std::endl;
|
||||||
break;
|
break;
|
||||||
case DOWN:
|
case kbdh::Down:
|
||||||
std::cout << "Keypress : Down" << std::endl;
|
std::cout << "Keypress : Down" << std::endl;
|
||||||
break;
|
break;
|
||||||
case LEFT:
|
case kbdh::Left:
|
||||||
std::cout << "Keypress : Left" << std::endl;
|
std::cout << "Keypress : Left" << std::endl;
|
||||||
break;
|
break;
|
||||||
case RIGHT:
|
case kbdh::Right:
|
||||||
std::cout << "Keypress : Right" << std::endl;
|
std::cout << "Keypress : Right" << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -62,16 +62,16 @@ void ConsoleController::play()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Direction ConsoleController::waitArrowKeyPress()
|
kbdh::Direction ConsoleController::waitArrowKeyPress()
|
||||||
{
|
{
|
||||||
//Initialise keyPress
|
//Initialise keyPress
|
||||||
Direction keyPress;
|
kbdh::Direction keyPress;
|
||||||
|
|
||||||
//Wait for keypress
|
//Wait for keypress
|
||||||
while(1){
|
while(1){
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
||||||
{
|
{
|
||||||
keyPress=LEFT;
|
keyPress=kbdh::Left;
|
||||||
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
||||||
{
|
{
|
||||||
//Wait for release
|
//Wait for release
|
||||||
|
@ -80,7 +80,7 @@ Direction ConsoleController::waitArrowKeyPress()
|
||||||
}
|
}
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
|
||||||
{
|
{
|
||||||
keyPress=RIGHT;
|
keyPress=kbdh::Right;
|
||||||
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
|
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
|
||||||
{
|
{
|
||||||
//Wait for release
|
//Wait for release
|
||||||
|
@ -89,7 +89,7 @@ Direction ConsoleController::waitArrowKeyPress()
|
||||||
}
|
}
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
||||||
{
|
{
|
||||||
keyPress=UP;
|
keyPress=kbdh::Up;
|
||||||
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
||||||
{
|
{
|
||||||
//Wait for release
|
//Wait for release
|
||||||
|
@ -99,7 +99,7 @@ Direction ConsoleController::waitArrowKeyPress()
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
|
||||||
{
|
{
|
||||||
// la touche "flèche gauche" est enfoncée : on bouge le personnage
|
// la touche "flèche gauche" est enfoncée : on bouge le personnage
|
||||||
keyPress=DOWN;
|
keyPress=kbdh::Down;
|
||||||
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
|
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
|
||||||
{
|
{
|
||||||
//Wait for release
|
//Wait for release
|
|
@ -8,6 +8,7 @@
|
||||||
* Date : 29/04/2915 */
|
* Date : 29/04/2915 */
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "../../Helpers/Keyboard.hpp"
|
||||||
#include "../../Model/Game.hpp"
|
#include "../../Model/Game.hpp"
|
||||||
|
|
||||||
class ConsoleController
|
class ConsoleController
|
||||||
|
@ -15,7 +16,7 @@ class ConsoleController
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Game * m_game;
|
Game * m_game;
|
||||||
Direction waitArrowKeyPress();
|
kbdh::Direction waitArrowKeyPress();
|
||||||
public:
|
public:
|
||||||
ConsoleController();
|
ConsoleController();
|
||||||
~ConsoleController();
|
~ConsoleController();
|
|
@ -6,7 +6,12 @@
|
||||||
* Creators : krilius, manzerbredes
|
* Creators : krilius, manzerbredes
|
||||||
* Date : 29/04/2015 */
|
* Date : 29/04/2015 */
|
||||||
|
|
||||||
enum Direction { UP, DOWN, LEFT, RIGHT };
|
namespace kbdh {
|
||||||
typedef enum Direction Direction;
|
|
||||||
|
|
||||||
#endif
|
//Key arrow
|
||||||
|
enum Direction { Up, Down, Left, Right };
|
||||||
|
typedef enum Direction Direction;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -82,86 +82,4 @@ void Grid::setCell(int i, int j, Cell *cell)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Grid::move(Direction direction)
|
|
||||||
{
|
|
||||||
switch (direction)
|
|
||||||
{
|
|
||||||
case UP:
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DOWN:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LEFT:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RIGHT:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Grid::moveDown()
|
|
||||||
{/*
|
|
||||||
for (int i = 0 ; i < m_size; i++)
|
|
||||||
{
|
|
||||||
// If the column is full, check the next column
|
|
||||||
bool columnIsFull = true;
|
|
||||||
|
|
||||||
for (int j = 0; j < m_size; j++)
|
|
||||||
{
|
|
||||||
if (m_table[j][i]->isEmpty())
|
|
||||||
{
|
|
||||||
columnIsFull = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!columnIsFull)
|
|
||||||
{
|
|
||||||
// Calculate the first line to merge
|
|
||||||
int firstLine = m_size - 1;
|
|
||||||
while (m_table[firstLine][i]->isEmpty() && firstLine > 0)
|
|
||||||
firstLine--;
|
|
||||||
if (firstLine == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Calculate the second line to merge
|
|
||||||
int secondLine = firstLine - 1;
|
|
||||||
while (m_table[secondLine][i]->isEmpty() && secondLine > 0)
|
|
||||||
secondLine--;
|
|
||||||
|
|
||||||
// If there is only one element, pull it down
|
|
||||||
if (m_table[secondLine][i]->isEmpty() && firstLine != m_size - 1)
|
|
||||||
{
|
|
||||||
Cell * originalCell = m_table[firstLine][i];
|
|
||||||
Cell * finalCell = m_table[m_size-1][i];
|
|
||||||
|
|
||||||
m_table[firstLine][i] = finalCell;
|
|
||||||
m_table[m_size-1][i] = originalCell;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there is only one element which is at the full bottom, break the loop
|
|
||||||
if (m_table[secondLine][i]->isEmpty())
|
|
||||||
break;
|
|
||||||
|
|
||||||
// If there are two "good" elements, begin the merge process
|
|
||||||
Cell * cell1 = m_table[firstLine][i];
|
|
||||||
Cell * cell2 = m_table[secondLine][i];
|
|
||||||
|
|
||||||
Cell * mergedCell = NULL;
|
|
||||||
|
|
||||||
// If the two cells are the same, merge them
|
|
||||||
if (cell1->equals(cell2))
|
|
||||||
{
|
|
||||||
int value = std::stoi(cell1->getValue());
|
|
||||||
mergedCell = new Cell(std::to_string(value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "ModelConstants.hpp"
|
//#include "ModelConstants.hpp"
|
||||||
#include "Cell.hpp"
|
#include "Cell.hpp"
|
||||||
|
|
||||||
class Grid
|
class Grid
|
||||||
|
@ -19,11 +19,6 @@ class Grid
|
||||||
int m_size;
|
int m_size;
|
||||||
std::vector<std::vector<Cell*> > m_table;
|
std::vector<std::vector<Cell*> > m_table;
|
||||||
|
|
||||||
void moveUp();
|
|
||||||
void moveDown();
|
|
||||||
void moveLeft();
|
|
||||||
void moveRight();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Grid(int size);
|
Grid(int size);
|
||||||
~Grid();
|
~Grid();
|
||||||
|
@ -33,7 +28,6 @@ class Grid
|
||||||
bool gridIsFull();
|
bool gridIsFull();
|
||||||
void setCell(int i, int j, Cell * cell);
|
void setCell(int i, int j, Cell * cell);
|
||||||
|
|
||||||
void move(Direction direction);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
//----- Personnal include -----
|
//----- Personnal include -----
|
||||||
#include "./Model/Grid.hpp"
|
#include "./Model/Grid.hpp"
|
||||||
#include "./Controller/ConsoleController/ConsoleController.hpp"
|
#include "./Controllers/ConsoleController/ConsoleController.hpp"
|
||||||
//-----------------------------
|
//-----------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue