示例#1
0
        public void NextTurn()           // следующий ход (игроку или бомжам)
        {
            do
            {
                CurrentTurn++;

                if (CurrentTurn % Players.Count == 0)  // ход бомжей после хода второго игрока если он жив
                {
                    ProcessEnemies();
                    SpawnEnemies();
                }
                // порверки живучести игроков/бомжей
                // если все игроки зарезаны бомжами то игра окончена поражением
                if (Players.All(player => !player.Alive))
                {
                    GameEnded(this, new GameEndedEventArgs(false));
                    return;
                }

                // если игроки убили всех бомжей то игра окончена победой
                if (SpawnsRemain == 0 && Enemies.Count == 0)
                {
                    GameEnded(this, new GameEndedEventArgs(true));
                    return;
                }
            } while (!GetPlayerForCurrentTurn().Alive);  // убираем возможность для мертвого игрока делать действия
        }
示例#2
0
 internal void PleaseRestart()
 {
     if (Players.All(p => p.IsDead && p.CurrentPenaltyTime == 0))
     {
         (upperPipes, lowerPipes) = GetNewPipes();
     }
 }
示例#3
0
        public async Task TryGoToNextStageAsync()
        {
            if (Players.All(player => player.Ready))
            {
                Stage += 1;
                if (Stage > 4)
                {
                    Stage = 1;
                    AddCardsToPlayers();
                    NewGame();
                    if (Players.All(player => player.Cards.Count.Equals(0)))
                    {
                        Stage = 0;
                    }
                }
                foreach (var player in Players)
                {
                    player.Ready = false;
                }
                if (Stage.Equals(2) || Stage.Equals(3))
                {
                    Players.SingleOrDefault(player => player.Token.Equals(MainPlayer)).Ready = true;
                }

                if (Stage.Equals(4))
                {
                    await Task.Run(() => CalculatePoints());
                }
            }
        }
示例#4
0
        public void PlayerSubscribe(User username, string connectionId)
        {
            var player = Players.Single(p => p.PlayerName == username.TwitchUsername);

            player.ClientIds.Add(connectionId);

            //MyEventLog.WriteEntry(player + " connected.", EventLogEntryType.Information);

            lock (_threadLock)
            {
                if (_currentPack == 0)
                {
                    if (Players.All(p => p.ClientIds.Count > 0))
                    {
                        _currentPack++;
                        Players.ForEach(p => p.NotifyPick());
                    }
                    else
                    {
                        var disconnectedPlayers = Players.Where(p => p.ClientIds.Count == 0).Select(p => p.PlayerId).ToArray();
                        foreach (
                            var clientId in
                            Players.Where(p => p.ClientIds.Count > 0).SelectMany(p => p.ClientIds))
                        {
                            _hubContext.Clients.Client(clientId).waitingForPlayers(disconnectedPlayers);
                        }
                    }
                    return;
                }
            }
            player.NotifyPick(true);
        }
示例#5
0
文件: Game.cs 项目: robisoft/Uno
        private GameState CalculateGameState()
        {
            // Not Started
            // 1. Zero players OR
            // 2. all players have no cards
            if (!Players.Any() || Players.All(p => !p.Hand.Cards.Any()))
            {
                return(GameState.NotStarted);
            }

            // Finished
            // 1. One player has no cards and the other players have one or more cards
            if (Players.Any(p => p.Hand.Cards.Any()) && Players.Any(p => !p.Hand.Cards.Any()))
            {
                return(GameState.Finished);
            }

            // Waiting For Player
            // 1. Current Player Index > -1
            if (CurrentPlayerIndex > -1)
            {
                return(GameState.WaitingForPlayer);
            }

            throw new Exception("Unable to determine game state!");
        }
示例#6
0
        public void Simulate()
        {
            while (true)
            {
                foreach (var currentPlayer in Players)
                {
                    if (currentPlayer.HasCards())
                    {
                        var currentCard = currentPlayer.Cards.TakeFromTop();
                        CentralPile.AddToTop(currentCard);
                        Console.WriteLine($"Player {currentPlayer.Id} added card {currentCard} to the pile.");

                        if (_snapDecider.IsSnap(CentralPile))
                        {
                            var winner = _winnerDecider.GetSnapWinner(currentPlayer, PlayersById);
                            Snap(winner);

                            if (winner.Cards.Count() == _numberOfCardsUsedInGame)
                            {
                                Console.WriteLine($"Player {winner.Id} Won!");
                                return;
                            }
                        }
                    }
                }

                if (Players.All(p => !p.HasCards()))
                {
                    Console.WriteLine("No more Cards Available");
                    return;
                }
            }
        }
示例#7
0
 internal void PleaseStop()
 {
     if (Players.All(p => (p.IsDead && p.CurrentPenaltyTime == 0)))
     {
         IsRunning = false;
     }
 }
        public virtual void BeginGame(string userId)
        {
            LinkedListNode <CsGamePlayer> player = FindPlayer(userId);

            if (Players.All(p => p.IsReady) && Players.Count == 4 && this.RoomPeoPleType == 0)
            {
                CardIndex = 0;
                RandCard();
                SendCard(false);
            }
            else if (Players.All(p => p.IsReady) && Players.Count == 3 && this.RoomPeoPleType == 1)
            {
                CardIndex = 0;
                RandCard();
                SendCard(false);
            }
            else
            {
                //DOTO: 待重构,不够人数加入房间因为想只给客户端发一次,将1003与1006合并为一个接口
                int playerLen = this.Players.Count;

                A1003AndA1006Response.Builder responseBase = this.Create1003And1006Req(playerLen);

                var responseArray = responseBase.Build().ToByteArray();

                var tempPlayer = this.Players.First;

                for (int i = 0; i < playerLen; i++)
                {
                    WebSocketServerWrappe.SendPackgeWithUser(tempPlayer.Value.PlayerUser.Uid, 10036, responseArray);
                    tempPlayer = tempPlayer.Next;
                }
            }
        }
示例#9
0
 public void CheckGameOver()
 {
     if (Players.Any(player => (player.History.FindAll(o => o == RollResult.Jackpot)).Count == 2) ||
         Players.All(player => player.History.Count == 6))
     {
         _isGameOver = true;
     }
 }
示例#10
0
        public bool IsOver()
        {
            var isOver = Players.All(player =>
            {
                return(player.HasFinishedFrame(9, _rolls[player]));
            });

            return(isOver);
        }
 private bool CanBuildGame()
 {
     return
         (Players.Count >= Config.MinPlayers &&
          Players.Any(player => player.Me) &&
          Players.All(player => !ReferenceEquals(player.Piece, _defaultCard) && !string.IsNullOrWhiteSpace(player.Name)) &&
          Players.Select(player => player.Name).Distinct().Count() == Players.Count &&
          Players.Select(player => player.Piece.Name).Distinct().Count() == Players.Count);
 }
示例#12
0
        private void CheckGameStatus(IGameStatus gameStatus)
        {
            if (Players.All(x => x.CurrentThreat >= 50))
            {
                gameStatus.IsPlayerDefeat = true;
            }

            TriggerEffectsForAllCardsInPlay <ICardInPlay, IDuringCheckGameStatus>();
        }
示例#13
0
 public void AddPlayer(string playerId)
 {
     //eh, a player can be added again, won't do anything
     if (Players.All(k => k != playerId))
     {
         Players.Add(playerId);
         _notificationFactory.GetInstance()?.PlayerAdded(playerId, GameId);
     }
 }
示例#14
0
        public ActionResult SelectedEloByTime(string[] playerNames, int?width, int?height, bool?title)
        {
            var players = Players.All().Where(p => playerNames.Contains(p.Name));
            var chart   = GenerateDateChart(players, width, height, title);

            chart.AddLegend();
            chart.Write("png");

            return(new EmptyResult());
        }
示例#15
0
 /// <summary>
 /// Checks if the current turn has been completed successfully, then ends the turn and
 /// </summary>
 public void EndTurn()
 {
     if (Players.All(p => p.PendingTransactions.Count == 0))
     {
         currentPlayerIndex = (currentPlayerIndex + 1) % Players.Count;
     }
     else
     {
         throw new TurnIncompleteException("Players still had pending transactions.");
     }
 }
示例#16
0
        public PlayerData DataOf(ulong userId)
        {
            Console.WriteLine($"[{Format.Time(DateTime.UtcNow)}] Getting data of {userId}");

            if (Players.All(x => x.Source.User.Id != userId))
            {
                throw new Exception("Cannot find session data for the specified user");
            }

            return(Players.First(x => x.Source.User.Id == userId));
        }
示例#17
0
 public override void Update()
 {
     if (!GameManager.Instance.CurrentlyChangingScenes)
     {
         var allPlayersReady = Players.All(x => x.IsReady);
         if (allPlayersReady)
         {
             GameManager.Instance.EndGame();
         }
     }
 }
示例#18
0
        public ActionResult WinRate()
        {
            var table = Players.All().OrderByDescending(p => p.WinRate);

            if (!table.Any())
            {
                return(Redirect("/Players/NewLeague"));
            }

            ViewData.Model = table;
            return(View());
        }
示例#19
0
 public bool IncrementCurrentRound()
 {
     if (Players.All(p => p.CanIncrementRound()))
     {
         CurrentRound++;
         Players.ForEach(p => p.Round = CurrentRound);
         OnIncrementRound(new NextRoundEventArgs(CurrentRound));
         GetNextPlayer();
         return(true);
     }
     return(false);
 }
示例#20
0
        // GET: Games
        public ActionResult Index()
        {
            var leaderboard = Players.All().OrderByDescending(p => p.Rating);

            if (!leaderboard.Any())
            {
                return(Redirect("~/Players/NewLeague"));
            }

            ViewData.Model = Games.MostRecent(20, Games.GamesSortOrder.MostRecentFirst);
            return(View());
        }
        void belongs_where_entity_belongs_more_than_one_relation()
        {
            before = () =>
            {
                seed = new Seed();

                GameSchema.CreateSchema(seed);

                players = new Players();

                player1Id = new { Name = "Jane" }.InsertInto("Players");

                player2Id = new { Name = "John" }.InsertInto("Players");

                game1Id = new { Title = "Mirror's Edge" }.InsertInto("Games");

                game2Id = new { Title = "Gears of War" }.InsertInto("Games");

                new { PlayerId = player1Id, GameId = game2Id }.InsertInto("Library");

                new { PlayerId = player2Id, GameId = game1Id }.InsertInto("Library");

                new { PlayerId = player2Id, GameId = game2Id }.InsertInto("Library");

                sqlQueries = new List <string>();

                DynamicRepository.WriteDevLog = true;

                DynamicRepository.LogSql = new Action <object, string, object[]>(
                    (sender, sql, @params) =>
                {
                    sqlQueries.Add(sql);
                });

                allPlayers = players.All();

                allPlayers.Include("Library");

                allPlayers.Library().Include("Game");
            };

            it["updates all references that map to the belongs to entity"] = () =>
            {
                (allPlayers.First().Library().First().Game().Title as object).should_be("Gears of War");

                (allPlayers.Last().Library().First().Game().Title as object).should_be("Mirror's Edge");

                (allPlayers.Last().Library().Last().Game().Title as object).should_be("Gears of War");


                sqlQueries.Count.should_be(3);
            };
        }
示例#22
0
        public ActionResult WorstEverLosingStreak()
        {
            var table = Players.All().OrderByDescending(p => p.LongestLosingStreak);

            if (!table.Any())
            {
                return(Redirect("/Players/NewLeague"));
            }

            ViewData.Model = table;
            return(View());
        }
示例#23
0
            protected override void SetResultOfRound()
            {
                // CHECK IF A RECURSIVE GAME SHOULD HAPPEN

                // If both players have at least as many cards remaining
                // in their deck as the value of the card they just drew,
                // the winner of the round is determined by playing a new game of Recursive Combat.
                Player playerWon;

                bool playSubgame = Players.All(p => p.NrOfCards >= p.PlayedCard);

                if (playSubgame)
                {
                    if (PRINT)
                    {
                        Console.WriteLine("Playing a sub-game to determine the winner...");
                    }

                    var playersWithNewCards = Players.Select(p => new Player(p.Name, p.Cards.ToList().Take(p.PlayedCard).ToList())).ToList();
                    SubGame++;
                    var newGame = new RecursiveCombat(playersWithNewCards, SubGame);
                    var playerWonRecursiceGame = newGame.PlayGame();
                    playerWon = Players.FirstOrDefault(p => p.Name == playerWonRecursiceGame.Name);
                    var otherPlayer = Players.FirstOrDefault(p => p.Name != playerWonRecursiceGame.Name);
                    // note that the winner's card might be the lower-valued of the two cards
                    playerWon.WonCards(playerWon.PlayedCard, otherPlayer.PlayedCard);

                    if (PRINT)
                    {
                        Console.WriteLine($"...anyway, back to game {GameNr}.");
                    }
                }
                else
                {
                    // find player with the highest card!
                    playerWon = Players.OrderBy(p => p.PlayedCard).Reverse().FirstOrDefault();

                    CardsOnTable.Sort();
                    CardsOnTable.Reverse();
                    playerWon.WonCards(CardsOnTable);
                }

                if (PRINT)
                {
                    Console.WriteLine($"{playerWon.Name} wins round {Round} of game {GameNr}!");
                }

                // reset round!
                Players.ForEach(p => p.ResetRound());
                CardsOnTable = new List <int>();
            }
示例#24
0
        // GET: Players
        public ActionResult Index()
        {
            var leaderboard = Players.All().OrderByDescending(p => p.Rating);

            if (!leaderboard.Any())
            {
                return(Redirect("/Players/NewLeague"));
            }

            var players = Players.All();

            ViewData.Model = players.OrderBy(p => p.Name);
            return(View());
        }
示例#25
0
        public bool CheckWin()
        {
            if (GameOver)
            {
                return(true);
            }
            var wabeList = GameMap.Wabes.Cast <Wabe>().ToList();

            foreach (var player in Players)
            {
                if (!_executedFirstPlace[player] || _isOut[player])
                {
                    continue;
                }
                if (wabeList.Count(w => w.Owner?.Id == player.Id) == 0)
                {
                    var reason = $"{player.Name} don't have any more wabes and has been eliminated!";
                    Message = reason;
                    if (CurrentPlayer.Id == player.Id)
                    {
                        CurrentPlayer = Players.NextOfPlayer(CurrentPlayer, _isOut);
                    }
                    _isOut[player] = true;
                }
            }

            foreach (var player in Players)
            {
                if (Players.All(p => _executedFirstPlace[p]) && Players.Count(p => !_isOut[p]) == 1 && !_isOut[player])
                {
                    var reason = $"{player.Name} is last man standing!";
                    GameOver = true;
                    Message  = reason;
                    Winner   = player;
                    Winner.Wins++;
                    return(true);
                }
                if (wabeList.Count(w => w.Owner != null && w.Owner == player) >= 25)
                {
                    var reason = $"{player.Name} has captured 25 wabes.";
                    GameOver = true;
                    Message  = reason;
                    Winner   = player;
                    Winner.Wins++;
                    return(true);
                }
            }
            return(false);
        }
        void selecting_many_off_of_collection()
        {
            act = () => selectMany = (players.All() as dynamic).Games();

            it["returns all games for all players"] = () =>
            {
                selectMany.Count().should_be(2);

                var firstGame = selectMany.First();

                (firstGame.Title as string).should_be("Gears of War");
            };

            it["links back to the specific player the query originated from"] = () =>
            {
                var firstGame = selectMany.First();

                (firstGame.Player.Name as string).should_be("Jane");

                var secondGame = selectMany.Last();

                (secondGame.Player.Name as string).should_be("John");
            };
        }
示例#27
0
        public void CurrentForm()
        {
            var store = new Store();

            var games = store.Games.OrderBy(x => x.Date).ToList();

            var dict = Players.All().ToDictionary(x => x, x => 0);

            for (int i = 0; i < games.Count; i++)
            {
                dict[games[i].Winner] += i + 1;
            }

            foreach (var pair in dict.OrderByDescending(x => x.Value))
            {
                Console.WriteLine(pair.Key + " " + pair.Value);
            }
        }
示例#28
0
 public bool Start()
 {
     if (Players.All(p => p.IsReady && p.Character.Name != CharacterName.Empty))
     {
         FlagPosition = gameMap.FlagSpawnPoint;
         for (int i = 0; i < Players.Count; i++)
         {
             Players[i].LevelUp();
             Players[i].SpawnPoint = gameMap.SpawnPoints[i];
             Players[i].Respawn();
         }
         Random random = new Random();
         PlayerTurn = random.Next(Players.Count);
         Players[PlayerTurn].IsTurn = true;
         IsStarted = true;
     }
     return(IsStarted);
 }
示例#29
0
        public void SendPublicMessage(IPlayer @from, string text)
        {
            if (from == null)
            {
                throw new ArgumentNullException(nameof(from));
            }
            if (string.IsNullOrWhiteSpace(text))
            {
                throw new ArgumentNullException(nameof(text));
            }

            if (Players.All(p => p.Identifier != from.Identifier))
            {
                return;
            }

            Messages.Add(new ChatMessage(DateTimeOffset.Now, from.Identifier, ChatMessage.PublicChannelName, text));
        }
示例#30
0
        public ActionResult Index(GraphsViewModel model)
        {
            if (model == null || model.Names == null)
            {
                var names = Players.All()
                            .OrderBy(p => p.Name)
                            .Select(p => new CheckBoxViewModel {
                    Checked = true, Text = p.Name
                })
                            .ToList();

                model = new GraphsViewModel {
                    Names = names, GraphType = GraphType.EloVsGames
                };
            }

            return(View(model));
        }