Ejemplo n.º 1
0
        public void GetLifepackMessageTests()
        {
            var lifepackMessageString   = "L:0,1:74546#";
            var lifepackMessage         = MessageFactory.GetMessage(lifepackMessageString);
            var lifepackMessageExpected = new LifepackMessage(new Point(0, 1), 74546);

            Assert.NotNull(lifepackMessage);
            Assert.IsInstanceOf <LifepackMessage>(lifepackMessage);
            Assert.AreEqual(lifepackMessageExpected, lifepackMessage);

            var lifepackMessageCast = lifepackMessage as LifepackMessage;

            Assume.That(lifepackMessageCast, Is.Not.Null);

            Assert.AreEqual(new Point(0, 1), lifepackMessageCast?.Location);
            Assert.AreEqual(74546, lifepackMessageCast?.RemainingTime);

            var lifepackMessageUnexpected = new LifepackMessage(new Point(0, 1), 78986 /* here */);

            Assert.AreNotEqual(lifepackMessageUnexpected, lifepackMessageCast);
            Assert.True(lifepackMessageCast != lifepackMessageUnexpected);

            Assert.True(lifepackMessageExpected.GetHashCode() == lifepackMessageCast?.GetHashCode());
            Assert.False(lifepackMessageExpected.GetHashCode() == lifepackMessageUnexpected.GetHashCode());
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Adds a new lifepack to the world.
        /// </summary>
        /// <param name="oldWorld">Current state of the world. </param>
        /// <param name="message">The LifepackMessage received. </param>
        /// <returns>New world based on both the old world and the LifepackMessage. </returns>
        private static World FromLifepackMessage(World oldWorld, LifepackMessage message)
        {
            var lifepack = new Lifepack(message.Location, message.RemainingTime);

            return(new World(oldWorld.PlayerNumber)
            {
                BrickWalls = oldWorld.BrickWalls,
                StoneWalls = oldWorld.StoneWalls,
                Waters = oldWorld.Waters,
                Tanks = oldWorld.Tanks,
                Coinpacks = oldWorld.Coinpacks,
                Lifepacks = new HashSet <Lifepack>(oldWorld.Lifepacks.Concat(new[] { lifepack }))
            });
        }