44

PEP 8 PEP 8 recommends that constants be written as "all capital letters with underscores separating words.". So something like: yellow = (255, 255, 0) Should be: YELLOW = (255, 255, 0) or possibly an enum (more on this later) Inconsistent quotations Usually a project will stick with either "" or '' unless you have particular reason not to.1 But for ...


22

In addition to another answer I will add these places to improve (I will not repeat all things from that answer, my answer is just an addition): 1. Code inconsistency You have several places in your code where your code is inconsistent def collision(): ... return 1 return 0 def wall_collision(): ... return True return False Both ...


10

size: int ... self.size = 2 You never read size, and Python Lists already know their own length in case you did need it. You're just duplicating functionality that List already gives you by manually keeping size in sync with the list length. Separate game logic from screen rendering details You keep snake coordinates scaled by pixels. This seems to ...


10

First of all congratulations for this little entertaining console game. It is simple but entertaining. I felt like I was back in the old mobile games era. I don't have the time to rewrite all of the code but I still want to give some hints for improvements. Here are some random observations: Don't use global variables, they are a maintenance hazard. ...


8

Your program is definitely improved over the last version. Good job! Here are some ideas for you about further improvements. Make the object interface easy for the user The app object has two public functions, start and end that are apparently intended to be called in that order. To me, it would make more sense to eliminate end and simply move the ...


8

Here are some things that may help you improve your code. Don't declare enum const In snake.h, the direction enum is declared as const but this is an error, since only functions and objects can be declared const. Use const where practical The Snake::getSnakeSize() doesn't alter the underlying Snake and so it should be declared const. Additionally, I'd ...


7

You include the modern random. #include <random> But in your code you use the old srand() and rand() functions. Also your usage of these functions is not correct. time_t tim = time(NULL); srand(tim + rand()); fX = rand() % (nFieldWidth - 2) + 1; fY = rand() % (nFieldHeight - 2) + 1; Here you are abusing the seeding ...


5

First on my Windows 10 computer in both Visual Studio 2015 and Visual Studio 2017 the console is killed by this line in the update function. WriteConsoleOutputCharacter(hConsole, buf, nScreenWidth * nScreenHeight, { 0, 0 }, &dwBytesWritten); This may have to do with settings on my computer. Second I get this warning message in both VS 2015 and ...


4

Broad Feedback It appears that you have incorporated most of the feedback from my answer to your previous post, except for a few places where var is still used but let or const could be used instead. The functions used in the misc. functions for drawing, like in the objects left and right, which get used in keyLookup might be more appropriate as methods in ...


4

Here are some things that may help you improve your program. Use consistent formatting It appears that your code uses tabs in some places and spaces in others, making the code appear badly formatted unless the settings in the reader's editor are set exactly the same as in yours. To prevent this, I recommend using spaces everywhere. It's a habit that may ...


4

Overall a good job, and much better than the version you answered. Better Not to Ignore Warning Messages Board.cpp generates 2 warning messages, the first is for a typo on the semicolon on this line: #include <iostream>; The second is for a type mismatch on this line for (auto i = 0; i < body.size(); ++i) { Auto comes in very handy for some ...


4

Good going on your first game. I completely agree with most of the points made by others. Here are a few more nitpicks. This answer is a bit long-winded, but take it as a complement. :-) Unpack the Coordinates This is what lines 195-197 currently look like: for item in snake.get_body(): pygame.draw.rect(window, snake.color, [item[0], ...


4

Const methods These: int posX() { return foodX; }; int posY() { return foodY; }; // ... int posX() { return headX; }; int posY() { return headY; }; int len() { return length; }; don't modify anything in this, so make them const: int posX() const { return foodX; }; int posY() const { return foodY; }; Setters This: void ...


3

Only call srand once. Continually reseeding it can result in non-random random numbers. The statements in ClearScreen should be on separate lines. With them all spread out like that it is hard to see what it is doing (which doesn't seem to actually clear the screen, just move the cursor to the top left of the console). In main, the if statements should ...


3

First of all, from an Object-Oriented perspective, you have objects that represent real objects within the game with behaviors and attributes, so on that note, well done! There are, however, other areas that need a bit of TLC. You have an enumeration of colors sitting there as individually-defined constants. For a bit more type-safety, I would suggest ...


3

Don't Ignore Warning Messages Please compile using the -Wall compiler switch that provides all warning messages. This code in Board.h generates a warning message: static enum Tile { OPEN = 1, WALL = 2, SNAKE = 3, FOOD = 4 }; The keyword static is ignored in this case, why are you trying to make an enum static? Style and How it Effects ...


3

Some observations: Comments: // Draws the objects void drawWindow(); // Handles events void handleEvents(); // Updates the window void updateWindow(); These comments don't tell you anything that the code doesn't already tell you, so they should be removed. Ideally the code is well named, like in that example, so you don't feel the need to even write a ...


3

while (true) { Some advise using for (;;) instead, but this loop really isn't necessary. But you don't even have a loop here; you'll exit the loop immediately no matter what is entered. Also this throws an exception if you enter a non-int. Clearing the terminal should be done in a separate routine in case you want to switch to a terminal library like ...


3

I saw the same problem Abdallah found: Unix.Unix_error (Unix.EINTR, "select", "") This can be fixed by using Unix.sleepf (OCaml version >= 4.03.0): let minisleep (sec: float) = Unix.sleepf sec


3

I only got to the core classes, not the game implementation. Hopefully this will give you something to think about. General Classes that are not designed for extension should be explicitly marked as final. Variables that will not be reassigned should also be marked as final. This makes it easier for readers of your code. I'm assuming this API is designed ...


3

I first played a few rounds of the game and I immediately liked it. The screen motion is smooth, the colors have a nice contrast, and I liked that it is even possible to play snake in single-player mode. On the start screen, the icing on the cake would be if the wasd text would be in blue, the arrow keys would be in green and the neutral text would be in a ...


3

General Feedback This code looks quite decent. Most of the functions and methods aren’t excessively long. Some lines are terminated with a semi-colon but others aren’t. It is best to be consistent. The code uses some ecmascript-6 AKA ES-6 features like classes and arrow functions so other ES-6 features could be used as well. See below for more details. ...


3

Coor has the comment coordinates ... yeah, that's exactly what the name should be then. But actually, Point seems easier and doesn't have to be abbreviated, or perhaps be more general and say Vector, or Vec2, that seems fairly common for games (despite it being an abbreviation). Not using the AWT class makes sense to me too. The hashCode method is okay, ...


3

Code improvements: Do not use using namespace std it saves you some time typing the code, but when other namespace get involved later on its a mess to debug this code. Furthermore I personally find it more aesthetic to see from which namespace a functions "comes from". Consider using a function that checks wether the user-input is valid. cout << "...


3

Making the code more modern Your code looks very old. This is because the <iostream.h> header in line 1 is not used anymore since about the year 1998. Same for the <dos.h> and <conio.h> headers. To get your program to compile with a modern C++ compiler, I had to replace the first paragraph of your code with this: #include <iostream>...


2

I see Block and Snake have constructors that both accept five identical parameters. You could consider using inheritance to make a parent-class, which the two child classes inherit from via extends. This would be congruent with the Don't Repeat Yourself principle Some of the variable are used globally - e.g. start, canvas, food, etc. You could at least ...


2

You've followed some conventions very well like CAPS for constants. Very nice. Here are some points: Standard library imports precede 3rd party ones import pygame import random should be changed to import random import pygame The middle line is to differentiate between the two types of imports Two lines after imports There should be two lines after ...


2

This is in addition to the answer provided by @1201ProgramAlarm, everything in their review is correct. I have made a console game using c++ without using OOP. The game works perfectly, but is it good that way or should I have used OOP? Bug The program doesn't work perfectly, the snake is supposed to die if it hits a wall. In this implementation the ...


2

Thanks for the game. I applied most changes suggested by @Dair and @vurmux as well as partially the suggestions from @Peter Cordes (some of them are not so simple). After that, there were still some things left: Game logic I'm not sure whether it was intentional, but the snake does not collide with itself. In usual snake games, if the snake bites into her ...


2

Here are some things that may help you improve your code. Understand how #include works On most platforms, the difference between #include "iostream" and #include <iostream> is that the former looks first in the current directory. So for system files such as SFML/Graphics.hpp, you should really use #include <SFML/Graphics.hpp> instead. See ...


Only top voted, non community-wiki answers of a minimum length are eligible