Skip to main content
added 191 characters in body
Source Link
Ethan Bierlein
  • 15.9k
  • 4
  • 60
  • 146

Using constants rather than macros adds readability to your code, and it has all the properties of a normal variable, e.g, a size, a type, linkage, etcetera. A macro has none of those.

I'd also define your SnakeSegment structure as a class, instead, like this:as seen below.

It's also worth noting, if you ever want to add more methods to this class in the future, you should define two separate files for it, classname.cpp, and classname.h. classname.h should contain the class declaration and the function/constructor signatures inside it, and classname.cpp should include classname.h and implement the functions/constructors.

I'd also define your SnakeSegment structure as a class, instead, like this:

Using constants rather than macros adds readability to your code, and it has all the properties of a normal variable, e.g, a size, a type, linkage, etcetera. A macro has none of those.

I'd also define your SnakeSegment structure as a class instead, as seen below.

It's also worth noting, if you ever want to add more methods to this class in the future, you should define two separate files for it, classname.cpp, and classname.h. classname.h should contain the class declaration and the function/constructor signatures inside it, and classname.cpp should include classname.h and implement the functions/constructors.

added 32 characters in body
Source Link
Ethan Bierlein
  • 15.9k
  • 4
  • 60
  • 146
void DisplayPlane(); void NormalisePlane(); void SnakeInit(); void FoodInit(); void Move(); void DeleteLastSnakeSegment(); bool HasEatenFood(); void WipeConsole(); bool Won(); bool Lost(); 
void DisplayPlane(); void NormalisePlane(); void SnakeInit(); void FoodInit(); void Move(); void DeleteLastSnakeSegment(); bool HasEatenFood(); void WipeConsole(); bool Won(); bool Lost(); 
void DisplayPlane(); void NormalisePlane(); void SnakeInit(); void FoodInit(); void Move(); void DeleteLastSnakeSegment(); bool HasEatenFood(); void WipeConsole(); bool Won(); bool Lost(); 
void DisplayPlane(); void NormalisePlane(); void SnakeInit(); void FoodInit(); void Move(); void DeleteLastSnakeSegment(); bool HasEatenFood(); void WipeConsole(); bool Won(); bool Lost(); 
added 29 characters in body; added 63 characters in body
Source Link
Ethan Bierlein
  • 15.9k
  • 4
  • 60
  • 146

These are a bit of code smell, and are not really necessary, they can be removed. (You may have to define these functions again above main.)

These are not really necessary, they can be removed.

These are a bit of code smell, and are not really necessary, they can be removed. (You may have to define these functions again above main.)

added 16 characters in body; deleted 1 character in body
Source Link
Ethan Bierlein
  • 15.9k
  • 4
  • 60
  • 146
Loading
Source Link
Ethan Bierlein
  • 15.9k
  • 4
  • 60
  • 146
Loading