![]() |
Snake Game problem
I have written a snake game. There are 2 levels in the game(I
finished 1st level). It can run in VC++ without problem but, when I run it on the dev C++ 4.9.9.2, it cannot run. I want to practice my programming in Dev C++ rather than in VC++. What can I do now? The Game: --- writing a snake game using color console window. 1-player game. The player makes use of 4 arrow keys to operate the movement to chase and eat as much food (#) as possible. Food with a different color has score. The game will end when the snake hits itself or the player hits ESC key. -----Use link list is a must. Thanks! |
Re: Snake Game problem
On Jun 10, 9:50 am, "foolsmart2...@gmail.com"
<foolsmart2...@gmail.com> wrote: > I have written a snake game. There are 2 levels in the game(I > finished 1st level). It can run in VC++ without problem but, when I > run it on the dev C++ 4.9.9.2, it cannot run. I want to practice my > programming in Dev C++ rather than in VC++. What can I do now? > > The Game: > --- writing a snake game using color console window. > 1-player game. The player makes use of 4 arrow keys to operate the > movement > to chase and eat as much food (#) as possible. Food with a different > color has > score. The game will end when the snake hits itself or the player hits > ESC key. > -----Use link list is a must. > > Thanks! You need to post more info regarding the compilation options and the error messages you got when you tried to compile in Dev C++, to be of more help. Shan |
Re: Snake Game problem
shan_rish@yahoo.com wrote:
> On Jun 10, 9:50 am, "foolsmart2...@gmail.com" > <foolsmart2...@gmail.com> wrote: >> I have written a snake game. There are 2 levels in the game(I >> finished 1st level). It can run in VC++ without problem but, when I >> run it on the dev C++ 4.9.9.2, it cannot run. I want to practice my >> programming in Dev C++ rather than in VC++. What can I do now? >> >> The Game: >> --- writing a snake game using color console window. >> 1-player game. The player makes use of 4 arrow keys to operate the >> movement >> to chase and eat as much food (#) as possible. Food with a different >> color has >> score. The game will end when the snake hits itself or the player hits >> ESC key. >> -----Use link list is a must. >> >> Thanks! > > You need to post more info regarding the compilation options and the > error messages you got when you tried to compile in Dev C++, to be of > more help. Also, the OP should post that additional info in a forum where it is topical. Compilation options of particular compilers and the quirks of platform specific libraries or tricks (needed for color console windows, of which standard C++ would not know anything) do not belong here. Best Kai-Uwe Bux |
Re: Snake Game problem
On Jun 10, 12:50*pm, "foolsmart2...@gmail.com"
<foolsmart2...@gmail.com> wrote: > I have written a snake game. *There are 2 levels in the game(I > finished 1st level). * It can run in VC++ without problem but, when I > run it on the dev C++ 4.9.9.2, it cannot run. * *I want to practice my > programming in Dev C++ rather than in VC++. What can I do now? > > The Game: > --- writing a snake game using color console window. > 1-player game. The player makes use of 4 arrow keys to operate the > movement > to chase and eat as much food (#) as possible. Food with a different > color has > score. The game will end when the snake hits itself or the player hits > ESC key. > -----Use link list is a must. > > Thanks! Owing to the file is quite a lot of code, I think I will use another method to tell you the error. But now, I suffer a problem in Dev C++, here is the code: #include<iostream> #include<iomanip> #include<string> using namespace std; struct CarType{ string maker; int year; float price; } void getYourCar(CarType & car); int main() { CarType myCar, yourCar; myCar.make = "Mercedes"; myCar.year = 2008; myCar.price = 556653; getYourCar(yourCar); cout << "Your car is a: " << yourCar.maker << endl; cout << fixed << showpoint << setprecision(2) << "I will offer $" << yourCar.price -100 << "for your car." <<endl; system("pause"); return 0; } void getYourCar(CarType & car) { cout << "Enter your maker: "; cin >> car.maker; cout << "Enter the year: "; cin >> car.year; cout << "Enter the price:$"; cin >> car.price; } Error messages are gotten. Compiler: Default compiler Executing g++.exe... g++.exe "C:\Documents and Settings\Desktop\structtest.cpp" -o "C: \Documents and Settings\Desktop\structtest.exe" -I"C:\Dev-Cpp\lib \gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++ \3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev- Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" C:\Documents and Settings\Desktop\structtest.cpp:12: error: new types may not be defined in a return type C:\Documents and Settings\Desktop\structtest.cpp:12: error: two or more data types in declaration of `getYourCar' C:\Documents and Settings\Desktop\structtest.cpp: In function `int main()': C:\Documents and Settings\Desktop\structtest.cpp:19: error: 'struct CarType' has no member named 'make' C:\Documents and Settings\Desktop\structtest.cpp: In function `void getYourCar(CarType&)': C:\Documents and Settings\Desktop\structtest.cpp:35: error: new declaration `void getYourCar(CarType&)' C:\Documents and Settings\Desktop\structtest.cpp:12: error: ambiguates old declaration `CarType getYourCar(CarType&)' Execution terminated This code should be no problem, why it still cannot run in Dev C++? |
Re: Snake Game problem
These is no ';' after your struct CarType definition. Does it cause
your problem? And try to use 'void getYourCar(struct CarType & car);' instead? On Jun 10, 7:06*pm, "foolsmart2...@gmail.com" <foolsmart2...@gmail.com> wrote: > On Jun 10, 12:50*pm, "foolsmart2...@gmail.com" > > > > <foolsmart2...@gmail.com> wrote: > > I have written a snake game. *There are 2 levels in the game(I > > finished 1st level). * It can run in VC++ without problem but, when I > > run it on the dev C++ 4.9.9.2, it cannot run. * *I want to practice my > > programming in Dev C++ rather than in VC++. What can I do now? > > > The Game: > > --- writing a snake game using color console window. > > 1-player game. The player makes use of 4 arrow keys to operate the > > movement > > to chase and eat as much food (#) as possible. Food with a different > > color has > > score. The game will end when the snake hits itself or the player hits > > ESC key. > > -----Use link list is a must. > > > Thanks! > > Owing to the file is quite a lot of code, I think I will use another > method to tell you the error. *But now, I suffer a problem in Dev C++, > here is the code: > #include<iostream> > #include<iomanip> > #include<string> > using namespace std; > > struct CarType{ > * * * *string maker; > * * * *int year; > * * * *float price; > > } > > *void getYourCar(CarType & car); > > int main() > { > * * CarType myCar, yourCar; > > * * myCar.make = "Mercedes"; > * * myCar.year = 2008; > * * myCar.price = 556653; > > * * getYourCar(yourCar); > > * * cout << "Your car is a: " << yourCar.maker << endl; > * * cout << fixed << showpoint << setprecision(2) << > * * * * *"I will offer $" << yourCar.price -100 << "for your car.." > <<endl; > > * * system("pause"); > * * return 0; > > } > > void getYourCar(CarType & car) > { > * * *cout << "Enter your maker: "; > * * *cin >> car.maker; > * * *cout << "Enter the year: "; > * * *cin >> car.year; > * * *cout << "Enter the price:$"; > * * *cin >> car.price; > *} > > Error messages are gotten. > > Compiler: Default compiler > Executing *g++.exe... > g++.exe "C:\Documents and Settings\Desktop\structtest.cpp" -o "C: > \Documents and Settings\Desktop\structtest.exe" * *-I"C:\Dev-Cpp\lib > \gcc\mingw32\3.4.2\include" *-I"C:\Dev-Cpp\include\c++ > \3.4.2\backward" *-I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" *-I"C:\Dev- > Cpp\include\c++\3.4.2" *-I"C:\Dev-Cpp\include" * -L"C:\Dev-Cpp\lib" > C:\Documents and Settings\Desktop\structtest.cpp:12: error: new types > may not be defined in a return type > C:\Documents and Settings\Desktop\structtest.cpp:12: error: two or > more data types in declaration of `getYourCar' > > C:\Documents and Settings\Desktop\structtest.cpp: In function `int > main()': > C:\Documents and Settings\Desktop\structtest.cpp:19: error: 'struct > CarType' has no member named 'make' > > C:\Documents and Settings\Desktop\structtest.cpp: In function `void > getYourCar(CarType&)': > C:\Documents and Settings\Desktop\structtest.cpp:35: error: new > declaration `void getYourCar(CarType&)' > C:\Documents and Settings\Desktop\structtest.cpp:12: error: ambiguates > old declaration `CarType getYourCar(CarType&)' > > Execution terminated > > This code should be no problem, why it still cannot run in Dev C++? |
Re: Snake Game problem
On Jun 10, 7:24 pm, Linlin Yan <yanlinli...@gmail.com> wrote:
> These is no ';' after your struct CarType definition. Does it cause > your problem? > And try to use 'void getYourCar(struct CarType & car);' instead? > > On Jun 10, 7:06 pm, "foolsmart2...@gmail.com" > > <foolsmart2...@gmail.com> wrote: > > On Jun 10, 12:50 pm, "foolsmart2...@gmail.com" > > > <foolsmart2...@gmail.com> wrote: > > > I have written a snake game. There are 2 levels in the game(I > > > finished 1st level). It can run in VC++ without problem but, when I > > > run it on the dev C++ 4.9.9.2, it cannot run. I want to practice my > > > programming in Dev C++ rather than in VC++. What can I do now? > > > > The Game: > > > --- writing a snake game using color console window. > > > 1-player game. The player makes use of 4 arrow keys to operate the > > > movement > > > to chase and eat as much food (#) as possible. Food with a different > > > color has > > > score. The game will end when the snake hits itself or the player hits > > > ESC key. > > > -----Use link list is a must. > > > > Thanks! > > > Owing to the file is quite a lot of code, I think I will use another > > method to tell you the error. But now, I suffer a problem in Dev C++, > > here is the code: > > #include<iostream> > > #include<iomanip> > > #include<string> > > using namespace std; > > > struct CarType{ > > string maker; > > int year; > > float price; > > > } > > > void getYourCar(CarType & car); > > > int main() > > { > > CarType myCar, yourCar; > > > myCar.make = "Mercedes"; > > myCar.year = 2008; > > myCar.price = 556653; > > > getYourCar(yourCar); > > > cout << "Your car is a: " << yourCar.maker << endl; > > cout << fixed << showpoint << setprecision(2) << > > "I will offer $" << yourCar.price -100 << "for your car." > > <<endl; > > > system("pause"); > > return 0; > > > } > > > void getYourCar(CarType & car) > > { > > cout << "Enter your maker: "; > > cin >> car.maker; > > cout << "Enter the year: "; > > cin >> car.year; > > cout << "Enter the price:$"; > > cin >> car.price; > > } > > > Error messages are gotten. > > > Compiler: Default compiler > > Executing g++.exe... > > g++.exe "C:\Documents and Settings\Desktop\structtest.cpp" -o "C: > > \Documents and Settings\Desktop\structtest.exe" -I"C:\Dev-Cpp\lib > > \gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++ > > \3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev- > > Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" > > C:\Documents and Settings\Desktop\structtest.cpp:12: error: new types > > may not be defined in a return type > > C:\Documents and Settings\Desktop\structtest.cpp:12: error: two or > > more data types in declaration of `getYourCar' > > > C:\Documents and Settings\Desktop\structtest.cpp: In function `int > > main()': > > C:\Documents and Settings\Desktop\structtest.cpp:19: error: 'struct > > CarType' has no member named 'make' > > > C:\Documents and Settings\Desktop\structtest.cpp: In function `void > > getYourCar(CarType&)': > > C:\Documents and Settings\Desktop\structtest.cpp:35: error: new > > declaration `void getYourCar(CarType&)' > > C:\Documents and Settings\Desktop\structtest.cpp:12: error: ambiguates > > old declaration `CarType getYourCar(CarType&)' > > > Execution terminated > > > This code should be no problem, why it still cannot run in Dev C++? Oh, you are right, it is my careless mistake. Now , the following is my snake game's error: Compiler: Default compiler Building Makefile: "E:\Dev C++\CityU\Snake\Makefile.win" Executing make... make.exe -f "E:\Dev C++\CityU\Snake\Makefile.win" all g++.exe -D__DEBUG__ -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/ mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" - I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/ 3.4.2" -I"C:/Dev-Cpp/include" -g3 In file included from SnakeList.h:5, from FoodList.h:10, from main.cpp:13: SnakeNode.h:19:7: warning: extra tokens at end of #endif directive g++.exe -D__DEBUG__ FoodList.o FoodNode.o main.o SnakeList.o SnakeNode.o -o "Snake.exe" -L"C:/Dev-Cpp/lib" colorScreen.a timer.a - g3 Execution terminated Compilation successful -----------here is SnakeList.h------------------ #ifndef _SNAKE_LIST_ #define _SNAKE_LIST_ #include "colorScreen.h" #include "SnakeNode.h" #include "FoodList.h" class SnakeList { public: SnakeList(ColorScreen& g); SnakeList(); ~SnakeList(); void adds (ColorScreen g, int x,int y,char in) ; //void adds (ColorScreen g,int x,int y,char in) ; void display(const SnakeNode* ptr,ColorScreen g,int sx,int sy,char in) ; void display(ColorScreen g,int sx, int sy,char in) ; // function to search X hits body; bool search(SnakeNode* ptr); bool search(); void move(ColorScreen g,int x,int y, char in); void move(SnakeNode*& ptr,ColorScreen g, int x,int y, char in); void clear(SnakeNode*& ptr,ColorScreen g, int sx,int sy); void clear(ColorScreen g,int sx,int sy); int length (const SnakeNode* ptr) const; int length() const; private: ColorScreen sGame; int maxlen,size; SnakeNode *head; }; #endif --------------------------------------- What is wrong? |
Re: Snake Game problem
<foolsmart2005@gmail.com> wrote:
>> > > The Game: >> > > --- writing a snake game using color console window. >> > > 1-player game. The player makes use of 4 arrow keys to operate the >> > > movement >> > > to chase and eat as much food (#) as possible. Food with a different >> > > color has >> > > score. The game will end when the snake hits itself or the player >> > > hits >> > > ESC key. There are several things in there that make this a non-standard program: The use of color, the use of the arrow keys, and the fact that ESC need not be followed by <Enter>. The topic cops inhibit answers to questions such as this. There is a brand new froup devoted to solving this problem, it is comp.lang.c++.misc. Try posting your question there and we will see if the cure seems to work. |
Re: Snake Game problem
On Tue, 10 Jun 2008 08:37:37 -0700, osmium wrote:
> not be followed by <Enter>. The topic cops inhibit answers to questions > such as this. There is a brand new froup devoted to solving this > problem, it is comp.lang.c++.misc. Try posting your question there and > we will see if the cure seems to work. Um... does comp.lang.c++.misc actually exist (yet) and if so, where? It doesn't show up on my news server or, so far as I can make out, on Google Groups. -- Lionel B |
Re: Snake Game problem
"Lionel B" wrote:
> On Tue, 10 Jun 2008 08:37:37 -0700, osmium wrote: >> not be followed by <Enter>. The topic cops inhibit answers to questions >> such as this. There is a brand new froup devoted to solving this >> problem, it is comp.lang.c++.misc. Try posting your question there and >> we will see if the cure seems to work. > > Um... does comp.lang.c++.misc actually exist (yet) and if so, where? It > doesn't show up on my news server or, so far as I can make out, on Google > Groups. It was made available on individual.net yesterday. The only message so far is an announcement (history, raison d'etre, etc) by a guy with a name I didn't recognize. I think the new froup is a Real Good Thing, abandon this group to the language lawyers and the green eyeshade set. Then they will have this one and the std one and the moderated one for their "mine is bigger than yours" talk and their endless fascination with minutiae. |
Re: Snake Game problem
foolsmart2005@gmail.com wrote:
> > SnakeNode.h:19:7: warning: extra tokens at end of #endif directive > [snip] > What is wrong? The compiler told you what and where exactly is it wrong. |
| All times are GMT. The time now is 06:06 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.