help my first game!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2006
Posts: 37
Reputation: wingwarp is an unknown quantity at this point 
Solved Threads: 0
wingwarp's Avatar
wingwarp wingwarp is offline Offline
Light Poster

help my first game!

 
0
  #1
Jul 25th, 2006
ok this will not work what im trying to do is create a game where you are a miner and need to put mines in 5 different spots im about 1/3 done but i cant get the money to come in after i build the mine i have gone through it three times maby one of yuo could help

code:
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. int Y; // up-down
  5. int X; //left-right
  6. int STATION;
  7. int MINE;
  8. int YOU;
  9. int SCAN;
  10. int FUEL;
  11. int SEL;
  12. int MONEY;
  13. int TCOUNTER;
  14.  
  15.  
  16. MONEY = 10000;
  17. if (MONEY = 10000){
  18. cout<<"money corect\n";
  19. }
  20. else{
  21. MONEY = 10000;
  22. }
  23. cout<<"checking int...\n"; //////////////
  24. Y = 50; // checking //
  25. X = 50; //////////////
  26. if (Y == 50){
  27. cout<<"y corect\n";
  28. }
  29. else {
  30. Y = 50; //setting int
  31. }
  32. if (X == 50){ // checking int
  33. cout<<"x corect\n";
  34. }
  35. else {
  36. X = 50; //resetting int
  37. }
  38. FUEL=10;
  39. if (FUEL == 10){
  40. cout<<"fuel corect\n";
  41. }
  42. else {
  43. FUEL=10;
  44. cout<<"fuel correct\n";
  45. }
  46. STATION = 1; //at 50,50
  47. if (STATION == 1){
  48. cout<<"station corect\n";
  49. }
  50. else {
  51. STATION = 1;
  52. cout<<"station corect\n";
  53. }
  54. while (STATION == 1){
  55. //------------------------------------------------------------------------------
  56. if (MINE == 1){
  57. cout<<"you have sucessfully mined 2metric tones of\n mixed rock coal and dirt!\n";
  58. cout<<"you sold the mixed dirt for 200$!";
  59. MONEY = MONEY+120;
  60. cout<<"taxes and gas out of 200 - 80 = 120\n";
  61. }
  62. if (MINE == 2){
  63. cout<<"you have sucessfully mined 4metric tones of\n mixed rock coal and dirt!\n";
  64. cout<<"you sold the mixed dirt for 400$!";
  65. MONEY = MONEY+240;
  66. cout<<"taxes and gas out of 400 - 160 = 240\n";
  67. }
  68. if (MINE == 3){
  69. cout<<"you have sucessfully mined 6metric tones of\n mixed rock coal and dirt!\n";
  70. cout<<"you sold the mixed dirt for 600$!";
  71. MONEY = MONEY+370;
  72. cout<<"taxes and gas out of 600 - 230 = 270\n";
  73. }
  74. if (MINE == 4){
  75. cout<<"you have sucessfully mined 8metric tones of\n mixed rock coal and dirt!\n";
  76. cout<<"you sold the mixed dirt for 800$!";
  77. MONEY = MONEY+480;
  78. cout<<"taxes and gas out of 800 - = 240\n";
  79. }
  80.  
  81. //------------------------------------------------------------------------------
  82. cout<<"you are at---"<< Y <<"-"<< X <<"\n";
  83. cout<<" 1=up 2=down 3=left 4=right 5=scan 6=skip 7=BUY-fuel 8=create sml mine\n9=create research lab 10=create refiner\n\n"; //choices
  84. cin>>SEL;
  85. //------------------------------------------------------------------------------
  86. if (SEL == 1){ //selection
  87. Y = Y+1; //stating NEW int
  88. if (Y > 100){ //checking not greater than 100
  89. cout<<"A sign clearley states :NO TRESSPASSING!: in big BOLD letters!\n";
  90. Y = Y-1;
  91. }
  92. else {
  93. cout<<"you have moved to" << Y << "-" << X <<"\n";
  94. FUEL = FUEL-1;
  95. cout<<"your current fuel level is="<<FUEL<<"0%\n";
  96. }
  97. }
  98. //------------------------------------------------------------------------------
  99. if (SEL == 2){
  100. Y = Y-1; //stating NEW int
  101. if (Y < 0){ //checking no lesser than 0
  102. cout<<"A sign clearley states :NO TRESSPASSING!: in big BOLD letters!\n";
  103. Y = Y+1;
  104. FUEL = FUEL+1;
  105. }
  106. else {
  107. cout<<"you have moved to" << Y << "-" << X <<"\n";
  108. FUEL = FUEL-1;
  109. cout<<"your current fuel level is="<<FUEL<<"0%\n";
  110. }
  111. }
  112. //------------------------------------------------------------------------------
  113. if (SEL == 3){
  114. X = X-1; //stating NEW int
  115. if (X < 0){ //checking not greater than 100
  116. cout<<"A sign clearley states :NO TRESSPASSING!: in big BOLD letters!\n";
  117. X = X-1;
  118. }
  119. else {
  120. cout<<"you have moved to" << Y << "-" << X <<"\n";
  121. FUEL = FUEL-1;
  122. cout<<"your current fuel level is="<<FUEL<<"0%\n";
  123. }
  124. }
  125. //------------------------------------------------------------------------------
  126. if (SEL == 4){
  127. X = X + 1;
  128. if (X > 100){ //checking not greater than 100
  129. cout<<"A sign clearley states :NO TRESSPASSING!: in big BOLD letters!\n";
  130. X = X-1;
  131. }
  132. else {
  133. cout<<"you have moved to" << Y << "-" << X <<"\n";
  134. FUEL = FUEL-1;
  135. cout<<"your current fuel level is="<<FUEL<<"0%\n";
  136. }
  137. }
  138. //------------------------------------------------------------------------------
  139. if (SEL==5){ // 1 2 3 4 5
  140. cout<<" there is 5 possibel mine spots they are at\n X-55 Y-52\n X-72 Y-75 \n X-32 U-45\n X-10 Y-34\n X-72 Y-12\n";
  141. }
  142. //------------------------------------------------------------------------------
  143. if (SEL==6){
  144. cout<<"SKIPPING\n";
  145. }
  146. //------------------------------------------------------------------------------
  147. if (SEL==7){
  148. cout<<"BUYING FUEL...\n";
  149. FUEL = 10;
  150. MONEY = MONEY-100;
  151. cout<<"you curently have="<<MONEY<<"$\n";
  152. }
  153. //------------------------------------------------------------------------------
  154. if (SEL==8){
  155. if (Y==55){ //1
  156. if(X==52){
  157. cout<<"you built a small mine 3 turns remaning!\n";
  158. MINE=MINE+1;
  159. MONEY = MONEY-1000;
  160. cout<<"your current money is="<<MONEY<<"\n";
  161. }
  162. }
  163. if (Y==72){//2
  164. if(X==75){
  165. cout<<"you built a small mine 3 turns remaning!\n";
  166. MINE=MINE+1;
  167. MONEY = MONEY-1000;
  168. cout<<"your current money is="<<MONEY<<"\n";
  169. }
  170. }
  171. if (Y == 32){//3
  172. if(X == 45){
  173. cout<<"you built a small mine 3 turns remaning!\n";
  174. MINE=MINE+1;
  175. MONEY = MONEY-1000;
  176. cout<<"your current money is="<<MONEY<<"\n";
  177. }
  178. }
  179. if (Y==10){//4
  180. if(X==34){
  181. cout<<"you built a small mine 3 turns remaning!\n";
  182. MINE=MINE+1;
  183. MONEY = MONEY-1000;
  184. cout<<"your current money is="<<MONEY<<"\n";
  185. }
  186. }
  187. if (Y==72){
  188. if (X==12){
  189. cout<<"you built a small mine 3 turns remaning!\n";
  190. MINE=MINE+1;
  191. MONEY = MONEY-1000;
  192. cout<<"your current money is="<<MONEY<<"\n";
  193. }
  194. }
  195. else {
  196. cout<<"you were unable to build the mine! there is no valid resource...\n";
  197. }
  198. }
  199. }
  200. }

-kbcubs-
With out programing i could not live.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: help my first game!

 
0
  #2
Jul 25th, 2006
  1. if ( MONEY = 10000 )
Perhaps you are inadvertently doing what you might not want to: = is assignment, == is comparison.
  1. if ( MINE == 1 )
Make sure MINE is assigned something in all branches before moving on. Perhaps initialize it on declaration.

Also consider a switch statement instead of a long string of ifs. And consider function to do the contents of each block.

Using cin for number input may be problematic -- consider taking user input as a string and then converting to a numeric value.

Avoid "magic" numbers. Given them a name via #define, const, or perhaps array index, or even character literal.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC