20
votes
C# - Standard 52 card deck
class Card {
readonly Ranks rank;
readonly Suits suit;
// ...
}
In this type definition, there is a grammatical mismatch: ...
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 ...
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.
...
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 ...
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 lines ...
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 ...
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.
...
8
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 ...
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 ...
6
votes
Accepted
Ability System Implementation
Glad you took my suggestion and posted over here. I'm going to start from the most important (but also high-level) bits, and work my way towards specifics and code here.
DESIGN ISSUES
The main issue ...
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 ...
6
votes
World resource system for Adventure Game/RPG
A few notes:
All IResource properties have public setters. Are you absolutely certain that other code should be able to modify those? I'd recommend making these ...
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 ...
6
votes
Quaternion and Vector3 transfomation Math
If you want DRY the KISS way, I suggest substituting the if-chain..
...
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 ...
6
votes
Accepted
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:
...
5
votes
BestHTTP asset download
Instead of using a foreach here, you need to use a for-loop, since you have to know the index of the image to assign it to the correct texture.
...
5
votes
Ability System Implementation
Ability
You have some properties and some public fields. In general you should not have public uncontrolled fields. As first step let's make them properties, for example:
...
5
votes
Accepted
Slot Machine game
Your code is a mess on all levels.
Sometimes you write Method () with a space, sometimes you write Method() without the space.
...
5
votes
Unity surface shader to blend between adjacent tiles
(Self-answer, and not comprehensive by any measure)
After some consideration and more experimenting, I can offer one insight to this approach. It does not relate to shader code in any way but rather ...
5
votes
Accepted
Unity animations code
That moment when you know Unity better than C#. I'm on other side: I know nothing about Unity (except docs that I've read while writing this review) but know C# well. Let's merge our knowledge.
...
5
votes
C# - Standard 52 card deck
Note: The traditional order of suits is (highest to lowest) Spades, Hearts, Diamonds, Clubs.
While this order does not matter for many games, there are also many games for which it does matter. ...
5
votes
Accepted
Code to determine move position in a hex grid when the user moves the stick on the gamepad
My main concern with this code is its repetition: you're making the same checks over and over, and performing very similar actions over and over. This gives lots of space for bugs to hide in, and ...
5
votes
C# items that don't follow rest of interface
With pattern matching you can avoid explicit casting:
...
5
votes
Accepted
C# items that don't follow rest of interface
If you have to cast to concrete type then that is a code smell. Why have the state managers in a dictionary?
Instead of a dictionary you can create another class to hold the state objects
...
5
votes
Accepted
Service Locator C#
Pattern or Anti-pattern
Generally speaking Dependency Injection is preferred over Service Locator. SL is considered anti-pattern sometimes because it makes unit testing harder and tightly couples all ...
4
votes
Slot Machine game
You said you comment code poorly, which isn't exactly true, you don't comment. I can't be bothered to read all that code and try and actually understand what it is doing, I just scanned it looking ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
unity3d × 227c# × 220
game × 35
performance × 31
beginner × 14
design-patterns × 10
object-oriented × 8
networking × 8
algorithm × 7
.net × 7
comparative-review × 5
pathfinding × 5
ai × 5
physics × 5
event-handling × 4
serialization × 4
graphics × 4
strings × 3
multithreading × 3
json × 3
random × 3
animation × 3
collections × 3
c++ × 2
unit-testing × 2