diff --git a/Makefile b/Makefile index 804e4e9..0b4a4a8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PROJECTNAME=MasterMakefile +PROJECTNAME=cli-casino BIN=build/$(PROJECTNAME) CC=g++ diff --git a/include/carte.hpp b/include/carte.hpp index 8fc96e4..012293b 100644 --- a/include/carte.hpp +++ b/include/carte.hpp @@ -27,6 +27,8 @@ enum CCarte{ struct carte{ VCarte valeur; CCarte couleur; -}CARTERETOURNE = {VCarte(0), CCarte(0)}; +}; + +static carte CARTERETOURNE = {VCarte(0), CCarte(0)}; #endif diff --git a/include/machine.hpp b/include/machine.hpp new file mode 100644 index 0000000..49612cc --- /dev/null +++ b/include/machine.hpp @@ -0,0 +1,6 @@ +#ifndef MACHINE_HPP +#define MACHINE_HPP + +void machine(); + +#endif diff --git a/src/machine.cpp b/src/machine.cpp new file mode 100644 index 0000000..fc8fad7 --- /dev/null +++ b/src/machine.cpp @@ -0,0 +1,93 @@ +#include +#include +#include + +#include "machine.hpp" +#include "screen.hpp" +#include "jdc.hpp" + +void spriteDel(sprite* s){ + for (int i=0; irow; 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> input; + while (input != 'q'){ + manche(&sm, input); + std::cin >> input; + } + + spriteDel(&sp); + spriteDel(&t); +} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..e40c507 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,131 @@ +#ifdef _WIN32 +#include +#endif + +#include +#include +#include + +#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> 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; +} diff --git a/test/sprot.cpp b/test/sprot.cpp index ea31d53..099ea02 100644 --- a/test/sprot.cpp +++ b/test/sprot.cpp @@ -60,10 +60,9 @@ int main(){ sp4.data[i] = new char[21]; } - float x, y; for (float i=0; i<2*3.14; i+=0.1){ - x = (std::cos(i)+1) * 5; - y = (std::sin(i)+1) * 10; + float x = (std::cos(i)+1) * 5; + float y = (std::sin(i)+1) * 10; sp4.data[(int)x][(int)y] = '@'; } diff --git a/test/testou.cpp b/test/testou.cpp index 5311a2d..1db1f6b 100644 --- a/test/testou.cpp +++ b/test/testou.cpp @@ -9,10 +9,9 @@ int main(){ s[i] = new char[size]; } - float x, y; for (float i=0; i<2*3.14; i+=0.1){ - x = (std::cos(i)+1) * 10; - y = (std::sin(i)+1) * 10; + float x = (std::cos(i)+1) * 10; + float y = (std::sin(i)+1) * 10; std::cout << "cos : " << x << " sin : " << y << std::endl; std::cout << (int)x << ';' << (int)y << std::endl; s[(int)x][(int)y] = '@';