unicode c'est de la merde, ci+1 retoure en ascii

This commit is contained in:
_N3m0 2023-08-13 13:50:05 +02:00
parent 8a122db98a
commit 69a6303031
6 changed files with 149 additions and 39 deletions

View File

@ -18,7 +18,7 @@ else
OPT=-Og -g
endif
DEPFLAGS=-MP -MD
MACROS=HW PI=3.14
MACROS=
FLAGS=-Wall -Wextra $(foreach F,$(INCDIRS),-I$(F)) $(OPT) $(DEPFLAGS) $(foreach M,$(MACROS),-D$(M))
SRC=$(shell find . -name "*.$(EXT)" -path "./src/*")

View File

@ -13,7 +13,7 @@ class JDC{
void init(){
this->len = 52;
int index = 0;
int index;
for (int i=0; i<4; i++){
for (int y=0; y<13; y++){
index = (i*13)+y;
@ -65,7 +65,7 @@ class JDC{
return this->jdc[index];
}
std::string valeur(carte c){
static std::string valeur(carte c){
if ((int)c.valeur < 10) return std::to_string(c.valeur);
switch(c.valeur){
case T:
@ -83,7 +83,7 @@ class JDC{
}
}
std::string couleur(carte c){
static std::string couleur(carte c){
switch(c.couleur){
case PIC:
return "";
@ -100,6 +100,12 @@ class JDC{
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│";

81
include/screen.hpp Normal file
View File

@ -0,0 +1,81 @@
#ifndef SCREEN_HPP
#define SCREEN_HPP
#include <iostream>
#include <cstdlib>
#include "jdc.hpp"
template <typename T>
struct point{
T x;
T y;
};
struct sprite{
std::string* s;
int row;
int col;
};
class Screen{
public:
std::string** screen;
Screen(int col, int row){
this->col = col;
this->row = row;
this->screen = new std::string*;
for (int i=0; i<row; i++){
this->screen[i] = new std::string;
}
};
~Screen(){
for (int i=0; i<row; i++){
delete this->screen[i];
}
delete this->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";
}
}
};
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;
}
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, "╰──╯");
};
int ligne(){
return this->row;
}
int colone(){
return this->col;
}
private:
int row;
int col;
};
#endif

View File

@ -3,7 +3,7 @@
int main(){
carte c = {III, TREFLE};
if (c.valeur == 3 && c.valeur == 3) std::cout << "\033[32mOK\033[0m" << std::endl;
if (c.valeur == 3 && c.couleur == TREFLE) std::cout << "\033[32mOK\033[0m" << std::endl;
return 0;
}

23
test/scroon.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <iostream>
#include "screen.hpp"
#include "jdc.hpp"
int main(){
Screen s(11, 5);
s.background();
s.display();
JDC jdc;
jdc.init();
jdc.shuffle();
point<int> p = {0, 0};
//sprite card = {jdc.ascii(jdc.top()), 3, 4};
s.addCard(p, jdc.top());
//card = {jdc.ascii(NULL), 3};
p = {0, 12};
s.addCard(p, jdc.get(0));
s.display();
}

View File

@ -6,42 +6,42 @@ int main(){
jdc.init();
jdc.shuffle();
//jdc.display();
//jdc.shuffle();
//jdc.display();
//
//carte c = jdc.top();
//std::cout << "c : " << c.valeur << '+' << c.couleur << std::endl;
//std::cout << jdc.length() << std::endl;
//c = jdc.pop();
//std::cout << "c : " << c.valeur << '+' << c.couleur << std::endl;
//std::cout << jdc.length() << std::endl;
//
//c = jdc.get(0);
//std::cout << "c : " << c.valeur << '+' << c.couleur << std::endl;
//std::cout << jdc.length() << std::endl;
//
//jdc.display();
//std::cout << jdc.length() << std::endl;
//
//jdc.push({K, COEUR});
//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;
//
//std::cout << "top = " << jdc.valeur(jdc.top()) << jdc.couleur(jdc.top()) << std::endl;
//std::cout << jdc.couleur(jdc.top()).length() << std::endl;
jdc.display();
jdc.shuffle();
jdc.display();
carte c = jdc.top();
std::cout << "c : " << c.valeur << '+' << c.couleur << std::endl;
std::cout << jdc.length() << std::endl;
c = jdc.pop();
std::cout << "c : " << c.valeur << '+' << c.couleur << std::endl;
std::cout << jdc.length() << std::endl;
c = jdc.get(0);
std::cout << "c : " << c.valeur << '+' << c.couleur << std::endl;
std::cout << jdc.length() << std::endl;
jdc.display();
std::cout << jdc.length() << std::endl;
jdc.push({K, COEUR});
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;
std::cout << "top = " << jdc.valeur(jdc.top()) << jdc.couleur(jdc.top()) << 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++){
std::string* ss = jdc.ascii(jdc.get(y));
for (int i=0; i<3; i++){
std::cout << "\033[1;48;5;22;38;5;235m" << ss[i] << std::endl;
}
}
std::cout << "\033[0m" << std::endl;
//for (int y=0; y<52; y++){
// std::string* ss = jdc.ascii(jdc.get(y));
// for (int i=0; i<3; i++){
// std::cout << "\033[1;48;5;22;38;5;235m" << ss[i] << std::endl;
// }
//}
//std::cout << "\033[0m" << std::endl;
return 0;
}