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 InstantiateFromDatabase()
        {
            RelayTwo relay = new RelayTwo();
            TableTwo table = relay.CreateTable(Ting.TABLE_NAME);
            relay.CreateTable(Room.TABLE_NAME);
            table.AddField<string>(RelayObjectTwo.CSHARP_CLASS_FIELD_NAME);
            table.AddField<string>("species");
            table.AddField<string>("name");
            table.AddField<int>("age");
            int row0 = table.CreateRow().row;
            int row1 = table.CreateRow().row;

            table.SetValue(row0, RelayObjectTwo.CSHARP_CLASS_FIELD_NAME, "Animal");
            table.SetValue(row0, "species", "Monkey");
            table.SetValue(row0, "name", "Herr Nilsson");
            table.SetValue(row0, "age", 78);

            table.SetValue(row1, RelayObjectTwo.CSHARP_CLASS_FIELD_NAME, "Animal");
            table.SetValue(row1, "species", "Horse");
            table.SetValue(row1, "name", "Lilla Gubben");
            table.SetValue(row1, "age", 50);

            TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay));

            Animal herrNilsson = tingRunner.GetTing("Herr Nilsson") as Animal;
            Animal lillaGubben = tingRunner.GetTing("Lilla Gubben") as Animal;

            Assert.IsNotNull(herrNilsson);
            Assert.IsNotNull(lillaGubben);
            Assert.AreEqual(78, herrNilsson.age);
            Assert.AreEqual(50, lillaGubben.age);
        }
Exemplo n.º 3
0
        public void InstantiateFromDatabase()
        {
            RelayTwo relay = new RelayTwo();
            TableTwo table = relay.CreateTable(Ting.TABLE_NAME);

            relay.CreateTable(Room.TABLE_NAME);
            table.AddField <string>(RelayObjectTwo.CSHARP_CLASS_FIELD_NAME);
            table.AddField <string>("species");
            table.AddField <string>("name");
            table.AddField <int>("age");
            int row0 = table.CreateRow().row;
            int row1 = table.CreateRow().row;


            table.SetValue(row0, RelayObjectTwo.CSHARP_CLASS_FIELD_NAME, "Animal");
            table.SetValue(row0, "species", "Monkey");
            table.SetValue(row0, "name", "Herr Nilsson");
            table.SetValue(row0, "age", 78);

            table.SetValue(row1, RelayObjectTwo.CSHARP_CLASS_FIELD_NAME, "Animal");
            table.SetValue(row1, "species", "Horse");
            table.SetValue(row1, "name", "Lilla Gubben");
            table.SetValue(row1, "age", 50);

            TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay));

            Animal herrNilsson = tingRunner.GetTing("Herr Nilsson") as Animal;
            Animal lillaGubben = tingRunner.GetTing("Lilla Gubben") as Animal;

            Assert.IsNotNull(herrNilsson);
            Assert.IsNotNull(lillaGubben);
            Assert.AreEqual(78, herrNilsson.age);
            Assert.AreEqual(50, lillaGubben.age);
        }
Exemplo n.º 4
0
        public void GetCurrentTile()
        {
            Ting          t = _tingRunner.GetTing("Ting0");
            PointTileNode n = t.tile;

            Assert.NotNull(n);
            Assert.AreEqual(t.localPoint, n.localPoint);
        }
Exemplo n.º 5
0
        private HashSet <Ting> GetLinkedExitsInOtherRooms(Ting pTing)
        {
            var exitNodes = new HashSet <Ting>();

            if (pTing is IExit)
            {
                var target = (pTing as IExit).GetLinkTarget();

                if (target != null)
                {
                    exitNodes.Add(target);
                }

                // Extra exits if it's an elevator door
                var elevator = pTing as Door;
                if (elevator != null && elevator.elevatorAlternatives.Length > 0)
                {
                    foreach (var alternative in elevator.elevatorAlternatives)
                    {
                        var elevatorExit = _tingRunner.GetTing(alternative);
                        exitNodes.Add(elevatorExit);
                    }
                                        #if LOG
                    string[] exitsAsStrings = exitNodes.Select(n => n.ToString()).ToArray();
                    //D.Log("Elevator " + elevator + " has exits: " + string.Join(", ", exitsAsStrings));
                                        #endif
                }
            }

            return(exitNodes);
        }
Exemplo n.º 6
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.º 7
0
        private HashSet <Node> GetLinkedExitNodes(Ting pTing)
        {
            //D.isNull(pTing, "pTing is null");

            var exitNodes = new HashSet <Node>();

            foreach (var exit in GetExits(pTing.room))
            {
                if (LinkAllowed(pTing, exit))
                {
                    exitNodes.Add(new Node()
                    {
                        ting = exit
                    });
                }
            }

            if (pTing is IExit)
            {
                var target = (pTing as IExit).GetLinkTarget();
                if (target != null)
                {
                    if (IsTargetDoorInABusyElevator(target as Door))
                    {
                        //D.Log("Target door " + target + " is in a busy elevator");
                    }
                    else
                    {
                        exitNodes.Add(new Node()
                        {
                            ting = target
                        });
                    }
                }

                // Extra exits if it's an elevator door
                var elevator = pTing as Door;
                if (elevator != null && elevator.elevatorAlternatives.Length > 0)
                {
                    foreach (var alternative in elevator.elevatorAlternatives)
                    {
                        var elevatorExit = _tingRunner.GetTing(alternative);
                        exitNodes.Add(new Node()
                        {
                            ting = elevatorExit
                        });
                    }
#if LOG
                    string[] exitsAsStrings = exitNodes.Select(n => n.ToString()).ToArray();
                    //D.Log("Elevator " + elevator + " has exits: " + string.Join(", ", exitsAsStrings));
#endif
                }
            }

            return(exitNodes);
        }
Exemplo n.º 8
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.º 9
0
        public void TryingToGetTingWithWrongName()
        {
            RelayTwo relay = new RelayTwo();

            relay.CreateTable(Ting.TABLE_NAME);
            relay.CreateTable(Room.TABLE_NAME);
            TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay));

            Assert.Throws <CantFindTingException>(() =>
            {
                tingRunner.GetTing("wrong ting name");
            });
        }
Exemplo n.º 10
0
        public void TryingToGetTingWithWrongName()
        {
            RelayTwo relay = new RelayTwo();
            relay.CreateTable(Ting.TABLE_NAME);
            relay.CreateTable(Room.TABLE_NAME);
            TingRunner tingRunner = new TingRunner(relay, new RoomRunner(relay));

            Assert.Throws<CantFindTingException>(() =>
            {
                tingRunner.GetTing("wrong ting name");
            });
        }
Exemplo n.º 11
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);
            }
        }