public void AttachingAMonstor_WillReduceItsHitPoints()
        {
            var state = MeleeWeapon.FormatState("Wooden Club", "Me1", 1, 12, -1, 1, 7.5, 0, 50);

            var testNum           = 1;
            var fakeRandomNumbers = GetGenerator(testNum);
            var registry          = new DispatchRegistry();
            var dispatcher        = new Dispatcher(registry);
            var fakeLogger        = new FakeLogger(_output);
            var mazeDescriptor    = FakeMazeDescriptorBuilder.Build(1, 1, 4, 2);

            var builder = new LevelBuilder(fakeRandomNumbers, mazeDescriptor, fakeLogger, dispatcher, registry);

            builder.Build(testNum);

            var me = ActorBuilder.Build <Me>(Coordinate.NotSet, registry, Me.FormatState(10, 10));

            dispatcher.EnqueueTeleport(me);
            var monster = ActorBuilder.Build <Monster>(Coordinate.NotSet, registry, Monster.FormatState(10, 10));

            dispatcher.EnqueueTeleport(monster);
            dispatcher.Dispatch();

            var weapon = new MeleeWeapon(fakeRandomNumbers, registry, dispatcher, state);

            dispatcher.EnqueueUse(weapon, Compass8Points.East);
            dispatcher.Dispatch();

            monster = (Monster)registry.GetDispatchee(monster.UniqueId);
            var expected = "HitPoints [7], ArmourClass [10]";
            var actual   = $"HitPoints [{monster.HitPoints}], ArmourClass [{monster.ArmourClass}]";

            Assert.Equal(expected, actual);
        }
Beispiel #2
0
 public void Can_create_interface_with_appropriately_named_class()
 {
     var builder = new ActorBuilder();
     var foo = builder.GetBuilder<IFoo>()();
     Assert.IsNotNull(foo);
     Assert.IsInstanceOfType(typeof(Foo), foo);
 }
Beispiel #3
0
        public void Move_Me_CanMoveIntoEmptySpace()
        {
            var testNum    = 1;
            var registry   = new DispatchRegistry();
            var dispatcher = new Dispatcher(registry);

            var fakeRandomNumbers = GetGenerator(testNum);
            var fakeLogger        = new FakeLogger(_output);
            var mazeDescriptor    = FakeMazeDescriptorBuilder.Build(1, 1, 4, 2);

            var builder = new LevelBuilder(fakeRandomNumbers, mazeDescriptor, fakeLogger, dispatcher, registry);

            builder.Build(GetLevel(testNum));
            var me = ActorBuilder.Build <Me>(Coordinate.NotSet, registry, Me.FormatState(10, 10));

            dispatcher.EnqueueTeleport(me);
            dispatcher.Dispatch();

            // t+1
            dispatcher.EnqueueMove(me, Compass8Points.South);
            dispatcher.Dispatch();

            var expected = GetExpectation(testNum);
            var actual   = registry.GetDispatchee("Maze1").ToString();

            _output.WriteLine(expected);
            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(actual);

            Assert.Equal(expected, actual);
        }
Beispiel #4
0
        public async Task UpdateActor_HasActor_SaveChanges()
        {
            //Arrange
            var actor = new ActorBuilder().WithId(1).Build();
            var data  = new List <Actor>()
            {
                actor
            }.AsQueryable();
            var dbSet   = GenerateEnumerableDbSetMock(data);
            var context = GenerateEnumerableContextMock(dbSet);

            context.Setup(x => x.Actors.FindAsync(It.IsAny <int>())).ReturnsAsync(actor);
            var service = new ActorsService(context.Object);

            var updatedActor = new ActorBuilder()
                               .WithId(1)
                               .WithFirstname("John")
                               .WithFirstname("Smith")
                               .Build();

            //Act
            await service.UpdateActor(updatedActor);

            //Assert
            context.Verify(x => x.SaveChangesAsync(default(CancellationToken)), Times.Once);
        }
Beispiel #5
0
        public async Task UpdateActor_WithoutActor_False()
        {
            //Arrange
            var actor = new ActorBuilder().WithId(1).Build();
            var data  = new List <Actor>()
            {
                actor
            }.AsQueryable();
            var dbSet   = GenerateEnumerableDbSetMock(data);
            var context = GenerateEnumerableContextMock(dbSet);
            //context.Setup(x => x.Actors.FindAsync(It.IsAny<int>())).ReturnsAsync(null);
            var service = new ActorsService(context.Object);

            var updatedActor = new ActorBuilder()
                               .WithId(1)
                               .WithFirstname("John")
                               .WithFirstname("Smith")
                               .Build();

            //Act
            var result = await service.UpdateActor(updatedActor);

            //Assert
            Assert.False(result);
        }
Beispiel #6
0
        internal Room AddDoor(int doorNumber)
        {
            IDispatchee dispatchee = null;

            while (dispatchee == null)
            {
                var tileName = FindWall();
                dispatchee = Registry.GetDispatchee(tileName);

                if (dispatchee.Name != "Wall")
                {
                    dispatchee = null;
                }
                else
                {
                    var wall = (Wall)dispatchee;
                    if (wall.IsCorner)
                    {
                        dispatchee = null;
                    }
                }
            }

            var door     = ActorBuilder.Build <Door>(dispatchee.Coordinates, Registry, doorNumber.ToString());
            var newState = door.Coordinates.ToTileState(door.UniqueId);

            return(Clone(newState));
        }
Beispiel #7
0
 public void Can_create_class()
 {
     var builder = new ActorBuilder();
     var foo = builder.GetBuilder<Foo>()();
     Assert.IsNotNull(foo);
     Assert.IsInstanceOfType(typeof(Foo),foo);
 }
Beispiel #8
0
        public LevelScene()
        {
            GameInformation.Instance.GameState = GameState.InGame;

            MobileList     = new List <Mobile>();
            WeatherHandler = new WeatherHandler();
            ThorSatellite  = new ThorSatellite();

            MineList            = new List <Mobile>();
            ToBeRemovedMineList = new List <Mobile>();

            //Popup related
            isLeaveGamePopupRendered = false;

            //Spawning units on the selected coordinates
            RoomMetadata room = GameInformation.Instance.RoomMetadata;

            ownedMobile = null;

            foreach (KeyValuePair <int, int[]> coordinate in room.SpawnPositions)
            {
                foreach (Player p in room.PlayerList)
                {
                    if (p.ID == coordinate.Key)
                    {
                        Mobile mob = ActorBuilder.BuildMobile(p.PrimaryMobile, p, new Vector2(coordinate.Value[0], coordinate.Value[1]));

                        MobileList.Add(mob);

                        if (p.ID == GameInformation.Instance.PlayerInformation.ID)
                        {
                            ownedMobile = mob;
                        }
                    }
                }
            }

            SpawnMapElements();

            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerInGameStartMatch, StartMatchAsyncCallback);
            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerInGameRequestShot, RequestShotAsyncCallback);
            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerInGameRequestItemUsage, RequestItemAsyncCallback);
            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerInGameRefreshSyncMobile, RefreshSyncMobileAsyncCallback);
            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerInGameRequestNextPlayerTurn, RequestNextPlayerTurnAsyncCallback);
            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerInGameRequestDeath, RequestDeathAsyncCallback);
            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerInGameRequestGameEnd, RequestGameEndAsyncCallback);
            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerInGameRequestDisconnect, RequestDisconnectAsyncCallback);

            //Gold Handler
            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerInGameRequestDamage, ReceiveGoldUpdateRequest);

            //Textbox handlers
            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerChatSendPlayerMessage, (o) => HUD.OnReceiveMessageAsyncCallback(o, 0));
            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerChatSendSystemMessage, (o) => HUD.OnReceiveMessageAsyncCallback(o, 1));

            //Threads
            TerminateThreads = false;
            StartTurnRequesterThread();
        }
 public void SetUp()
 {
     map     = new Map(5, 5);
     builder = new ActorBuilder <Player>();
     builder.SetSymbol('X');
     builder.SetPosition(new Vector(0, 0));
     player = builder.Get();
 }
Beispiel #10
0
 public static Actor Construct(ActorBuilder ab)
 {
     ab.BuildType();
     ab.BuildSex();
     ab.BuildFace();
     ab.BuildCostume();
     ab.BuildHairstyle();
     return(actor);
 }
Beispiel #11
0
        ///<summary>
        ///Метод, который создает игрока
        ///</summary>
        internal Player CreatePlayer()
        {
            var builder = new ActorBuilder <Player>();

            Console.WriteLine("Hello, enter your name plz: ");
            builder.SetName(Console.ReadLine());
            builder.SetSymbol('X');
            builder.SetColor(ConsoleColor.DarkRed);
            return(builder.Get());
        }
Beispiel #12
0
        /// <summary>
        /// 逐步构建复杂产品对象
        /// </summary>
        public Actor Construct(ActorBuilder builder)
        {
            builder.BuildType();
            builder.BuildSex();
            builder.BuildFace();
            builder.BuildCostume();
            builder.BuildHairStyle();

            return(builder.CreateActor());;
        }
Beispiel #13
0
        //逐步构建复杂产品对象
        public Actor Construct(ActorBuilder ab)
        {
            Actor actor;

            ab.BuildType();
            ab.BuildSex();
            ab.BuildFace();
            ab.BuildCostume();
            ab.BuildHairstyle();
            actor = ab.CreateActor();
            return(actor);
        }
Beispiel #14
0
        public static void Main(string[] args)
        {
            ActorBuilder    builder  = (ActorBuilder)AppConfigHelper.GetConcreteBuilderInstance();
            ActorController director = new ActorController();
            Actor           actor    = director.Construct(builder);

            Console.WriteLine("角色类型:{0}", actor.Type);
            Console.WriteLine("角色性别:{0}", actor.Sex);
            Console.WriteLine("角色面容:{0}", actor.Face);
            Console.WriteLine("角色服装:{0}", actor.Costume);
            Console.WriteLine("角色发型:{0}", actor.HairStyle);

            Console.ReadKey();
        }
Beispiel #15
0
        public PlayerButton(Player Player, Action <object> OnClick, Vector2 ButtonOffset)
            : base(ButtonType.PlayerButton, DepthParameter.InterfaceButton, OnClick, ButtonOffset)
        {
            //Hide button placeholder
            spriteList   = new List <Sprite>();
            flipbookList = new List <Flipbook>();

            ButtonSprite.Color = Color.Transparent;
            this.Player        = Player;

            //Since the button elements dont update, the screencenter
            //must be added in order to create the right position
            //on the elements
            ButtonOffset += Parameter.ScreenCenter;

            int sidePositionFactor = (Player.PlayerTeam == PlayerTeam.Red) ? 1 : -1;

            PlayerStatus = new Flipbook(
                ButtonOffset + new Vector2(82 * sidePositionFactor, 0),
                new Vector2((296 / 4) / 2, 76 / 2),
                74, 76, "Interface/StaticButtons/GameRoom/Player/StatusMarker",
                PlayerStatusPreset[Player.PlayerTeam][Player.PlayerRoomStatus],
                DepthParameter.InterfaceButtonIcon);
            flipbookList.Add(PlayerStatus);

            PlayerStatusText = new Flipbook(
                ButtonOffset + new Vector2(78 * sidePositionFactor, 28),
                new Vector2((150 / 3) / 2, 16 / 2),
                50, 16, "Interface/StaticButtons/GameRoom/Player/StatusText",
                PlayerStatusTextPreset[Player.PlayerTeam][Player.PlayerRoomStatus],
                DepthParameter.InterfaceButtonText);
            flipbookList.Add(PlayerStatusText);

            spriteList.Add(new Sprite("Interface/StaticButtons/GameRoom/Player/Shadow",
                                      ButtonOffset + new Vector2(-20 * sidePositionFactor, 33),
                                      DepthParameter.Mobile - 0.01f));

            Mobile = ActorBuilder.BuildMobile(Player.PrimaryMobile, Player, ButtonOffset + new Vector2(-20 * sidePositionFactor, 7), false);
            Mobile.Rider.Update();

            if (Player.PlayerTeam == PlayerTeam.Red)
            {
                Mobile.Flip();
            }

            Nameplate = new Nameplate(Player, Alignment.Left, ButtonOffset - new Vector2(100, 47));

            Mobile.MobileFlipbook.JumpToRandomAnimationFrame();
        }
Beispiel #16
0
        public async Task GetActorById_ActorWithIdExists_ActorWithId()
        {
            //Arrange
            var expected = new ActorBuilder().WithId(2).Build();
            var context  = GenerateEnumerableEmptyContextMock();
            var service  = new ActorsService(context.Object);

            context.Setup(x => x.Actors.FindAsync(2)).ReturnsAsync(expected);

            //Act
            var actor = await service.GetActorById(2);

            //Assert
            Assert.Equal(expected.Id, actor.Id);
        }
Beispiel #17
0
        public async Task AddNewActor_NewActor_AddAndSaveChanges()
        {
            //Arrange
            var actor = new ActorBuilder().WithId(1).Build();

            var dbSet   = GenerateEnumerableDbSetMock(new List <Actor>().AsQueryable());
            var context = GenerateEnumerableContextMock(dbSet);
            var service = new ActorsService(context.Object);

            //Act
            await service.AddNewActor(actor);

            //Assert
            dbSet.Verify(x => x.Add(It.IsAny <Actor>()), Times.Once);
            context.Verify(x => x.SaveChangesAsync(default(CancellationToken)), Times.Once);
        }
Beispiel #18
0
        public async Task RemoveActor_HasActor_True()
        {
            //Arrange
            var actor = new ActorBuilder().WithId(1).Build();
            var data  = new List <Actor>()
            {
                actor
            }.AsQueryable();
            var dbSet   = GenerateEnumerableDbSetMock(data);
            var context = GenerateEnumerableContextMock(dbSet);

            context.Setup(x => x.Actors.FindAsync(It.IsAny <int>())).ReturnsAsync(actor);
            var service = new ActorsService(context.Object);

            //Act
            var result = await service.RemoveActor(1);

            //Assert
            Assert.True(result);
        }
Beispiel #19
0
        private static TilesChange StateChangeForInput(DispatchRegistry registry, IList <string> lines)
        {
            var tilesChanged = new TilesChange();

            var row = 0;

            foreach (var line in lines)
            {
                var column = 0;
                foreach (var actorChar in line)
                {
                    var coordinates = new Coordinate(row, column);
                    var actor       = ActorBuilder.Build(actorChar, coordinates, registry);

                    tilesChanged.Add((actor?.UniqueId, coordinates));

                    column++;
                }

                row++;
            }

            return(tilesChanged);
        }
Beispiel #20
0
        static async Task Main(string[] args)
        {
            var Actor = new ActorBuilder()
                        .UseActorLambda()
                        //.ConfigureActorScheduler(p=>ActorScheduler.TaskFactory)
                        .RegisterService <TestActorController>()
                        .RegisterService <NextActorController>().Build();


            #region use akka model

            var lambda = Actor.Get <IActorLambda>();
            {
                int icount = 0;

                List <Task> waitlist = new List <Task>();

                for (int i = 0; i < 10000; i++)
                {
                    waitlist.Add(Task.Factory.StartNew((p) =>
                    {
                        lambda.Tell(() =>
                        {
                            icount += (int)p;
                        });
                    }, i));
                }


                for (int i = 0; i < 10000; i++)
                {
                    waitlist.Add(Task.Factory.StartNew((p) =>
                    {
                        lambda.Tell(() =>
                        {
                            icount -= (int)p;
                        });
                    }, i));
                }


                await Task.WhenAll(waitlist);

                Debug.Assert(icount == 0);
                Console.WriteLine($"tell:{icount}");
            }

            {
                int icount = 0;

                List <Task> waitlist = new List <Task>();
                for (int i = 0; i < 10000; i++)
                {
                    waitlist.Add(Task.Factory.StartNew(async(p) =>
                    {
                        var res = await lambda.Ask(() => p);
                        icount -= res;
                    }, i));
                }

                for (int i = 0; i < 10000; i++)
                {
                    waitlist.Add(Task.Factory.StartNew(async(p) =>
                    {
                        var res = await lambda.Ask(() => p);
                        icount += res;
                    }, i));
                }

                await Task.WhenAll(waitlist);

                Debug.Assert(icount == 0);

                Console.WriteLine($"tell:{icount}");
            }

            {
                int icount = 0;

                List <Task> waitlist = new List <Task>();
                for (int i = 0; i < 10000; i++)
                {
                    waitlist.Add(Task.Factory.StartNew(async(p) =>
                    {
                        await lambda.Ask(() =>
                        {
                            icount += (int)p;
                        });
                    }, i));
                }

                for (int i = 0; i < 10000; i++)
                {
                    waitlist.Add(Task.Factory.StartNew(async(p) =>
                    {
                        await lambda.Ask(() =>
                        {
                            icount -= (int)p;
                        });
                    }, i));
                }

                await Task.WhenAll(waitlist);

                Debug.Assert(icount == 0);

                Console.WriteLine($"tell:{icount}");
            }

            #endregion

            #region testsql
            var server = Actor.Get <ICallServer>();

            await server.Add(0, 0);

            await server.SetUserCoin(1, 100);

            var user = await server.GetUser(1);

            Console.WriteLine($"{user.Name} current coin:{user.Coin}");


            var task1 = Task.Run(() =>
            {
                for (int i = 0; i < 10; i++)
                {
                    server.AddUserCoin(1, 100);
                }
            });

            var task2 = Task.Run(() =>
            {
                for (int i = 0; i < 10; i++)
                {
                    server.SubUserCoin(1, 100);
                }
            });

            await Task.WhenAll(task1, task2);

            user = await server.GetUser(1);

            Console.WriteLine($"{user.Name} current coin:{user.Coin}");

            await server.TestWait();

            server.TestWrite($"{user.Name} coin is Reset");
            await server.SetUserCoin(1, 100);

            #endregion

            #region TestCount
            var stop = System.Diagnostics.Stopwatch.StartNew();

            var x = 0;

            long count = 0;

            for (int i = 0; i < 2000000; i++)
            {
                x = await server.Add(i, x);

                count++;
            }

            stop.Stop();

            var t = await server.GetV();

            Console.WriteLine(x);
            Console.WriteLine(t);
            Console.WriteLine($"Count:{count} time {stop.ElapsedMilliseconds}");


            stop.Restart();

            x     = 0;
            count = 0;

            for (int i = 0; i < 2000000; i++)
            {
                x = await Actor.CallFunc <int>(i, 2000, OpenAccess.Internal, i, x);

                count++;
            }

            stop.Stop();

            t = await server.GetV();

            Console.WriteLine(x);
            Console.WriteLine(t);
            Console.WriteLine($"Count:{count} time {stop.ElapsedMilliseconds}");


            stop.Restart();

            x     = 0;
            count = 0;

            for (int i = 0; i < 2000000; i++)
            {
                await lambda.Ask(() => { x += i; });

                count++;
            }

            stop.Stop();

            t = await server.GetV();

            Console.WriteLine(x);
            Console.WriteLine(t);
            Console.WriteLine($"Count:{count} time {stop.ElapsedMilliseconds}");

            #endregion

            Console.ReadLine();
        }
 public void SetUp()
 {
     builder = new ActorBuilder <Player>();
 }