Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <windows.h>
- #include <time.h>
- #include <locale.h>
- #define HEAD1 printf("%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,187)
- #define HEAD2 printf("%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,188)
- #define MID1 printf("%c %c %c",186,254,186)
- #define MID2 printf("%c %c %c %c",186,254,254,186)
- #define LEFT1 printf("%c %c %c",186,254,186)
- #define RIGHT1 printf("%c %c %c",186,254,186)
- #define EMPTY printf("%c %c",186,186)
- #define BR printf("\n")
- #define SP printf(" ")
- #define W8 Sleep(80)
- #define CLS system("cls")
- #define STOP system("pause")
- #define LINE1(a) (randomValue[a] == 1 ? EMPTY : (randomValue[a] == 2 || randomValue[a] == 3) ? LEFT1 : (randomValue[a] == 4 || randomValue[a] == 5 || randomValue[a] == 6) ? MID2 : EMPTY)
- #define LINE2(a) ((randomValue[a] == 1 || randomValue[a] == 3 || randomValue[a] == 5) ? MID1 : (randomValue[a] == 2 || randomValue[a] == 4) ? EMPTY : (randomValue[a] == 6) ? MID2 : EMPTY)
- #define LINE3(a) (randomValue[a] == 1 ? EMPTY : (randomValue[a] == 2 || randomValue[a] == 3) ? RIGHT1 : (randomValue[a] == 4) || (randomValue[a] == 5) || (randomValue[a] == 6) ? MID2 : EMPTY)
- //print random four dice adjacent
- void fourDice()
- {
- setlocale(LC_ALL,"en_US");
- srand(time(NULL));
- //array of random value from 1 to 6
- int randomValue[4];
- for(int i=0; i<4; i++)
- {
- randomValue[i] = rand()%6+1;
- if((i>0) && (randomValue[i]==randomValue[i-1]))
- {
- do
- {
- randomValue[i] = rand()%6+1;
- }
- while(randomValue[i] != randomValue[i-1]);
- }
- }
- //print header
- HEAD1;SP;HEAD1;SP;HEAD1;SP;HEAD1;BR;
- //print line 1
- for(int i=0; i<4; i++)
- {
- LINE1(randomValue[i]);
- SP;
- }
- BR;
- //print line 2
- for(int i=0; i<4; i++)
- {
- LINE2(randomValue[i]);
- SP;
- }
- BR;
- //print line 3
- for(int i=0; i<4; i++)
- {
- LINE3(randomValue[i]);
- SP;
- }
- BR;
- //print footer
- HEAD2;SP;HEAD2;SP;HEAD2;SP;HEAD2;BR;
- printf("The first random value is: %d\n",randomValue[0]);
- printf("The second random value is: %d\n",randomValue[1]);
- printf("The third random value is: %d\n",randomValue[2]);
- printf("The fourth random value is: %d\n",randomValue[3]);
- }
- //animation of dice
- void switchAnimation(int e)
- {
- setlocale(LC_ALL, "en_US");
- switch(e)
- {
- case 1:
- //2564
- HEAD1;SP;HEAD1;SP;HEAD1;SP;HEAD1;BR;
- LEFT1;SP;MID2;SP;MID2;SP;MID2;BR;
- EMPTY;SP;MID1;SP;MID2;;SP;EMPTY;BR;
- RIGHT1;SP;MID2;SP;MID2;SP;MID2;BR;
- HEAD2;SP;HEAD2;SP;HEAD2;SP;HEAD2;BR;
- break;
- case 2:
- //4215
- HEAD1;SP;HEAD1;SP;HEAD1;SP;HEAD1;BR;
- MID2;SP;LEFT1;SP;EMPTY;SP;MID2;BR;
- EMPTY;SP;EMPTY;SP;MID1;SP;MID1;BR;
- MID2;SP;RIGHT1;SP;EMPTY;SP;MID2;BR;
- HEAD2;SP;HEAD2;SP;HEAD2;SP;HEAD2;BR;
- break;
- case 3:
- //6351
- HEAD1;SP;HEAD1;SP;HEAD1;SP;HEAD1;BR;
- MID2;SP;LEFT1;SP;MID2;SP;EMPTY;BR;
- MID2;SP;MID1;SP;MID1;SP;MID1;BR;
- MID2;SP;RIGHT1;SP;MID2;SP;EMPTY;BR;
- HEAD2;SP;HEAD2;SP;HEAD2;SP;HEAD2;BR;
- break;
- case 4:
- //1436
- HEAD1;SP;HEAD1;SP;HEAD1;SP;HEAD1;BR;
- EMPTY;SP;MID2;SP;LEFT1;SP;MID2;BR;
- MID1;SP;EMPTY;SP;MID1;SP;MID2;BR;
- EMPTY;SP;MID2;SP;RIGHT1;SP;MID2;BR;
- HEAD2;SP;HEAD2;SP;HEAD2;SP;HEAD2;BR;
- break;
- case 5:
- //3625
- HEAD1;SP;HEAD1;SP;HEAD1;SP;HEAD1;BR;
- LEFT1;SP;MID2;SP;LEFT1;SP;MID2;BR;
- MID1;SP;MID2;SP;EMPTY;SP;MID1;BR;
- RIGHT1;SP;MID2;SP;RIGHT1;SP;MID2;BR;
- HEAD2;SP;HEAD2;SP;HEAD2;SP;HEAD2;BR;
- break;
- case 6:
- //5142
- HEAD1;SP;HEAD1;SP;HEAD1;SP;HEAD1;BR;
- MID2;SP;EMPTY;SP;MID2;SP;LEFT1;BR;
- MID1;SP;MID1;SP;EMPTY;SP;EMPTY;BR;
- MID2;SP;EMPTY;SP;MID2;SP;RIGHT1;BR;
- HEAD2;SP;HEAD2;SP;HEAD2;SP;HEAD2;BR;
- break;
- }
- }
- void diceAnimation(int n)
- {
- setlocale(LC_ALL,"en_US");
- int u,u_before=0;
- srand(time(NULL));
- for(int i=0; i<n; i++)
- {
- u = rand()%6+1;
- if(u_before == u)u++;
- switchAnimation(u);
- u_before=u;
- W8;CLS;
- }
- }
- int main()
- {
- char repeat;
- setlocale(LC_ALL, "en_US");
- printf("The program generates you a random value on a gambling dice\n\n");
- STOP;CLS;
- do
- {
- diceAnimation(5);
- fourDice();
- BR;
- printf("Do you want to repeat the program? (y/n)\n> ");
- scanf(" %c",&repeat);
- }
- while(repeat=='Y'||repeat=='y');
- STOP;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement