diff --git a/include/carte.hpp b/include/carte.hpp index 0e78d38..8fc96e4 100644 --- a/include/carte.hpp +++ b/include/carte.hpp @@ -18,7 +18,7 @@ enum VCarte{ }; enum CCarte{ - PIC, + PIC = 1, CARREAU, COEUR, TREFLE, @@ -27,6 +27,6 @@ enum CCarte{ struct carte{ VCarte valeur; CCarte couleur; -}; +}CARTERETOURNE = {VCarte(0), CCarte(0)}; #endif diff --git a/include/jdc.hpp b/include/jdc.hpp index bb95dbb..66374fa 100644 --- a/include/jdc.hpp +++ b/include/jdc.hpp @@ -65,54 +65,54 @@ class JDC{ return this->jdc[index]; } - static std::string valeur(carte c){ - if ((int)c.valeur < 10) return std::to_string(c.valeur); + static char valeur(carte c){ + if ((int)c.valeur >= 1 && (int)c.valeur < 10) return char(c.valeur+48); switch(c.valeur){ case T: - return "T"; + return 'T'; case J: - return "J"; + return 'J'; case Q: - return "Q"; + return 'Q'; case K: - return "K"; + return 'K'; case A: - return "A"; + return 'A'; default: - return "?"; + return '?'; } } - static std::string couleur(carte c){ + static char couleur(carte c){ switch(c.couleur){ case PIC: - return "♠"; + return 'P'; case COEUR: - return "♥"; + return 'C'; case TREFLE: - return "♣"; + return 'T'; case CARREAU: - return "♦"; + return 'K'; default: - return "?"; + return '?'; } }; - std::string* ascii(carte c){ - std::string* s = new std::string[3]; - //if (c == NULL){ - // s[0] = "\033[38;5;235m╭──╮"; - // s[1] = "│ȸȹ│"; - // s[2] = "╰──╯\033[0m"; - // return s; - //} - std::string co = this->couleur(c); - s[0] = "\033[38;5;235m╭──╮"; - if (co == "♥" || co == "♦") s[1] = "│\033[31m"+this->valeur(c)+co+"\033[38;5;235m│"; - else s[1] = "│\033[30m"+this->valeur(c)+co+"\033[38;5;235m│"; - s[2] = "╰──╯"; - return s; - }; + //std::string* ascii(carte c){ + // std::string* s = new std::string[3]; + // //if (c == NULL){ + // // s[0] = "\033[38;5;235m╭──╮"; + // // s[1] = "│ȸȹ│"; + // // s[2] = "╰──╯\033[0m"; + // // return s; + // //} + // std::string co = this->couleur(c); + // s[0] = "\033[38;5;235m╭──╮"; + // if (co == "♥" || co == "♦") s[1] = "│\033[31m"+this->valeur(c)+co+"\033[38;5;235m│"; + // else s[1] = "│\033[30m"+this->valeur(c)+co+"\033[38;5;235m│"; + // s[2] = "╰──╯"; + // return s; + //}; int length(){ return this->len; diff --git a/include/screen.hpp b/include/screen.hpp index cd51f02..2509b41 100644 --- a/include/screen.hpp +++ b/include/screen.hpp @@ -2,32 +2,31 @@ #define SCREEN_HPP #include -#include #include "jdc.hpp" template struct point{ - T x; T y; + T x; }; struct sprite{ - std::string* s; + char** data; int row; int col; }; class Screen{ public: - std::string** screen; + char** screen; - Screen(int col, int row){ + Screen(int row, int col){ this->col = col; this->row = row; - this->screen = new std::string*; + this->screen = new char*[row]; for (int i=0; iscreen[i] = new std::string; + this->screen[i] = new char[col]; } }; @@ -40,11 +39,11 @@ class Screen{ void background(){ for (int i=0; iscreen[i] = new std::string; for (int y=0; yscreen[i]) += "X"; - else if (!(i%2) && !(y%2)) *(this->screen[i]) += "X"; - else *(this->screen[i]) += "O"; + if (y%2 && i%2) this->screen[i][y] = 'X'; + else if (!(i%2) && !(y%2)) this->screen[i][y] = 'X'; + else this->screen[i][y] = 'O'; + //this->screen[i][y] = 'X'; } } }; @@ -52,20 +51,34 @@ class Screen{ void display(){ std::cout << "\033[1;48;5;22m" << std::endl; for (int i=0; iscreen[i]) << std::endl; + for (int y=0; yscreen[i][y]; + } + std::cout << std::endl; } std::cout << "\033[0m" << std::endl; } void addCard(point p, carte c){ - this->screen[p.x]->replace(p.y, 4, "╭──╮"); - this->screen[p.x+1]->replace(p.y+1, 1, JDC::valeur(c)); - this->screen[p.x+1]->replace(p.y, 1, "│"); - this->screen[p.x+1]->replace(p.y+5, 1, "│"); - this->screen[p.x+1]->replace(p.y+4, 1, JDC::couleur(c)); - this->screen[p.x+2]->replace(p.y, 4, "╰──╯"); + this->screen[p.x][p.y] = '+'; + this->screen[p.x][p.y+3] = '+'; + this->screen[p.x+2][p.y+3] = '+'; + this->screen[p.x+2][p.y] = '+'; + + this->screen[p.x][p.y+1] = '-'; + this->screen[p.x][p.y+2] = '-'; + this->screen[p.x+2][p.y+1] = '-'; + this->screen[p.x+2][p.y+2] = '-'; + + this->screen[p.x+1][p.y] = '|'; + this->screen[p.x+1][p.y+3] = '|'; + + this->screen[p.x+1][p.y+1] = JDC::valeur(c); + this->screen[p.x+1][p.y+2] = JDC::couleur(c); }; + //void addSprite(point p, sprite s){}; + int ligne(){ return this->row; } diff --git a/test/scroon.cpp b/test/scroon.cpp index 8f9d9ec..6fd1c1a 100644 --- a/test/scroon.cpp +++ b/test/scroon.cpp @@ -3,7 +3,9 @@ #include "jdc.hpp" int main(){ - Screen s(11, 5); + int row = 5; + int col = 11; + Screen s(row, col); s.background(); s.display(); @@ -12,12 +14,10 @@ int main(){ jdc.shuffle(); point p = {0, 0}; - //sprite card = {jdc.ascii(jdc.top()), 3, 4}; s.addCard(p, jdc.top()); + s.display(); - //card = {jdc.ascii(NULL), 3}; - p = {0, 12}; - s.addCard(p, jdc.get(0)); - + p = {col-4, row-3}; + s.addCard(p, CARTERETOURNE); s.display(); } diff --git a/test/testjdc.cpp b/test/testjdc.cpp index 0f2a9a2..15a2a1c 100644 --- a/test/testjdc.cpp +++ b/test/testjdc.cpp @@ -28,11 +28,14 @@ int main(){ jdc.display(); std::cout << jdc.length() << std::endl; - std::cout << "bottom = " << jdc.valeur(jdc.get(0)) << jdc.couleur(jdc.get(0)) << std::endl; - std::cout << "2 = " << jdc.valeur(jdc.get(2)) << jdc.couleur(jdc.get(2)) << std::endl; + c = jdc.get(0); + std::cout << "bottom = " << jdc.valeur(c) << jdc.couleur(c) << std::endl; + c = jdc.get(2); + std::cout << "2 = " << jdc.valeur(c) << jdc.couleur(c) << std::endl; - std::cout << "top = " << jdc.valeur(jdc.top()) << jdc.couleur(jdc.top()) << std::endl; - std::cout << jdc.couleur(jdc.top()).length() << std::endl; + c = jdc.top(); + std::cout << "top = " << jdc.valeur(c) << jdc.couleur(c) << std::endl; + //std::cout << jdc.couleur(jdc.top()).length() << std::endl; //std::cout << "\033[1;48;5;22m" << std::endl; //for (int y=0; y<52; y++){