Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ConsoleApp3
- {
- class StateMachine
- {
- private enum State
- {
- NoPuck,
- Puck,
- }
- private Dictionary<State, Action> m_handleUpdate;
- private State m_currentState;
- public StateMachine()
- {
- m_currentState = State.NoPuck;
- InitializeUpdateFunctions();
- }
- private void InitializeUpdateFunctions()
- {
- // here we create a map of functions to state values and assign them to anonymous functions
- m_handleUpdate = new Dictionary<State, Action>();
- m_handleUpdate[State.NoPuck] = () =>
- {
- // This lambda handles the update functionality in the NoPuck state
- };
- m_handleUpdate[State.Puck] = () =>
- {
- // this lambda handles the update functionality in the Puck state
- };
- }
- public void Update()
- {
- // We can call this dictionary element as we could any function now
- m_handleUpdate[m_currentState]();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement