Skip to main content
20 votes

C# - Standard 52 card deck

class Card { readonly Ranks rank; readonly Suits suit; // ... } In this type definition, there is a grammatical mismatch: ...
Roland Illig's user avatar
  • 21.3k
19 votes
Accepted

C# - Standard 52 card deck

You have nicely read the rank count into the variable rankCount, but later, you are writing index % 13. It is not immediately ...
Olivier Jacot-Descombes's user avatar
17 votes
Accepted

Snake Game in C#

Just a few remarks. Reviewing bottom-up. public class MultipleValuesDictionary<key, value> Don't name classes dictionary if they aren't one (implementing ...
t3chb0t's user avatar
  • 44.3k
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
14 votes

Snake Game in C#

I sense that you think too much about SOLID, padawon. You need to think about what the game IS, and the things that ARE. Objects do things. What they do defines what they are. Properties capture the ...
radarbob's user avatar
  • 7,654
12 votes

C# - Standard 52 card deck

It always seems odd in code to see a constant whose name is a number and for it to have a value different to that number. You can set a value on an enum and the later ones automatically increment ...
Pete Kirkham's user avatar
10 votes

Snake Game in C#

Beyond the SOLID principles, think about your classes and methods. Classes/objects are things that exist, methods are things they do. So when naming them, class names should be nouns, methods should ...
Seth R's user avatar
  • 209
10 votes
Accepted

Bouncing map back into its bounds, after user dragged it out

Readability Mainly looking for readability improvements/getting rid of those double ifs. Since you are considered about readability, I will focus on that part. Declare a flags enum on multiple ...
dfhwze's user avatar
  • 13.9k
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
  • 9,279
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
  • 29.4k
9 votes
Accepted

Multiplayer Peer-To-Peer position interpolation

I recommend you always write access modifiers for class members and for classes itself. It will make code more clear and understandable. So instead of ...
Maxim's user avatar
  • 2,542
8 votes

Changing a sprite depending on variables

I suggest writing it as currentSprite = playerSprites[4 * (gunUpgrade + 1) + (moveUpgrade - 1)]; Consider laying out the elements of ...
200_success's user avatar
7 votes
Accepted

Custom struct design: Range

Only targeting public struct Range If possible a struct should be immutable so you shouldn't let a user of this struct set the ...
Heslacher's user avatar
  • 50.4k
7 votes
Accepted

A* Algorithm in C# for pathfinding 2D tile grid

There is a lot of code here, so there is a lot to say; no way I'll covered everything! I'll do the easy things first, and then assume lots of them before we look at the algorithm. Style Usually C#ers ...
VisualMelon's user avatar
  • 7,431
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
  • 195
6 votes

Event system in Unity RPG game

...
t3chb0t's user avatar
  • 44.3k
6 votes

Sims-style walls part 2: Flood fill

I happen to like the way I've lined stuff up since it helps with debugging and spotting patterns I do not necessarily reflect this opinion. You use a lot of very short variable names for parameters ...
t3chb0t's user avatar
  • 44.3k
6 votes

Rock Paper Scissors coding challenge

... "too mathematical" and "lacking object oriented principles" These go hand in hand. An algorithm is what it is. Not that it is or is not too mathematical but that necessarily busy, complex, or ...
radarbob's user avatar
  • 7,654
6 votes

Quaternion and Vector3 transfomation Math

If you want DRY the KISS way, I suggest substituting the if-chain.. ...
dfhwze's user avatar
  • 13.9k
6 votes
Accepted

Averaging quaternions

Below you can find some of my reflections. Method InputTracking.GetLocalRotation(XRNode.Head) is obsolete as DOCS says. There is a lot calculations per one frame indeed, but Quaternions are structs ...
Karol Miszczyk's user avatar
6 votes
Accepted

Generate Unique ID in C#

...
Jeff's user avatar
  • 850
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

Tic Tac Toe (decoupling patterns and component based design)

There's is no use of interfaces in a Tic Tac Toe game. They are used whenever many objects have things in common, this allows you to group them up easily. Imagine a big mmorpg game they have a lot of ...
Denis's user avatar
  • 8,508
5 votes
Accepted

Hotkey detection for UI elements

The easiest way to solve this with one dictionary is to simply create an action for the Button.ButtonClickedEvent calls: ...
Der Kommissar's user avatar
5 votes

Simple Q&A game

You should avoid duplication of code. e.g. 1. You can extract ...
MrSmith42's user avatar
  • 2,070
5 votes

Snake Game in C#

Overall design First a summary of your design: The Game class initializes the game and runs the main game loop (Update). Every ...
Pieter Witvoet's user avatar
5 votes

Wait for multiple functions to run

Your code is not thread-safe on many levels. Even if you replace regular increments/decrements with methods from Interlocked class, you will still need additional ...
Nikita B's user avatar
  • 13k
5 votes

Testing procedure with several nested yield statements in Unity3D

Before I start, just a small disclaimer: I've only ever written C# in the context of Unity, and I'm going to be providing a good deal of controversial opinions. I do hope that I can back them up with ...
CAD97's user avatar
  • 1,944
5 votes
Accepted

C# to C++ function call that fills and auto resize array if size is not enough

Your situation immediately reminded me of the "PC loser-ing" problem: a classic case study contrasting the design philosophies of MIT's ITS operating system and the UNIX operating system developed at ...
200_success's user avatar

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