Created
December 3, 2017 08:22
-
-
Save OwiseKyawMinOo/a29eb3ea438e7056093468557f61df15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<conio.h> | |
#include<stdlib.h> | |
#include<time.h> | |
#define sh1 5 //snack head | |
#define st1 29//snack tail | |
#define sh2 11 | |
#define st2 41 | |
#define sh3 21 | |
#define st3 13 | |
#define sh4 34 | |
#define st4 47 | |
#define lb1 10 //ladder bottom | |
#define lt1 24//ladder top | |
#define lb2 19 | |
#define lt2 39 | |
#define lb3 35 | |
#define lt3 45 | |
#define lb4 31 | |
#define lt4 49 | |
int genRandom(int n);//function declare(prototype) | |
//main function start | |
int main() | |
{ | |
//user player | |
int u=1; | |
int dice=0; | |
int count=0; | |
time_t t; | |
srand((unsigned)time(&t)); | |
while(u!=50) | |
{ | |
printf("Please press key to dice \n"); | |
getch(); | |
dice=genRandom(6); | |
count++; | |
u=u+dice; //u+=dice;same to same | |
printf("\n"); | |
printf("dice! = %d",dice); | |
printf("\n"); | |
printf("Now user moves to %d",u); | |
printf("\n"); | |
if(u>50) {u=100-u; printf("Over 50....,Now user moves to %d",u);} | |
printf("\n"); | |
switch(u) | |
{ | |
case sh1: u=lt1;printf(" you moved to tail %d",u);break; | |
case sh2: u=lt2;printf(" you moved to tail %d",u);break; | |
case sh3: u=lt3;printf(" you moved to tail %d",u);break; | |
case sh4: u=lt4;printf(" you moved to tail %d",u);break; | |
} | |
printf("\n"); | |
switch(u) | |
{ | |
case lb1: u=lt1;printf(" you moved to tOP %d",u);break; | |
case lb2: u=lt2;printf(" you moved to tOP %d",u);break; | |
case lb3: u=lt3;printf(" you moved to tOP %d",u);break; | |
case lb4: u=lt4;printf(" you moved to tOP %d",u);break; | |
} | |
printf("\n"); | |
} | |
printf("game over! total dice %d times",count); | |
getch(); | |
} | |
// main function ends here | |
//random number generator for 1 to n | |
int genRandom(int n) | |
{ | |
int i=0; | |
i=rand(); | |
i=(i%n)+1; | |
return i; | |
} | |
//fun genRandom ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment