1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| struct SCoffre {
SCoffre(std::string containt):
contenue(containt){}
std::string contenue;
};
struct SMap {
size_t rows;
size_t cols;/* supprimé car pris en charge par Joueur
int position_x; // cols
int position_y; // rows*/
std::vector<unsigned char> tiles;
std::map<Position, SWrap> wraps;
std::map<Position, SCoffre> coffres;
std::string title;
/* et, comme on peut travailler en orienté objets, on peut rajouter
* une fonction membre qui renvoie le caractère qui se trouve en X,Y ;)
*/
const unsigned char tileAt(size_t x, size_t y) const
{return tiles[y*cols + x];}
/* et la même chose avec une Position (sait on jamais ;)) */
const unsigned char tileAt(Position const & pos)
{return tileAt(pos.x(), pos.y());}
void tilegamer(Joueur & joueur)
{
tiles[joueur.y()*cols + joueur.x()] = '@';
}
void tileremplace(Joueur & joueur)
{
tiles[joueur.y()*cols + joueur.x()] = '.';
}
void tilecoffre(Joueur & joueur)
{
tiles[joueur.y()*cols + joueur.x()] = 'O';
}
void tilecoffre(size_t x, size_t y, std::string etat)
{
std::string state = "fermer";
char c;
if(etat.compare(state) == 0)
{
c = 'C';
//tilecoffre(x, y, c);
tiles[y*cols + x] = c;
}
else
{
c = 'O';
//tilecoffre(x, y, c);
tiles[y*cols + x] = c;
}
}
/*void tilecoffre(size_t x, size_t y, char c)
{
if(c == 'O')
{
tiles[y*cols + x] = c;
}
else
tiles[y*cols + x] = c;
}*/
bool hasTeleportAt(size_t x, size_t y) const
{
return wraps.find(Position(x,y)) != wraps.end();
}
Position nextMap(size_t x, size_t y)
{
//auto it = wraps.begin();
auto it = wraps.find(Position(x,y));
if(it == wraps.end()) // ne devrait pas arriver, mais qui sait
{
return Position(0,0);
}
return it->second.destinationMap;
}
Position gamerNextPosition(size_t x, size_t y)
{
//auto it = wraps.begin();
std::cout << x << " " << y << std::endl;
auto it = wraps.find(Position(x,y));
if(it == wraps.end()) // ne devrait pas arriver, mais qui sait
{
std::cout << "non trouver" << std::endl;
return Position(0,0);
}
return it->second.destinationCoordinates;
}
std::string coffreContaint(size_t x, size_t y)
{
auto it = coffres.find(Position(x,y));
if(it == coffres.end())
{
std::cout << "non trouver" << std::endl;
std::string erreur="vide";
return erreur;
}
return it->second.contenue;
}
}; |