示例#1
0
        public void CanUndoSubLaunch()
        {
            Outpost outpost1          = Game.TimeMachine.GetState().GetOutposts()[0];
            Outpost outpost2          = Game.TimeMachine.GetState().GetOutposts()[1];
            int     outpostOneInitial = outpost1.GetDrillerCount();
            int     outpostTwoInitial = outpost2.GetDrillerCount();

            LaunchEvent launch = new LaunchEvent(new GameTick(), outpost1, 1, outpost2);

            Assert.AreEqual(true, launch.ForwardAction());

            // Ensure the sub was launched, outpost lost drillers, etc.
            Assert.AreEqual(1, Game.TimeMachine.GetState().GetSubList().Count);
            Assert.AreEqual(outpostOneInitial - 1, outpost1.GetDrillerCount());

            Assert.AreEqual(true, launch.BackwardAction());
            Assert.AreEqual(outpostOneInitial, outpost1.GetDrillerCount());
            Assert.AreEqual(outpostTwoInitial, outpost2.GetDrillerCount());
            Assert.AreEqual(0, Game.TimeMachine.GetState().GetSubList().Count);
        }
        public void CanUndoSubLaunch()
        {
            Outpost outpost1 = new Generator("0", new RftVector(new Rft(300, 300), 0, 0));
            Outpost outpost2 = new Generator("1", new RftVector(new Rft(300, 300), 0, 0));

            outpost1.GetComponent <DrillerCarrier>().SetOwner(_game.TimeMachine.GetState().GetPlayers()[0]);
            outpost2.GetComponent <DrillerCarrier>().SetOwner(_game.TimeMachine.GetState().GetPlayers()[1]);
            outpost1.GetComponent <DrillerCarrier>().SetDrillerCount(10);
            outpost2.GetComponent <DrillerCarrier>().SetDrillerCount(10);
            int outpostOneInitial = outpost1.GetComponent <DrillerCarrier>().GetDrillerCount();
            int outpostTwoInitial = outpost2.GetComponent <DrillerCarrier>().GetDrillerCount();

            _game.TimeMachine.GetState().GetOutposts().Add(outpost1);
            _game.TimeMachine.GetState().GetOutposts().Add(outpost2);

            LaunchEvent launch = new LaunchEvent(new GameEventModel()
            {
                EventData = new LaunchEventData()
                {
                    DestinationId = outpost2.GetComponent <IdentityManager>().GetId(),
                    DrillerCount  = 1,
                    SourceId      = outpost1.GetComponent <IdentityManager>().GetId(),
                }.ToByteString(),
                Id           = "a",
                EventType    = EventType.LaunchEvent,
                OccursAtTick = 1,
            });

            Assert.AreEqual(true, launch.ForwardAction(_game.TimeMachine, _game.TimeMachine.GetState()));

            // Ensure the sub was launched, outpost lost drillers, etc.
            Assert.AreEqual(1, _game.TimeMachine.GetState().GetSubList().Count);
            Assert.AreEqual(outpostOneInitial - 1, outpost1.GetComponent <DrillerCarrier>().GetDrillerCount());

            Assert.AreEqual(true, launch.BackwardAction(_game.TimeMachine, _game.TimeMachine.GetState()));
            Assert.AreEqual(outpostOneInitial, outpost1.GetComponent <DrillerCarrier>().GetDrillerCount());
            Assert.AreEqual(outpostTwoInitial, outpost2.GetComponent <DrillerCarrier>().GetDrillerCount());
            Assert.AreEqual(0, _game.TimeMachine.GetState().GetSubList().Count);
        }
        public void CanUndoSubLaunch()
        {
            List <Player> players = new List <Player>();

            players.Add(new Player("1"));

            GameConfiguration config = new GameConfiguration(players, DateTime.Now, new MapConfiguration(players));
            Game game = new Game(config);

            game.TimeMachine.GetState().GetOutposts().Add(_outpost);
            game.TimeMachine.GetState().GetOutposts().Add(_outpost2);

            var launchEvent = new LaunchEvent(new GameEventModel()
            {
                EventData = new LaunchEventData()
                {
                    DestinationId = _outpost2.GetId(),
                    DrillerCount  = 10,
                    SourceId      = _outpost.GetId(),
                }.ToByteString(),
                EventId      = "123",
                EventType    = EventType.LaunchEvent,
                OccursAtTick = 10,
            });

            int initialDrillers = _outpost.GetDrillerCount();

            launchEvent.ForwardAction(game.TimeMachine, game.TimeMachine.GetState());

            Assert.AreEqual(initialDrillers - 10, _outpost.GetDrillerCount());
            Assert.AreEqual(1, game.TimeMachine.GetState().GetSubList().Count);

            launchEvent.BackwardAction(game.TimeMachine, game.TimeMachine.GetState());

            Assert.AreEqual(initialDrillers, _outpost.GetDrillerCount());
            Assert.AreEqual(0, game.TimeMachine.GetState().GetSubList().Count);
        }