could you help me to compile this snake game in c++

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2009
Posts: 3
Reputation: beset123 is an unknown quantity at this point 
Solved Threads: 0
beset123 beset123 is offline Offline
Newbie Poster

could you help me to compile this snake game in c++

 
0
  #1
Jul 13th, 2009
  1. #include<iostream>
  2. using std::cout;
  3. using std::cin;
  4. using std::endl;
  5. #include<conio.h>
  6. class Mouse
  7. { public:
  8. void move();
  9. void turn();
  10. };
  11. void Mouse::move()
  12. {
  13. char ch;
  14. int length;
  15. int width;
  16.  
  17. switch (ch)
  18. {
  19. case '1':
  20. cout<<"To move forward";
  21. for(int y;y==length;y--)
  22. break;
  23. case'2':
  24. for(int x;x<width;x++)
  25. break;
  26. case'3':
  27. for(int x;x>0;x--)
  28. break;
  29. }
  30. }
  31. void Mouse::turn()
  32. {
  33. for(int a=0;a<200;a++)
  34. cout<<a<<"^"<<(char)23<<endl;
  35. }
  36. int main()
  37. {
  38. int length,width;
  39. cout<<"Please enter the width of the room:";
  40. cin>>width;
  41. cout<<"Please enter the length of the room:";
  42. cin>>length;
  43. int ** myArray = 0;
  44. myArray = new int*[length];
  45. if (myArray != NULL) {
  46. for (int i = 0; i < length; i++) {
  47. myArray[i] = new int[width];
  48. cout<<"X";
  49. }
  50. }
  51. for(int x=0;x<width;x++)
  52. {
  53. for(int y=0;y<length;y++)
  54. myArray[x][y]=0;
  55. }
  56. cout<<length<<"x"<<width<<"x";
  57. int x,y;
  58. if(x<4&&y<4){
  59. myArray[3][4]=1;
  60. myArray[1][3]=1;
  61. }
  62. else
  63. cout<<"you entered wrong obstacles"<<endl;
  64. getch();
  65. return 0;
  66. }



/*The compilergives this runtime error could you solve the problem about it?

'hgh.exe': Loaded 'C:\Users\medion\Documents\Visual Studio 2008\Projects\hgh\Debug\hgh.exe', Symbols loaded.
'hgh.exe': Loaded 'C:\Windows\System32\ntdll.dll'
'hgh.exe': Loaded 'C:\Windows\System32\kernel32.dll'
'hgh.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.1_none_bb1f6aa1308c35eb\msvcp90d.dll'
'hgh.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.1_none_bb1f6aa1308c35eb\msvcr90d.dll'
Run-Time Check Failure #3 - The variable 'x' is being used without being initialized.
Run-Time Check Failure #3 - The variable 'y' is being used without being initialized.
First-chance exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
Unhandled exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
First-chance exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
Unhandled exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
First-chance exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
Unhandled exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
First-chance exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
Unhandled exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
First-chance exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
Unhandled exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
First-chance exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
Unhandled exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
The program '[3028] hgh.exe: Native' has exited with code 0 (0x0).*/
Last edited by Ancient Dragon; Jul 13th, 2009 at 7:25 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,678
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1503
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: could you help me to compile this snake game in c++

 
-1
  #2
Jul 13th, 2009
lines 21 and 24: >> for(int x;x<width;x++)
You forgot the variable initializer. Should be like this: for(int x = 0;x<width;x++)
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 3
Reputation: beset123 is an unknown quantity at this point 
Solved Threads: 0
beset123 beset123 is offline Offline
Newbie Poster

Re: could you help me to compile this snake game in c++

 
0
  #3
Jul 13th, 2009
thanks a lot!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 3
Reputation: beset123 is an unknown quantity at this point 
Solved Threads: 0
beset123 beset123 is offline Offline
Newbie Poster

Re: could you help me to compile this snake game in c++

 
0
  #4
Jul 13th, 2009
But i couldnt create the walls of the game and comile it could you help me
Ancient Dragon
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,678
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1503
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: could you help me to compile this snake game in c++

 
0
  #5
Jul 13th, 2009
line 17: the value of ch is undefined. Similar problem with all the other variables declared in that function. Variables have to be initialized with something before using them.
Reply With Quote Quick reply to this message  
Reply

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




Views: 413 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC