示例#1
0
        private void LootingPhase()
        {
            while (GetUnarmedPlayers().Any())
            {
                var unarmedPlayers = GetUnarmedPlayers();
                var armedPlayers   = GetArmedPlayers();

                var isAttack = armedPlayers.Any() && rnd.Next(0, 11) == 10;

                if (isAttack)
                {
                    var playerIndex  = rnd.Next(0, armedPlayers.Count());
                    var actingPlayer = armedPlayers[playerIndex];

                    var targets           = GetTargetsForPlayer(actingPlayer);
                    var targetPlayerIndex = rnd.Next(0, targets.Count());
                    var target            = targets[targetPlayerIndex];

                    var attack = actionHelper.AttackAction(actingPlayer, target);

                    hub.Broadcast(messageHelper.GetMessageForAction(attack));

                    if (attack.IsKill)
                    {
                        actingPlayer.Kills.Add(attack);
                    }
                }
                else
                {
                    var playerIndex  = rnd.Next(0, unarmedPlayers.Count());
                    var actingPlayer = unarmedPlayers[playerIndex];

                    var weaponIndex  = rnd.Next(0, weaponPool.Count());
                    var targetWeapon = weaponPool[weaponIndex];

                    var loot = actionHelper.LootAction(actingPlayer, null, targetWeapon);
                    weaponPool.RemoveAt(weaponIndex);

                    hub.Broadcast(messageHelper.GetMessageForAction(loot));
                }

                System.Threading.Thread.Sleep(2000);
            }
        }
示例#2
0
        public void Start(ChatHub chatHub, List <string> playerNames, Leaderboard leaderboard)
        {
            hub     = chatHub;
            players = new List <Player>();

            foreach (var name in playerNames)
            {
                var player = new Player()
                {
                    Name  = name,
                    IsBot = name.StartsWith("Bot")
                };
                players.Add(player);
                var newPlayer = new PlayerStats {
                    Player = name
                };

                if (!player.IsBot)
                {
                    leaderboard.LeaderboardEntries.Add(newPlayer);
                }
            }

            var WeaponHelper = new WeaponHelper();

            weaponPool = WeaponHelper.CreateWeapons(players.Count);

            hub.Broadcast(messageHelper.Begin(players));
            hub.Broadcast("--------------------------------------------------");
            LootingPhase();
            WarPhase();

            var winner = players.First(p => p.State != PlayerState.Dead);

            if (!winner.IsBot)
            {
                var leaderboardEntry = leaderboard.LeaderboardEntries.Where(x => x.Player == winner.Name).FirstOrDefault();
                leaderboardEntry.Wins++;
                leaderboardEntry.TotalKills += winner.KillCount;
            }
            hub.Broadcast("--------------------------------------------------");
            hub.Broadcast(messageHelper.PlayerWins(winner));
            hub.Broadcast("--------------------------------------------------");

            var kills = messageHelper.GetPlayersKilled(players);

            foreach (var kill in kills)
            {
                hub.Broadcast(kill);
            }
        }