From 69a630303135bfc4b755f88de7b5a5ba9e16502c Mon Sep 17 00:00:00 2001 From: _N3m0 Date: Sun, 13 Aug 2023 13:50:05 +0200 Subject: [PATCH] unicode c'est de la merde, ci+1 retoure en ascii --- Makefile | 2 +- include/jdc.hpp | 12 +++++-- include/screen.hpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++ test/cartest.cpp | 2 +- test/scroon.cpp | 23 +++++++++++++ test/testjdc.cpp | 68 +++++++++++++++++++------------------- 6 files changed, 149 insertions(+), 39 deletions(-) create mode 100644 include/screen.hpp create mode 100644 test/scroon.cpp diff --git a/Makefile b/Makefile index 6049237..804e4e9 100644 --- a/Makefile +++ b/Makefile @@ -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/*") diff --git a/include/jdc.hpp b/include/jdc.hpp index a12ed48..bb95dbb 100644 --- a/include/jdc.hpp +++ b/include/jdc.hpp @@ -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│"; diff --git a/include/screen.hpp b/include/screen.hpp new file mode 100644 index 0000000..cd51f02 --- /dev/null +++ b/include/screen.hpp @@ -0,0 +1,81 @@ +#ifndef SCREEN_HPP +#define SCREEN_HPP + +#include +#include +#include "jdc.hpp" + +template +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; iscreen[i] = new std::string; + } + }; + + ~Screen(){ + for (int i=0; iscreen[i]; + } + delete this->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"; + } + } + }; + + void display(){ + std::cout << "\033[1;48;5;22m" << std::endl; + for (int i=0; iscreen[i]) << 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, "╰──╯"); + }; + + int ligne(){ + return this->row; + } + + int colone(){ + return this->col; + } + private: + int row; + int col; +}; + +#endif diff --git a/test/cartest.cpp b/test/cartest.cpp index c98b80e..457535a 100644 --- a/test/cartest.cpp +++ b/test/cartest.cpp @@ -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; } diff --git a/test/scroon.cpp b/test/scroon.cpp new file mode 100644 index 0000000..8f9d9ec --- /dev/null +++ b/test/scroon.cpp @@ -0,0 +1,23 @@ +#include +#include "screen.hpp" +#include "jdc.hpp" + +int main(){ + Screen s(11, 5); + s.background(); + s.display(); + + JDC jdc; + jdc.init(); + jdc.shuffle(); + + point 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(); +} diff --git a/test/testjdc.cpp b/test/testjdc.cpp index 8a9b730..0f2a9a2 100644 --- a/test/testjdc.cpp +++ b/test/testjdc.cpp @@ -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; }