Advertisement

right architecture to make a turn based game?

Started by February 27, 2021 01:20 PM
2 comments, last by TheBlackRattie 3 years, 8 months ago

Hi.

i need to work on a turn based game (backgommon). im just wondering what can be the best way for the architecture to be most flexible.

my best option is to make game logic and game state totally seperate from input and graphics and…

this is what in my mind:

make a class that holds state of the game.

make a library that queries on the game state. for example:

GetAllPossibleMoves( Player p1);

ApplyMove(Move x, Player p1);

….

On Any Plyer Input You query on Game State.

after any change on game state, apply the results on UI.

my problem is, how can i make sure that UI is exacly foloowing the game state.

queries can be tested and unit tested but whay about UI and ….

do you think its the best approach for this type of game?

What you are looking for might be a state machine (FSM). There are plenty of tutorials on the net about them so have a look if you want an idea how to implement it. The FSM in general keeps track of your current state and what staes it can enter from there. You can add paths dynamically to the FSM, for example if you have a trigger effect that depends on certain circumstances in your game.

So if you want the UI to react on current game state, you can get the current node of the FSM and perform a lookup into the states that this node can reach (and probably also do some checks if the state is enabled to gray some buttons out). Then attach your button events to a logic that will move the FSM into the state the button points to and let everything else be done by the game logic reacting on the FSM state change

Advertisement

Backgammon is such a basic game it is going to be a simple set up.

I wouldn't overthink it (unless you are taking on a simple project to learn classes and overthinking ?)

An array can hold the board

A few functions can return possible moves etc

Probably the most time consuming thing here will be the UI and graphics

This topic is closed to new replies.

Advertisement