COOOOOOONST
This commit is contained in:
parent
8ace7d1d01
commit
994a073ee5
4
README
4
README
@ -5,6 +5,10 @@ Nommage en anglais
|
|||||||
Pas de fonctions de +100 lignes
|
Pas de fonctions de +100 lignes
|
||||||
Les guards sont de cette forme : GUARD_<filename>_H
|
Les guards sont de cette forme : GUARD_<filename>_H
|
||||||
|
|
||||||
|
Concernant les const :
|
||||||
|
Afin de limiter l'utilisation du mot const (pour garder une certaine lisibilité du code), les cas suivants n'ont pas besoin d'etre déclarés comme const :
|
||||||
|
- déclaration/défintion de fonctions : les types primitifs/valeurs d'enum passés par valeurs ne sont pas notés const
|
||||||
|
|
||||||
écran : constante 1280x720
|
écran : constante 1280x720
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,9 +40,9 @@ private:
|
|||||||
void handleScoreSaving();
|
void handleScoreSaving();
|
||||||
|
|
||||||
// drawing methods
|
// drawing methods
|
||||||
void display();
|
void display() const;
|
||||||
void displayGod();
|
void displayGod() const;
|
||||||
void displayInvader(const Position& basePos, unsigned size, InvaderType type);
|
void displayInvader(const Position& basePos, unsigned size, InvaderType type) const;
|
||||||
|
|
||||||
|
|
||||||
// managers
|
// managers
|
||||||
@ -56,7 +56,7 @@ private:
|
|||||||
void moveTorpedos();
|
void moveTorpedos();
|
||||||
bool checkMissilesAndPlayers();
|
bool checkMissilesAndPlayers();
|
||||||
bool checkTorpedosAndInvaders();
|
bool checkTorpedosAndInvaders();
|
||||||
bool invadersTouchPlayer();
|
bool invadersTouchPlayer() const;
|
||||||
|
|
||||||
// god things
|
// god things
|
||||||
void manageGod();
|
void manageGod();
|
||||||
@ -67,8 +67,6 @@ public:
|
|||||||
Game();
|
Game();
|
||||||
void managedGames();
|
void managedGames();
|
||||||
WinValue playGame();
|
WinValue playGame();
|
||||||
PlayMode initialMenuHandler();
|
|
||||||
bool deathMenuHandler();
|
|
||||||
|
|
||||||
bool reloadConfig();
|
bool reloadConfig();
|
||||||
};
|
};
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "mingl/shape/circle.h"
|
#include "mingl/shape/circle.h"
|
||||||
#include "mingl/gui/sprite.h"
|
#include "mingl/gui/sprite.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "playMode.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace nsGraphics;
|
using namespace nsGraphics;
|
||||||
@ -21,28 +22,28 @@ public:
|
|||||||
|
|
||||||
explicit PixelManager(MinGL&);
|
explicit PixelManager(MinGL&);
|
||||||
|
|
||||||
void drawInvaderA(const Position& baseVector, unsigned size, RGBAcolor& color);
|
void drawInvaderA(const Position& baseVector, unsigned size, const RGBAcolor& color) const;
|
||||||
void drawInvaderB(const Position& baseVector, unsigned size, RGBAcolor& color);
|
void drawInvaderB(const Position& baseVector, unsigned size, const RGBAcolor& color) const;
|
||||||
void drawInvaderC(const Position& baseVector, unsigned size, RGBAcolor& color);
|
void drawInvaderC(const Position& baseVector, unsigned size, const RGBAcolor& color) const;
|
||||||
void drawPlayer(const unsigned x, unsigned width, const nsGraphics::RGBAcolor& color);
|
void drawPlayer(unsigned x, unsigned width, const nsGraphics::RGBAcolor& color) const;
|
||||||
void drawTorpedo(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color);
|
void drawTorpedo(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const;
|
||||||
void drawMissile(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color);
|
void drawMissile(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const;
|
||||||
void drawBackground();
|
void drawBackground() const;
|
||||||
|
|
||||||
unsigned showInitialMenu();
|
PlayMode showInitialMenu() const;
|
||||||
unsigned showDeathMenu();
|
bool showDeathMenu() const;
|
||||||
unsigned getScreenHeight();
|
unsigned getScreenHeight() const;
|
||||||
unsigned getScreenWidth();
|
unsigned getScreenWidth() const;
|
||||||
void startFrame();
|
void startFrame() const;
|
||||||
void endFrame();
|
void endFrame() const;
|
||||||
|
|
||||||
void askPlayerNameMenu(playerID pID, string& name);
|
void askPlayerNameMenu(playerID pID, string& name) const;
|
||||||
|
|
||||||
// y will be negative sometimes, so not unsigned
|
// y will be negative sometimes, so not unsigned
|
||||||
void displayGodBench(int y);
|
void displayGodBench(int y) const;
|
||||||
|
|
||||||
void displayGodRightHand(const Position& pos);
|
void displayGodRightHand(const Position& pos) const;
|
||||||
void displayGodLeftHand(const Position& pos);
|
void displayGodLeftHand(const Position& pos) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ public:
|
|||||||
vector<ScoreLink> scores;
|
vector<ScoreLink> scores;
|
||||||
void inputScore(const string& name, unsigned score);
|
void inputScore(const string& name, unsigned score);
|
||||||
void readFile();
|
void readFile();
|
||||||
void writeFile();
|
void writeFile() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +27,8 @@ enum class InvaderType {
|
|||||||
};
|
};
|
||||||
class InvadersColumn : public vector<InvaderType>{
|
class InvadersColumn : public vector<InvaderType>{
|
||||||
public:
|
public:
|
||||||
size_t getOutterInvader();
|
// idk why CLion says this is not implemented, but it is
|
||||||
|
size_t getOutterInvader() const;
|
||||||
};
|
};
|
||||||
typedef vector<InvadersColumn> InvadersGrid;
|
typedef vector<InvadersColumn> InvadersGrid;
|
||||||
typedef nsGraphics::Vec2D Position; // in case we need to ad dmore methods, we defined our own type
|
typedef nsGraphics::Vec2D Position; // in case we need to ad dmore methods, we defined our own type
|
||||||
|
@ -6,21 +6,21 @@ public:
|
|||||||
ConfigData collectedData;
|
ConfigData collectedData;
|
||||||
void parseFile(const string& fname);
|
void parseFile(const string& fname);
|
||||||
void readConfig();
|
void readConfig();
|
||||||
void dumpInternalValues();
|
void dumpInternalValues() const;
|
||||||
private:
|
private:
|
||||||
map<string, string> internalValues;
|
map<string, string> internalValues;
|
||||||
string& getString(const configKey& key);
|
const string& getString(const configKey& key) const;
|
||||||
char getChar(const configKey& key);
|
char getChar(const configKey& key) const;
|
||||||
int getInt(const configKey& key);
|
int getInt(const configKey& key) const;
|
||||||
nsGraphics::RGBAcolor getColor(const configKey& key);
|
void getColor(const configKey& key, nsGraphics::RGBAcolor&) const;
|
||||||
void getList(const configKey& key, vector<string>&);
|
void getList(const configKey& key, vector<string>&) const;
|
||||||
|
|
||||||
void readGrid(const configKey& key);
|
void readGrid(const configKey& baseKey);
|
||||||
void readPlayer(const configKey& baseKey, PlayerDef&);
|
void readPlayer(const configKey& baseKey, PlayerDef&);
|
||||||
void readInvaderType(const configKey& baseKey, InvaderTypeDef&);
|
void readInvaderType(const configKey& baseKey, InvaderTypeDef&);
|
||||||
};
|
};
|
||||||
|
|
||||||
void ConfigBuilder::dumpInternalValues(){
|
void ConfigBuilder::dumpInternalValues() const {
|
||||||
for(const auto& ite : internalValues){
|
for(const auto& ite : internalValues){
|
||||||
cerr << ite.first << " -> " << ite.second << endl;
|
cerr << ite.first << " -> " << ite.second << endl;
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ void ConfigBuilder::parseFile(const string& fname) {
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigBuilder::readGrid(const configKey& key){
|
void ConfigBuilder::readGrid(const configKey& baseKey) {
|
||||||
vector<string> tmp;
|
vector<string> tmp;
|
||||||
getList("grid", tmp);
|
getList("grid", tmp);
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ void ConfigBuilder::readGrid(const configKey& key){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ConfigBuilder::readPlayer(const configKey& baseKey, PlayerDef& pdef) {
|
void ConfigBuilder::readPlayer(const configKey& baseKey, PlayerDef& pdef) {
|
||||||
pdef.color = getColor(baseKey+".color");
|
getColor(baseKey+".color", pdef.color);
|
||||||
pdef.keys.left = getChar(baseKey+".keys.left");
|
pdef.keys.left = getChar(baseKey+".keys.left");
|
||||||
pdef.keys.right = getChar(baseKey+".keys.right");
|
pdef.keys.right = getChar(baseKey+".keys.right");
|
||||||
pdef.keys.shoot = getChar(baseKey+".keys.shoot");
|
pdef.keys.shoot = getChar(baseKey+".keys.shoot");
|
||||||
@ -155,7 +155,7 @@ void ConfigBuilder::readPlayer(const configKey& baseKey, PlayerDef& pdef){
|
|||||||
|
|
||||||
void ConfigBuilder::readInvaderType(const configKey& baseKey, InvaderTypeDef& invDef) {
|
void ConfigBuilder::readInvaderType(const configKey& baseKey, InvaderTypeDef& invDef) {
|
||||||
invDef.points = getInt(baseKey+".points");
|
invDef.points = getInt(baseKey+".points");
|
||||||
invDef.color = getColor(baseKey+".color");
|
getColor(baseKey+".color", invDef.color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigBuilder::readConfig() {
|
void ConfigBuilder::readConfig() {
|
||||||
@ -188,23 +188,23 @@ void ConfigBuilder::readConfig() {
|
|||||||
collectedData.missilesWidth = getInt("projectiles.missiles.width");
|
collectedData.missilesWidth = getInt("projectiles.missiles.width");
|
||||||
collectedData.missilesLength = collectedData.missilesWidth*PROJ_LENGTH_FACTOR;
|
collectedData.missilesLength = collectedData.missilesWidth*PROJ_LENGTH_FACTOR;
|
||||||
collectedData.missilesSpeed = getInt("projectiles.missiles.speed");
|
collectedData.missilesSpeed = getInt("projectiles.missiles.speed");
|
||||||
collectedData.missilesColor = getColor("projectiles.missiles.color");
|
getColor("projectiles.missiles.color", collectedData.missilesColor);
|
||||||
|
|
||||||
collectedData.torpedosWidth = getInt("projectiles.torpedos.width");
|
collectedData.torpedosWidth = getInt("projectiles.torpedos.width");
|
||||||
collectedData.torpedosLength = collectedData.torpedosWidth*PROJ_LENGTH_FACTOR;
|
collectedData.torpedosLength = collectedData.torpedosWidth*PROJ_LENGTH_FACTOR;
|
||||||
collectedData.torpedosSpeed = getInt("projectiles.torpedos.speed");
|
collectedData.torpedosSpeed = getInt("projectiles.torpedos.speed");
|
||||||
collectedData.torpedosColor = getColor("projectiles.torpedos.color");
|
getColor("projectiles.torpedos.color", collectedData.torpedosColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigBuilder::getInt(const configKey& key) {
|
int ConfigBuilder::getInt(const configKey& key) const {
|
||||||
return stoi(getString(key));
|
return stoi(getString(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
char ConfigBuilder::getChar(const configKey& key) {
|
char ConfigBuilder::getChar(const configKey& key) const {
|
||||||
return getString(key)[0];
|
return getString(key)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
string& ConfigBuilder::getString(const configKey& key) {
|
const string& ConfigBuilder::getString(const configKey& key) const {
|
||||||
if(internalValues.contains(key)){
|
if(internalValues.contains(key)){
|
||||||
return internalValues.at(key);
|
return internalValues.at(key);
|
||||||
}else{
|
}else{
|
||||||
@ -212,7 +212,7 @@ string& ConfigBuilder::getString(const configKey& key) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigBuilder::getList(const configKey& key, vector<string>& toPopulate) {
|
void ConfigBuilder::getList(const configKey& key, vector<string>& toPopulate) const {
|
||||||
size_t i=0;
|
size_t i=0;
|
||||||
string fullKey = key+".0";
|
string fullKey = key+".0";
|
||||||
if(!internalValues.contains(fullKey))throw runtime_error("Non-existent list key requested : "+key);
|
if(!internalValues.contains(fullKey))throw runtime_error("Non-existent list key requested : "+key);
|
||||||
@ -224,25 +224,25 @@ void ConfigBuilder::getList(const configKey& key, vector<string>& toPopulate) {
|
|||||||
}while(internalValues.contains(key+"."+to_string(i)));
|
}while(internalValues.contains(key+"."+to_string(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
nsGraphics::RGBAcolor ConfigBuilder::getColor(const configKey& key) {
|
void ConfigBuilder::getColor(const configKey& key, nsGraphics::RGBAcolor& color) const {
|
||||||
// switch do not work with strings, and I don't want to implement a constexpr hash function
|
// switch do not work with strings, and I don't want to implement a constexpr hash function
|
||||||
string colorStr = getString(key);
|
string colorStr = getString(key);
|
||||||
if (colorStr == "black")return nsGraphics::KBlack;
|
if (colorStr == "black")color = nsGraphics::KBlack;
|
||||||
else if (colorStr == "white")return nsGraphics::KWhite;
|
else if (colorStr == "white")color = nsGraphics::KWhite;
|
||||||
else if (colorStr == "red")return nsGraphics::KRed;
|
else if (colorStr == "red")color = nsGraphics::KRed;
|
||||||
else if (colorStr == "lime")return nsGraphics::KLime;
|
else if (colorStr == "lime")color = nsGraphics::KLime;
|
||||||
else if (colorStr == "blue")return nsGraphics::KBlue;
|
else if (colorStr == "blue")color = nsGraphics::KBlue;
|
||||||
else if (colorStr == "yellow")return nsGraphics::KYellow;
|
else if (colorStr == "yellow")color = nsGraphics::KYellow;
|
||||||
else if (colorStr == "cyan")return nsGraphics::KCyan;
|
else if (colorStr == "cyan")color = nsGraphics::KCyan;
|
||||||
else if (colorStr == "magenta")return nsGraphics::KMagenta;
|
else if (colorStr == "magenta")color = nsGraphics::KMagenta;
|
||||||
else if (colorStr == "silver")return nsGraphics::KSilver;
|
else if (colorStr == "silver")color = nsGraphics::KSilver;
|
||||||
else if (colorStr == "gray")return nsGraphics::KGray;
|
else if (colorStr == "gray")color = nsGraphics::KGray;
|
||||||
else if (colorStr == "maroon")return nsGraphics::KMaroon;
|
else if (colorStr == "maroon")color = nsGraphics::KMaroon;
|
||||||
else if (colorStr == "olive")return nsGraphics::KOlive;
|
else if (colorStr == "olive")color = nsGraphics::KOlive;
|
||||||
else if (colorStr == "green")return nsGraphics::KGreen;
|
else if (colorStr == "green")color = nsGraphics::KGreen;
|
||||||
else if (colorStr == "purple")return nsGraphics::KPurple;
|
else if (colorStr == "purple")color = nsGraphics::KPurple;
|
||||||
else if (colorStr == "teal")return nsGraphics::KTeal;
|
else if (colorStr == "teal")color = nsGraphics::KTeal;
|
||||||
else if (colorStr == "navy")return nsGraphics::KNavy;
|
else if (colorStr == "navy")color = nsGraphics::KNavy;
|
||||||
else throw runtime_error("Invalid color string : "+colorStr);
|
else throw runtime_error("Invalid color string : "+colorStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
/** Displays the screen once, and returns
|
/** Displays the screen once, and returns
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void Game::display() {
|
void Game::display() const {
|
||||||
pm.drawBackground();
|
pm.drawBackground();
|
||||||
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){
|
||||||
@ -16,10 +16,10 @@ void Game::display() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(missile& miss : missiles){
|
for(const missile& miss : missiles){
|
||||||
pm.drawMissile(miss, confData.missilesWidth, confData.missilesColor);
|
pm.drawMissile(miss, confData.missilesWidth, confData.missilesColor);
|
||||||
}
|
}
|
||||||
for(torpedo& tor : torpedos){
|
for(const torpedo& tor : torpedos){
|
||||||
pm.drawTorpedo(tor, confData.torpedosWidth, confData.torpedosColor);
|
pm.drawTorpedo(tor, confData.torpedosWidth, confData.torpedosColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,9 +30,9 @@ void Game::display() {
|
|||||||
displayGod();
|
displayGod();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::displayInvader(const Position& pos, unsigned size, InvaderType type){
|
void Game::displayInvader(const Position& pos, unsigned size, InvaderType type) const {
|
||||||
if(type==InvaderType::NONE)return;
|
if(type==InvaderType::NONE)return;
|
||||||
InvaderTypeDef invDef = confData.invadersDef[type];
|
InvaderTypeDef invDef = confData.invadersDef.at(type);
|
||||||
switch(type){
|
switch(type){
|
||||||
case InvaderType::TYPEA:{
|
case InvaderType::TYPEA:{
|
||||||
pm.drawInvaderA(pos, size, invDef.color);
|
pm.drawInvaderA(pos, size, invDef.color);
|
||||||
|
@ -45,13 +45,13 @@ void Game::managedGames() {
|
|||||||
|
|
||||||
while(playMode!=PlayMode::EXIT){
|
while(playMode!=PlayMode::EXIT){
|
||||||
if(playMode==PlayMode::NONE){
|
if(playMode==PlayMode::NONE){
|
||||||
playMode = initialMenuHandler();
|
playMode = pm.showInitialMenu();
|
||||||
}else{
|
}else{
|
||||||
playGame(); // will read the playMode
|
playGame(); // will read the playMode
|
||||||
handleScoreSaving();
|
handleScoreSaving();
|
||||||
cout << "END OF GAME" << endl;
|
cout << "END OF GAME" << endl;
|
||||||
break; // TODO remove
|
break; // TODO remove
|
||||||
if(!deathMenuHandler()) playMode = PlayMode::NONE; // back to the main menu
|
if(!pm.showDeathMenu()) playMode = PlayMode::NONE; // back to the main menu
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,31 +60,6 @@ void Game::managedGames() {
|
|||||||
|
|
||||||
// TODO maybe directly call theses from pm and do not use getters ?
|
// TODO maybe directly call theses from pm and do not use getters ?
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the mode the use chose, we he clicks it
|
|
||||||
*/
|
|
||||||
PlayMode Game::initialMenuHandler(){
|
|
||||||
switch(pm.showInitialMenu()){
|
|
||||||
case 0:{
|
|
||||||
return PlayMode::SINGLE;
|
|
||||||
}
|
|
||||||
case 1:{
|
|
||||||
return PlayMode::TWO_LOCAL;
|
|
||||||
}
|
|
||||||
case 2:{
|
|
||||||
return PlayMode::TWO_TCPIP;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PlayMode::EXIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return if true, the user wants to play again, same mode, false if he wants to go back to the main menu
|
|
||||||
*/
|
|
||||||
bool Game::deathMenuHandler(){
|
|
||||||
return pm.showDeathMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays the game, and returns once the game is finished
|
* Plays the game, and returns once the game is finished
|
||||||
*
|
*
|
||||||
|
@ -201,8 +201,8 @@ bool Game::checkTorpedosAndInvaders() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Game::invadersTouchPlayer(){
|
bool Game::invadersTouchPlayer() const {
|
||||||
for(InvadersColumn& line : grid){
|
for(const InvadersColumn& line : grid){
|
||||||
if(basePos.getY() + line.size() * confData.invadersSize >= pm.getScreenHeight() - PLAYER_HEIGHT){
|
if(basePos.getY() + line.size() * confData.invadersSize >= pm.getScreenHeight() - PLAYER_HEIGHT){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -6,21 +6,37 @@ void Game::manageGod(){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case GodState::LOAD:{
|
case GodState::LOAD:{
|
||||||
++god.counter;
|
|
||||||
if(god.counter==GOD_BENCH_SIZE){
|
if(god.counter==GOD_BENCH_SIZE){
|
||||||
god.counter = 0;
|
god.counter = 0;
|
||||||
god.state = GodState::WAIT;
|
god.state = GodState::WAIT;
|
||||||
|
}else ++god.counter;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
case GodState::WAIT: {
|
||||||
|
if (god.counter == 1000) {
|
||||||
|
// init throw
|
||||||
|
god.counter = 0;
|
||||||
|
god.state = GodState::RETRIEVE1;
|
||||||
|
unsigned rx = rand() % grid.size();
|
||||||
|
unsigned ry = rand() % grid[0].size();
|
||||||
|
god.throwedInvPos.setX(rx);
|
||||||
|
god.throwedInvPos.setY(ry);
|
||||||
|
|
||||||
|
god.thrownInvType = grid[rx][ry];
|
||||||
|
|
||||||
|
god.thrownTransition.setX(GOD_HAND_SIZE);
|
||||||
|
god.thrownTransition.setY(rx);
|
||||||
|
} else ++god.counter;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void applyBezier(Position& pos, const Position& point, double percent){
|
void applyBezier(Position& pos, const Position& point, const double percent) {
|
||||||
pos += (point-pos)*percent;
|
pos += (point-pos)*percent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::displayGod() {
|
void Game::displayGod() const {
|
||||||
switch (god.state) {
|
switch (god.state) {
|
||||||
case GodState::NONE:
|
case GodState::NONE:
|
||||||
return;
|
return;
|
||||||
@ -39,22 +55,6 @@ void Game::displayGod() {
|
|||||||
Position rightHand(pm.getScreenWidth()-GOD_HAND_DISTANCE-GOD_HAND_SIZE, 0);
|
Position rightHand(pm.getScreenWidth()-GOD_HAND_DISTANCE-GOD_HAND_SIZE, 0);
|
||||||
pm.displayGodLeftHand(leftHand);
|
pm.displayGodLeftHand(leftHand);
|
||||||
pm.displayGodRightHand(rightHand);
|
pm.displayGodRightHand(rightHand);
|
||||||
|
|
||||||
++god.counter;
|
|
||||||
if(god.counter==1000){
|
|
||||||
// init throw
|
|
||||||
god.counter = 0;
|
|
||||||
god.state = GodState::RETRIEVE1;
|
|
||||||
unsigned rx = rand()%grid.size();
|
|
||||||
unsigned ry = rand()%grid[0].size();
|
|
||||||
god.throwedInvPos.setX(rx);
|
|
||||||
god.throwedInvPos.setY(ry);
|
|
||||||
|
|
||||||
god.thrownInvType = grid[rx][ry];
|
|
||||||
|
|
||||||
god.thrownTransition.setX(GOD_HAND_SIZE);
|
|
||||||
god.thrownTransition.setY(rx);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GodState::RETRIEVE1:{
|
case GodState::RETRIEVE1:{
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include <playMode.h>
|
||||||
#include "pixelManager.h"
|
#include "pixelManager.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
@ -6,7 +7,7 @@ PixelManager::PixelManager(MinGL& a) : window(a) {
|
|||||||
window.initGraphic();
|
window.initGraphic();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::drawInvaderA(const Position& baseVector, unsigned size, RGBAcolor& color){
|
void PixelManager::drawInvaderA(const Position& baseVector, unsigned size, const RGBAcolor& color) const {
|
||||||
float scale = size/(float)100;
|
float scale = size/(float)100;
|
||||||
window << nsShape::Circle(Position(50*scale, 50*scale)+baseVector, 50*scale, nsGraphics::KGray);
|
window << nsShape::Circle(Position(50*scale, 50*scale)+baseVector, 50*scale, nsGraphics::KGray);
|
||||||
window << nsShape::Triangle(Position(35*scale, 50*scale)+baseVector, Position(15*scale, 25*scale)+baseVector, Position(15*scale, 75*scale)+baseVector, nsGraphics::KBlack);
|
window << nsShape::Triangle(Position(35*scale, 50*scale)+baseVector, Position(15*scale, 25*scale)+baseVector, Position(15*scale, 75*scale)+baseVector, nsGraphics::KBlack);
|
||||||
@ -16,7 +17,7 @@ void PixelManager::drawInvaderA(const Position& baseVector, unsigned size, RGBAc
|
|||||||
window << nsShape::Rectangle(Position(35*scale, 65*scale)+baseVector, Position(65*scale, 72*scale)+baseVector, nsGraphics::KBlack);
|
window << nsShape::Rectangle(Position(35*scale, 65*scale)+baseVector, Position(65*scale, 72*scale)+baseVector, nsGraphics::KBlack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::drawInvaderB(const Position& baseVector, unsigned size, RGBAcolor& color){
|
void PixelManager::drawInvaderB(const Position& baseVector, unsigned size, const RGBAcolor& color) const {
|
||||||
float scale = size/(float)100;
|
float scale = size/(float)100;
|
||||||
window << nsShape::Circle(Position(50*scale, 50*scale)+baseVector, 50*scale, nsGraphics::KRed);
|
window << nsShape::Circle(Position(50*scale, 50*scale)+baseVector, 50*scale, nsGraphics::KRed);
|
||||||
window << nsShape::Rectangle(Position(25*scale, 30*scale)+baseVector, Position(45*scale, 40*scale)+baseVector, nsGraphics::KBlack);
|
window << nsShape::Rectangle(Position(25*scale, 30*scale)+baseVector, Position(45*scale, 40*scale)+baseVector, nsGraphics::KBlack);
|
||||||
@ -24,7 +25,7 @@ void PixelManager::drawInvaderB(const Position& baseVector, unsigned size, RGBAc
|
|||||||
window << nsShape::Rectangle(Position(35*scale, 65*scale)+baseVector, Position(65*scale, 72*scale)+baseVector, nsGraphics::KBlack);
|
window << nsShape::Rectangle(Position(35*scale, 65*scale)+baseVector, Position(65*scale, 72*scale)+baseVector, nsGraphics::KBlack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::drawInvaderC(const Position& baseVector, unsigned size, RGBAcolor& color){
|
void PixelManager::drawInvaderC(const Position& baseVector, unsigned size, const RGBAcolor& color) const {
|
||||||
float scale = size/(float)100;
|
float scale = size/(float)100;
|
||||||
window << nsShape::Circle(Position(50*scale, 50*scale)+baseVector, 50*scale, nsGraphics::KGreen);
|
window << nsShape::Circle(Position(50*scale, 50*scale)+baseVector, 50*scale, nsGraphics::KGreen);
|
||||||
window << nsShape::Circle(Position(35*scale, 35*scale)+baseVector, 10*scale, nsGraphics::KBlack);
|
window << nsShape::Circle(Position(35*scale, 35*scale)+baseVector, 10*scale, nsGraphics::KBlack);
|
||||||
@ -32,7 +33,7 @@ void PixelManager::drawInvaderC(const Position& baseVector, unsigned size, RGBAc
|
|||||||
window << nsShape::Rectangle(Position(35*scale, 65*scale)+baseVector, Position(65*scale, 72*scale)+baseVector, nsGraphics::KBlack);
|
window << nsShape::Rectangle(Position(35*scale, 65*scale)+baseVector, Position(65*scale, 72*scale)+baseVector, nsGraphics::KBlack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::drawPlayer(const unsigned x, unsigned width, const nsGraphics::RGBAcolor& color){
|
void PixelManager::drawPlayer(unsigned x, unsigned width, const nsGraphics::RGBAcolor& color) const {
|
||||||
width = width-10-10;
|
width = width-10-10;
|
||||||
width = width/2;
|
width = width/2;
|
||||||
window << nsShape::Triangle(Position(0+x, 720), Position(5+x, 720), Position(5+x, 720-PLAYER_HEIGHT/2), color);
|
window << nsShape::Triangle(Position(0+x, 720), Position(5+x, 720), Position(5+x, 720-PLAYER_HEIGHT/2), color);
|
||||||
@ -44,55 +45,55 @@ void PixelManager::drawPlayer(const unsigned x, unsigned width, const nsGraphics
|
|||||||
window << nsShape::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 << nsShape::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){
|
void PixelManager::askPlayerNameMenu(playerID pID, string& name) const {
|
||||||
cout << "ask for player " << (pID+1) << endl;
|
cout << "ask for player " << (pID+1) << endl;
|
||||||
name = "Thomas";
|
name = "Thomas";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::drawMissile(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color){
|
void PixelManager::drawMissile(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const {
|
||||||
window << nsShape::Rectangle(baseVector, baseVector + Position(width, width * PROJ_LENGTH_FACTOR), color);
|
window << nsShape::Rectangle(baseVector, baseVector + Position(width, width * PROJ_LENGTH_FACTOR), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::drawTorpedo(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color){
|
void PixelManager::drawTorpedo(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const {
|
||||||
window << nsShape::Rectangle(baseVector, baseVector + Position(width, width * PROJ_LENGTH_FACTOR), color);
|
window << nsShape::Rectangle(baseVector, baseVector + Position(width, width * PROJ_LENGTH_FACTOR), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::drawBackground(){
|
void PixelManager::drawBackground() const {
|
||||||
background.draw(window);
|
background.draw(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned PixelManager::showInitialMenu(){
|
PlayMode PixelManager::showInitialMenu() const {
|
||||||
return 1;
|
return PlayMode::SINGLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned PixelManager::showDeathMenu() {
|
bool PixelManager::showDeathMenu() const {
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned PixelManager::getScreenHeight() {
|
unsigned PixelManager::getScreenHeight() const {
|
||||||
return window.getWindowSize().getY();
|
return window.getWindowSize().getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned PixelManager::getScreenWidth() {
|
unsigned PixelManager::getScreenWidth() const {
|
||||||
return window.getWindowSize().getX();
|
return window.getWindowSize().getX();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::startFrame() {
|
void PixelManager::startFrame() const {
|
||||||
window.clearScreen();
|
window.clearScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::endFrame() {
|
void PixelManager::endFrame() const {
|
||||||
window.finishFrame();
|
window.finishFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::displayGodBench(int y) {
|
void PixelManager::displayGodBench(int y) const {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::displayGodRightHand(const Position& pos) {
|
void PixelManager::displayGodRightHand(const Position& pos) const {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::displayGodLeftHand(const Position& pos) {
|
void PixelManager::displayGodLeftHand(const Position& pos) const {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#define SECRET_KEY "WeAreAGroupOf3"
|
#define SECRET_KEY "WeAreAGroupOf3"
|
||||||
|
|
||||||
void readWholeFile(ifstream& ifs, string& str){
|
void readWholeFile(const ifstream& ifs, string& str){
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
ss << ifs.rdbuf();
|
ss << ifs.rdbuf();
|
||||||
str.assign(ss.str());
|
str.assign(ss.str());
|
||||||
@ -18,7 +18,7 @@ void readWholeFile(ifstream& ifs, string& str){
|
|||||||
|
|
||||||
static std::hash<string> hasher;
|
static std::hash<string> hasher;
|
||||||
|
|
||||||
bool verifyHash(size_t savedHash, string& content){
|
bool verifyHash(size_t savedHash, const string& content){
|
||||||
// non-cryptographic hash, but it is part of the std, and openssl is REALLY difficult
|
// non-cryptographic hash, but it is part of the std, and openssl is REALLY difficult
|
||||||
// to use in C++ while keeping semantic, because there are no wrappers...
|
// to use in C++ while keeping semantic, because there are no wrappers...
|
||||||
size_t actualHash = hasher(content+SECRET_KEY);
|
size_t actualHash = hasher(content+SECRET_KEY);
|
||||||
@ -57,11 +57,11 @@ void ScoresManager::readFile() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScoresManager::writeFile() {
|
void ScoresManager::writeFile() const {
|
||||||
ofstream ofs(SCORE_FILE);
|
ofstream ofs(SCORE_FILE);
|
||||||
|
|
||||||
string str; // this one must be counted in the hash too
|
string str; // this one must be counted in the hash too
|
||||||
for(ScoreLink& sc : scores){
|
for(const ScoreLink& sc : scores){
|
||||||
str.append(sc.name);
|
str.append(sc.name);
|
||||||
str.append(",");
|
str.append(",");
|
||||||
str.append(to_string(sc.score));
|
str.append(to_string(sc.score));
|
||||||
|
@ -8,7 +8,7 @@ bool areLinesColliding(unsigned start1, unsigned end1, unsigned start2, unsigned
|
|||||||
// if it returns true, lines are colliding. I like truth tables
|
// if it returns true, lines are colliding. I like truth tables
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t InvadersColumn::getOutterInvader(){
|
size_t InvadersColumn::getOutterInvader() const {
|
||||||
size_t i=size();
|
size_t i=size();
|
||||||
while(i>0){
|
while(i>0){
|
||||||
--i;
|
--i;
|
||||||
|
Loading…
Reference in New Issue
Block a user