Exemplo n.º 1
0
        public async Task StartGame()
        {
            if (Started)
            {
                return;
            }
            Started = true;

            Logger.Log(this, $"Game started: {Dimension}x{Dimension} grid. {Players.Count} players:");

            Locations = LocationFactory.CreateLocations(Dimension);

            //for (int i = 0; i < 20; i++)
            //    Players.Add(new RandomBot());

            var startLocation = Locations.First(x => x.IsStartingPoint);

            foreach (var player in Players)
            {
                Logger.Log(player, $"Player starting at {startLocation.Name}");
                player.Location = startLocation;
            }

            Notificator.GameHasStarted();

            Round = 0;
            while (Players.Count > 1)
            {
                // Round start
                PlayersThisRound = Players.Count;
                Round++;

                Logger.Log(this, $"Runde {Round}, {Players.Count} spillere");

                // Movement
                //if(Locations.Count(x=>!x.IsDeadly) > 1)
                {
                    await DoMovements();
                }

                // Kill players that are still in the storm - they either moved into the storm, or stood still
                KillPlayersInDeadZone();

                // Run encounters
                await DoEncountersAsync();

                // Round end
                Notificator.RoundHasEnded(Round);

                // Limit play area every n rounds

                int n = 3;
                if (PlayersThisRound <= 15)
                {
                    n = 2;
                }

                if (PlayersThisRound <= 7)
                {
                    n = 1;
                }

                if (Round % n == 0)
                {
                    await LimitPlayArea();
                }

                await Task.Delay(TimeSpan.FromSeconds(10));
            }

            PlayersThisRound = Players.Count;

            foreach (var actor in Players.ToList())
            {
                RemovePlayer(actor);
            }

            Notificator.GameHasEnded(Results);

            Logger.Log(this, $"Spillet er over.\n\nResultater:");
            Logger.Log(this, string.Join("\n ", Results.Select(x => $"{x.Rank}. {x.Name}")));

            Completed = true;
        }