Skip to content

opeious/test-city-builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sample City Builder

Features:

Regular Mode

Player can select a building by clicking on it and see a building name on top of it and current production progress. (or can start a new production if no production is running)

Build Mode

The Player can buy a new building from the left hand side. The player can only buy a building for which enough resources are present. Player will not be able to select a building which he doesn't have enough resources for, the building card will also be red in color to indicate the same. Resources can be tracked from the panel on the top. After a new building is placed, it starts its construction. Construction progress can be tracked by the progress bar on the top of the building.

If the building is a resource production building, production can only begin once construction is complete.

After construction is complete the player can also click on the building to pick up and move it.

The mode can be switched using the buttons in the bottom panel

Tech Design Choices:

I chose a Singleton and Events based architecture because it is easy to understand, makes the code modular. The singleton GameObject is already present in the scene (FinalScene) and pre configured. The singletons can be interfaced such that their variables can be saved and loaded to allow for persistence across scenes and sessions.

DataManager

Initializes and parses the data from scriptable objects. Other managers and views can use the data manager to get the buildings data. All the buildings data is passed to the data manager as editor reference.

I chose ScriptableObjects as data containers because after creation editing the data to change some values becomes a trivial task. Each building data contains static data such production time, construction time, cost, footprint (size on grid) and the visual prefab to spawn on the grid location.

If given more time, I would have preferred to have an editor script parse the data from a JSON or xml into a custom data class or scriptable object, for scalability.

GameModeManager

Stores the current mode of the game. When they mode is changed from the UI it changes a manager variable, Triggering a OnGameModeChanged event. Other UIs and Managers can use this event to track game mode changes.

InputManager

Just a simple class to detect mouse left clicks. Should be replaced with a Gesture/Touch extension to enable play on Mobile devices.

GameboardManager

Keeps track of the grid and does grid operations. Input manager forwards grid touches to the grid.

ResourceManager

Keeps track of the player inventory and all actions to player inventory are performed through resource manager functions. (Add, Remove, etc). Also triggers events when resources are added or removed for UIs and other managers.

TooltipsManager

Deals with player clicks and popups on building clicks. Handles the creation and deletion of tooltip UI elements. Has a reference of which prefab to spawn depending the game mode and current state of the building, also spawns the construction progress bars.

EntityManager

An Entity is anything that can be placed on the gameboard. A building an extension to an entity adding additional properties and functionality to the same.

The entity manager keeps track of all the entities on the gameboard. The entity placement controller in the manager allows the player to pickup and move around existing entities and place new entities.

It also checks if the position the player is trying to move a building to or trying to place a new building at is not out of bounds or currently occupied by another entity. (It is better to check only the existing entities on the scenes instead of every tile on the grid)

If I had more time, I would re-factor this manager to make the code more self-explainable and cleaner.

TimeManager

Keeps track of time, so that other game elements and managers don't have to keep track of time in their Update loops. Can be modified to change the time scale to make the game more responsive as a trade-off for performance.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published