Ejemplo n.º 1
0
        private bool CheckDefault()
        {
            DsFilter defaultFilter = new DsFilter();

            if (MinDuration == defaultFilter.MinDuration &&
                MaxDuration == defaultFilter.MaxDuration &&
                MinArmy == defaultFilter.MinArmy &&
                MinIncome == defaultFilter.MinIncome &&
                MaxLeaver == defaultFilter.MaxLeaver &&
                MinKills == defaultFilter.MinKills &&
                PlayerCount == defaultFilter.PlayerCount &&
                Mid == defaultFilter.Mid &&
                !(GameModes.Except(new List <int>()
            {
                (int)Gamemode.Commanders, (int)Gamemode.CommandersHeroic
            }).Any() ||
                  (new List <int>()
            {
                (int)Gamemode.Commanders, (int)Gamemode.CommandersHeroic
            }).Except(GameModes).Any()) &&
                !Players.Any() &&
                DefaultTime
                )
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        // Player subscriptions
        // ----------
        private static void OnPlayerLoseHandler(PlayerEventArgs e)
        {
            if (e.Uuid != TableDealer._id)
            {
                // if a player exceeds blackjack value
                // move to next player
                PlayerTurnIndex++;

                // if its dealers turn, check if there are any players left to play against.
                // if not end the game directly
                if (PlayerTurnIndex == Players.Count &&
                    Players.Any(player => !player.Hand.hasExceeded()) &&
                    TableDealer.shouldDrawCard())
                {
                    // there more more players to win against, draw cards if needed
                    hitForCurrentPlayer();
                }
                else
                {
                    endGame();
                }
            }
            else
            {
                // dealer lost by exceeding
                endGame();
            }
        }
Ejemplo n.º 3
0
        public void AddPlayer(IPlayer player)
        {
            if (player == null)
            {
                throw new ArgumentNullException(nameof(player));
            }
            if (player.Id == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(player.Id));
            }
            if (player.Name == null)
            {
                throw new ArgumentNullException(nameof(player.Name));
            }

            if (Players.Any(p => p.Id == player.Id))
            {
                // The player is already added.
                return;
            }

            if (Players.Any(p => p.Name.ToLower() == player.Name.ToLower()))
            {
                throw new PlayerWithSameNameAlreadyExistsException(player.Name);
            }

            Players.Add(player);
        }
Ejemplo n.º 4
0
Archivo: Game.cs Proyecto: 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!");
        }
Ejemplo n.º 5
0
        public string[] View()
        {
            StringBuilder stringBuilder = new StringBuilder();
            List <string> view          = new List <string>();

            view.Add(Name);
            view.Add("");
            view.Add(Description);
            view.Add("");
            if (Exits.Any())
            {
                stringBuilder.Append("Exits: " + Function.GetNames(Exits.ToArray()));
                view.Add(stringBuilder.ToString());
                stringBuilder.Clear();
            }
            if (Mobs.Any())
            {
                stringBuilder.Append("Mobs: " + Function.GetNames(Mobs.ToArray()));
                view.Add(stringBuilder.ToString());
                stringBuilder.Clear();
            }
            if (Players.Any())
            {
                stringBuilder.Append("Players: " + Function.GetNames(Players.ToArray()));
                view.Add(stringBuilder.ToString());
                stringBuilder.Clear();
            }
            if (Items.Any())
            {
                // items on floor; need to search for duplicates, pronouns, etc., and display them in friendly grammar form
                // You see (an) orange, 23 pumpkin seed(s), (a) hungry cat, Toetag('s) nose.
            }
            return(view.ToArray());
        }
Ejemplo n.º 6
0
        public async void Play()
        {
            if (Players.Any() == false)
            {
                return;
            }
            foreach (var item in Players)
            {
                item.IsWinner = false;
            }

            var random = new Random(DateTime.Now.Millisecond);

            var lucky          = random.Next(0, Players.Count());
            var selectedPlayer = Players.ElementAtOrDefault(lucky);

            if (selectedPlayer != null)
            {
                selectedPlayer.IsWinner = true;
                Winner = selectedPlayer;

                //History.Add(new EventLogViewModel(string.Format("{0} winned!", selectedPlayer.PlayerName)));
                Model.History.Add(string.Format("{0} winned!", selectedPlayer.PlayerName));

                await GameService.SaveHistoryAsync(Model);
            }
        }
Ejemplo n.º 7
0
        public async Task Run()
        {
            while (GameState != GameState.Running)
            {
                await Task.Delay(1000);
            }

            SetUpGame();

            while (Players.Any() && QuestionPile.Any() && AnswerPile.Any())
            {
                SetUpRound();
                await DealCards();
                await ShowQuestion();

                // Wait for users to pick their answers
                await Sleep(60, CheckIfMaxAnswersHaveBeenSubmitted);
                await ShowAnswers();

                // Wait for users to cast their votes
                await Sleep(60, CheckIfMaxVotesHaveBeenCast);
                await CalculateAndDisplayWinningCard();
                await Sleep(8, () => false);
                await UpdateLeaderboard();
            }

            await ChangeGameState(GameState.Ended);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 当玩家退出游戏时,调用此方法
        /// </summary>
        /// <param name="player">退出游戏的玩家</param>
        public override void OnPlayerQuitted(GamePlayerBase player)
        {
            lock ( SyncRoot )
            {
                if (GameState == GameState.NotInitialized)
                {
                    throw new InvalidOperationException();
                }


                if (!PlayerCollection.Contains(player))   //如果不存在这个玩家,则忽略。
                {
                    return;
                }


                AnnounceSystemMessage("玩家 {0} 退出了游戏", player.PlayerName);
                PlayerCollection.Remove(player);

                lock ( SyncRoot )
                {
                    if (!Players.Any())                   //若已经没有玩家了,释放游戏资源
                    {
                        ReleaseGame();
                    }

                    if (GameState == GameState.Running)   //如果游戏正在进行,则强行终止游戏。
                    {
                        Abort();
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public async Task CheckMaster()
        {
            if (Players.Any(x => x.Value.Rank == ClubRank.Master))
            {
                return;
            }

            var nextMaster = Players.Values.OrderBy(x => x.Rank).FirstOrDefault(x => x.Rank <= ClubRank.Regular);

            if (nextMaster != null)
            {
                nextMaster.Rank = ClubRank.Master;
                using (var db = GameDatabase.Open())
                {
                    var nextMasterDto = new ClubPlayerDto
                    {
                        PlayerId = nextMaster.Account.Id,
                        ClubId   = Id,
                        Rank     = (byte)ClubRank.Master,
                        State    = (int)ClubState.Joined
                    };
                    await DbUtil.UpdateAsync(db, nextMasterDto);
                }
                Logger.Information("Passing Master to next Staff");
                Logger.Information("Auto MasterChange in Clan {0} to player {1}", ClanName,
                                   nextMaster.Account.Nickname);
            }
        }
Ejemplo n.º 10
0
 internal void AddPlayer(Player player)
 {
     if (!Players.Any(p => p.Name == player.Name))
     {
         Players.Add(player);
     }
 }
Ejemplo n.º 11
0
        public virtual void Join(string userName, IPlayerController controller)
        {
            if (Players.Count >= SeatsCount)
            {
                throw new Exception($"Table is full - {userName} cannot join");
            }

            if (Players.Any(p => p.Name == userName))
            {
                throw new Exception($"{userName} is already in the room");
            }

            //if (userName == "Tommy")
            //{
            //    InitialCash = 0;
            //}

            //if (userName == "Ratchet")
            //{
            //    InitialCash = 10;
            //}

            //if (userName == "Corail")
            //{
            //    InitialCash = 2000;
            //}


            var player = new Player(userName, InitialCash, controller, _notifier, this);

            Players.Add(player);
            _satPlayers.Add(player);

            player.ActionGiven += Player_ActionGiven;
        }
Ejemplo n.º 12
0
        public string EndTurn(string currentUser)
        {
            var(error, player) = CheckTurn(currentUser);
            if (error != null)
            {
                return(error);
            }
            if (LastRoll1 == 0 || (LastRoll1 == LastRoll2 && DoubleCount >= 0))
            {
                return("You can't end your turn yet");
            }
            if (MoneyOwed > 0)
            {
                return("You must pay your debts before ending your turn!");
            }
            if (Players.Any(t => t.MoneyOwed > 0M))
            {
                return("Waiting on other players to pay");
            }
            if (AuctionsEnabled && AuctionProperty < 0)
            {
                return("You must decide if you want to purchase the property");
            }
            if (AuctionsEnabled && AuctionProperty > 0)
            {
                return("Waiting on auction to finish");
            }

            return(DoEndTurn(player));
        }
Ejemplo n.º 13
0
        public Player JoinGame(string userName)
        {
            switch (Status)
            {
            case GameStatus.Running:
                throw new BadRequestException("Cannot join game that has already started");

            case GameStatus.Finished:
                throw new BadRequestException("Cannot join game that is finished");
            }

            if (Players.Length >= MaxPlayers)
            {
                throw new BadRequestException("Max number of players");
            }

            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new BadRequestException("Username cannot be empty");
            }

            if (Players.Any(pl => userName.Equals(pl.UserName, StringComparison.InvariantCultureIgnoreCase)))
            {
                throw new BadRequestException("User with same name already registered");
            }

            var player = new Player(userName);

            Players = Players.Append(player).ToArray();
            return(player);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Updates the level.
        /// </summary>
        /// <param name="gameTime">Game time.</param>
        public void Update(GameTime gameTime)
        {
            if (!_bgmStarted || LevelCollection.CurrentPlayers.Count() == 1)
            {
                SoundManager.PlayBGM(BGM);
                _bgmStarted = true;
            }

            if (Players.Any(p => p.LevelTransitionPercent != 0))
            {
                return;
            }

            while (_oldEntities.Count > 0)
            {
                _entities.Remove(_oldEntities.Dequeue());
            }

            while (_newEntities.Count > 0)
            {
                _entities.Add(_newEntities.Dequeue());
            }

            foreach (Entity e in _entities)
            {
                e.Update(gameTime, this);
            }
        }
Ejemplo n.º 15
0
        private void GuessQadim1()
        {
            /*
             *  case 20934: //Qadim1
             * "ID": 21285,
             * "NameEN": "Ancient Invoked Hydra",
             * "ID": 21183,
             * "NameEN": "Wyvern Patriarch",
             * "ID": 21073,
             * "NameEN": "Apocalypse Bringer",
             * "ID": 20997,
             * "NameEN": "Wyvern Matriarch",
             */

            /* 1. Tank least damage chrono? toughness
             * 2. Healer least damage healing power
             * 3. kite deadeye or deardeaviel least overall dps
             * ?. bs warrier least dps ??
             * 4. lamp deadeye or deardeaviel or reaper or anyting? least overall dps
             * 5. res is dps
             */

            SetTank();
            if (!Players.Any(p => p.Role == Role.Tank))
            {
                AssigenSupporter();

                var tank = Players.Where(p => p.Role == Role.Empty || p.Role == Role.Utility && p.Class == eProfession.Chronomancer)
                           .OrderBy(p => p.Class == eProfession.Chronomancer ? 0 : 1)
                           .ThenBy(p => p.DPS)
                           .FirstOrDefault();
                if (tank != null)
                {
                    tank.Role = Role.Tank;
                }
            }
            else
            {
                AssigenSupporter();
            }
            var kiter = Players.Where(p => p.Role == Role.Empty && (p.Class == eProfession.Deadeye || p.Class == eProfession.Daredevil))
                        .OrderBy(p => p.DPS)
                        .FirstOrDefault();

            if (kiter != null)
            {
                kiter.Role = Role.Kiter;
            }
            SetBS();
            var lamp = Players.Where(p => p.Role == Role.Empty)
                       .OrderBy(p => (p.Class == eProfession.Deadeye || p.Class == eProfession.Daredevil || p.Class == eProfession.Reaper) ? 0 : 1)
                       .ThenBy(p => p.DPS)
                       .FirstOrDefault();

            if (lamp != null)
            {
                lamp.Role = Role.Special;
            }
            FillUpDps();
        }
Ejemplo n.º 16
0
        private void CheckNextAction()
        {
            // Need to place more penguins ?
            if (PlayersObject.Any(e => e.Penguins < penguinsByPlayer))
            {
                NextAction = NextActionType.PlacePenguin;
                return;
            }

            if (!Players.Any(e => BoardObject.BoardObject.GetMyPenguins(e.Identifier).Count > 0))
            {
                // No more penguins, we can stop the game :
                NextAction = NextActionType.Nothing;
            }
            else
            {
                NextAction = NextActionType.MovePenguin;
                // We check the current player available actions :
                var penguinCells = BoardObject.BoardObject.GetMyPenguins(CurrentPlayer.Identifier);
                if (penguinCells.Count == 0)
                {
                    CheckActions();
                }
            }
        }
        private void ReadPlayer(NetIncomingMessage inc)
        {
            var name = inc.ReadString();

            if (Players.Any(p => p.Username == name))
            {
                var oldPlayer = Players.FirstOrDefault(p => p.Username == name);
                oldPlayer.XPosition         = inc.ReadInt16();
                oldPlayer.YPosition         = inc.ReadInt16();
                oldPlayer.Animation.XRecPos = inc.ReadInt16();
                oldPlayer.Animation.YRecPos = inc.ReadInt16();
                oldPlayer.Animation.Height  = inc.ReadInt16();
                oldPlayer.Animation.Width   = inc.ReadInt16();
                oldPlayer.Health            = inc.ReadSByte();
                oldPlayer.IntersectingLava  = inc.ReadBoolean();
                oldPlayer.Type            = (Player.ClassType)inc.ReadByte();
                oldPlayer.OrbiterRotation = inc.ReadDouble();
            }
            else
            {
                var player = new Player();
                player.Username          = name;
                player.XPosition         = inc.ReadInt16();
                player.YPosition         = inc.ReadInt16();
                player.Animation.XRecPos = inc.ReadInt16();
                player.Animation.YRecPos = inc.ReadInt16();
                player.Animation.Height  = inc.ReadInt16();
                player.Animation.Width   = inc.ReadInt16();
                player.Health            = inc.ReadSByte();
                player.IntersectingLava  = inc.ReadBoolean();
                player.Type            = (Player.ClassType)inc.ReadByte();
                player.OrbiterRotation = inc.ReadFloat();
                Players.Add(player);
            }
        }
Ejemplo n.º 18
0
 private void CheckIsOver()
 {
     if (Players.Any(p => p.Health <= 0))
     {
         IsOver = true;
     }
 }
Ejemplo n.º 19
0
 public void Process()
 {
     if (LastPlayer.AddMinutes(1) < DateTime.Now && Players.Any())
     {
         LastPlayer = DateTime.Now;
     }
 }
Ejemplo n.º 20
0
        private IEnumerator UpdateSetups()
        {
            while (true)
            {
                yield return(null);

                if (Players.Any(x => x == null))
                {
                    Players.Clear();
                    AllPlayerEntities.Clear();
                    PlayerStates.Clear();
                    Players.AddRange(Scene.SceneTracker.allPlayers);
                    for (int i = 0; i < Scene.SceneTracker.allPlayers.Count; i++)
                    {
                        BoltEntity b = Scene.SceneTracker.allPlayers[i].GetComponent <BoltEntity>();
                        if (b != null)
                        {
                            AllPlayerEntities.Add(b);
                            PlayerStates.Add(b.GetState <IPlayerState>());
                        }
                    }
                }

                yield return(new WaitForSeconds(10));
            }
        }
Ejemplo n.º 21
0
            protected override bool RoundHasEnded()
            {
                // if there was a previous round in this game that had exactly the same cards in the same order in the same players' decks,
                // the game instantly ends in a win for player 1.
                var shouldEnd = Players.Any(p => p.HasPlayedCardBefore());

                if (shouldEnd)
                {
                    if (PRINT)
                    {
                        Console.WriteLine("Game ended! Same cards appeared..");
                    }
                    Players.FirstOrDefault().Won = true;
                    return(true);
                }

                var player = Players.FirstOrDefault(p => p.NrOfCards == TotalNumberOfCards);

                if (player != null)
                {
                    player.Won = true;
                    return(true);
                }
                return(false);
            }
Ejemplo n.º 22
0
 public void RemovePlayer(Player player)
 {
     if (Players.Any(it => it.Equals(player)))
     {
         Players.Remove(player);
     }
 }
Ejemplo n.º 23
0
 public bool IsDuplicateCharClassType(IList <IPlayer> players)
 {
     return(Players.Any(p => {
         return players.Any(pl =>
                            { return pl.CharClass.CharClassType.Equals(p.CharClass.CharClassType); });
     }));
 }
Ejemplo n.º 24
0
 private bool CoordinatIsNOTValid(Kordinat kordinater)
 {
     if (!Players.Any(p => p.Kordinater.X == kordinater.X && p.Kordinater.Y == kordinater.Y) && Grid.GetLength(0) > kordinater.X && Grid.GetLength(1) > kordinater.Y && kordinater.X >= 0 && kordinater.Y >= 0)
     {
         return(false);
     }
     return(true);
 }
 private void AssignCurrentPlayer(int index)
 {
     CurrentPlayer = Players[index];
     if (!Players.Any(x => x.State == PlayerState.Winner))
     {
         Players.ForEach(x => x.State = (x == Players[index] ? PlayerState.Active : PlayerState.Inactive));
     }
 }
Ejemplo n.º 26
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;
     }
 }
Ejemplo n.º 27
0
 public void RemovePlayer(Player player)
 {
     Entities.Remove(player);
     if (!Players.Any())
     {
         this.Sector.RemoveLocation(this);
     }
 }
Ejemplo n.º 28
0
        private PlayerTemplate GetPlayerTemplate()
        {
            if (Players.Any(i => i.Template == PlayerTemplate.GreenCat))
            {
                return(PlayerTemplate.PinkCat);
            }

            return(PlayerTemplate.GreenCat);
        }
 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);
 }
Ejemplo n.º 30
0
Archivo: Game.cs Proyecto: emilol/Kitty
        public void AddPlayer(User user)
        {
            if (Players.Any(p => p.User.Id == user.Id))
            {
                throw new DomainException("Cannot add player - player is already in game");
            }

            Players.Add(new Player(Guid.NewGuid(), this, user));
        }