Did things
This commit is contained in:
parent
09bce989d2
commit
f2822815dd
@ -50,7 +50,7 @@ private:
|
|||||||
ConfigData confData;
|
ConfigData confData;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief
|
* @brief ScoresManager : utility to handle score saving and signing
|
||||||
*/
|
*/
|
||||||
ScoresManager sm;
|
ScoresManager sm;
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ public:
|
|||||||
* @param[]
|
* @param[]
|
||||||
* @fn
|
* @fn
|
||||||
*/
|
*/
|
||||||
void drawSprite(const nsGui::Sprite& sprite, const Position& pos) const;
|
void drawSprite(const nsGui::Sprite& sprite, const Position& pos = Position(0, 0)) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief
|
* @brief
|
||||||
@ -162,16 +162,6 @@ public:
|
|||||||
* @param[]
|
* @param[]
|
||||||
* @fn
|
* @fn
|
||||||
*/
|
*/
|
||||||
void drawGameBackground() const;
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* @brief
|
|
||||||
* @param[]
|
|
||||||
* @fn
|
|
||||||
*/
|
|
||||||
void drawMenuBackground() const;
|
|
||||||
|
|
||||||
// TODO remove because unused ?
|
|
||||||
void displayText(const Position& pos, const string& text, const nsGraphics::RGBAcolor& color = nsGraphics::KWhite) const;
|
void displayText(const Position& pos, const string& text, const nsGraphics::RGBAcolor& color = nsGraphics::KWhite) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -182,8 +172,7 @@ public:
|
|||||||
void drawFPS(unsigned fps) const;
|
void drawFPS(unsigned fps) const;
|
||||||
|
|
||||||
PlayMode showInitialMenu();
|
PlayMode showInitialMenu();
|
||||||
PlayMode showDeathMenu();
|
bool showDeathMenu();
|
||||||
string nameMenu(playerID pID);
|
|
||||||
|
|
||||||
unsigned getScreenHeight() const;
|
unsigned getScreenHeight() const;
|
||||||
unsigned getScreenWidth() const;
|
unsigned getScreenWidth() const;
|
||||||
|
@ -21,13 +21,13 @@ using namespace std;
|
|||||||
struct ScoreLink{
|
struct ScoreLink{
|
||||||
string name;
|
string name;
|
||||||
unsigned score;
|
unsigned score;
|
||||||
ScoreLink(const string& name, unsigned score);
|
ScoreLink(string&& name, unsigned score);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ScoresManager {
|
class ScoresManager {
|
||||||
public:
|
public:
|
||||||
vector<ScoreLink> scores;
|
vector<ScoreLink> scores;
|
||||||
void inputScore(const string& name, unsigned score);
|
void inputScore(string&& name, unsigned score);
|
||||||
void readFile();
|
void readFile();
|
||||||
void writeFile() const;
|
void writeFile() const;
|
||||||
};
|
};
|
||||||
|
@ -69,11 +69,6 @@ void PixelManager::drawPlayer(unsigned x, unsigned width, const nsGraphics::RGBA
|
|||||||
window << Triangle(Position(15+width+x,720-PLAYER_HEIGHT/2), Position(15+width*2+x,720-PLAYER_HEIGHT/2), Position(15+width+x,720-PLAYER_HEIGHT*0.9), color);
|
window << Triangle(Position(15+width+x,720-PLAYER_HEIGHT/2), Position(15+width*2+x,720-PLAYER_HEIGHT/2), Position(15+width+x,720-PLAYER_HEIGHT*0.9), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::askPlayerNameMenu(playerID pID, string& name) {
|
|
||||||
cout << "ask for player " << (pID+1) << endl;
|
|
||||||
name = nameMenu(pID);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PixelManager::drawMissile(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const {
|
void PixelManager::drawMissile(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const {
|
||||||
window << Rectangle(baseVector, baseVector + Position(width, width * PROJ_LENGTH_FACTOR), color);
|
window << Rectangle(baseVector, baseVector + Position(width, width * PROJ_LENGTH_FACTOR), color);
|
||||||
}
|
}
|
||||||
@ -88,14 +83,6 @@ void PixelManager::drawSprite(const Sprite& sprite, const Position& pos) const {
|
|||||||
sprite.draw(window);
|
sprite.draw(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::drawGameBackground() const {
|
|
||||||
gameBackground.draw(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PixelManager::drawMenuBackground() const {
|
|
||||||
menuBackground.draw(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned PixelManager::getScreenHeight() const {
|
unsigned PixelManager::getScreenHeight() const {
|
||||||
return window.getWindowSize().getY();
|
return window.getWindowSize().getY();
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ void PixelManager::displayButton(const Position& baseVector,const string& text,n
|
|||||||
|
|
||||||
void PixelManager::displayMenu(const Position& pos, Menu& currentMenu){
|
void PixelManager::displayMenu(const Position& pos, Menu& currentMenu){
|
||||||
startFrame();
|
startFrame();
|
||||||
drawMenuBackground();
|
drawSprite(menuBackground);
|
||||||
drawSprite(logo,Position(100,50));
|
drawSprite(logo,Position(100,50));
|
||||||
displayText(Position(1150,700), "version 1.0.0");
|
displayText(Position(1150,700), "version 1.0.0");
|
||||||
size_t margin = 0;
|
size_t margin = 0;
|
||||||
@ -74,15 +74,16 @@ PlayMode PixelManager::showInitialMenu(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
string PixelManager::nameMenu(playerID pID){
|
void PixelManager::askPlayerNameMenu(playerID pID, string& name) {
|
||||||
string name (6,'A');
|
name = string(6, 'A');
|
||||||
size_t currentSelected = 0 ;
|
size_t currentSelected = 0 ;
|
||||||
chrono::milliseconds waitTime = chrono::milliseconds(100);
|
chrono::milliseconds waitTime = chrono::milliseconds(100);
|
||||||
while (window.isOpen()){
|
while (window.isOpen()){
|
||||||
startFrame();
|
startFrame();
|
||||||
drawMenuBackground();
|
drawSprite(menuBackground);
|
||||||
displayText(Position(600,100),"Nom du joueur "+ string(1,pID));
|
displayText(Position(600,100),"Nom du joueur "+ string(1,pID));
|
||||||
for (size_t i = 0; i < name.size(); ++i){
|
for (size_t i = 0; i < name.size(); ++i){
|
||||||
displayText(Position(600+30*i,200),string(1,name[i]),(i == currentSelected) ? nsGraphics::KRed : nsGraphics::KWhite);
|
displayText(Position(600+30*i,200),string(1,name[i]),(i == currentSelected) ? nsGraphics::KRed : nsGraphics::KWhite);
|
||||||
@ -115,14 +116,19 @@ string PixelManager::nameMenu(playerID pID){
|
|||||||
// select option
|
// select option
|
||||||
else if (window.isPressed({13, false}))
|
else if (window.isPressed({13, false}))
|
||||||
{
|
{
|
||||||
this_thread::sleep_for(waitTime);
|
window.resetKey({13, false});
|
||||||
return name;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayMode PixelManager::showDeathMenu() {
|
/**
|
||||||
vector<string> entries {"main menu","exit"};
|
*
|
||||||
|
* @return true if the player plays again
|
||||||
|
*/
|
||||||
|
bool PixelManager::showDeathMenu() {
|
||||||
|
vector<string> entries {"retry","main menu"};
|
||||||
Menu death {entries,0,nsGraphics::KRed,nsGraphics::KWhite};
|
Menu death {entries,0,nsGraphics::KRed,nsGraphics::KWhite};
|
||||||
const unsigned xOffset = getScreenHeight() / 2 ;
|
const unsigned xOffset = getScreenHeight() / 2 ;
|
||||||
const unsigned yOffset = getScreenWidth() / 2 - 90;
|
const unsigned yOffset = getScreenWidth() / 2 - 90;
|
||||||
@ -144,14 +150,13 @@ PlayMode PixelManager::showDeathMenu() {
|
|||||||
else if (window.isPressed({13, false})){
|
else if (window.isPressed({13, false})){
|
||||||
switch(death.currentValue){
|
switch(death.currentValue){
|
||||||
case 0:
|
case 0:
|
||||||
return PlayMode::NONE;
|
return true;
|
||||||
case 1:
|
case 1:
|
||||||
return PlayMode::EXIT;
|
return false;
|
||||||
default:
|
|
||||||
return PlayMode::EXIT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* The more important stuff must be drawn last
|
* The more important stuff must be drawn last
|
||||||
*/
|
*/
|
||||||
void Game::displayAll(unsigned fps) const {
|
void Game::displayAll(unsigned fps) const {
|
||||||
pm.drawGameBackground();
|
pm.drawSprite(pm.gameBackground);
|
||||||
for (unsigned i = 0; i < this->grid.size(); ++i){
|
for (unsigned i = 0; i < this->grid.size(); ++i){
|
||||||
for (unsigned j = 0; j < this->grid[i].size(); ++j){
|
for (unsigned j = 0; j < this->grid[i].size(); ++j){
|
||||||
Position vec(
|
Position vec(
|
||||||
|
@ -39,15 +39,13 @@ bool Game::updateColumns(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::handleScoreSaving(){
|
void Game::handleScoreSaving(){
|
||||||
cout << players[0].score << endl; // will remove
|
|
||||||
|
|
||||||
string pName;
|
string pName;
|
||||||
pm.askPlayerNameMenu(0, pName);
|
pm.askPlayerNameMenu(PLAYER1, pName);
|
||||||
sm.inputScore(pName, players[0].score);
|
sm.inputScore(move(pName), players[0].score);
|
||||||
if(playMode==PlayMode::TWO_LOCAL){
|
if(playMode==PlayMode::TWO_LOCAL){
|
||||||
string pName2;
|
string pName2;
|
||||||
pm.askPlayerNameMenu(1, pName2);
|
pm.askPlayerNameMenu(PLAYER2, pName2);
|
||||||
sm.inputScore(pName, players[1].score);
|
sm.inputScore(move(pName2), players[1].score);
|
||||||
}
|
}
|
||||||
sm.writeFile();
|
sm.writeFile();
|
||||||
}
|
}
|
||||||
@ -65,7 +63,7 @@ void Game::managedGames() {
|
|||||||
enterGameLoop(); // will read the playMode
|
enterGameLoop(); // will read the playMode
|
||||||
handleScoreSaving();
|
handleScoreSaving();
|
||||||
cout << "END OF GAME" << endl;
|
cout << "END OF GAME" << endl;
|
||||||
playMode = pm.showDeathMenu();
|
if(!pm.showDeathMenu())playMode = PlayMode::NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,10 +81,12 @@ void ScoresManager::writeFile() const {
|
|||||||
ofs << hasher(str+SECRET_KEY) << endl << str;
|
ofs << hasher(str+SECRET_KEY) << endl << str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SCORE_LIMIT 10
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insertion sort, probably the most efficient here
|
* Insertion sort, probably the most efficient here
|
||||||
*/
|
*/
|
||||||
void ScoresManager::inputScore(const string& name, unsigned score) {
|
void ScoresManager::inputScore(string&& name, unsigned score) {
|
||||||
auto ite = scores.begin();
|
auto ite = scores.begin();
|
||||||
while(ite!=scores.end()){
|
while(ite!=scores.end()){
|
||||||
if(score > ite->score) {
|
if(score > ite->score) {
|
||||||
@ -94,12 +96,11 @@ void ScoresManager::inputScore(const string& name, unsigned score) {
|
|||||||
++ite;
|
++ite;
|
||||||
}
|
}
|
||||||
if(ite==scores.end())scores.emplace(ite, name, score);
|
if(ite==scores.end())scores.emplace(ite, name, score);
|
||||||
if(scores.size()==6)scores.pop_back();
|
if(scores.size()>SCORE_LIMIT)scores.erase(scores.begin()+SCORE_LIMIT);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not sure if I should use move semantics
|
ScoreLink::ScoreLink(string&& name, unsigned int score) {
|
||||||
ScoreLink::ScoreLink(const string& name, unsigned int score) {
|
|
||||||
this->name = name;
|
this->name = name;
|
||||||
this->score = score;
|
this->score = score;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user