944,100 Members | Top Members by Rank

Ad:
  • C++ Code Snippet
  • Views: 5174
  • C++ RSS
0

Bowling game

by on Nov 29th, 2005
I created a bowling game, Which for the most part works correctly. I toiled for hours trying to figure out how to do the scoring so i gave up. Its fairly simple code so not much of a description needed.
C++ Code Snippet (Toggle Plain Text)
  1. /*This Is the longest project I have planned, It will likeley take over
  2. a month and It will be a hard one. I plan on creating a bowling game in which
  3. you choose the power, spin, and location and the game will determine how
  4. many pins that combination will knock down, add it to your score and change
  5. the frame. If a strike occurs on the last (tenth) frame it will allow for another
  6. frame. Hopefully like my other project I will include a highscore list to see
  7. the skillful bowlers in this wonky bowling attempt*/
  8. #include <iostream.h>//required files
  9. #include <stdlib.h>
  10. #include <time.h>
  11. #include <fstream.h>
  12. #define MAX_SCORE 300
  13. #define MAX_RANGE 10
  14. main ()
  15. {system("color 70");
  16. system("title Text'o'Rama Bowling");
  17. char highscore, name[20], instra;
  18. int frames=0;
  19. long pins;
  20. int spin, power, arrow, score, roll, total, BASE, framescore, divy, divider;
  21. int tries;
  22. pins=10;
  23. tries=0;
  24. total=0;
  25. framescore=0;
  26. // Get random between 1 and MAX_RANGE
  27. cout<<" Welcome to Shawn Biddle's Text'o'Rama Bowling\n";
  28. cout<<"Please enter your name for the highscore list:";
  29. cin>> name;
  30. cout<<"Would you like to see the instructions?"<< endl;
  31. cin>> instra;
  32. if (instra=='y'){instra:
  33. cout<<"The objective is simple, Knock down the pins... Yeah I know you \ncan't see them. ";
  34.  
  35. cout<<"Choose Your power, spin and alignment. Power being\nfairly obvious, spin is how ";
  36.  
  37. cout<<"much spin is on the ball \ntherefor how far it will go to either side of your placement.\n";
  38.  
  39. cout<<"Finally placement or alignment being which marker on \nthe lane you line up your bowler ";
  40.  
  41. cout<<"with."<< endl;
  42. system("PAUSE");
  43. goto begin;}
  44. else {
  45. begin:
  46. do{
  47. newframe:
  48. frames++;
  49. roll+total;
  50. framestart:
  51. tries++;
  52. if (tries==1){framescore=0;}
  53. else if (tries>1){framescore=roll;}
  54. if (tries==3){tries=0;goto newframe;}
  55. system("cls");score=total;
  56. cout<<"| | 0 0 0 0 | |\n";
  57. cout<<"| | (_0_0_0_) | |\n";
  58. cout<<"| | (_0_0_) | |\n";
  59. cout<<"| | (_0_) | |\n";
  60. cout<<"| | (_) | |\n";
  61. cout<<"| | | |\n";
  62. cout<<"| | | |\n";
  63. cout<<"| |^ ^| |\n";
  64. cout<<"| |1 ^ ^ ^ 5| |\n";
  65. cout<<"| | 2 3 4 | |\n";
  66. cout<<"---------------------\n";
  67. cout<<name<<" You are in frame "<<frames<<".Score:"<<total<<"\n";
  68. cout<<"There are "<<pins-framescore<<" pins left. Try "<<tries<<"\n";
  69. cout<<"Alignment (1-5):\n";
  70. cin>> arrow;
  71. system("cls");
  72. if (arrow==1){
  73. cout<<"| | 0 0 0 0 | |\n";
  74. cout<<"| | (_0_0_0_) | |\n";
  75. cout<<"| | (_0_0_) | |\n";
  76. cout<<"| | (_0_) | |\n";
  77. cout<<"| | (_) | |\n";
  78. cout<<"| | | |\n";
  79. cout<<"| | | |\n";
  80. cout<<"| |^ ^| |\n";
  81. cout<<"| |1 ^ ^ ^ 5| |\n";
  82. cout<<"| | 2 3 4 | |\n";
  83. cout<<"-----V---------------\n";}
  84. if (arrow==2){
  85. cout<<"| | 0 0 0 0 | |\n";
  86. cout<<"| | (_0_0_0_) | |\n";
  87. cout<<"| | (_0_0_) | |\n";
  88. cout<<"| | (_0_) | |\n";
  89. cout<<"| | (_) | |\n";
  90. cout<<"| | | |\n";
  91. cout<<"| | | |\n";
  92. cout<<"| |^ ^| |\n";
  93. cout<<"| |1 ^ ^ ^ 5| |\n";
  94. cout<<"| | 2 3 4 | |\n";
  95. cout<<"-------V-------------\n";}
  96. else if (arrow==3){
  97. cout<<"| | 0 0 0 0 | |\n";
  98. cout<<"| | (_0_0_0_) | |\n";
  99. cout<<"| | (_0_0_) | |\n";
  100. cout<<"| | (_0_) | |\n";
  101. cout<<"| | (_) | |\n";
  102. cout<<"| | | |\n";
  103. cout<<"| | | |\n";
  104. cout<<"| |^ ^| |\n";
  105. cout<<"| |1 ^ ^ ^ 5| |\n";
  106. cout<<"| | 2 3 4 | |\n";
  107. cout<<"----------V----------\n";}
  108. else if (arrow==4){
  109. cout<<"| | 0 0 0 0 | |\n";
  110. cout<<"| | (_0_0_0_) | |\n";
  111. cout<<"| | (_0_0_) | |\n";
  112. cout<<"| | (_0_) | |\n";
  113. cout<<"| | (_) | |\n";
  114. cout<<"| | | |\n";
  115. cout<<"| | | |\n";
  116. cout<<"| |^ ^| |\n";
  117. cout<<"| |1 ^ ^ ^ 5| |\n";
  118. cout<<"| | 2 3 4 | |\n";
  119. cout<<"-------------V-------\n";}
  120. else if (arrow==5){cout<<"| | 0 0 0 0 | |\n";
  121. cout<<"| | (_0_0_0_) | |\n";
  122. cout<<"| | (_0_0_) | |\n";
  123. cout<<"| | (_0_) | |\n";
  124. cout<<"| | (_) | |\n";
  125. cout<<"| | | |\n";
  126. cout<<"| | | |\n";
  127. cout<<"| |^ ^| |\n";
  128. cout<<"| |1 ^ ^ ^ 5| |\n";
  129. cout<<"| | 2 3 4 | |\n";
  130. cout<<"---------------V-----\n";}
  131. cout<<"Ok "<<name<<" You are in frame "<<frames<<".Score:"<<total<<"\n";
  132. cout<<"Power (1-10):\n";
  133. cin>> power;
  134. cout<<"Spin (0-10):\n";
  135. cin>> spin;
  136. pins=10;
  137. divy=pins-framescore;
  138. if (tries==2){srand ( time (NULL) );roll = rand()%divy+1;}
  139. else {srand ( time (NULL) );roll = rand()%MAX_RANGE+1;}
  140. if (roll==0){cout<<"*CRASH* *THUMP* GUTTERBALL!\n";}
  141. if (roll==10){cout<<" STEEEEEEEEERIKE!\n";}
  142. else if (roll>0 && roll<6){cout<<"Well Atleast You Hit Something.\n";}
  143. else if (roll>6){cout<<"Good Roll, Candyass!\n";}
  144. cout<<"You knocked down "<< roll <<"\n";
  145. total=score+roll;
  146. cout<<"Your score is "<< total <<" in frame "<<frames<<"\n";
  147. divider=total/frames;
  148. system("PAUSE");
  149. if (frames==10 && roll==10){goto newframe;}
  150. if (roll==10){tries=0;goto newframe;}
  151. while (tries<3 && roll<10 && frames<10){pins-roll;goto framestart;}
  152. }while(frames<10);
  153. ofstream examplefile ("highscore.txt", ios::ate | ios::app);
  154. if (examplefile.is_open())
  155. {
  156. examplefile << ""<< name <<"--------"<< total <<"\n";
  157. examplefile.close(); }
  158. bah: cout<<"Would you like to see the highscore list? [Y][N]"<< endl;
  159. cin>> highscore;
  160. if (highscore=='y'){
  161. system("cls");
  162. char buffer[256];
  163. ifstream examplefile ("highscore.txt");
  164. if (! examplefile.is_open()) { cout << "Error opening file"; exit (1); }
  165. while (! examplefile.eof() ){
  166. examplefile.getline (buffer,100);
  167. cout << buffer <<endl;}}
  168. else {cout<<"Thanks for playing!\n";
  169. system("PAUSE");
  170. return 0;}
  171. cout<<"Thank You very much for playing my game!"<< endl;
  172. system("PAUSE");
  173. return 0;}}
Comments on this Code Snippet
Nov 29th, 2005
0

Re: Bowling game

sorry for the overlapping text, and despite the look here, the big blocky things do actually look like a lane with bowling pins in a console window
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Nov 12th, 2006
0

Re: Bowling game

I LIKE THIS PROGRAM, BECAUSE HELP ME TO MAKE MY PROJEK TUTORIAL . THANK YOU! SO MUCH
:lol:
Newbie Poster
A.FATHA is offline Offline
1 posts
since Nov 2006
Nov 20th, 2006
0

Re: Bowling game

1)Main should have a type: int main (void)
2) O-o-out dated: goto begin;
3) What's with the indentation?
4) Seed rand only once, at the start of the app.
5) Could you have made this any less portable?
Junior Poster
manutd is offline Offline
100 posts
since Nov 2006
Nov 21st, 2006
0

Re: Bowling game

6) Take out the .h's:
include <iostream>
//etc...
Junior Poster
manutd is offline Offline
100 posts
since Nov 2006
Dec 17th, 2006
0

Re: Bowling game

sorry mautd, when I wrote this program I had no formal experience my entire knowledge of C++ was based off tutorials. and there was no real reason to make it portable, if you are speaking of linux then just include the cstdlib header and replace "cls" with "clear".
As to A.FATHA I'm glad I could help.
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Message:
Previous Thread in C++ Forum Timeline: Adding binary values from a file
Next Thread in C++ Forum Timeline: Link errors in C/C++ extension modules





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


Follow us on Twitter


© 2011 DaniWeb® LLC