Re snek game tutorial 14b.

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
pjtaylor2011
Posts: 2
Joined: August 3rd, 2019, 11:02 pm

Re snek game tutorial 14b.

Post by pjtaylor2011 » August 24th, 2019, 7:30 pm

Ooookay...Love the series so far. This is a big jump, BUT, i managed to write a successful snake game on my own before watching the tutorial..(i watched the first half explaining the planning)...so kudos to me...more importantly kudos to you, coz without your tutorials I'd never have done this. Thanks. Unfortunately my solution used just 2 classes, board and game, I couldn't figure out the location class, but I think I've got it now. So after creating my own version...I followed along with your tutorial and I've so many questions, but I'm trying to figure them out on my own. The ONE problem i've got I don't understand is;
I'm writing the goal class.
void respawn(std::mt19937 & rng, const board& brd, const snake& snake)
{ std::uniform_int_distribution<int> xdist(0,brd.getwidth()-1); //renamed from GetGridWidth
}

I've included "board.h"

but I'm gettting 2 errors.... 1. E1086 the object has type qualifiers that are not compatible with the member function "board::getwidth"
2. C2662 'int board::getwidth(void)': cannot convert 'this' pointer from 'const board' to 'board &'

Can anyone help...Im sure its a typo somewhere, but can't see it for the life of me...My 50yr old brain dont work like the kidses.

Slidy
Posts: 80
Joined: September 9th, 2017, 1:19 pm

Re: Re snek game tutorial 14b.

Post by Slidy » August 25th, 2019, 3:27 am

When you have const objects you can only call their const functions. The issue here is that you have a const board& brd variable but getwidth() is not declared as const.

The simple solution here is to just chuck a const on getwidth()

Side note: I hate your all no-caps and no-underscores naming style :evil:

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Re snek game tutorial 14b.

Post by albinopapa » August 25th, 2019, 5:30 am

Slidy wrote:
August 25th, 2019, 3:27 am
Side note: I hate your all no-caps and no-underscores naming style :evil:
Do you prefer camelCase?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Re snek game tutorial 14b.

Post by chili » August 25th, 2019, 5:37 am

camelCase *would* be an improvement :D
Chili

pjtaylor2011
Posts: 2
Joined: August 3rd, 2019, 11:02 pm

Re: Re snek game tutorial 14b.

Post by pjtaylor2011 » August 25th, 2019, 8:34 am

Thanks guys....was being lazy with the naming conventions...Will change!

Post Reply