Exemplo n.º 1
0
        public void SetupTingsThenSaveAndLoadFromDisk()
        {
            {
                TingRunner tingRunner = CreateTingRunnerWithSomeRoom();

                Animal bo = tingRunner.CreateTing <Animal>("Bo", new WorldCoordinate("SomeRoom", IntPoint.Zero));
                bo.species = "cow";
                bo.age     = 10;
                Animal howly = tingRunner.CreateTing <Animal>("Howly", new WorldCoordinate("SomeRoom", IntPoint.Zero));
                howly.species = "owl";

                Assert.AreEqual("cow", bo.species);
                Assert.AreEqual(10, bo.age);
                Assert.AreEqual("owl", howly.species);
                Assert.AreEqual(0, howly.age); // <- default value

                howly.age = 35;

                relay.SaveAll("farm.json");
            }

            {
                relay = new RelayTwo();
                relay.LoadAll("farm.json");
                TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay));

                Animal bo    = tingRunner.GetTing("Bo") as Animal;
                Animal howly = tingRunner.GetTing("Howly") as Animal;

                Assert.AreEqual("cow", bo.species);
                Assert.AreEqual(10, bo.age);
                Assert.AreEqual("owl", howly.species);
                Assert.AreEqual(35, howly.age);
            }
        }
Exemplo n.º 2
0
        public void RemoveTingUsingName()
        {
            TingRunner tingRunner = CreateTingRunnerWithSomeRoom();

            tingRunner.CreateTing <Animal>("Bee", new WorldCoordinate("SomeRoom", IntPoint.Zero));
            tingRunner.CreateTing <Animal>("Spider", new WorldCoordinate("SomeRoom", IntPoint.Zero));
            tingRunner.CreateTing <Animal>("Ant", new WorldCoordinate("SomeRoom", IntPoint.Zero));

            tingRunner.RemoveTing("Bee");

            Assert.IsFalse(tingRunner.HasTing("Bee"));
            Assert.IsTrue(tingRunner.HasTing("Spider"));
            Assert.IsTrue(tingRunner.HasTing("Ant"));
        }
Exemplo n.º 3
0
        public void GetTingFromObjectId()
        {
            TingRunner tingRunner = CreateTingRunnerWithSomeRoom();
            Ting       puma       = tingRunner.CreateTing <Animal>("Puma", new WorldCoordinate("SomeRoom", IntPoint.Zero));
            Ting       samePuma   = tingRunner.GetTing(puma.name);

            Assert.AreSame(puma, samePuma);
        }
Exemplo n.º 4
0
        public void Setup()
        {
            _relay = new RelayTwo();
            _table = _relay.CreateTable(Ting.TABLE_NAME);
            _relay.CreateTable(Room.TABLE_NAME);
            _roomRunner = new RoomRunner(_relay);
            Room room = _roomRunner.CreateRoom <Room>(ROOM_NAME);

            for (int i = 0; i < 100; i++)
            {
                room.AddTile(new PointTileNode(new IntPoint(i % 10, i / 10), room));
            }

            _tingRunner = new TingRunner(_relay, _roomRunner);
            _tingRunner.CreateTing <MyTing>("Ting0", new WorldCoordinate(ROOM_NAME, new IntPoint(0, 0)));
            _tingRunner.CreateTing <MyTing>("Ting1", new WorldCoordinate(ROOM_NAME, new IntPoint(1, 0)));
        }
Exemplo n.º 5
0
        public void Setup()
        {
            _relay = new RelayTwo();
            _table = _relay.CreateTable(Ting.TABLE_NAME);
            _relay.CreateTable(Room.TABLE_NAME);
            _roomRunner = new RoomRunner(_relay);
            Room room = _roomRunner.CreateRoom<Room>(ROOM_NAME);

            for (int i = 0; i < 100; i++)
            {
                room.AddTile(new PointTileNode(new IntPoint(i % 10, i / 10), room));
            }

            _tingRunner = new TingRunner(_relay, _roomRunner);
            _tingRunner.CreateTing<MyTing>("Ting0", new WorldCoordinate(ROOM_NAME, new IntPoint(0, 0)));
            _tingRunner.CreateTing<MyTing>("Ting1", new WorldCoordinate(ROOM_NAME, new IntPoint(1, 0)));
        }
Exemplo n.º 6
0
        public void HasTing()
        {
            TingRunner tingRunner = CreateTingRunnerWithSomeRoom();

            tingRunner.CreateTing <Animal>("Puma", new WorldCoordinate("SomeRoom", IntPoint.Zero));

            Assert.IsTrue(tingRunner.HasTing("Puma"));
            Assert.IsFalse(tingRunner.HasTing("Donkey"));
        }
Exemplo n.º 7
0
        public void CreateNewTingDuringRuntime()
        {
            TingRunner tingRunner = CreateTingRunnerWithSomeRoom();

            tingRunner.CreateTing <Animal>("Joe", new WorldCoordinate("SomeRoom", IntPoint.Zero));

            Animal a = tingRunner.GetTing("Joe") as Animal;

            Assert.IsNotNull(a);
        }
Exemplo n.º 8
0
 private static void UsingNormalAccessor()
 {
     RelayTwo relay = new RelayTwo();
     relay.CreateTable(Ting.TABLE_NAME);
     TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay));
     TestTing2UsingNormalAccessor t = tingRunner.CreateTing<TestTing2UsingNormalAccessor>("TestTing", WorldCoordinate.NONE);
     Console.WriteLine("Using class " + t.ToString());
     for(int i = 0; i < COUNTER; i++)
     {
         float a = t.awesome;
         a += 1.0f;
         t.awesome = a;
     }
     Console.WriteLine("2. awesome = " + t.awesome);
 }
Exemplo n.º 9
0
 private static void UsingCellId()
 {
     RelayTwo relay = new RelayTwo();
     relay.CreateTable(Ting.TABLE_NAME);
     TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay));
     TestTing1UsingCellIdWithConvenienceFunctions t = tingRunner.CreateTing<TestTing1UsingCellIdWithConvenienceFunctions>("TestTing", WorldCoordinate.NONE);
     Console.WriteLine("Using class " + t.ToString());
     for(int i = 0; i < COUNTER; i++)
     {
         float a = t.awesome;
         a += 1.0f;
         t.awesome = a;
     }
     Console.WriteLine("1. awesome = " + t.awesome);
 }
Exemplo n.º 10
0
        private static void UsingNormalAccessor()
        {
            RelayTwo relay = new RelayTwo();

            relay.CreateTable(Ting.TABLE_NAME);
            TingRunner tingRunner          = new TingRunner(relay, new RoomRunner(relay));
            TestTing2UsingNormalAccessor t = tingRunner.CreateTing <TestTing2UsingNormalAccessor>("TestTing", WorldCoordinate.NONE);

            Console.WriteLine("Using class " + t.ToString());
            for (int i = 0; i < COUNTER; i++)
            {
                float a = t.awesome;
                a        += 1.0f;
                t.awesome = a;
            }
            Console.WriteLine("2. awesome = " + t.awesome);
        }
Exemplo n.º 11
0
        private static void UsingCellId()
        {
            RelayTwo relay = new RelayTwo();

            relay.CreateTable(Ting.TABLE_NAME);
            TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay));
            TestTing1UsingCellIdWithConvenienceFunctions t = tingRunner.CreateTing <TestTing1UsingCellIdWithConvenienceFunctions>("TestTing", WorldCoordinate.NONE);

            Console.WriteLine("Using class " + t.ToString());
            for (int i = 0; i < COUNTER; i++)
            {
                float a = t.awesome;
                a        += 1.0f;
                t.awesome = a;
            }
            Console.WriteLine("1. awesome = " + t.awesome);
        }
Exemplo n.º 12
0
 public void AddDuplicateTing()
 {
     Assert.Throws <TingDuplicateException>(() => { _tingRunner.CreateTing <MyTing>("Ting0", WorldCoordinate.NONE); });
 }