public void InteractWithMysticalCubeToRunItsProgram()
        {
            const string saveName = "InteractWithMysticalCubeToRunItsProgram.json";
            {
                MysticalCube cube = _world.tingRunner.CreateTing <MysticalCube>("The Cube", testDefaultCoordinate);
                Assert.AreEqual(0, cube.programs.Length);
                Assert.AreEqual(0, cube.mysteryLevel);

                Character bosse = _world.tingRunner.CreateTing <Character>("Bosse", testDefaultCoordinate);
                bosse.InteractWith(cube);
                WorldTestHelper.UpdateWorld(_world, 5f);

                Assert.AreEqual(5, cube.mysteryLevel);                 // uses the default "TheCube.sprak" program
                _world.Save(saveName);
            }
            {
                _world = new World(saveName);

                MysticalCube cube = _world.tingRunner.GetTing("The Cube") as MysticalCube;
                Assert.AreEqual(5, cube.mysteryLevel);

                Character bosse = _world.tingRunner.GetTing("Bosse") as Character;
                bosse.InteractWith(cube);

                WorldTestHelper.UpdateWorld(_world, 5f);
                Assert.AreEqual(10, cube.mysteryLevel);
            }
        }
        public static void GenerateInitData()
        {
            InitialSaveFileCreator i = new InitialSaveFileCreator();
            World world = new World(i.CreateEmptyRelay());

            SimpleRoomBuilder srb = new SimpleRoomBuilder(world.roomRunner);

            srb.CreateRoomWithSize("Eden", 5, 5);
            srb.CreateRoomWithSize("Hallway", 5, 5);
            srb.CreateRoomWithSize("Kitchen", 10, 5);
            srb.CreateRoomWithSize("Bedroom", 5, 5);

            world.tingRunner.CreateTing <Character>("Adam", new WorldCoordinate("Eden", new IntPoint(0, 0)));
            world.tingRunner.CreateTing <Character>("Eva", new WorldCoordinate("Eden", new IntPoint(4, 4)));

            MysticalCube c = world.tingRunner.CreateTing <MysticalCube>("PowerCube", new WorldCoordinate("Eden", new IntPoint(2, 2)));

            c.onInteractionSourceCodeName = "PowerCube";

            world.relay.SaveTableSubsetSeparately(Room.TABLE_NAME, INIT_DATA_PATH + "Rooms.json");
            RelayLib.RelayTwo tingSubset = new RelayLib.RelayTwo();

            foreach (string table in world.tingRunner.loadedTingTables)
            {
                tingSubset.MergeWith(world.relay.Subset(table, (o) => { return(true); }));
            }

            tingSubset.SaveAll(INIT_DATA_PATH + "Tings.json");
        }
Exemple #3
0
        public void WalkThroughSeveralRoomsToInteractWithSomethingAtTheEnd()
        {
            MimanPathfinder2.ClearRoomNetwork();

            _adam.logger.AddListener(Console.WriteLine);
            SmartWalkBehaviour.s_logger.AddListener(Console.WriteLine);

            /*
             * _adam.AddDataListener<Character.WalkMode>("walkMode", ((Character.WalkMode prev, Character.WalkMode newWalkMode) => {
             *      //throw new Exception("NEW WALK MODE: " + newWalkMode);
             *      Console.WriteLine("NEW WALK MODE: " + newWalkMode);
             * }));
             */

            _adam.position = new WorldCoordinate("Eden", 0, 4);

            MysticalCube cube = _world.tingRunner.GetTing <MysticalCube>("PowerCube");

            cube.position = new WorldCoordinate("Kitchen", 3, 3);

            _adam.WalkToTingAndInteract(cube);
            WorldTestHelper.UpdateWorld(_world, 60f);

            Assert.AreEqual(cube, _adam.handItem);
        }
        public void SetUp()
        {
            WorldTestHelper.GenerateInitData();
            InitialSaveFileCreator i = new InitialSaveFileCreator();

            _world = new World(i.CreateRelay(WorldTestHelper.INIT_DATA_PATH));
            _adam  = _world.tingRunner.GetTing("Adam") as Character;
            _eva   = _world.tingRunner.GetTing("Eva") as Character;
            _cube  = _world.tingRunner.GetTing("PowerCube") as MysticalCube;
        }
        public void UsePowerCubeLoadedFromInitData1()
        {
            MysticalCube powerCube = _world.tingRunner.GetTing("PowerCube") as MysticalCube;

            Assert.AreEqual(0, powerCube.programs.Length);
            Assert.AreEqual(0, powerCube.mysteryLevel);

            Character erik = _world.tingRunner.CreateTing <Character>("Erik", testDefaultCoordinate);

            erik.InteractWith(powerCube);

            WorldTestHelper.UpdateWorld(_world, 5f);
            Assert.AreEqual(100, powerCube.mysteryLevel);             // power!
        }
        public void CharacterInteractsWithTingOnSameTile()
        {
            Character    adam      = _world.tingRunner.GetTing("Adam") as Character;
            MysticalCube powerCube = _world.tingRunner.GetTing("PowerCube") as MysticalCube;

            adam.logger.AddListener(Console.WriteLine);
            SmartWalkBehaviour.s_logger.AddListener(Console.WriteLine);

            powerCube.position = adam.position;
            adam.WalkToTingAndInteract(powerCube);
            WorldTestHelper.UpdateWorld(_world, 5.0f);

            Assert.AreEqual(powerCube, adam.handItem);
        }
        public void CharacterInteractsWithTingThatIsDestroyed()
        {
            Character    adam      = _world.tingRunner.GetTing("Adam") as Character;
            MysticalCube powerCube = _world.tingRunner.GetTing("PowerCube") as MysticalCube;

            adam.logger.AddListener(Console.WriteLine);
            //CharacterWalkBehaviour.logger.AddListener(Console.WriteLine);

            powerCube.position = new WorldCoordinate("Eden", 4, 0);
            adam.WalkToTingAndInteract(powerCube);
            WorldTestHelper.UpdateWorld(_world, 0.5f);

            // Destroy before he reaches it!
            _world.tingRunner.RemoveTingAfterUpdate(powerCube.name);
            WorldTestHelper.UpdateWorld(_world, 6.0f);

            Assert.AreEqual(null, adam.handItem);
        }
        public void CharacterInteractsWithTingThatMoves()
        {
            Character    adam      = _world.tingRunner.GetTing("Adam") as Character;
            MysticalCube powerCube = _world.tingRunner.GetTing("PowerCube") as MysticalCube;

            adam.logger.AddListener(Console.WriteLine);

            powerCube.position = new WorldCoordinate("Eden", 4, 0);
            adam.WalkToTingAndInteract(powerCube);
            WorldTestHelper.UpdateWorld(_world, 0.5f);

            // Move before he reaches it!
            powerCube.position = new WorldCoordinate("Eden", 4, 4);
            WorldTestHelper.UpdateWorld(_world, 6.0f);

            Assert.AreEqual(powerCube, adam.handItem);
            Assert.AreEqual(new WorldCoordinate("Eden", 4, 3), adam.position);
        }
        public void CharacterInteractsWithHandItem()
        {
            Character    adam      = _world.tingRunner.GetTing("Adam") as Character;
            MysticalCube powerCube = _world.tingRunner.GetTing("PowerCube") as MysticalCube;

            Assert.AreEqual(0, powerCube.mysteryLevel);

            adam.PickUp(powerCube);
            WorldTestHelper.UpdateWorld(_world, 3.0f);
            Assert.AreEqual(powerCube, adam.handItem);

            adam.InteractWith(powerCube);
            WorldTestHelper.UpdateWorld(_world, 3.0f);
            Assert.AreEqual(100, powerCube.mysteryLevel);

            adam.InteractWith(powerCube);
            WorldTestHelper.UpdateWorld(_world, 3.0f);
            Assert.AreEqual(200, powerCube.mysteryLevel);
        }
        public void CharacterInteractsWithCubeToChangeItsColor()
        {
            Character    adam      = _world.tingRunner.GetTing("Adam") as Character;
            MysticalCube powerCube = _world.tingRunner.GetTing("PowerCube") as MysticalCube;

            powerCube.onInteractionSourceCodeName = "CubeColorSetter";

            Assert.AreEqual(0f, powerCube.color.x, 0.05f);
            Assert.AreEqual(0f, powerCube.color.y, 0.05f);
            Assert.AreEqual(0f, powerCube.color.z, 0.05f);

            adam.PickUp(powerCube);
            WorldTestHelper.UpdateWorld(_world, 3.0f);

            adam.InteractWith(powerCube);
            WorldTestHelper.UpdateWorld(_world, 3.0f);

            Assert.AreEqual(0.9f, powerCube.color.x, 0.05f);
            Assert.AreEqual(0.2f, powerCube.color.y, 0.05f);
            Assert.AreEqual(0.6f, powerCube.color.z, 0.05f);
        }