Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - priyeshgeete

Pages: [1]
1
SFML projects / Re: Yet Another Snake Clone
« on: August 24, 2017, 11:56:51 am »
Alright, FRex. I cannot thank you enough for your valuable feedback. I'll try to keep all these things in mind. :)

2
SFML projects / Re: Yet Another Snake Clone
« on: August 23, 2017, 04:54:29 pm »
FRex, Thanks for your detailed feedback. I might not have grasped all the points at once but they are all appreciated and didn't get unnoticed.

Quote
names in all caps and starting with _ shouldn't be used (but many projects do it to not clutter auto complete with them, yes), see: https://stackoverflow.com/a/228797
I am trying to understand everything in that post but I think I get the point. In my case, my header guards should not have started with an underscore. Did I get that right?

Quote
many people use hpp for C++ headers to signify they aren't C headers, if you ever mix C and C++ or happen to use a library that has binding/APIs in both (i.e. like SFML does) then you will appreciate the difference
Alright, its .hpp from now on.

Quote
you could use sf::RenderTaraget, not sf::RenderWindow in draw functions
So, it can be like
Code: [Select]
drawableObject.drawTo(sf::RenderTarget &window); Can you tell me the difference it will make?

Quote
some magic numbers are present, ie. 735 and 375 in Food.cpp
Noted: Hard coding should be avoided.

Quote
it's customary and nice towards the reader to name the file with main function main.cpp
Makes sense.

Quote
you might want to look into c++ <random> header instead of using C randomness
Well, I tried using that but it gave me same number pattern when the game restarts. May be I should have researched more to find a way to put current time as a seed in  c++11 random generator.

Quote
your key handling is wrong, you should use evnt.key.code to see which key got pressed in sf::Event::KeyPressed
Well, thanks for pointing this out. I didn't know this. event.key.code for polling event and sf::Keyboard::isKeyPressed for real time key capturing.

Quote
you might actually reconsider using numeric keypad and use normal numeric keys (Num1, etc.) since many older laptops don't have it
Hahaha.. damn my short-sightedness. :D

Food.cpp
Quote
you might make spawn take snake by reference if it's never null
Err. I am confused.

Block.cpp
Quote
setFillColor is weird, why the & and then -> ?
I needed to do that in order to change the color of existing blocks. I also used the following code initially, but it didn't work.
Code: [Select]
snake[i].setFillColor
Quote
vector has a 'back' member that you can use to access the last element
I should have gone through the std::vector documentation properly. Well, I learned something new. Thanks

Quote
in drawTo you use a for loop but without a & so you copy each block, then render it, then throw it away
That is why code reviewing is necessary. I'll be cautious of this in future practices.

Quote
deletePlayer and createPlayer are a bad interface, just clear the snake on each player creation
Are you suggesting I should have handled creation and clearing of vector through Player's constructor? If yes, then in my case I would have to create two player objects in snake.cpp: once at the start of the game before the game loop and then once after the game is over if player chose to retry the game. I can definitely see the problem of structuring in my snake.cpp now. May be, I should have added pressing space to start the game for the first time as well. Good point.

Again thanking you for taking time to review the code, your suggestions are immensely helpful. :)

3
SFML projects / Re: Yet Another Snake Clone
« on: August 21, 2017, 09:08:25 pm »
You seem to have forgotten stdafx.h in the repo, it's also not a very usual/portable feature (I know it's in VS, not sure about it on GCC/Clang, I think it's present but I don't know how it works) so it's best avoided IMO.

I purposefully submitted only those files which were necessary for reviewing the code, I didn't think if anyone would need to compile the code. Should stdafx.h be avoided in my projects? What about this other header file "targetver.h"which VS includes by default?

Quote
At a glance the code looks okay but it's a bit messy C++, I'll try to take a better look at it later.
Any guidance is awaited and will be appreciated. Thanks. :)

4
SFML projects / Yet Another Snake Clone
« on: August 20, 2017, 06:09:59 pm »
Hello all. I have just started learning sfml and I'm c++beginner: pointers give me headaches kind of beginner.

To practice I started making Snake, like many other beginners, and just finished it.

Snake Game - https://drive.google.com/file/d/0B_XEonRcHGvwNnhXTVFHMEJGSEE/view?usp=sharing
Snake Code - https://github.com/gitPriyesh/Snake

I am requesting you all to go through the code and guide me what could be better and how.
Also, please play the game and see if its working alright.

I found practicing through making small games to be really a good learning experience.

Pages: [1]