summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2015-05-04 16:55:32 +0200
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2015-05-04 16:55:32 +0200
commit1570bc62105de67871e98599506f7bee6f1b400d (patch)
tree4c3db08b701958442bae22f20ba43d95037ad926
parent8488827025f25743ef18eca8c55cfdff5767341b (diff)
parenta1c9b58c29746793f00520d46e1397abe2b0e711 (diff)
Merge branch 'develop'HEADmaster
apply SFML develop change
-rw-r--r--Readme.md2
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/Controllers/CMakeLists.txt1
-rw-r--r--src/Controllers/ConsoleController/ConsoleController.cpp11
-rw-r--r--src/Controllers/SFMLController/CMakeLists.txt3
-rw-r--r--src/Controllers/SFMLController/SFMLController.cpp124
-rw-r--r--src/Controllers/SFMLController/SFMLController.hpp26
-rw-r--r--src/Model/CMakeLists.txt2
-rw-r--r--src/Model/Game.cpp43
-rw-r--r--src/Model/Game.hpp16
-rw-r--r--src/Model/Grid.cpp6
-rw-r--r--src/Model/Grid.hpp6
-rw-r--r--src/Model/Stats.cpp29
-rw-r--r--src/Model/Stats.hpp30
-rw-r--r--src/View/CMakeLists.txt2
-rw-r--r--src/View/MainWindow.cpp255
-rw-r--r--src/View/MainWindow.hpp43
-rw-r--r--src/main.cpp4
-rw-r--r--src/skin/original/Pragmatica-Medium.ttfbin0 -> 87416 bytes
19 files changed, 569 insertions, 37 deletions
diff --git a/Readme.md b/Readme.md
new file mode 100644
index 0000000..d0acd15
--- /dev/null
+++ b/Readme.md
@@ -0,0 +1,2 @@
+#2P11
+-----
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index da444d2..e7b7f73 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -12,7 +12,8 @@ set_property(GLOBAL PROPERTY SFML_INCLUDE_DIR "${SFML_INCLUDE_DIR}")
#Include "Includes" and "Libraries"
include_directories(${SFML_INCLUDE_DIR})
-target_link_libraries(2P11 ${SFML_LIBRARIES} Model ConsoleController)
+target_link_libraries(2P11 ${SFML_LIBRARIES} Model ConsoleController View SFMLController)
add_subdirectory(./Model)
add_subdirectory(./Controllers/)
+add_subdirectory(./View/)
diff --git a/src/Controllers/CMakeLists.txt b/src/Controllers/CMakeLists.txt
index 7ebeb19..13b1c20 100644
--- a/src/Controllers/CMakeLists.txt
+++ b/src/Controllers/CMakeLists.txt
@@ -1 +1,2 @@
add_subdirectory(./ConsoleController/)
+add_subdirectory(./SFMLController/)
diff --git a/src/Controllers/ConsoleController/ConsoleController.cpp b/src/Controllers/ConsoleController/ConsoleController.cpp
index 1bc9b84..57f626f 100644
--- a/src/Controllers/ConsoleController/ConsoleController.cpp
+++ b/src/Controllers/ConsoleController/ConsoleController.cpp
@@ -70,6 +70,9 @@ kbdh::Direction ConsoleController::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))
@@ -78,7 +81,7 @@ kbdh::Direction ConsoleController::waitArrowKeyPress()
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
//Wait for release and try to remove arrow printed characters
- std::cout << "\r" << " ";
+ std::cout << "\r" << spaces;
}
break;
}
@@ -88,7 +91,7 @@ kbdh::Direction ConsoleController::waitArrowKeyPress()
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
//Wait for release and try to remove arrow printed characters
- std::cout << "\r" << " ";
+ std::cout << "\r" << spaces;
}
break;
}
@@ -98,7 +101,7 @@ kbdh::Direction ConsoleController::waitArrowKeyPress()
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
//Wait for release and try to remove arrow printed characters
- std::cout << "\r" << " ";
+ std::cout << "\r" << spaces;
}
break;
}
@@ -108,7 +111,7 @@ kbdh::Direction ConsoleController::waitArrowKeyPress()
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
//Wait for release and try to remove arrow printed characters
- std::cout << "\r" << " ";
+ std::cout << "\r" << spaces;
}
break;
}
diff --git a/src/Controllers/SFMLController/CMakeLists.txt b/src/Controllers/SFMLController/CMakeLists.txt
new file mode 100644
index 0000000..e3e60c4
--- /dev/null
+++ b/src/Controllers/SFMLController/CMakeLists.txt
@@ -0,0 +1,3 @@
+#Make Model lib
+add_library(SFMLController ./SFMLController.cpp)
+target_link_libraries(SFMLController Model View)
diff --git a/src/Controllers/SFMLController/SFMLController.cpp b/src/Controllers/SFMLController/SFMLController.cpp
new file mode 100644
index 0000000..1c21753
--- /dev/null
+++ b/src/Controllers/SFMLController/SFMLController.cpp
@@ -0,0 +1,124 @@
+#include "SFMLController.hpp"
+
+
+
+
+
+
+SFMLController::SFMLController() : m_game(), m_MainWindow(600,800, "2P11"){
+}
+
+
+SFMLController::~SFMLController(){
+
+}
+
+
+
+
+void SFMLController::run(){
+
+ kbdh::Direction keyPress;
+
+ m_game.popRandomNumber();
+ while(m_MainWindow.isOpen()){
+
+
+ sf::Event event;
+ while (m_MainWindow.pollEvent(event))
+ {
+ // évènement "fermeture demandée" : on ferme la fenêtre
+ if (event.type == sf::Event::Closed)
+ m_MainWindow.close();
+ if (event.type == sf::Event::KeyPressed)
+ {
+ if (event.key.code == sf::Keyboard::Up)
+ {
+ m_game.swipe(kbdh::Direction::Up);
+ }
+ if (event.key.code == sf::Keyboard::Down)
+ {
+ m_game.swipe(kbdh::Direction::Down);
+ // Do something when W is pressed...
+ }
+ if (event.key.code == sf::Keyboard::Left){
+
+ m_game.swipe(kbdh::Direction::Left);
+ }
+ if (event.key.code == sf::Keyboard::Right){
+ m_game.swipe(kbdh::Direction::Right);
+ }
+
+ // And so on.
+ }
+ }
+
+
+ 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());
+ 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;
+}
diff --git a/src/Controllers/SFMLController/SFMLController.hpp b/src/Controllers/SFMLController/SFMLController.hpp
new file mode 100644
index 0000000..0bb0eea
--- /dev/null
+++ b/src/Controllers/SFMLController/SFMLController.hpp
@@ -0,0 +1,26 @@
+
+
+
+#include <iostream>
+#include <string>
+#include <SFML/Window.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();
+
+};
diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt
index 888589e..4ebe544 100644
--- a/src/Model/CMakeLists.txt
+++ b/src/Model/CMakeLists.txt
@@ -1,2 +1,2 @@
#Make Model lib
-add_library(Model Grid.cpp Game.cpp)
+add_library(Model Grid.cpp Game.cpp Stats.cpp)
diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp
index 284d82b..5781f54 100644
--- a/src/Model/Game.cpp
+++ b/src/Model/Game.cpp
@@ -4,7 +4,7 @@
//==================== Constructor and Destructor ====================
//Constructor
-Game::Game() : m_grid(), m_score(0), m_nbMove(0){
+Game::Game() : Grid(), m_stats(){
}
//Destructor
@@ -21,22 +21,22 @@ bool Game::swipe(kbdh::Direction direction){
switch(direction){
case kbdh::Left:
- moveDone=m_grid.swipeLeft();
+ moveDone=swipeLeft();
break;
case kbdh::Right:
- moveDone=m_grid.swipeRight();
+ moveDone=swipeRight();
break;
case kbdh::Up:
- moveDone=m_grid.swipeUp();
+ moveDone=swipeUp();
break;
case kbdh::Down:
- moveDone=m_grid.swipeDown();
+ moveDone=swipeDown();
break;
}
if(moveDone){
- m_score+=m_grid.getLastMoveScore();
- m_nbMove++;
+ m_stats.incScore(m_lastMoveScore);
+ m_stats.incnbMove();
this->popRandomNumber();
}
@@ -46,17 +46,17 @@ bool Game::swipe(kbdh::Direction direction){
//Cout the grid
void Game::coutGrid(){
- std::cout << m_grid.description();
+ std::cout << this->description();
}
//Return true if the game is lost. False else.
-bool Game::isOver(){
- return m_grid.isOver();
-}
+//bool Game::isOver(){
+ //return m_grid.isOver();
+//}
//Pop a random number on the grid
void Game::popRandomNumber(){
- std::tuple<int, int> coord(m_grid.getRandomEmptyCellCoord());
+ std::tuple<int, int> coord(Grid::getRandomEmptyCellCoord());
int percent=rand() % 100;
@@ -70,16 +70,21 @@ void Game::popRandomNumber(){
}
- m_grid.setCell(coord, number);
+ Grid::setCell(coord, number);
}
//==================== Getters and Setter ====================
//Retrieve the Score
-int Game::getScore(){
- return m_score;
+Stats Game::getStats(){
+ return m_stats;
}
-//Retrieve the number of moves
-int Game::getNbMove(){
- return m_nbMove;
-}
+
+//std::vector<std::vector<int> > Game::getGrid(){
+ //return m_grid.getGrid();
+//}
+
+
+//int Game::maxStrLenInGrid(){
+ //return m_grid.maxStrLenInGrid();
+//}
diff --git a/src/Model/Game.hpp b/src/Model/Game.hpp
index 0b2ee4d..e468176 100644
--- a/src/Model/Game.hpp
+++ b/src/Model/Game.hpp
@@ -11,16 +11,15 @@
#include <string>
#include "../Helpers/Keyboard.hpp"
#include "Grid.hpp"
+#include "Stats.hpp"
#include <tuple>
-class Game
+class Game : public Grid
{
private:
//Members
- Grid m_grid;
- int m_score;
- int m_nbMove;
-
+ //Grid m_grid;
+ Stats m_stats;
public:
//Constructor and Destructor
Game();
@@ -30,11 +29,12 @@ class Game
bool swipe(kbdh::Direction direction);
void coutGrid();
void popRandomNumber();
- bool isOver();
+ //bool isOver();
//Getters and Setters
- int getScore();
- int getNbMove();
+ Stats getStats();
+ //int maxStrLenInGrid();
+ //std::vector<std::vector<int> > getGrid();
};
#endif
diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp
index cc0fe60..64d8048 100644
--- a/src/Model/Grid.cpp
+++ b/src/Model/Grid.cpp
@@ -11,6 +11,7 @@ Grid::Grid(): m_size(4), m_grid(4){
m_grid.at(i).push_back(0);
}
}
+ //m_grid.at(3).at(0)=2048;
}
//Destructor
@@ -345,3 +346,8 @@ std::vector<int> Grid::getCol(int col){
return colVect;
}
+
+
+std::vector<std::vector<int> > Grid::getGrid(){
+ return m_grid;
+}
diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp
index 51168a9..22416b0 100644
--- a/src/Model/Grid.hpp
+++ b/src/Model/Grid.hpp
@@ -16,12 +16,12 @@ class Grid
{
private:
//Members
- int m_size;
+ protected:
std::vector<std::vector<int> > m_grid;
+ int m_size;
int m_lastMoveScore;
//Private methods
- int maxStrLenInGrid();
public:
//Constructor and Destructor
@@ -34,6 +34,7 @@ class Grid
std::vector<int> rightMerge(std::vector<int> line);
std::vector<int> leftMerge(std::vector<int> line);
+ int maxStrLenInGrid();
//Swipe methods
bool swipeRight();
bool swipeLeft();
@@ -55,6 +56,7 @@ class Grid
std::vector<int> getCol(int col);
void setCol(int col, std::vector<int> colVect);
int getLastMoveScore();
+ std::vector<std::vector<int> > getGrid();
};
diff --git a/src/Model/Stats.cpp b/src/Model/Stats.cpp
new file mode 100644
index 0000000..8bada78
--- /dev/null
+++ b/src/Model/Stats.cpp
@@ -0,0 +1,29 @@
+#include "Stats.hpp"
+
+
+Stats::Stats() :
+ m_score(0),
+ m_nbMove(0)
+{
+
+}
+
+Stats::~Stats(){
+}
+
+
+
+void Stats::incScore(int value){
+ m_score+=value;
+}
+void Stats::incnbMove(){
+ m_nbMove++;
+}
+
+
+int Stats::getScore(){
+ return m_score;
+}
+int Stats::getNbMove(){
+ return m_nbMove;
+}
diff --git a/src/Model/Stats.hpp b/src/Model/Stats.hpp
new file mode 100644
index 0000000..49c7356
--- /dev/null
+++ b/src/Model/Stats.hpp
@@ -0,0 +1,30 @@
+#ifndef __STATS__
+#define __STATS__
+
+#include <iostream>
+
+
+
+
+
+class Stats{
+
+ private:
+ int m_score;
+ int m_nbMove;
+ public:
+
+ Stats();
+ ~Stats();
+ void incScore(int value);
+ void incnbMove();
+
+
+ int getScore();
+ int getNbMove();
+
+
+
+};
+
+#endif
diff --git a/src/View/CMakeLists.txt b/src/View/CMakeLists.txt
new file mode 100644
index 0000000..9a13671
--- /dev/null
+++ b/src/View/CMakeLists.txt
@@ -0,0 +1,2 @@
+#Make Model lib
+add_library(View ./MainWindow.cpp)
diff --git a/src/View/MainWindow.cpp b/src/View/MainWindow.cpp
new file mode 100644
index 0000000..ea4346d
--- /dev/null
+++ b/src/View/MainWindow.cpp
@@ -0,0 +1,255 @@
+#include "MainWindow.hpp"
+
+
+
+
+
+
+MainWindow::MainWindow(int width, int height, std::string title):
+ RenderWindow(sf::VideoMode(width,height), title,sf::Style::Titlebar | sf::Style::Close),
+ m_skin(),
+ m_windowSize(),
+ m_cellSize(105,105),
+ m_gridSize(0,0),
+ m_gridPosition(),
+ m_spaceBetweenCell(15),
+ m_font()
+{
+ //Set windows size
+ m_windowSize=RenderWindow::getSize();
+
+ m_gridPosition=sf::Vector2u(0,200);
+
+
+
+ //Load font
+ m_font.loadFromFile("./src/skin/original/Pragmatica-Medium.ttf");
+
+ //Define original skin:
+ m_skin.push_back(sf::Color(250,248,239)); //Background MainWindow
+ m_skin.push_back(sf::Color(205,192,180)); //Background cells
+ m_skin.push_back(sf::Color(187,173,160)); //Background grid color
+ m_skin.push_back(sf::Color(119,110,101)); //2 and 4 font color
+ m_skin.push_back(sf::Color(143,122,102)); //Button color
+ m_skin.push_back(sf::Color(249,246,242)); //other number font Color
+ m_skin.push_back(sf::Color(238,228,218,186)); //Game over color bg
+
+ //Skin 2 et le 4
+ m_skin.push_back(sf::Color(238,228,218)); //2
+ m_skin.push_back(sf::Color(237,224,200)); //4
+
+ //Skin 8 à 64
+ m_skin.push_back(sf::Color(242,177,121)); //8
+ m_skin.push_back(sf::Color(245,149,99)); //16
+ m_skin.push_back(sf::Color(246,124,95)); //32
+ m_skin.push_back(sf::Color(246,94,59)); //64
+
+ //Skin 128 à 2048
+ m_skin.push_back(sf::Color(237,207,114)); //128
+ m_skin.push_back(sf::Color(237,204,97)); //256
+ m_skin.push_back(sf::Color(237,200,80)); //512
+ m_skin.push_back(sf::Color(237,197,63)); //1024
+ m_skin.push_back(sf::Color(238,194,46)); //2048
+
+ //Skin for other number
+ m_skin.push_back(sf::Color(60,58,50)); //More than 2048
+
+}
+
+
+MainWindow::~MainWindow(){
+}
+
+void MainWindow::clearBG(){
+ RenderWindow::clear(m_skin.at(0));
+}
+
+
+void MainWindow::drawGrid(std::vector<std::vector<int> > grid, bool gameIsOver){
+
+
+ //First draw the grid
+ int gridX=m_gridPosition.x;
+ int gridY=m_gridPosition.y;
+
+ m_gridSize.x=(grid.at(0).size()*m_cellSize.x)+(grid.at(0).size()*m_spaceBetweenCell)+m_spaceBetweenCell;
+ m_gridSize.y=(grid.size()*m_cellSize.y)+(grid.size()*m_spaceBetweenCell)+m_spaceBetweenCell;
+
+ //Center:
+ m_gridPosition.x=m_windowSize.x/2-m_gridSize.x/2;
+ m_gridPosition.y=220;
+
+
+ //Draw the grid
+ sf::RectangleShape gridShape(sf::Vector2f(m_gridSize.x,m_gridSize.y));
+ gridShape.setFillColor(m_skin.at(2));
+ gridShape.setPosition(gridX,gridY);
+ RenderWindow::draw(gridShape);
+
+ for(int i=0;i<grid.size();i++){
+
+ for(int j=0;j<grid.at(0).size();j++){
+
+ int cellX=(gridX+m_spaceBetweenCell)+j*(m_cellSize.x+m_spaceBetweenCell);
+ int cellY=(gridY+m_spaceBetweenCell)+i*(m_cellSize.y+m_spaceBetweenCell);
+ int value=grid.at(i).at(j);
+
+ this->drawCell(cellX,cellY,value);
+
+ }
+
+ }
+
+ if(gameIsOver)
+ this->drawGameOver(gridX,gridY);
+}
+
+
+void MainWindow::drawCell(int x, int y, int value){
+
+ //Init RectangleShape
+ sf::RectangleShape cell(sf::Vector2f(m_cellSize.x, m_cellSize.y));
+
+ //Define color, checking skin
+ cell.setFillColor(this->getCellColor(value));
+
+ //Set position
+ cell.setPosition(x,y);
+
+ //Draw the cell
+ RenderWindow::draw(cell);
+
+
+ std::stringstream valueStream;
+ valueStream << value;
+
+ std::string valueString(valueStream.str());
+
+ int fontSize(m_cellSize.x/2);
+ int fontSizeFact=15;
+ if(value>=1024)
+ fontSize-=fontSizeFact;
+ int valueSize(valueString.size());
+
+
+ int fontX=x+(m_cellSize.x/2)-((valueSize*(fontSize-20))/2);
+ int fontY=y+(m_cellSize.y/2)-(fontSize/2)-9;
+
+
+ sf::Text text;
+ text.setFont(m_font);
+ text.setStyle(sf::Text::Bold);
+ text.setCharacterSize(fontSize);
+ text.setString(valueString);
+ if(value==2 || value==4)
+ text.setColor(m_skin.at(3));
+ else
+ text.setColor(m_skin.at(4));
+ text.setPosition(fontX,fontY);
+
+ if(value != 0)
+ RenderWindow::draw(text);
+}
+
+sf::Color MainWindow::getCellColor(int value){
+
+ //Id of the first cell color skin
+ int idStart=7;
+
+ if(value==0){
+ return m_skin.at(1);
+ }
+ else if(value%2==0){
+ int result(value);
+ int id(idStart);
+ while(result!=2){
+ result/=2;
+ id++;
+ }
+ return m_skin.at(id);
+ }
+
+ return m_skin.at(idStart+11);
+}
+
+void MainWindow::drawGameOver(int gridX, int gridY){
+
+ sf::RectangleShape gridShape(sf::Vector2f(m_gridSize.x,m_gridSize.y));
+ gridShape.setFillColor(m_skin.at(6));
+ gridShape.setPosition(gridX,gridY);
+ RenderWindow::draw(gridShape);
+}
+
+
+void MainWindow::drawATH(Stats stats){
+
+ int titleX=m_gridPosition.x;
+ int titleY=m_gridPosition.y-190;
+
+
+ //==================== Draw title ====================
+ sf::Text text;
+ text.setFont(m_font);
+ text.setStyle(sf::Text::Bold);
+ text.setCharacterSize(80);
+ text.setColor(m_skin.at(3));
+ text.setPosition(titleX,titleY);
+ text.setString("2048");
+
+ RenderWindow::draw(text);
+
+
+ //==================== Draw best score ====================
+
+ int scoreAndBestScoreFontSize(20);
+
+ int bestScoreSizeX=110;
+ int bestScoreSizeY=60;
+ int bestScoreX=m_gridPosition.x+m_gridSize.x-bestScoreSizeX;
+ int bestScoreY=titleY+25;
+
+ sf::RectangleShape bestScoreShape(sf::Vector2f(bestScoreSizeX,bestScoreSizeY));
+ bestScoreShape.setFillColor(m_skin.at(2));
+ bestScoreShape.setPosition(bestScoreX,bestScoreY);
+ RenderWindow::draw(bestScoreShape);
+
+ text.setString("BEST");
+ text.setPosition(bestScoreX+bestScoreSizeY-scoreAndBestScoreFontSize-5,bestScoreY+12);
+ text.setCharacterSize(scoreAndBestScoreFontSize-5);
+ text.setColor(m_skin.at(7));
+
+ RenderWindow::draw(text);
+
+ //==================== Draw score ====================
+
+ int scoreX=bestScoreX-bestScoreSizeX-5;
+ int scoreY=bestScoreY;
+ int scoreSizeX=bestScoreSizeX;
+ int scoreSizeY=bestScoreSizeY;
+ int scoreLength=std::to_string(stats.getScore()).size();
+
+ sf::RectangleShape scoreShape(sf::Vector2f(scoreSizeX,scoreSizeY));
+ scoreShape.setFillColor(m_skin.at(2));
+ scoreShape.setPosition(scoreX,scoreY);
+ RenderWindow::draw(scoreShape);
+
+
+ text.setString("SCORE");
+ text.setPosition(scoreX+scoreSizeY-scoreAndBestScoreFontSize-10,scoreY+12);
+ text.setCharacterSize(scoreAndBestScoreFontSize-5);
+ text.setColor(m_skin.at(7));
+
+ RenderWindow::draw(text);
+
+ text.setString(std::to_string(stats.getScore()));
+ text.setPosition(scoreX+scoreSizeY-((scoreLength+20)/2)-scoreAndBestScoreFontSize+10,scoreY+scoreSizeY - scoreAndBestScoreFontSize-10);
+ text.setCharacterSize(scoreAndBestScoreFontSize);
+ text.setColor(sf::Color::White);
+
+ RenderWindow::draw(text);
+}
+
+void MainWindow::drawGame(std::vector<std::vector<int> > grid, bool gameIsOver, Stats stats){
+ this->drawGrid(grid,gameIsOver);
+ this->drawATH(stats);
+}
diff --git a/src/View/MainWindow.hpp b/src/View/MainWindow.hpp
new file mode 100644
index 0000000..072a7ec
--- /dev/null
+++ b/src/View/MainWindow.hpp
@@ -0,0 +1,43 @@
+
+
+
+#include <iostream>
+#include <vector>
+#include <string>
+#include <sstream>
+#include "../Model/Stats.hpp"
+#include <SFML/Window.hpp>
+#include <SFML/Graphics.hpp>
+
+
+class MainWindow : public sf::RenderWindow{
+
+ private:
+ std::vector<sf::Color> m_skin;
+ //int m_windowMargin;
+ //int m_sizeCell;
+
+ sf::Font m_font;
+ //Coordonates
+ sf::Vector2u m_windowSize;
+ sf::Vector2u m_gridSize;
+ sf::Vector2u m_cellSize;
+
+ sf::Vector2u m_gridPosition;
+ int m_spaceBetweenCell;
+
+ public:
+ MainWindow(int width, int height, std::string title);
+ ~MainWindow();
+
+ void clearBG();
+ void drawGrid(std::vector<std::vector<int> > grid, bool gameIsOver);
+ void drawCell(int x, int y, int value);
+ sf::Color getCellColor(int value);
+
+ void drawGameOver(int gridX, int griY);
+
+ void drawATH(Stats stats);
+
+ void drawGame(std::vector<std::vector<int> > grid, bool gameIsOver, Stats stats);
+};
diff --git a/src/main.cpp b/src/main.cpp
index 48c1766..70f3a6b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -6,7 +6,7 @@
//----------------------
//----- Personnal include -----
-#include "./Controllers/ConsoleController/ConsoleController.hpp"
+#include "./Controllers/SFMLController/SFMLController.hpp"
//-----------------------------
@@ -20,7 +20,7 @@ int main()
srand(time(NULL));
//Init controller
- ConsoleController controller;
+ SFMLController controller;
//Run the game
controller.run();
diff --git a/src/skin/original/Pragmatica-Medium.ttf b/src/skin/original/Pragmatica-Medium.ttf
new file mode 100644
index 0000000..f5fee8d
--- /dev/null
+++ b/src/skin/original/Pragmatica-Medium.ttf
Binary files differ