Merge branch 'linux'
This commit is contained in:
commit
320d0aef42
4 changed files with 71 additions and 24 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
|||
pdf/*
|
||||
!pdf/pdf.tex
|
||||
!pdf/pdf.pdf
|
||||
.vscode
|
||||
blackjack
|
||||
|
|
77
blackjack.c
77
blackjack.c
|
@ -1,6 +1,13 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <conio.h>
|
||||
|
||||
#ifdef _WIN32 // si windows
|
||||
#include <conio.h>
|
||||
#else // sinon
|
||||
#include <curses.h> // fonction de conio.h en linux
|
||||
#include <unistd.h> // fonction sleep
|
||||
#include <time.h> // fonction time
|
||||
#endif
|
||||
|
||||
int cards[53] = {1,2,3,4,5,6,7,8,9,10,11,12,13,
|
||||
14,15,16,17,18,19,20,21,22,23,24,25,26,
|
||||
|
@ -11,6 +18,32 @@ int player1[10];
|
|||
int player2[10];
|
||||
int dealer[10];
|
||||
|
||||
int isWindows() {
|
||||
#ifdef _WIN32
|
||||
return 0;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int waitUser() {
|
||||
if(isWindows()) {
|
||||
printf("Press ENTER to continue...\n\n");
|
||||
getchar();
|
||||
} else {
|
||||
printf("Press any key to continue...\n\n");
|
||||
getch();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int clearUserScreen() {
|
||||
if(isWindows()) system("clear"); else system("cls");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int real_value(int nb) {
|
||||
if (nb == 1 || nb == 14 || nb == 27 || nb == 40) {
|
||||
return 1;
|
||||
|
@ -39,6 +72,8 @@ int real_value(int nb) {
|
|||
} else if (nb == 13 || nb == 26 || nb == 39 || nb == 52) {
|
||||
return 10;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char real_color(int nb) {
|
||||
|
@ -59,6 +94,8 @@ int victory(int sum) {
|
|||
} else if (sum > 21) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void draw_card(int value, char couleur) {
|
||||
|
@ -110,7 +147,7 @@ void draw_card(int value, char couleur) {
|
|||
printf("| |\n");
|
||||
printf("| |\n");
|
||||
printf("| |\n");
|
||||
printf("| %2d %c|\n");
|
||||
printf("| %2d %c|\n",real_value(value),couleur);
|
||||
printf(" ------------\n\n");
|
||||
}
|
||||
|
||||
|
@ -122,8 +159,7 @@ int main() {
|
|||
int res_p2, sum2 = 0;
|
||||
|
||||
printf("Welcome to BLACKJACK !\n");
|
||||
printf("Press any key to continue...\n\n");
|
||||
getch();
|
||||
waitUser();
|
||||
|
||||
printf(" -> Your goal is to score exactly 21 points or the nearest possible to 21.\n");
|
||||
sleep(1);
|
||||
|
@ -133,10 +169,8 @@ int main() {
|
|||
sleep(1);
|
||||
printf(" -> If the dealer's final score is greater than 21, everyone who has a score less or equal to 21 wins the game.\n\n");
|
||||
sleep(1);
|
||||
printf("Are you ready ?\n\n");
|
||||
printf("Press any key to continue...\n");
|
||||
getch();
|
||||
system("cls");
|
||||
waitUser();
|
||||
clearUserScreen();
|
||||
|
||||
printf("The game begins in...\n");
|
||||
printf("3\n");
|
||||
|
@ -147,7 +181,7 @@ int main() {
|
|||
sleep(1);
|
||||
printf("GO!");
|
||||
sleep(1);
|
||||
system("cls");
|
||||
clearUserScreen();
|
||||
|
||||
srand(time(NULL));
|
||||
dealer[0] = (rand() % 52) + 1;
|
||||
|
@ -165,9 +199,8 @@ int main() {
|
|||
sleep(1);
|
||||
printf("hidden card\n\n");
|
||||
sleep(1);
|
||||
printf("Press any key to continue...\n");
|
||||
getch();
|
||||
system("cls");
|
||||
waitUser();
|
||||
clearUserScreen();
|
||||
|
||||
printf("Each player will now receive their two first initial cards :\n\n");
|
||||
sleep(2);
|
||||
|
@ -228,9 +261,8 @@ int main() {
|
|||
sleep(1);
|
||||
draw_card(player2[1],real_color(player2[1]));
|
||||
|
||||
printf("Press any key to continue...");
|
||||
getch();
|
||||
system("cls");
|
||||
waitUser();
|
||||
clearUserScreen();
|
||||
|
||||
printf("Player 1, you can now choose either to turn more cards up or to keep your current values :\n\n");
|
||||
sleep(2);
|
||||
|
@ -293,9 +325,8 @@ int main() {
|
|||
printf("\n");
|
||||
printf("You decided to keep your current values. You can no longer have more cards. Your final score is : %d\n", sum1);
|
||||
}
|
||||
printf("Press any key to continue...");
|
||||
getch();
|
||||
system("cls");
|
||||
waitUser();
|
||||
clearUserScreen();
|
||||
|
||||
i = 0;
|
||||
acc = 2;
|
||||
|
@ -361,9 +392,8 @@ int main() {
|
|||
printf("\n");
|
||||
printf("You decided to keep your current values. You can no longer have more cards. Your final score is : %d\n", sum2);
|
||||
}
|
||||
printf("Press any key to continue...");
|
||||
getch();
|
||||
system("cls");
|
||||
waitUser();
|
||||
clearUserScreen();
|
||||
|
||||
acc = 2;
|
||||
|
||||
|
@ -463,8 +493,7 @@ int main() {
|
|||
}
|
||||
}
|
||||
|
||||
printf("Press any key to continue...");
|
||||
getch();
|
||||
waitUser();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
BIN
blackjack.exe
BIN
blackjack.exe
Binary file not shown.
16
makefile
Normal file
16
makefile
Normal file
|
@ -0,0 +1,16 @@
|
|||
CC = gcc
|
||||
CFLAGS = -Wall -Wextra
|
||||
ALL = blackjack
|
||||
CLEAN = rm -f *.o
|
||||
|
||||
all: $(ALL)
|
||||
|
||||
blackjack: blackjack.o
|
||||
$(CC) $^ -o blackjack -lncurses
|
||||
$(CLEAN)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
clean:
|
||||
$(CLEAN) $(ALL)
|
Reference in a new issue