943,458 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 6745
  • C RSS
May 10th, 2004
0

C craps game

Expand Post »
hi people i was wondering how you create a test plan im new to this and just created my 1st c game... need some help as im not sure how to create a test plan preferably in a table.
  1.  
  2. /*In order to play the game of craps. each player rolls 2 dice.
  3. Each die has 6 faces. These faces contain 1, 2, 3, 4, 5, and 6 spots.
  4. After the dice have come to rest, the sum of the spots on the 2 upward
  5. faces is calculated. If the sum is 7 or 11 on the first throw, the
  6. player wins. If the sum is 2, 3, or 12 on the first throw (called "craps"),
  7. the payer loses (i.e., the "house" wins). If the sum is 4, 5, 6, 8, 9, or 10
  8. on the first throw, then that sum becomes the player's "point".
  9. To win, the player must continue rolling the dice until he/she
  10. "makes the point". You lose by rolling a 7 before making the point.*/
  11.  
  12. #include <stdio.h> ////fuction prototypes for standard I/O library fuctions
  13. #include <stdlib.h> //function prototypes for conversion of numbers to text and text to numbers, random numbers
  14. #include <time.h> //fuction prototypes and types for manimpulating time and date
  15. int rollDice(void);
  16. main()
  17. {
  18.  
  19. printf(" **** **** * **** *** \n");
  20. printf(" * * * * * * * * \n");
  21. printf(" * *--* *---* *--* * \n");
  22. printf(" * * * * * * * \n");
  23. printf(" **** * * * * * *** \n");
  24. printf(" G A M E \n\n");
  25. printf(" --- --- --- \n");
  26. printf(" |O O| |O O| |O O| \n");
  27. printf(" |O O| | O | | | \n");
  28. printf(" |O O| |O O| |O O| \n");
  29. printf(" ---\t ---\t --- \n");
  30. printf(" Created by Timothy \n\n\n");
  31. printf("-------------------------------------------------\n\n");
  32.  
  33. int CONTINUE;
  34. int gameStatus;
  35. int sum;
  36. int myPoint;
  37. char roll;
  38. char r;
  39.  
  40. do{
  41. printf("To roll dice press (r) :\n\n");
  42. scanf("%c",&r);
  43. while(roll==r);
  44.  
  45. srand((unsigned)time(NULL));
  46. sum=rollDice();
  47. switch(sum){
  48. case 7:
  49. case 11:
  50.  
  51. gameStatus=1;//won
  52. break;
  53. case 2:
  54. case 3:
  55. case 12:
  56.  
  57. gameStatus =2;//lost
  58. break;
  59. default:
  60. gameStatus =0;
  61. myPoint =sum;
  62. printf("\t your current point is %d\n",myPoint);
  63. break;
  64. }
  65. while(gameStatus==0)
  66. {
  67. sum=rollDice();
  68. if(sum==myPoint)
  69. {
  70. gameStatus =1;
  71. }
  72. else
  73. {
  74. if(sum==7)
  75. gameStatus=2;
  76. }
  77. }
  78. if(gameStatus==1)
  79. {
  80. printf("\t YOU WIN $$$$$$$$$$ lucky roll!\n\n\t\t******\n\a");
  81.  
  82. }
  83. else
  84. {
  85. printf("\t YOU LOSE! try again !\n\n\a");
  86. }
  87. printf("\t Do you wish to continue?\n\n\t Press (-1) to continue (-2) to end) :\n");
  88. //control flag gives the user an option to try the game of craps again
  89.  
  90. scanf("%d", &CONTINUE);
  91. }while(CONTINUE==-1);
  92.  
  93. if(CONTINUE==-2){
  94. ;
  95. }
  96. return 0;
  97. }
  98. int rollDice()
  99. {
  100. int dice1,dice2,worksum;
  101. dice1 = 1 + (rand()%6);
  102. dice2 = 1 + (rand()%6);
  103. worksum = dice1 + dice2;
  104. printf("\t player rolled %d + %d = %d\n",dice1,dice2,worksum);
  105.  
  106. return worksum;
  107. return 0;
  108. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bones is offline Offline
1 posts
since May 2004
May 10th, 2004
0

Re: C craps game

a test plan is designed to test the robustness of your program. if you are taking in any input from the user, you would want to try many values for those inputs. most importantly, u would want to try values that a "nice" user wouldn't give u. for example, would ur program properly handle a negative value? would it properly handle the user entering NO value at all, and just sendin u EOF?
Reputation Points: 47
Solved Threads: 2
Junior Poster in Training
infamous is offline Offline
77 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Possibility of mini servers
Next Thread in C Forum Timeline: sorting file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC