| name | programming-architecture |
| version | 2.0.0 |
| description | Game code architecture, design patterns, scalable systems, and maintainable
code structure for complex games.
|
| sasmp_version | 1.3.0 |
| bonded_agent | 02-game-programmer |
| bond_type | PRIMARY_BOND |
| parameters | [{"name":"pattern","type":"string","required":false,"validation":{"enum":["ecs","state_machine","observer","command","object_pool","singleton"]}}] |
| retry_policy | {"enabled":true,"max_attempts":3,"backoff":"exponential"} |
| observability | {"log_events":["start","complete","error"],"metrics":["execution_time","code_complexity"]} |
Game Programming Architecture
Design Patterns for Games
1. State Machine
Best for: Character states, AI, game flow
public abstract class State<T> where T : class
{
protected T Context { get; private set; }
public void SetContext(T context) => Context = context;
public virtual void Enter() { }
public virtual void Update() { }
public virtual void Exit() { }
}
public class StateMachine<T> where T : class
{
private State<T> _current;
private readonly T _context;
public StateMachine(T context) => _context = context;
public void ChangeState(State<T> newState)
{
_current?.Exit();
_current = newState;
_current.SetContext(_context);
_current.Enter();
}
=> _current?.Update();
}
: <>
{
=> Context.Animator.Play();
{
(Context.Input.magnitude > )
Context.StateMachine.ChangeState( PlayerMoveState());
}
}