compatibilité windows/linux
This commit is contained in:
parent
40e72053e8
commit
36e1e7795c
1 changed files with 46 additions and 72 deletions
118
blackjack.c
118
blackjack.c
|
@ -1,13 +1,13 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// linux
|
||||
#include <curses.h> // fonction de conio.h en linux
|
||||
#include <unistd.h> // fonction sleep
|
||||
#include <time.h> // fonction time
|
||||
|
||||
// windows
|
||||
// #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,
|
||||
|
@ -18,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("cls"); else system("clearUserScreen");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int real_value(int nb) {
|
||||
if (nb == 1 || nb == 14 || nb == 27 || nb == 40) {
|
||||
return 1;
|
||||
|
@ -129,13 +155,7 @@ int main() {
|
|||
int res_p2, sum2 = 0;
|
||||
|
||||
printf("Welcome to BLACKJACK !\n");
|
||||
// linux
|
||||
printf("Press ENTER to continue...\n\n");
|
||||
getchar();
|
||||
|
||||
// windows
|
||||
// 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);
|
||||
|
@ -145,16 +165,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);
|
||||
// linux
|
||||
printf("Are you ready ?\n\n");
|
||||
printf("Press ENTER to continue...\n\n");
|
||||
getchar();
|
||||
system("clear");
|
||||
|
||||
// windows
|
||||
// printf("Press any key to continue...\n\n");
|
||||
// getch();
|
||||
//system("cls");
|
||||
waitUser();
|
||||
clearUserScreen();
|
||||
|
||||
printf("The game begins in...\n");
|
||||
printf("3\n");
|
||||
|
@ -165,11 +177,7 @@ int main() {
|
|||
sleep(1);
|
||||
printf("GO!");
|
||||
sleep(1);
|
||||
// linux
|
||||
system("clear");
|
||||
|
||||
// windows
|
||||
// system("cls");
|
||||
clearUserScreen();
|
||||
|
||||
srand(time(NULL));
|
||||
dealer[0] = (rand() % 52) + 1;
|
||||
|
@ -187,15 +195,8 @@ int main() {
|
|||
sleep(1);
|
||||
printf("hidden card\n\n");
|
||||
sleep(1);
|
||||
// linux
|
||||
printf("Press ENTER to continue...\n\n");
|
||||
getchar();
|
||||
system("clear");
|
||||
|
||||
// windows
|
||||
// printf("Press any key to continue...\n\n");
|
||||
// getch();
|
||||
// system("cls");
|
||||
waitUser();
|
||||
clearUserScreen();
|
||||
|
||||
printf("Each player will now receive their two first initial cards :\n\n");
|
||||
sleep(2);
|
||||
|
@ -256,15 +257,8 @@ int main() {
|
|||
sleep(1);
|
||||
draw_card(player2[1],real_color(player2[1]));
|
||||
|
||||
// linux
|
||||
printf("Press ENTER to continue...\n\n");
|
||||
getchar();
|
||||
system("clear");
|
||||
|
||||
// windows
|
||||
// printf("Press any key to continue...\n\n");
|
||||
// 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);
|
||||
|
@ -327,15 +321,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);
|
||||
}
|
||||
// linux
|
||||
printf("Press ENTER to continue...\n\n");
|
||||
getchar();
|
||||
system("clear");
|
||||
|
||||
// windows
|
||||
// printf("Press any key to continue...\n\n");
|
||||
// getch();
|
||||
// system("cls");
|
||||
waitUser();
|
||||
clearUserScreen();
|
||||
|
||||
i = 0;
|
||||
acc = 2;
|
||||
|
@ -401,15 +388,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);
|
||||
}
|
||||
// linux
|
||||
printf("Press ENTER to continue...\n\n");
|
||||
getchar();
|
||||
system("clear");
|
||||
|
||||
// windows
|
||||
// printf("Press any key to continue...\n\n");
|
||||
// getch();
|
||||
// system("cls");
|
||||
waitUser();
|
||||
clearUserScreen();
|
||||
|
||||
acc = 2;
|
||||
|
||||
|
@ -509,13 +489,7 @@ int main() {
|
|||
}
|
||||
}
|
||||
|
||||
// linux
|
||||
printf("Press ENTER to continue...\n\n");
|
||||
getchar();
|
||||
|
||||
// windows
|
||||
// printf("Press any key to continue...\n\n");
|
||||
// getch();
|
||||
waitUser();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Reference in a new issue