Snake Class Question
-
- Posts: 7
- Joined: June 10th, 2018, 12:09 pm
Snake Class Question
Hello Everyone,
iv been trying to do the snake game on my own and iv hit a dead end in the inizialization of the "Snake" Class, im getting the following Compilation error:
error C3646: 'brd': unknown override specifier (compiling source file Snake.cpp)
I dont know why that pops up, could u guys check out my code and help me out please?
Thanks alot!
iv been trying to do the snake game on my own and iv hit a dead end in the inizialization of the "Snake" Class, im getting the following Compilation error:
error C3646: 'brd': unknown override specifier (compiling source file Snake.cpp)
I dont know why that pops up, could u guys check out my code and help me out please?
Thanks alot!
- Attachments
-
- test.7z
- (225.49 KiB) Downloaded 129 times
-
- Posts: 7
- Joined: June 10th, 2018, 12:09 pm
Re: Snake Class Question
Ah damn it guys, im sorry for the Spam.
Found my problem...
Forgot to add #include "Board.h" in the "Snake.h" Header file
Found my problem...
Forgot to add #include "Board.h" in the "Snake.h" Header file
Re: Snake Class Question
I don't think board should be a member of the snake class. You would just need it to draw the snake so just pass it as a reference to the draw function.
Also you're including board.h in the snakes cpp file. If you want it as a member variable for whatever reason you need to include board in snakes h file. Unless you just wanna cache a pointer to the board, then you can forward declare it
Also you're including board.h in the snakes cpp file. If you want it as a member variable for whatever reason you need to include board in snakes h file. Unless you just wanna cache a pointer to the board, then you can forward declare it
-
- Posts: 7
- Joined: June 10th, 2018, 12:09 pm
Re: Snake Class Question
Thanks alot for your quick response Yumtard!
That Tip with the "pass it as a reference" is awesome!
I implemented it and also removed the obsolte include.
Love you guys.
That Tip with the "pass it as a reference" is awesome!
I implemented it and also removed the obsolte include.
Love you guys.
-
- Posts: 7
- Joined: June 10th, 2018, 12:09 pm
Re: Snake Class Question
Iv already hit another "wall", i think iv gotten myself in a circular dependancy Problem.
Could you guys take a look at my code and help me out?
Thanks alot!
Could you guys take a look at my code and help me out?
Thanks alot!
- Attachments
-
- test.7z
- (225.51 KiB) Downloaded 126 times
Re: Snake Class Question
Well you COULD solve it by passing snake as a pointer and do forward declaration. However, in this case you shouldn't.
You're including snake in board just to send it to the draw function where you use the snake to get its position. Why not just pass the position to the function?
DrawBoard(Graphics& gfx, Vec2& pos);
You're including snake in board just to send it to the draw function where you use the snake to get its position. Why not just pass the position to the function?
DrawBoard(Graphics& gfx, Vec2& pos);
Re: Snake Class Question
also you will then want apple positions, obstacle positions and what not, so rather than sending a bunch of things to a DrawBoard() you could just have a DrawCell(const vec& pos)
Then in Snake:Draw() you loop over the snakes segments and call the boards draw function on their positions. And do the same thing in Obstacle::Draw() and Apple::Draw()
Then in Snake:Draw() you loop over the snakes segments and call the boards draw function on their positions. And do the same thing in Obstacle::Draw() and Apple::Draw()
-
- Posts: 7
- Joined: June 10th, 2018, 12:09 pm
Re: Snake Class Question
Thanks again Yumtard, uv helped me alot.
Re: Snake Class Question
No problem! Gl with the rest of the game
Re: Snake Class Question
yeh good advice, pass around the minimal info necessary. Minimize dependencies and coupling.
Chili