/SimpleTurnBasedGame

A simple turn-based game exercise

Primary LanguageC#

Simple Turn-Based Game Core Mechanics

The repository contains the realization of the concepts described in this repo

Description of the game:

The player who starts the match is decided randomly before the game starts, and the game play consists in a fight between two players who start the match with some health points. On each of the players turns, they have to choose one of the actions below:

  • give some damage to the opponent;
  • heal some damage itself;
  • a random option above with a bonus in the result;
  • wait the timeout and pass the turn doing nothing.

The loser is the player who reaches zero life points first.

Structures and funcionalities:

  • Two players, both sitting in the respective positions: Top and Bottom; (can be extended to more players)
  • Events such as Start and End match integrated with a simple UI;
  • Events like Player Started and Finished Turn also integrated with a simple UI;
  • Events that when players Heal and Deal damage;
  • Timeouts for players turns;
  • Restart point.

I am not going to go further with details about the implementation because you can check the repo. But the idea is to have a MVC with a separation between logic and the data. The game logic driven by pure C# classes named Processes which change the game data and dispatch events to the interested listeners.

The listeners are the UI components and the following State Machine that has two purposes: to control the flow in the client side and hold the controllers (States) that provide access to the Processes mentioned earlier:

All the comunication among the Views and Controller is done using the Singleton Pattern and the Observer Pattern.

  1. Game Controller and Turn-Based States
  2. Processes
  3. Game Model
  4. Game Events
  5. Game Data
  6. Game UI
  7. Game AI
  8. Some Patterns Used in the Implementation
  9. Configurations

Gif for a better visualization of the Game Flow:

alt text

The game is also a bit configurable, you can define:

  • Players Health;
  • Turn time out and time until start game;
  • Damage, Heal and Bonus for Random
  • AI Archetypes for both players;

Configurations