menu + machine a sous

This commit is contained in:
_N3m0 2023-08-15 16:25:28 +02:00
parent c119abf31e
commit 6c9d716b9a
7 changed files with 238 additions and 8 deletions

View File

@ -1,4 +1,4 @@
PROJECTNAME=MasterMakefile PROJECTNAME=cli-casino
BIN=build/$(PROJECTNAME) BIN=build/$(PROJECTNAME)
CC=g++ CC=g++

View File

@ -27,6 +27,8 @@ enum CCarte{
struct carte{ struct carte{
VCarte valeur; VCarte valeur;
CCarte couleur; CCarte couleur;
}CARTERETOURNE = {VCarte(0), CCarte(0)}; };
static carte CARTERETOURNE = {VCarte(0), CCarte(0)};
#endif #endif

6
include/machine.hpp Normal file
View File

@ -0,0 +1,6 @@
#ifndef MACHINE_HPP
#define MACHINE_HPP
void machine();
#endif

93
src/machine.cpp Normal file
View File

@ -0,0 +1,93 @@
#include <iostream>
#include <unistd.h>
#include <cstring>
#include "machine.hpp"
#include "screen.hpp"
#include "jdc.hpp"
void spriteDel(sprite* s){
for (int i=0; i<s->row; i++){
delete s->data[i];
}
delete s->data;
}
void jack(Screen* s){
strcpy(s->screen[5], " J A C K P O T ");
}
void manche(Screen* s, char in){
strcpy(s->screen[5], " ");
strcpy(s->screen[3], "| - - | - - | - - |");
s->display();
srand(time(0));
char symbole[] = "OP@7AX";
int symb_l = 6;
// cheat &
if (in == '&'){
char c = symbole[(rand()%symb_l)];
s->screen[3][3] = c;
s->screen[3][9] = c;
s->screen[3][15] = c;
jack(s);
s->display();
return;
}
for (int i=0; i<15; i++){
for (int y=0; y<(i%3)+1; y++){
s->screen[3][3+6*y] = symbole[(rand()%symb_l)];
}
s->display();
usleep(200000);
}
if (s->screen[3][3] == s->screen[3][9] && s->screen[3][9] == s->screen[3][15]) jack(s);
else strcpy(s->screen[5], " P E R D U ");
s->display();
};
void machine(){
Screen sm(6, 19);
sprite sp = {NULL, 3, 19};
sp.data = new char*[sp.row];
for (int i=0; i<sp.row; i++){
sp.data[i] = new char[sp.col];
}
strcpy(sp.data[0], "+-----+-----+-----+");
strcpy(sp.data[1], "| - - | - - | - - |");
strcpy(sp.data[2], "+-----+-----+-----+");
sprite t = {NULL, 2, 19};
t.data = new char*[t.row];
for (int i=0; i<t.row; i++){
t.data[i] = new char[t.col];
}
strcpy(t.data[0], "Pour jouer : * ");
strcpy(t.data[1], "Pour quitter : q ");
sm.addSprite({0, 2}, sp);
sm.addSprite({0, 0}, t);
jack(&sm);
sm.display();
// game
char input;
std::cin >> input;
while (input != 'q'){
manche(&sm, input);
std::cin >> input;
}
spriteDel(&sp);
spriteDel(&t);
}

131
src/main.cpp Normal file
View File

@ -0,0 +1,131 @@
#ifdef _WIN32
#include <windows.h>
#endif
#include <iostream>
#include <unistd.h>
#include <cstring>
#include "screen.hpp"
#include "jdc.hpp"
#include "machine.hpp"
void menu(){
static Screen s(7, 18);
sprite sp = {NULL, 7, 18};
sp.data = new char*[sp.row];
for (int i=0; i<sp.row; i++){
sp.data[i] = new char[sp.col];
}
strcpy(sp.data[0], "Choisisez un jeu :");
strcpy(sp.data[1], " ");
strcpy(sp.data[2], "1 - Blackjack ");
strcpy(sp.data[3], "2 - Roulette ");
strcpy(sp.data[4], "3 - Machine a sous");
strcpy(sp.data[5], "4 - Course d'as ");
strcpy(sp.data[6], "q - Quitter ");
s.addSprite({0, 0}, sp);
s.display();
}
void selectGame(){
char input;
std::cin >> input;
switch (input){
case '1':
//blackjack();
std::cout << "blackjack" << std::endl;
break;
case '2':
//roulette();
std::cout << "roulette" << std::endl;
break;
case '3':
machine();
break;
case '4':
//course();
std::cout << "course" << std::endl;
break;
}
if (input != 'q'){
menu();
selectGame();
}
}
void setup(){
#ifndef _WIN32
// echo off
struct termios term;
tcgetattr(1, &term);
term.c_lflag &= ~ECHO;
tcsetattr(1, TCSANOW, &term);
// canon off
struct termios term2;
tcgetattr(1, &term2);
term2.c_lflag &= ~ICANON;
tcsetattr(1, TCSANOW, &term2);
#else
// active couleur sur windows
DWORD outMode = 0;
stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
if(stdoutHandle == INVALID_HANDLE_VALUE){
exit(GetLastError());
}
if(!GetConsoleMode(stdoutHandle, &outMode)){
exit(GetLastError());
}
outModeInit = outMode;
outMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
if(!SetConsoleMode(stdoutHandle, outMode)){
exit(GetLastError());
}
#endif
}
void tearDown(){
std::cout << "\033[0m \033[?25h \033[?1049l\033[?1049l\033[?1049l" << std::endl;
puts("\033[2J");
puts("\033[0;0H");
#ifndef _WIN32
// echo on
struct termios term;
tcgetattr(1, &term);
term.c_lflag |= ECHO;
tcsetattr(1, TCSANOW, &term);
// canon on
struct termios term2;
tcgetattr(1, &term2);
term2.c_lflag |= ICANON;
tcsetattr(1, TCSANOW, &term2);
#else
// restore la console sur windows
if(!SetConsoleMode(stdoutHandle, outModeInit)){
exit(GetLastError());
}
#endif
}
int main(){
setup();
menu();
selectGame();
tearDown();
return 0;
}

View File

@ -60,10 +60,9 @@ int main(){
sp4.data[i] = new char[21]; sp4.data[i] = new char[21];
} }
float x, y;
for (float i=0; i<2*3.14; i+=0.1){ for (float i=0; i<2*3.14; i+=0.1){
x = (std::cos(i)+1) * 5; float x = (std::cos(i)+1) * 5;
y = (std::sin(i)+1) * 10; float y = (std::sin(i)+1) * 10;
sp4.data[(int)x][(int)y] = '@'; sp4.data[(int)x][(int)y] = '@';
} }

View File

@ -9,10 +9,9 @@ int main(){
s[i] = new char[size]; s[i] = new char[size];
} }
float x, y;
for (float i=0; i<2*3.14; i+=0.1){ for (float i=0; i<2*3.14; i+=0.1){
x = (std::cos(i)+1) * 10; float x = (std::cos(i)+1) * 10;
y = (std::sin(i)+1) * 10; float y = (std::sin(i)+1) * 10;
std::cout << "cos : " << x << " sin : " << y << std::endl; std::cout << "cos : " << x << " sin : " << y << std::endl;
std::cout << (int)x << ';' << (int)y << std::endl; std::cout << (int)x << ';' << (int)y << std::endl;
s[(int)x][(int)y] = '@'; s[(int)x][(int)y] = '@';