retoure au char**

This commit is contained in:
_N3m0 2023-08-14 13:12:08 +02:00
parent 69a6303031
commit 2c3d79c581
5 changed files with 75 additions and 59 deletions

View File

@ -18,7 +18,7 @@ enum VCarte{
}; };
enum CCarte{ enum CCarte{
PIC, PIC = 1,
CARREAU, CARREAU,
COEUR, COEUR,
TREFLE, TREFLE,
@ -27,6 +27,6 @@ enum CCarte{
struct carte{ struct carte{
VCarte valeur; VCarte valeur;
CCarte couleur; CCarte couleur;
}; }CARTERETOURNE = {VCarte(0), CCarte(0)};
#endif #endif

View File

@ -65,54 +65,54 @@ class JDC{
return this->jdc[index]; return this->jdc[index];
} }
static std::string valeur(carte c){ static char valeur(carte c){
if ((int)c.valeur < 10) return std::to_string(c.valeur); if ((int)c.valeur >= 1 && (int)c.valeur < 10) return char(c.valeur+48);
switch(c.valeur){ switch(c.valeur){
case T: case T:
return "T"; return 'T';
case J: case J:
return "J"; return 'J';
case Q: case Q:
return "Q"; return 'Q';
case K: case K:
return "K"; return 'K';
case A: case A:
return "A"; return 'A';
default: default:
return "?"; return '?';
} }
} }
static std::string couleur(carte c){ static char couleur(carte c){
switch(c.couleur){ switch(c.couleur){
case PIC: case PIC:
return ""; return 'P';
case COEUR: case COEUR:
return ""; return 'C';
case TREFLE: case TREFLE:
return ""; return 'T';
case CARREAU: case CARREAU:
return ""; return 'K';
default: default:
return "?"; return '?';
} }
}; };
std::string* ascii(carte c){ //std::string* ascii(carte c){
std::string* s = new std::string[3]; // std::string* s = new std::string[3];
//if (c == NULL){ // //if (c == NULL){
// s[0] = "\033[38;5;235m╭──╮"; // // s[0] = "\033[38;5;235m╭──╮";
// s[1] = "│ȸȹ│"; // // s[1] = "│ȸȹ│";
// s[2] = "╰──╯\033[0m"; // // s[2] = "╰──╯\033[0m";
// return s; // // return s;
//} // //}
std::string co = this->couleur(c); // std::string co = this->couleur(c);
s[0] = "\033[38;5;235m╭──╮"; // s[0] = "\033[38;5;235m╭──╮";
if (co == "" || co == "") s[1] = "\033[31m"+this->valeur(c)+co+"\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│"; // else s[1] = "│\033[30m"+this->valeur(c)+co+"\033[38;5;235m│";
s[2] = "╰──╯"; // s[2] = "╰──╯";
return s; // return s;
}; //};
int length(){ int length(){
return this->len; return this->len;

View File

@ -2,32 +2,31 @@
#define SCREEN_HPP #define SCREEN_HPP
#include <iostream> #include <iostream>
#include <cstdlib>
#include "jdc.hpp" #include "jdc.hpp"
template <typename T> template <typename T>
struct point{ struct point{
T x;
T y; T y;
T x;
}; };
struct sprite{ struct sprite{
std::string* s; char** data;
int row; int row;
int col; int col;
}; };
class Screen{ class Screen{
public: public:
std::string** screen; char** screen;
Screen(int col, int row){ Screen(int row, int col){
this->col = col; this->col = col;
this->row = row; this->row = row;
this->screen = new std::string*; this->screen = new char*[row];
for (int i=0; i<row; i++){ for (int i=0; i<row; i++){
this->screen[i] = new std::string; this->screen[i] = new char[col];
} }
}; };
@ -40,11 +39,11 @@ class Screen{
void background(){ void background(){
for (int i=0; i<row; i++){ for (int i=0; i<row; i++){
this->screen[i] = new std::string;
for (int y=0; y<col; y++){ for (int y=0; y<col; y++){
if (y%2 && i%2) *(this->screen[i]) += "X"; if (y%2 && i%2) this->screen[i][y] = 'X';
else if (!(i%2) && !(y%2)) *(this->screen[i]) += "X"; else if (!(i%2) && !(y%2)) this->screen[i][y] = 'X';
else *(this->screen[i]) += "O"; else this->screen[i][y] = 'O';
//this->screen[i][y] = 'X';
} }
} }
}; };
@ -52,20 +51,34 @@ class Screen{
void display(){ void display(){
std::cout << "\033[1;48;5;22m" << std::endl; std::cout << "\033[1;48;5;22m" << std::endl;
for (int i=0; i<row; i++){ for (int i=0; i<row; i++){
std::cout << *(this->screen[i]) << std::endl; for (int y=0; y<col; y++){
std::cout << this->screen[i][y];
}
std::cout << std::endl;
} }
std::cout << "\033[0m" << std::endl; std::cout << "\033[0m" << std::endl;
} }
void addCard(point<int> p, carte c){ void addCard(point<int> p, carte c){
this->screen[p.x]->replace(p.y, 4, "╭──╮"); this->screen[p.x][p.y] = '+';
this->screen[p.x+1]->replace(p.y+1, 1, JDC::valeur(c)); this->screen[p.x][p.y+3] = '+';
this->screen[p.x+1]->replace(p.y, 1, ""); this->screen[p.x+2][p.y+3] = '+';
this->screen[p.x+1]->replace(p.y+5, 1, ""); this->screen[p.x+2][p.y] = '+';
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+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<int> p, sprite s){};
int ligne(){ int ligne(){
return this->row; return this->row;
} }

View File

@ -3,7 +3,9 @@
#include "jdc.hpp" #include "jdc.hpp"
int main(){ int main(){
Screen s(11, 5); int row = 5;
int col = 11;
Screen s(row, col);
s.background(); s.background();
s.display(); s.display();
@ -12,12 +14,10 @@ int main(){
jdc.shuffle(); jdc.shuffle();
point<int> p = {0, 0}; point<int> p = {0, 0};
//sprite card = {jdc.ascii(jdc.top()), 3, 4};
s.addCard(p, jdc.top()); s.addCard(p, jdc.top());
s.display();
//card = {jdc.ascii(NULL), 3}; p = {col-4, row-3};
p = {0, 12}; s.addCard(p, CARTERETOURNE);
s.addCard(p, jdc.get(0));
s.display(); s.display();
} }

View File

@ -28,11 +28,14 @@ int main(){
jdc.display(); jdc.display();
std::cout << jdc.length() << std::endl; std::cout << jdc.length() << std::endl;
std::cout << "bottom = " << jdc.valeur(jdc.get(0)) << jdc.couleur(jdc.get(0)) << std::endl; c = jdc.get(0);
std::cout << "2 = " << jdc.valeur(jdc.get(2)) << jdc.couleur(jdc.get(2)) << std::endl; 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; c = jdc.top();
std::cout << jdc.couleur(jdc.top()).length() << std::endl; 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; //std::cout << "\033[1;48;5;22m" << std::endl;
//for (int y=0; y<52; y++){ //for (int y=0; y<52; y++){