compatibilité windows/linux

This commit is contained in:
Mylloon 2021-03-24 20:30:57 +01:00
parent 40e72053e8
commit 36e1e7795c

View file

@ -1,13 +1,13 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
// linux #ifdef _WIN32 // si windows
#include <curses.h> // fonction de conio.h en linux #include <conio.h>
#include <unistd.h> // fonction sleep #else // sinon
#include <time.h> // fonction time #include <curses.h> // fonction de conio.h en linux
#include <unistd.h> // fonction sleep
// windows #include <time.h> // fonction time
// #include <conio.h> #endif
int cards[53] = {1,2,3,4,5,6,7,8,9,10,11,12,13, 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, 14,15,16,17,18,19,20,21,22,23,24,25,26,
@ -18,6 +18,32 @@ int player1[10];
int player2[10]; int player2[10];
int dealer[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) { int real_value(int nb) {
if (nb == 1 || nb == 14 || nb == 27 || nb == 40) { if (nb == 1 || nb == 14 || nb == 27 || nb == 40) {
return 1; return 1;
@ -129,13 +155,7 @@ int main() {
int res_p2, sum2 = 0; int res_p2, sum2 = 0;
printf("Welcome to BLACKJACK !\n"); printf("Welcome to BLACKJACK !\n");
// linux waitUser();
printf("Press ENTER to continue...\n\n");
getchar();
// windows
// printf("Press any key to continue...\n\n");
// getch();
printf(" -> Your goal is to score exactly 21 points or the nearest possible to 21.\n"); printf(" -> Your goal is to score exactly 21 points or the nearest possible to 21.\n");
sleep(1); sleep(1);
@ -145,16 +165,8 @@ int main() {
sleep(1); 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"); 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); sleep(1);
// linux waitUser();
printf("Are you ready ?\n\n"); clearUserScreen();
printf("Press ENTER to continue...\n\n");
getchar();
system("clear");
// windows
// printf("Press any key to continue...\n\n");
// getch();
//system("cls");
printf("The game begins in...\n"); printf("The game begins in...\n");
printf("3\n"); printf("3\n");
@ -165,11 +177,7 @@ int main() {
sleep(1); sleep(1);
printf("GO!"); printf("GO!");
sleep(1); sleep(1);
// linux clearUserScreen();
system("clear");
// windows
// system("cls");
srand(time(NULL)); srand(time(NULL));
dealer[0] = (rand() % 52) + 1; dealer[0] = (rand() % 52) + 1;
@ -187,15 +195,8 @@ int main() {
sleep(1); sleep(1);
printf("hidden card\n\n"); printf("hidden card\n\n");
sleep(1); sleep(1);
// linux waitUser();
printf("Press ENTER to continue...\n\n"); clearUserScreen();
getchar();
system("clear");
// windows
// printf("Press any key to continue...\n\n");
// getch();
// system("cls");
printf("Each player will now receive their two first initial cards :\n\n"); printf("Each player will now receive their two first initial cards :\n\n");
sleep(2); sleep(2);
@ -256,15 +257,8 @@ int main() {
sleep(1); sleep(1);
draw_card(player2[1],real_color(player2[1])); draw_card(player2[1],real_color(player2[1]));
// linux waitUser();
printf("Press ENTER to continue...\n\n"); clearUserScreen();
getchar();
system("clear");
// windows
// printf("Press any key to continue...\n\n");
// getch();
// system("cls");
printf("Player 1, you can now choose either to turn more cards up or to keep your current values :\n\n"); printf("Player 1, you can now choose either to turn more cards up or to keep your current values :\n\n");
sleep(2); sleep(2);
@ -327,15 +321,8 @@ int main() {
printf("\n"); 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("You decided to keep your current values. You can no longer have more cards. Your final score is : %d\n", sum1);
} }
// linux waitUser();
printf("Press ENTER to continue...\n\n"); clearUserScreen();
getchar();
system("clear");
// windows
// printf("Press any key to continue...\n\n");
// getch();
// system("cls");
i = 0; i = 0;
acc = 2; acc = 2;
@ -401,15 +388,8 @@ int main() {
printf("\n"); 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("You decided to keep your current values. You can no longer have more cards. Your final score is : %d\n", sum2);
} }
// linux waitUser();
printf("Press ENTER to continue...\n\n"); clearUserScreen();
getchar();
system("clear");
// windows
// printf("Press any key to continue...\n\n");
// getch();
// system("cls");
acc = 2; acc = 2;
@ -509,13 +489,7 @@ int main() {
} }
} }
// linux waitUser();
printf("Press ENTER to continue...\n\n");
getchar();
// windows
// printf("Press any key to continue...\n\n");
// getch();
return 0; return 0;
} }