9 template <
class T,
class U>
10 void ShowMap (
const map<T,U> & AMap){
11 for (
const pair <T,U> & Val : AMap) cout <<
"Cle : " << Val.first <<
" " <<
"Valeur : " << Val.second << endl;
20 cout <<
"Saisir un indice de ligne, un indice de column,\n" 21 <<
" et un sens de Deplacements : \n" 22 << Params.
MapParamChar.find(
"KeyLeft")->second <<
" a gauche,\n " 23 << Params.
MapParamChar.find(
"KeyDown")->second <<
" en bas,\n" 24 << Params.
MapParamChar.find(
"KeyRight")->second <<
" a droite,\n " 25 << Params.
MapParamChar.find(
"KeyUp")->second <<
" en haut\n" 27 cin >> Pos.first >> Pos.second >> Direction;
33 unsigned NewLineNumber (Pos.first), NewColumnNumber (Pos.second);
34 if (Direction == Params.
MapParamChar.find(
"KeyLeft")->second )
36 else if (Direction == Params.
MapParamChar.find(
"KeyDown")->second)
38 else if (Direction == Params.
MapParamChar.find(
"KeyRight")->second)
40 else if (Direction == Params.
MapParamChar.find(
"KeyUp")->second)
44 swap (Grid [Pos.first][Pos.second], Grid [NewLineNumber][NewColumnNumber]);
49 for (
unsigned LineNumber = 0; LineNumber < Mat.size (); ++LineNumber)
51 for (
unsigned ColNmber = 0; ColNmber < Mat.size () -2; ++ColNmber)
53 if (
KImpossible == Mat[LineNumber][ColNmber])
continue;
54 for (HowMany = 1; ColNmber + HowMany < Mat.size() && Mat [LineNumber][ColNmber] == Mat[LineNumber][ColNmber + HowMany]; ++HowMany);
57 Pos = make_pair (LineNumber, ColNmber);
67 for (
unsigned ColNmber = 0; ColNmber < Mat.size (); ++ColNmber)
69 for (
unsigned LineNumber = 0; LineNumber < Mat.size () -2; ++LineNumber)
71 if (
KImpossible == Mat[LineNumber][ColNmber])
continue;
72 for (HowMany = 1; LineNumber + HowMany < Mat.size() && Mat [LineNumber][ColNmber] == Mat[LineNumber + HowMany][ColNmber]; ++HowMany);
76 Pos = make_pair (LineNumber, ColNmber);
87 for (; Pos.first + Nb + HowMany < Mat.size (); ++Nb)
89 Mat [Pos.first + Nb][Pos.second] = Mat [Pos.first + Nb + HowMany][Pos.second];
90 Mat [Pos.first + Nb + HowMany][Pos.second] =
KImpossible;
92 for (; Pos.first + Nb < Mat.size (); ++Nb)
99 for (
unsigned i (0); i < HowMany; ++i)
102 ++PosToRemove.second;
108 return HowMany * (HowMany + 1) / 2;
114 cout <<
"Welcome to number crush!" << endl;
123 unsigned HowMany, Score (0);
126 for (
unsigned Count (0); Count <
KMaxTimes; ++Count)
129 Menu (Pos, Dirrection, Params);
130 if (
'q' == Dirrection)
break;
131 MakeAMove (Grid, Pos, Dirrection, Params);
144 cout <<
"Your score is : " << Score << endl <<
"That's not so bad for a dummy ;)" << endl;
bool AtLeastThreeInAColumn(const CMat &Mat, CPosition &Pos, unsigned &HowMany)
Chek if there is at least 3 token in the same column.
std::map< std::string, char > MapParamChar
void LoadParams(CMyParam &Param)
Load the set of parameters from a YAML file.
Set of functions usefull for the game.
bool AtLeastThreeInARow(const CMat &Mat, CPosition &Pos, unsigned &HowMany)
Chek if there is at least 3 token in the same row.
const unsigned KImpossible
KImpossible :
void RemovalInColumn(CMat &Mat, const CPosition &Pos, const unsigned &HowMany)
Remove "Howmany" same tokens starting from "Pos".
unsigned ComputeScore(const unsigned &HowMany)
Computer the score.
std::pair< unsigned, unsigned > CPosition
CPosition : a pair gathering the coordinates in the grid.
void DisplayGrid(const CMat &Mat, const CMyParam &Params, bool ShowLineNumber=true, bool ShowColor=true)
Display the grid according to the parameters.
Struct containing all the game's parameters.
void RemovalInRow(CMat &Mat, const CPosition &Pos, const unsigned &HowMany)
Remove "Howmany" same tokens starting from "Pos".
Paramters' definition and associated functions.
std::vector< CVLine > CMat
CMat : alias to a game grid type.
void InitGrid(CMat &Grid, const unsigned &Size)
Initialize the grid according to the size.
void Menu(CPosition &Pos, char &Direction, const CMyParam &Params)
Display the menu according to the set of parameters.
void MakeAMove(CMat &Grid, const CPosition &Pos, const char &Direction, const CMyParam &Params)
Swap the token from its inital place to its final destination.
const unsigned KMaxTimes
KMaxTimes : number of maximum allowed turns to win.
Set of usefull functions for the grid management.
void InitParams(CMyParam &Param)
Initialize the set of parameters from scratch.