cli-casino/include/jdc.hpp

127 lines
2.4 KiB
C++
Raw Normal View History

2023-08-05 19:33:43 +02:00
#ifndef JDC_HPP
#define JDC_HPP
#include <iostream>
#include <cstdlib>
#include "carte.hpp"
class JDC{
public:
JDC(){
this->len = 0;
};
void init(){
this->len = 52;
int index;
2023-08-05 19:33:43 +02:00
for (int i=0; i<4; i++){
for (int y=0; y<13; y++){
index = (i*13)+y;
this->jdc[index].couleur = (CCarte)i;
this->jdc[index].valeur = (VCarte)(y+2);
}
}
}
void shuffle(){
srand(time(0));
for (int i=0; i<52; i++){
int randomIndex = rand()%52;
carte swap = this->jdc[randomIndex];
this->jdc[randomIndex] = this->jdc[i];
this->jdc[i] = swap;
}
};
void display(){
for (int i=0; i<this->len; i++){
if (!(i%13)) std::cout << std::endl;
std::cout << i << ':' << this->jdc[i].valeur << '+' << this->jdc[i].couleur << '\t';
}
std::cout << std::endl;
};
carte top(){
if (this->len <= 0) throw "jdc empty";
return this->jdc[this->len-1];
}
carte pop(){
if (this->len <= 0) throw "jdc empty";
this->len--;
return this->jdc[this->len];
}
carte push(carte c){
if (this->len == 52) throw "jdc full";
this->jdc[this->len] = c;
this->len++;
return c;
}
carte get(int index){
if (index < 0 || index > this->len) throw "jdc out of bound";
return this->jdc[index];
}
static std::string valeur(carte c){
2023-08-05 19:33:43 +02:00
if ((int)c.valeur < 10) return std::to_string(c.valeur);
switch(c.valeur){
case T:
return "T";
case J:
return "J";
case Q:
return "Q";
case K:
return "K";
case A:
return "A";
default:
return "?";
}
}
static std::string couleur(carte c){
2023-08-05 19:33:43 +02:00
switch(c.couleur){
case PIC:
return "";
case COEUR:
return "";
case TREFLE:
return "";
case CARREAU:
return "";
default:
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;
//}
2023-08-05 19:33:43 +02:00
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;
}
private:
carte jdc[52];
int len;
};
#endif