Exemplo n.º 1
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.º 2
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.º 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 static MimanTing GetTingFromNameOrSourceCodeName(TingRunner pTingRunner, string pName)
        {
            //Console.WriteLine("Will get ting with name " + pName);

            var mimanTing = pTingRunner.GetTingUnsafe(pName) as MimanTing;

            if (mimanTing != null)
            {
                return(mimanTing);
            }

            // now try to get it through program name
            foreach (var ting in pTingRunner.GetTings())
            {
                var mimanTingWithProgram = (ting as MimanTing);

                if (mimanTingWithProgram.masterProgram == null)
                {
                    continue;
                }

                if (mimanTingWithProgram.masterProgram.sourceCodeName == pName)
                {
                    return(mimanTingWithProgram);
                }
//				else {
//					Console.WriteLine("Discarding miman ting with sourceCodeName " + mimanTingWithProgram.masterProgram.sourceCodeName);
//				}
            }

            return(null);
        }
Exemplo n.º 5
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.º 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
        TingRunner CreateTingRunnerWithSomeRoom()
        {
            relay = new RelayTwo();
            relay.CreateTable(Ting.TABLE_NAME);
            relay.CreateTable(Room.TABLE_NAME);
            RoomRunner rr = new RoomRunner(relay);

            rr.CreateRoom <Room>("SomeRoom");
            TingRunner tingRunner = new TingRunner(relay, rr);

            return(tingRunner);
        }
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 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.º 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
 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.º 13
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.º 14
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.º 15
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.º 16
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.º 17
0
        public SmartWalkBehaviour(Character pCharacter, RoomRunner pRoomRunner, TingRunner pTingRunner, WorldSettings pWorldSettings)
        {
            #if LOG && DEEP
            s_logger.Log("Created SmartWalkBehaviour for character " + pCharacter.name);
            #endif

            _character = pCharacter;
            _roomRunner = pRoomRunner;
            _tingRunner = pTingRunner;
            _worldSettings = pWorldSettings;

            _mimanPathFinder = new MimanPathfinder2(_tingRunner, _roomRunner);
            //_mimanPathFinder = new MimanPathfinder_DEPRECATED(_tingRunner);

            CalculateFinalTargetPosition();
            bool startWalkingAgain = RefreshPaths();
            if(startWalkingAgain) {
                _character.StartAction("Walking", null, Character.LONG_TIME, Character.LONG_TIME);
            }
            else {

            }
        }
Exemplo n.º 18
0
        public SmartWalkBehaviour(Character pCharacter, RoomRunner pRoomRunner, TingRunner pTingRunner, WorldSettings pWorldSettings)
        {
#if LOG && DEEP
            s_logger.Log("Created SmartWalkBehaviour for character " + pCharacter.name);
#endif

            _character     = pCharacter;
            _roomRunner    = pRoomRunner;
            _tingRunner    = pTingRunner;
            _worldSettings = pWorldSettings;

            _mimanPathFinder = new MimanPathfinder2(_tingRunner, _roomRunner);
            //_mimanPathFinder = new MimanPathfinder_DEPRECATED(_tingRunner);

            CalculateFinalTargetPosition();
            bool startWalkingAgain = RefreshPaths();
            if (startWalkingAgain)
            {
                _character.StartAction("Walking", null, Character.LONG_TIME, Character.LONG_TIME);
            }
            else
            {
            }
        }
Exemplo n.º 19
0
 TingRunner CreateTingRunnerWithSomeRoom()
 {
     relay = new RelayTwo();
     relay.CreateTable(Ting.TABLE_NAME);
     relay.CreateTable(Room.TABLE_NAME);
     RoomRunner rr = new RoomRunner(relay);
     rr.CreateRoom<Room>("SomeRoom");
     TingRunner tingRunner = new TingRunner(relay, rr);
     return tingRunner;
 }
Exemplo n.º 20
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.º 21
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.º 22
0
 public VoiceAPI(Computer pComputer, TingRunner pTingRunner, DialogueRunner pDialogueRunner)
 {
     _computer = pComputer;
     //_tingRunner = pTingRunner;
     _dialogueRunner = pDialogueRunner;
 }
Exemplo n.º 23
0
 public TingrunnerAPI(Computer pComputer, TingRunner pTingRunner, RoomRunner pRoomRunner)
 {
     _computer = pComputer;
     _tingRunner = pTingRunner;
     _roomRunner = pRoomRunner;
 }
Exemplo n.º 24
0
        public TrapAPI(Computer pComputer, TingRunner pTingRunner, DialogueRunner pDialogueRunner)
        {
            _computer = pComputer;
            _tingRunner = pTingRunner;
            _dialogueRunner = pDialogueRunner;

            _tingRunner.onTingHasNewRoom += OnTingHasNewRoom;
            _dialogueRunner.AddOnEventListener (OnEvent);

            _computerRoomCache = _computer.room.name;

            //D.Log("Trap API for " + pComputer + " is rigged!");
        }
Exemplo n.º 25
0
 public LampAPI(Computer pComputer, TingRunner pTingRunner)
 {
     _computer = pComputer;
     _tingRunner = pTingRunner;
 }
Exemplo n.º 26
0
 public MemoryAPI(Computer pComputer, TingRunner pTingRunner)
 {
     _computer = pComputer;
     _tingRunner = pTingRunner;
 }
Exemplo n.º 27
0
 public HeartAPI(Computer pComputer, TingRunner pTingRunner, DialogueRunner pDialogueRunner)
 {
     _computer = pComputer;
     _tingRunner = pTingRunner;
     _dialogueRunner = pDialogueRunner;
 }
Exemplo n.º 28
0
 //TingRunner _tingRunner;
 public InternetAPI(Computer pComputer, TingRunner pTingRunner)
 {
     _computer = pComputer;
     //_tingRunner = pTingRunner;
 }
Exemplo n.º 29
0
 //TingRunner _tingRunner;
 public FloppyAPI(Computer pComputer, TingRunner pTingRunner)
 {
     _computer = pComputer;
     //_tingRunner = pTingRunner;
 }
Exemplo n.º 30
0
 //TingRunner _tingRunner;
 public ElevatorAPI(Computer pComputer, TingRunner pTingRunner)
 {
     _computer = pComputer;
     //_tingRunner = pTingRunner;
 }
Exemplo n.º 31
0
 // OBS!!! With this solution only one program in the Ting can use the API safely!!!
 public ConnectionAPI(MimanTing pCaller, TingRunner pTingRunner, Program pProgram)
 {
     _caller = pCaller;
     _tingRunner = pTingRunner;
     _program = pProgram;
 }
Exemplo n.º 32
0
 public MimanPathfinder2(TingRunner pTingRunner, RoomRunner pRoomRunner)
 {
     _tingRunner = pTingRunner;
     _roomRunner = pRoomRunner;
 }
Exemplo n.º 33
0
 public MimanPathfinder_DEPRECATED(TingRunner pTingRunner)
 {
     _tingRunner = pTingRunner;
 }
Exemplo n.º 34
0
        // OBS!!! With this solution only one program in the Ting can use the API safely!!!

        public ConnectionAPI_Optimized(MimanTing pCaller, TingRunner pTingRunner, Program pProgram)
        {
            _caller     = pCaller;
            _tingRunner = pTingRunner;
            _program    = pProgram;
        }
Exemplo n.º 35
0
        public static MimanTing GetTingFromNameOrSourceCodeName(TingRunner pTingRunner, string pName)
        {
            //Console.WriteLine("Will get ting with name " + pName);

            var mimanTing = pTingRunner.GetTingUnsafe(pName) as MimanTing;

            if(mimanTing != null) {
                return mimanTing;
            }

            // now try to get it through program name
            foreach(var ting in pTingRunner.GetTings()) {
                var mimanTingWithProgram = (ting as MimanTing);

                if(mimanTingWithProgram.masterProgram == null) {
                    continue;
                }

                if(mimanTingWithProgram.masterProgram.sourceCodeName == pName) {
                    return mimanTingWithProgram;
                }
            //				else {
            //					Console.WriteLine("Discarding miman ting with sourceCodeName " + mimanTingWithProgram.masterProgram.sourceCodeName);
            //				}
            }

            return null;
        }
Exemplo n.º 36
0
 internal void SetupBaseRunners(TingRunner pTingRunner, RoomRunner pRoomRunner)
 {
     _roomRunner = pRoomRunner;
     _tingRunner = pTingRunner;
 }
Exemplo n.º 37
0
 public MimanPathfinder_DEPRECATED(TingRunner pTingRunner)
 {
     _tingRunner = pTingRunner;
 }