catch me if you can  0.1
params.cpp
Go to the documentation of this file.
1 #include <string>
2 #include <fstream>
3 #include <iostream>
4 
5 #include "params.h"
6 
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  Param.MapParamChar["KeyRight"] = 'd';
19  Param.MapParamChar["TokenP1"] = 'O';
20  Param.MapParamChar["TokenP2"] = 'X';
21 
22  //Size of grid -- suppose to be a rectangle
23  Param.MapParamUnsigned["NbColumn"] = 10;
24  Param.MapParamUnsigned["NbRow"] = 15;
25 
26  //Display Colors
27  Param.MapParamString["ColorP1"] = KColor.find("KRed")->second ;
28  Param.MapParamString["ColorP2"] = KColor.find("KGreen")->second ;
29 }
30 
31 int LoadParams (CMyParam & Param, const std::string & FileName)
32 {
33  ifstream ifs (FileName);
34  if (!ifs.is_open())
35  {
36  cerr << "pas le bon fichier de configuration";
37  return 2;
38  }
39  string Key;
40  while (ifs >> Key)
41  {
42  char tmp;
43  ifs >> tmp;
44  if (find (KAuthorizedKey.VParamChar.begin(), KAuthorizedKey.VParamChar.end(), Key) != KAuthorizedKey.VParamChar.end())
45  ifs >> Param.MapParamChar[Key];
46  else if (find (KAuthorizedKey.VParamUnsigned.begin(), KAuthorizedKey.VParamUnsigned.end(), Key) != KAuthorizedKey.VParamUnsigned.end())
47  ifs >> Param.MapParamUnsigned[Key];
48  else if (find (KAuthorizedKey.VParamString.begin(), KAuthorizedKey.VParamString.end(), Key) != KAuthorizedKey.VParamString.end())
49  {
50  string Val;
51  ifs >> Val;
52  Param.MapParamString[Key] = KColor.find(Val)->second;
53  }
54  }
55  return 0;
56 }
std::map< std::string, char > MapParamChar
Definition: type.h:37
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.
void InitParams(CMyParam &Param)
Initialize the set of parameters from scratch.
Definition: params.cpp:11
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
int LoadParams(CMyParam &Param, const std::string &FileName)
Definition: params.cpp:31
const AuthorizedKey KAuthorizedKey
KAuthorizedKey.
Definition: type.h:59
const std::vector< std::string > VParamString
Definition: type.h:51