World of Warcats

Object Oriented with UML - UML Diagram / C# sample

Overview & Diagram:

The objective of this project was to create a UML diagram to demonstrate the use of interfaces and dependancy injection. This example is an empty framework for a video game engine which can load levels from objects which implement the IWorld interface. Dependancy injection is demonstrated by the constructor for GameEngine which requires the IWorld Implementation to be passed in.

I have also included a sample C# project which I wrote by referencing the diagram. Both the project and executable can be found in the source section below.

Download Source (.zip archived)

Download Executable (.zip archived)


Program.cs

using System;
namespace WorldOfWarcats
{
    class Program
    {
        static void Main(string[] args)
        {
            Game game = new Game();

            game.Play();

            Console.ReadLine();
        }
    }
}

Game.cs

namespace WorldOfWarcats
{
    class Game
    {
        GameEngine fGameEngine = new GameEngine(new SteppeWorld());

        public void Play()
        {
            fGameEngine.Play();
        }
    }
}

GameEngine.cs

namespace WorldOfWarcats
{
    class GameEngine
    {
        IWorld fWorld;

        public GameEngine(IWorld newWorld)
        {
            fWorld = newWorld;
        }

        public void Play()
        {
            fWorld.Play();
        }
    }
}

IWorld.cs

namespace WorldOfWarcats
{
    interface IWorld
    {
        void Play();
    }
}

MainWorld.cs

namespace WorldOfWarcats
{
    class MainWorld : IWorld
    {
        LandSquare[] fLandSquares = new LandSquare[1024];

        public void Play()
        {

        }
    }
}

IslandWorld.cs

namespace WorldOfWarcats
{
    class IslandWorld : IWorld
    {
        LandSquare[] fLandSquares = new LandSquare[1024];
        public void Play()
        {

        }
    }
}

SteppeWorld.cs

using System;
namespace WorldOfWarcats
{
    class SteppeWorld : IWorld
    {
        LandSquare[] fLandSquares = new LandSquare[1024];

        public void Play()
        {
            Console.WriteLine("You look around and see a european country side.");
        }
    }
}

LandSquare.cs

namespace WorldOfWarcats
{
    class LandSquare
    {
    }
}