Game Development Reference
In-Depth Information
public void Update(double elapsedTime)
{
if (_currentState == null)
{
return; // nothing to update
}
_currentState.Update(elapsedTime);
}
public void Render()
{
if (_currentState == null)
{
return; // nothing to render
}
_currentState.Render();
}
public void AddState(string stateId, IGameObject state)
{
System.Diagnostics.Debug.Assert( Exists(stateId) == false );
_stateStore.Add(stateId, state);
}
public void ChangeState(string stateId)
{
System.Diagnostics.Debug.Assert(Exists(stateId));
_currentState = _stateStore[stateId];
}
public bool Exists(string stateId)
{
return _stateStore.ContainsKey(stateId);
}
}
The StateSystem class is a good class for unit testing—try writing some tests
in NUnit. The tests should be short snippets of code that check just one area;
here's an example:
[TestFixture]
public class Test_StateSystem
 
Search WWH ::




Custom Search