Hexen
Learning Intermediate C# in unity
Intent
Goal
SAMPLE
Software
Learning intermediate C#.
A tile-based game, using MVC pattern, with A* Pathfinding.
Skills improved
- Unity
- Debugging Unity in VS
- Unity prefabs variants
- C#
- Visual Studio
- MVC pattern
- Programming: Deck & hand card system, state machine, C# events & delegates, A* Pathfinding, ...
The next level: Intermediate C#
This project was to learn more advanced C# programming. A turn-based card game using a
tile-based map would be perfect. I'd be making use of delegates, C# events, generics, and
more. To ensure, I had to apply Model-View pattern to split functional logic from view logic.
I'd be creating a state system to have a "player-turn" and an "AI-turn", and add A*
pathfinding.
Events & Delegates
C# Events somehow took quite a long while to understand, especially delegates. I struggled a lot with where to invoke them, and when to subscribe and unsubscribe. I had to rely on slowly walking through the code in debug mode to fully get a clear understanding.
Delegates were another thing, also took a while to wrap my head around. Even when I had an understanding, this project didn't push me to use delegates. Simply making use of events, I was able to implement the MVC.
Generics & Interfaces
Another skill to pick up was using generics and interfaces. Generics was quite easy to comprehend. After all, I'd been using generic methods this whole time created by the framework I was using. Generics were step one to creating a working state machine.
Step 2 was creating an interface. The use of interfaces was not clear to me when I started, only when I was actively wrapping my head around the workings of the state machine did it start becoming clear. I'd need interfaces to be able to call the same method on different classes, each implementing the interface.
Side dishes
Away from the main goal, I had to add A* pathfinding, which sounded more imposing than it actually was. As I was guided to set up a breadth-first area search logic; it was easy to adapt it to using the A* pathfinding algorithm.
Aside from the pathfinding, this project also had me working with: Extension classes, Singletons, Object pooling, helper classes, scriptable objects, and custom inspector scripts.