Game Development Reference
In-Depth Information
{
[Test]
public void TestAddedStateExists()
{
StateSystem stateSystem = new StateSystem();
stateSystem.AddState("splash", new SplashScreenState
(stateSystem));
// Does the added function now exist?
Assert.IsTrue(stateSystem.Exists("splash"));
}
The rest of the tests can be found on the CD at Code\Chapter 6\Chapter6-2\
Test_StateSystem.cs. Try to write your own and then compare them with the
code on the CD.
Game State Demo
Now that the StateSystem has been created, a simple demo can show it in
action. We can start with implementing the splash screen state. As we can only
draw spinning triangles, it's not going to be that impressive, but it's good enough
for a demo. Let's begin by implementing the title splash screen.
class SplashScreenState : IGameObject
{
StateSystem _system;
double _delayInSeconds = 3;
public SplashScreenState(StateSystem system)
{
_system = system;
}
#region IGameObject Members
public void Update(double elapsedTime)
{
_delayInSeconds -= elapsedTime;
if (_delayInSeconds <= 0)
{
_delayInSeconds = 3;
_system.ChangeState("title_menu");
 
 
Search WWH ::




Custom Search