daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest Oct 12th, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Programmer: Dr. Aung Win Htut
  2. //Start:                2017101201
  3. //SnakeGame.cpp
  4. //Single Player Only Snake and Ladder Game
  5.  
  6. //Header Files
  7. #include<stdio.h>
  8. #include<conio.h>
  9. #include<stdlib.h>
  10. #include<time.h>
  11.  
  12. //sh - snake head , st - snake tail  
  13. #define sh1 99
  14. #define st1 78
  15. #define sh2 95
  16. #define st2 75
  17. #define sh3 93
  18. #define st3 73
  19. #define sh4 87
  20. #define st4 24
  21. #define sh5 62
  22. #define st5 19
  23. #define sh6 64
  24. #define st6 60
  25. #define sh7 54
  26. #define st7 34
  27. #define sh8 17
  28. #define st8 7
  29.  
  30. //lb - ladder bottom , lt - ladder top
  31. #define lb1 4
  32. #define lt1 14
  33. #define lb2 9
  34. #define lt2 31
  35. #define lb3 20
  36. #define lt3 38
  37. #define lb4 28
  38. #define lt4 84
  39. #define lb5 40
  40. #define lt5 59
  41. #define lb6 51
  42. #define lt6 67
  43. #define lb7 63
  44. #define lt7 81
  45. #define lb8 71
  46. #define lt8 91
  47.  
  48. //function prototype declarations
  49. int genRandom(int n);
  50.  
  51.  
  52. //main function starts here
  53. int main()
  54. {
  55.     int u1=1;
  56.     int u2=1;
  57.     int u3=1;
  58.     int dice=0;
  59.     int count=0;
  60.     time_t t;
  61.     srand((unsigned)time(&t)); 
  62.    
  63.     while(u1!=100)
  64.     {
  65.         printf("Please press ANY key to dice \n");
  66.         getch();
  67.         dice=genRandom(6);
  68.         count++;
  69.         u1=u1+dice; //u1+=dice;
  70.         printf("\n");      
  71.         printf("dice! = %d",dice);
  72.         printf("\n");
  73.         printf("Now user moves to %d",u1);
  74.         printf("\n");
  75.         if(u1>100) {u1=200-u1; printf("Over 100!!! So,Now user moves to %d",u1);}
  76.         printf("\n");
  77.         if(u1==sh1){ u1=st1; printf("Ohhhh.... Snake1 !!!! you moved to its tail %d",u1); }
  78.         if(u1==sh2){ u1=st2;printf("Ohhhh.... Snake2 !!!! you moved to its tail %d",u1); }
  79.         if(u1==sh3){ u1=st3;printf("Ohhhh.... Snake3 !!!! you moved to its tail %d",u1); }
  80.         if(u1==sh4){ u1=st4;printf("Ohhhh.... Snake4 !!!! you moved to its tail %d",u1); }
  81.         if(u1==sh5){ u1=st5;printf("Ohhhh.... Snake5 !!!! you moved to its tail %d",u1); }
  82.         if(u1==sh6){ u1=st6;printf("Ohhhh.... Snake6 !!!! you moved to its tail %d",u1); }
  83.         if(u1==sh7){ u1=st7;printf("Ohhhh.... Snake7 !!!! you moved to its tail %d",u1); }
  84.         if(u1==sh8){ u1=st8;printf("Ohhhh.... Snake8 !!!! you moved to its tail %d",u1); }
  85.         printf("\n");
  86.         switch(u1)
  87.         {
  88.             case lb1: u1=lt1;printf("Yayyyy.... Ladder1 !!!! you moved to its TOP %d",u1);break;
  89.             case lb2: u1=lt2;printf("Yayyyy.... Ladder2 !!!! you moved to its TOP %d",u1);break;
  90.             case lb3: u1=lt3;printf("Yayyyy.... Ladder3 !!!! you moved to its TOP %d",u1);break;
  91.             case lb4: u1=lt4;printf("Yayyyy.... Ladder4 !!!! you moved to its TOP %d",u1);break;
  92.             case lb5: u1=lt5;printf("Yayyyy.... Ladder5 !!!! you moved to its TOP %d",u1);break;
  93.             case lb6: u1=lt6;printf("Yayyyy.... Ladder6 !!!! you moved to its TOP %d",u1);break;
  94.             case lb7: u1=lt7;printf("Yayyyy.... Ladder7 !!!! you moved to its TOP %d",u1);break;
  95.             case lb8: u1=lt8;printf("Yayyyy.... Ladder8 !!!! you moved to its TOP %d",u1);break;
  96.         }
  97.             printf("\n");
  98.     }
  99.     printf("game over! total dice %d times",count);
  100.    
  101.     getch();
  102. }
  103. // main function ends here
  104.  
  105. //random number generator for 1 to n
  106. int genRandom(int n)
  107. {
  108.     int i=0;   
  109.     i=rand();
  110.     i=(i%n)+1;
  111.     return i;
  112. }
  113. //fun genRandom ends here
RAW Paste Data
Top