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

View File

@ -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){
//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╭──╮";
// s[1] = "│ȸȹ│";
// s[2] = "╰──╯\033[0m";
// 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 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;

View File

@ -2,32 +2,31 @@
#define SCREEN_HPP
#include <iostream>
#include <cstdlib>
#include "jdc.hpp"
template <typename T>
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; i<row; i++){
this->screen[i] = new std::string;
this->screen[i] = new char[col];
}
};
@ -40,11 +39,11 @@ class Screen{
void background(){
for (int i=0; i<row; i++){
this->screen[i] = new std::string;
for (int y=0; y<col; y++){
if (y%2 && i%2) *(this->screen[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; 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;
}
void addCard(point<int> 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<int> p, sprite s){};
int ligne(){
return this->row;
}

View File

@ -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<int> 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();
}

View File

@ -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++){