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;
2023-08-15 20:36:09 +02:00
this->jdc[index].couleur = (CCarte)(i+1);
2023-08-05 19:33:43 +02:00
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];
}
2023-08-14 13:12:08 +02:00
static char valeur(carte c){
if ((int)c.valeur >= 1 && (int)c.valeur < 10) return char(c.valeur+48);
2023-08-05 19:33:43 +02:00
switch(c.valeur){
case T:
2023-08-14 13:12:08 +02:00
return 'T';
2023-08-05 19:33:43 +02:00
case J:
2023-08-14 13:12:08 +02:00
return 'J';
2023-08-05 19:33:43 +02:00
case Q:
2023-08-14 13:12:08 +02:00
return 'Q';
2023-08-05 19:33:43 +02:00
case K:
2023-08-14 13:12:08 +02:00
return 'K';
2023-08-05 19:33:43 +02:00
case A:
2023-08-14 13:12:08 +02:00
return 'A';
2023-08-05 19:33:43 +02:00
default:
2023-08-14 13:12:08 +02:00
return '?';
2023-08-05 19:33:43 +02:00
}
}
2023-08-14 13:12:08 +02:00
static char couleur(carte c){
2023-08-05 19:33:43 +02:00
switch(c.couleur){
case PIC:
2023-08-14 13:12:08 +02:00
return 'P';
2023-08-05 19:33:43 +02:00
case COEUR:
2023-08-14 13:12:08 +02:00
return 'C';
2023-08-05 19:33:43 +02:00
case TREFLE:
2023-08-14 13:12:08 +02:00
return 'T';
2023-08-05 19:33:43 +02:00
case CARREAU:
2023-08-14 13:12:08 +02:00
return 'K';
2023-08-05 19:33:43 +02:00
default:
2023-08-14 13:12:08 +02:00
return '?';
2023-08-05 19:33:43 +02:00
}
};
2023-08-14 13:12:08 +02:00
//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│";
// else s[1] = "│\033[30m"+this->valeur(c)+co+"\033[38;5;235m│";
// s[2] = "╰──╯";
// return s;
//};
2023-08-05 19:33:43 +02:00
int length(){
return this->len;
}
private:
carte jdc[52];
int len;
};
#endif