Hot answers tagged

17 votes

Can I lessen the use of boolean flag variables in this snippet?

Can I lessen the use of boolean flag variables in this snippet? Consider 1st comparing. ...
chux - Reinstate Monica's user avatar
11 votes

Simulation of hero vs monster

Reminds me of one of my first programs from a couple years ago. :) Here is some basic, (hopefully) uncontroversial feedback. Small bug: "while hero and monster > 0" You are probably ...
rh-calvin's user avatar
  • 151
10 votes
Accepted

Spin the wheel game

I think the biggest improvement that you can make is to use functions instead of putting all functionality in one big block of code. The main advantage of functions is that it will be easier to ...
wovano's user avatar
  • 237
10 votes

Tic-Tac-Toe game in C++

Avoid using namespace std; If you are coding professionally you probably should get out of the habit of using the ...
pacmaninbw's user avatar
  • 23.5k
10 votes

Can I lessen the use of boolean flag variables in this snippet?

I'm not familiar with unity so, I can't review your code from that perspective. But we can certainly make this code more concise. Let me show you how to get started with refactor this code. 1. Get rid ...
Peter Csala's user avatar
  • 8,520
10 votes

Can I lessen the use of boolean flag variables in this snippet?

Each call to handleInputEvents() can set bShow to a new boolean value. We could approach the display update task by making a truth table. ...
J_H's user avatar
  • 17.1k
9 votes

Rock, Paper, Scissors game with CPU

int games_number = 0, games_played = 0, user_wins = 0, computer_wins = 0, even_games = 0; //Counters Wow, that's a lot of counters! When choosing a data ...
J_H's user avatar
  • 17.1k
8 votes
Accepted

"Rock Paper Scissors" game

Overview I don't like how you are simply passing strings around for the values. Its simple but not very optimal. I would create some enum types to represent the different states (Win, Lose, Draw) and/...
Martin York's user avatar
  • 94.3k
7 votes

Spin the wheel game

Use while True instead of while flag: An idiomatic and simpler way to loop until condition is changed, is using: ...
Tomerikoo's user avatar
  • 312
7 votes
Accepted

Tic-Tac-Toe game in C++

I think the only 'major' change I might make is to replace the switch..case with if...else to remove duplicate code and actually ...
depperm's user avatar
  • 860
7 votes

Crossword puzzle app

There's a lot of improvement in both style and structure. I will concentrate on style only. Use variable names that represent the purpose of the value. For example ...
TorbenPutkonen's user avatar
7 votes
Accepted

Event System using C++

Avoid macros There are many issues with macros, the general advice is to avoid them where possible. Let's look at EVENT_TYPE_FUNCTION(): it's there to add a few ...
G. Sliepen's user avatar
  • 50.7k
7 votes

Can I lessen the use of boolean flag variables in this snippet?

Why don't you make button.show() simply do an early exit if the visibility state being passed in is already the same? I'm surprised it doesn't already work this ...
selbie's user avatar
  • 197
7 votes

"Rock Paper Scissors" game

Computing pcSelection can be factored out into a separate function. If users enter an invalid choice, promptUserInput still ...
Ajay Theetharappan's user avatar
6 votes

Rock, Paper, Scissors game with CPU

Many points already covered. Check input functions return values ...
chux - Reinstate Monica's user avatar
6 votes
Accepted

Command-line Tower of Hanoi game

General Observations Interesting! Decent job of coding. The partitioning of the code seems pretty good, but it can be improved. In the display of towers, the towers should be numbered so that the user ...
pacmaninbw's user avatar
  • 23.5k
6 votes

Event System using C++

General Observations This code review request does not present any C++ source files (.cpp files). It appears that you are trying to write close code without the <...
pacmaninbw's user avatar
  • 23.5k
6 votes

Here is a Tic Tac Toe game in Python using functions

I would say you did an excellent job overall! The only suggestions I would make are: The User Is Capable of Entering Unexpected Input You have: ...
Booboo's user avatar
  • 749
6 votes

Can I lessen the use of boolean flag variables in this snippet?

Since this is tagged unity3d, rather than setting a flag somewhere else in the script, you can just do the following: ...
crass_sandwich's user avatar
5 votes
Accepted

Slot Machine Project

Some of the initial comment lines look like they should be a module """docstring""". The os.system() call is expensive and non-portable. You might assign ...
J_H's user avatar
  • 17.1k
5 votes
Accepted

Intersecting rectangles on a torus

bool IntersectsOnTorus(int x1, int w1, int y1, int h1, int x2, int w2, int y2, int h2, int domain) Choosing to phrase it as (x, w, y, h) instead of (x, y, w, h) ...
J_H's user avatar
  • 17.1k
5 votes

Command-line Tower of Hanoi game

In addition to pacmaninbw's excellent answer, I'd like to add: Avoid using system() system() is very expensive: it has to fork ...
G. Sliepen's user avatar
  • 50.7k
5 votes
Accepted

Little CLI game in C++ with random words

General Observations An interesting new twist on an old game! Using Wikipedia as a source gives a lot of possible words. There is a lot of good ideas here, but there can be some improvement. An ...
pacmaninbw's user avatar
  • 23.5k
5 votes
Accepted

Recreated Snake in Rust

Clippy One of the most important tools when writing good rust code is clippy. I recommend to configure your editor to run clippy on-the fly. It has very nice messages and includes an explanation for ...
corvus_192's user avatar
4 votes

"Asteroids" style arcade game

Loop like a native In modern C++, we have range-based for. We can replace ...
Toby Speight's user avatar
4 votes

Simple N Puzzle console game

I have a few scattered observations. Your Tile.Value is a field rather than a property. If using a public access modifier, you ...
Rick Davin's user avatar
  • 6,257
4 votes
Accepted

Rock, Paper, Scissors game with CPU

move the srand to the top, no reason to call it multiple times Get rid of the goto and instead rely an outer ...
depperm's user avatar
  • 860
4 votes

Rock, Paper, Scissors game with CPU

When it comes to code structure, here are some tips that may be helpful: Don't use gotos when you can achieve the same behaviour with ...
Chris Geber's user avatar
4 votes

Chess Game with GUI in C++ using SDL2

Since you're already on C++11, it shouldn't be too much effort to move to C++17 or 20, which you should pursue. Since you have a project with multiple translation units (object files), strongly ...
Reinderien's user avatar
  • 59.1k
4 votes

Chess Game with GUI in C++ using SDL2

Answers to your questions Is my use of namespaces correct? It's definitely better than not using namespaces. However, you can improve it: Move more things into the namespaces. For example, why not ...
G. Sliepen's user avatar
  • 50.7k

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