Number Crush  1.0
..
params.cpp
1 #include <string>
2 #include <fstream>
3 #include <iostream>
4 
5 #include "Correc_prof/params.h"
6 #include "game.h"
7 
8 using namespace std;
9 
10 
11 void InitParams (CMyParam & Param)
12 {
13  //Move Keys
14  Param.MapParamChar["KeyUp"] = 'z';
15  Param.MapParamChar["KeyDown"] = 's';
16  Param.MapParamChar["KeyLeft"] = 'q';
17  Param.MapParamChar["KeyRight"] = 'd';
18 
19 
20  //Size of grid -- suppose to be squared
21  Param.MapParamUnsigned["GridSize"] = 10;
22 
23  //Display Colors
24  Param.MapParamString["LineColor"] = KColor.find("KRed")->second ;
25  Param.MapParamString["RowColor"] = KColor.find("KGreen")->second ;
26  Param.MapParamString["IndexColor"] = KColor.find("KBlue")->second ;
27  Param.MapParamString["MyColor"] = KColor.find("KBack")->second ;
28 }
29 
30 void LoadParams (CMyParam & Param)
31 {
32  ifstream ifs ("../M1103-ProjetNumberCrush/Nos_fichiers/config.yaml");
33  if (!ifs.is_open())
34  {
35  cerr << "pas le bon fichier de configuration";
36  exit (2);
37  }
38  string Key;
39  while (ifs >> Key)
40  {
41  char tmp;
42  ifs >> tmp;
43  if (find (KAuthorizedKey.VParamChar.begin(), KAuthorizedKey.VParamChar.end(), Key) != KAuthorizedKey.VParamChar.end())
44  ifs >> Param.MapParamChar[Key];
45  else if (find (KAuthorizedKey.VParamUnsigned.begin(), KAuthorizedKey.VParamUnsigned.end(), Key) != KAuthorizedKey.VParamUnsigned.end())
46  ifs >> Param.MapParamUnsigned[Key];
47  else if (find (KAuthorizedKey.VParamString.begin(), KAuthorizedKey.VParamString.end(), Key) != KAuthorizedKey.VParamString.end())
48  {
49  string Val;
50  ifs >> Val;
51  Param.MapParamString[Key] = KColor.find(Val)->second;
52  }
53  }
54 }
std::map< std::string, char > MapParamChar
Definition: type.h:37
void LoadParams(CMyParam &Param)
Load the set of parameters from a YAML file.
Definition: params.cpp:30
Set of functions usefull for the game.
std::map< std::string, unsigned > MapParamUnsigned
Definition: type.h:39
std::map< std::string, std::string > MapParamString
Definition: type.h:41
const std::vector< std::string > VParamUnsigned
Definition: type.h:53
Struct containing all the game&#39;s parameters.
Definition: type.h:35
const std::vector< std::string > VParamChar
Definition: type.h:49
Paramters&#39; definition and associated functions.
const std::map< std::string, std::string > KColor
KColor : map between the "human" color and its correspondence for the Unix terminal.
Definition: type.h:66
const AuthorizedKey KAuthorizedKey
KAuthorizedKey.
Definition: type.h:59
const std::vector< std::string > VParamString
Definition: type.h:51
void InitParams(CMyParam &Param)
Initialize the set of parameters from scratch.
Definition: params.cpp:11