Page 1 of 1

Re snek game tutorial 14b.

Posted: August 24th, 2019, 7:30 pm
by pjtaylor2011
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.

Re: Re snek game tutorial 14b.

Posted: August 25th, 2019, 3:27 am
by Slidy
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:

Re: Re snek game tutorial 14b.

Posted: August 25th, 2019, 5:30 am
by albinopapa
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?

Re: Re snek game tutorial 14b.

Posted: August 25th, 2019, 5:37 am
by chili
camelCase *would* be an improvement :D

Re: Re snek game tutorial 14b.

Posted: August 25th, 2019, 8:34 am
by pjtaylor2011
Thanks guys....was being lazy with the naming conventions...Will change!