Number Crush  1.0
..
gridmanagement.cpp
1 #include <iostream>
2 #include <iomanip>
3 #include "gridmanagement.h"
4 
5 #include "Correc_prof/type.h" //nos types
6 #include "Correc_prof/params.h" //nos parametres
7 
8 using namespace std;
9 
10 
11 
13 {
14  cout << "\033[H\033[2J";
15 }// ClearScreen ()
16 
17 void Color (const string & Col)
18 {
19  cout << "\033[" << Col.c_str () <<"m";
20 } // Color ()
21 
22 
24 {
25 
26  ClearScreen ();
27  cout << string (4, ' ');
28  for (unsigned i (0); i < Mat.size (); ++i)
29  {
30  Color (Param.MapParamString.find("IndexColor")->second);
31 
32  cout << setw (2) << i;
33 
34  Color (Param.MapParamString.find("RowColor")->second);
35  cout<< setw (2) << '|';
36  }
37  cout << endl;
38  string Rule (4*Mat.size () + 1, '=');
39  Rule = string (3, ' ') + Rule;
40 
41 
42  Color (Param.MapParamString.find("LineColor")->second);
43  cout << Rule << endl;
44  unsigned LineNumber (0);
45  for (const CVLine & Aline : Mat)
46  {
47 
48  Color (Param.MapParamString.find("IndexColor")->second);
49 
50  cout << setw (2) << LineNumber++;
51  Color (Param.MapParamString.find("RowColor")->second);
52 
53  cout << "||";
54  for (auto Cel : Aline)
55  {
56 
57  Color (Param.MapParamString.find("MyColor")->second);
58  cout << setw (2);
59  if (KImpossible == Cel)
60  cout << ' ';
61  else
62  cout << Cel;
63  Color (Param.MapParamString.find("RowColor")->second);
64 
65  cout<< setw (2) << '|';
66  }
67  Color (Param.MapParamString.find("LineColor")->second);
68 
69  cout << endl << Rule << endl;
70  }
71  Color (KColor.find("KReset")->second);
72 
73 } // DisplayWithLineAndColumnNumbersAndColor ()
74 
76 {
77  ClearScreen ();
78  cout << string (4, ' ');
79  for (unsigned i (0); i < Mat.size (); ++i)
80  cout << setw (2) << i << setw (2) << '|';
81  cout << endl;
82  string Rule (4*Mat.size () + 1, '=');
83  Rule = string (3, ' ') + Rule;
84  cout << Rule << endl;
85  unsigned LineNumber (0);
86  for (const CVLine & Aline : Mat)
87  {
88  cout << setw (2) << LineNumber++ << '|';
89  cout << '|';
90  for (auto Cel : Aline)
91  cout << setw (2) << Cel << setw (2) << '|';
92  cout << endl << Rule << endl;
93  }
94 } // DisplayWithLineAndColumnNumbers ()
95 
96 void DisplayGrid (const CMat & Mat, const CMyParam & Param, bool ShowLineNumber /*= true*/, bool ShowColor /*= true*/)
97 {
98  ClearScreen ();
99  if (ShowLineNumber)
100  {
101  if (ShowColor)
103  else
105  return;
106  }
107 
108  string Rule (4*Mat.size () + 1, '=');
109  cout << Rule << endl;
110  for (const CVLine & Aline : Mat)
111  {
112  cout << '|';
113  for (auto Cel : Aline)
114  cout << setw (2) << Cel << setw (2) << '|';
115  cout << endl << Rule << endl;
116  }
117 }// DisplayGrid ()
118 
119 
120 void InitGrid (CMat & Grid, unsigned Size)
121 {
122  Grid.resize (Size);
123  for (auto & Line : Grid)
124  {
125  Line.resize (Size);
126  for (auto & Cel : Line)
127  Cel = Rand () +1;
128  }
129 } // InitMat ()
void DisplayGridWithLineAndColumnNumbers(const CMat &Mat)
Display the grid showing the line and the column numbers.
std::vector< unsigned > CVLine
CVLine : alias to a line of the matrix.
Definition: type.h:19
std::map< std::string, std::string > MapParamString
Definition: type.h:41
void ClearScreen()
Clear the current terminal.
const unsigned KImpossible
KImpossible :
Definition: params.h:28
void Color(const std::string &Col)
Set the color of the future input in the terminal.
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&#39;s parameters.
Definition: type.h:35
void DisplayGridWithLineAndColumnNumbersAndColor(const CMat &Mat, const CMyParam &Params)
Display the grid showing the line and the column numbers. Everything is colored according to the set ...
Paramters&#39; definition and associated functions.
std::vector< CVLine > CMat
CMat : alias to a game grid type.
Definition: type.h:25
void InitGrid(CMat &Grid, const unsigned &Size)
Initialize the grid according to the size.
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
Set of usefull functions for the grid management.
unsigned Rand()
Return a random number between 1 and KNbCandies.
Definition: nsutil.cpp:4
Definition of usefull types or aliases for the project.