private List <string> ValidateGender() { List <string> errorMessages = new List <string>(); if (Gender.Name == "Female") { if (Players.Count(p => p.Gender != "F") > 0) { errorMessages.Add("Your team is registered as a Female team and you have a player who is not Female."); } } if (Gender.Name == "Male") { if (Players.Count(p => p.Gender != "M") > 0) { errorMessages.Add("Your team is registered as a Male team and you have a player who is not Male."); } } if (Gender.Name == "Co-Ed") { if (Players.Count(p => p.Gender == "M") == 0 || Players.Count(p => p.Gender == "F") == 0) { errorMessages.Add("Your team is registered as a Co-Ed team and you either don't have a Male or Female on the roster."); } } return(errorMessages); }
public void RemovePlayer(User Player) { User inUser = Players.Find(o => o.UserName == Player.UserName); Players.Remove(inUser); PlayersNum = Players.Count(); }
public void NextTurn() { _currentPlayer++; _currentPlayer %= Players.Count(); Dice.Roll(); }
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); } }
public GameDbContext(DbContextOptions <GameDbContext> options, IConfiguration config) : base(options) { //Database.EnsureDeleted(); Database.EnsureCreated(); //Database.Migrate(); if (Players.Count() == 0) { try { var hash = new Guid().ToString(); Players.Add(new Player() { UserName = "******", Name = "Armando Lozada", Email = "*****@*****.**", Identity = new PlayerIdentity() { Hash = hash, Password = Encryption.EncryptPassword("123", hash) } }); this.SaveChanges(); } catch (Exception ex) { } } }
private void CheckStatuses() { if (Players.Count(x => x.Checked) == Players.Count) { EndPhase(); } }
private bool EvalRoundEnd() { var maxBid = Players.Max(player => player.Bid); var playersRoundOverCount = Players.Count(player => player.IsRoundOver(maxBid)); if (playersRoundOverCount == Players.Count) { return(true); } if (playersRoundOverCount == Players.Count - 1) { var lastPlayer = Players.Single(player => !player.IsRoundOver(maxBid)); if (lastPlayer.State == PlayerState.None && lastPlayer.Bid == maxBid && Players.Count(player => player.IsOut()) == Players.Count - 1) { return(true); } if (Players.Count(player => player.State == PlayerState.Fold || (player.State == PlayerState.AllIn && player.Bid == 0)) == Players.Count - 1) { return(true); } } return(false); }
private void CheckNumberOfPlayers() { var playerCount = (from e in Players where e.IsHumanPlayer select e).Count(); switch (CurrentGameType) { case GameType.NORMAL: case GameType.VS_CPU: //Anything is allowed here. break; case GameType.COOPERATIVE: if (playerCount < 2) { RequestReturnToMainMenu(); } break; case GameType.TEAM: var blueCount = Players.Count(e => e.Team == 1 && e.Playing); var redCount = Players.Count(e => e.Team == 2 && e.Playing); if (blueCount == 0 || redCount == 0) { RequestReturnToMainMenu(); } break; } }
/// <summary> /// Place penguin for non human player /// </summary> public void PlacePenguin() { if (CurrentPlayer.PlayerType == PlayerType.AIEasy) { AI_easy.PlacePenguins((BoardClass)Board, (PlayerClass)CurrentPlayer); } else if (CurrentPlayer.PlayerType == PlayerType.AIMedium) { AI_medium.PlacePenguin(Board, CurrentPlayer, AIPenguins); NextAction = NextActionType.PlacePenguin; if (Turn == Players.Count() * PenguinsByPlayer) { NextAction = NextActionType.MovePenguin; } } NextAction = NextActionType.PlacePenguin; if (Turn == Players.Count() * PenguinsByPlayer) { NextAction = NextActionType.MovePenguin; } Turn++; NextPlayer(); StateChanged.Invoke(this, null); }
public void CheckForGameOver() { if (Players.Count() <= 1) { State = GameState.GameEnded; } }
private void CheckStatuses() { if (Players.Count(x => x.Checked) == Players.Count && Players.Count > 1) { End(); } }
public DomainResult BuyPlayer(string playerTypeId) { var playerBuyConfig = AllowedPlayers.FirstOrDefault(ap => ap.PlayerTypeId.Equals(playerTypeId)); if (playerBuyConfig == null) { return(DomainResult.Error(new CanNotUsePlayerInThisRaceError(playerTypeId))); } var amountOfPlayerTypeToBuy = Players.Count(p => p.PlayerTypeId.Equals(playerTypeId)); if (amountOfPlayerTypeToBuy >= playerBuyConfig.MaximumPlayers) { return(DomainResult.Error(new TeamFullError(playerBuyConfig.MaximumPlayers))); } if (playerBuyConfig.Cost.MoreThan(TeamMoney)) { return(DomainResult.Error(new FewMoneyInTeamChestError(playerBuyConfig.Cost.Value, TeamMoney.Value))); } var newTeamMoney = TeamMoney.Minus(playerBuyConfig.Cost); var orderedPositions = Players.Select(p => p.PlayerPositionNumber).OrderBy(p => p).ToList(); var travers = FindFirstFreeNumber(orderedPositions, 1); var playerBought = _teamState.BoughtEvent(TeamId, playerTypeId, travers, Guid.NewGuid(), newTeamMoney); Apply(new List <IDomainEvent> { playerBought }); return(DomainResult.Ok(playerBought)); }
public async System.Threading.Tasks.Task OnTick() { if (Players.Count() == 0) { m_variables.Clear(); } }
private async Task DoEncountersAsync() { var locations = Players.GroupBy(x => x.Location); List <IEncounter> encounters = new List <IEncounter>(); foreach (var location in locations) { encounters.AddRange(GetLocationEncounters(location.ToList())); } foreach (var encounter in encounters) { encounter.Prompt(); } await Task.Delay(RoundDelay); foreach (var encounter in encounters) { encounter.RunEncounter(); } PlayersThisRound = Players.Count(x => !x.IsDead) + 1; foreach (var encounter in encounters) { foreach (var player in encounter.GetDeadPlayers()) { RemovePlayer(player); } } }
public Player SelectRandonPlayer() { var rnd = new Random(); var index = rnd.Next(Players.Count()); return(Players[index]); }
public void EndTurn() { //if (CurrentPlayer.Hand.Count == 0) //{ // //end the game //} PreviousPlayer = CurrentPlayer; if (Direction == Direction.clockwise) { nextPlayerTurn = (nextPlayerTurn + 1) % Players.Count(); } else { nextPlayerTurn = (nextPlayerTurn - 1 + Players.Count) % Players.Count(); } CurrentPlayer = Players[nextPlayerTurn]; CurrentPlayer.AlreadyPickedCards = false; // If player has one card at beginning of turn, he is safe from Uno //CurrentPlayer.UnoSaid = (CurrentPlayer.Hand.Count == 1); foreach (Player p in Players) { if (p != PreviousPlayer) { p.IGameCallback.TurnChanged(CurrentPlayer.UserName); } } }
public void NewTurn() { CurrentPlayer = Players[(CurrentPlayer_id + 1) % Players.Count()]; SetActivePlayer(); // Player to select Origin region CurrentMode = new SelectOrigin(this); }
public void PlayAttackRound() { DoActionForAllPlayersInOrder((player) => { //TODO !!!: Might be able to reduce the condition in `if' if (Players.Count(p => p.Health > 0) > 1) { var availablePlayerOptions = new List <BasicActions>() { BasicActions.StrengthAttack, BasicActions.PerceptionAttack, BasicActions.Heal, BasicActions.RollForCard, BasicActions.DoNothing }; var action = player.PerformAction(GameplayEvent.AttackPhase, availablePlayerOptions, this); PerformAttackPhaseAction(action, player); } }); RemoveDeadPlayers(); State = GameState.InProgress; }
public override void AddPlayer(Player newPlayer, bool spawn) { base.AddPlayer(newPlayer, spawn); Player removed; TempPlayers.TryRemove(newPlayer, out removed); Game.PlayerCount++; newPlayer.ClearPopups(); Task.Run(delegate { try { } catch (Exception exeption) { Log.Error("Playerexeption add: " + exeption.Message); Log.Info("Playerexeption add: " + exeption.Message); } }); foreach (Player pl in GetSpawnedPlayers()) { BroadcastTip(pl, newPlayer.Username + " §3joined §e(" + (Players.Count()) + "/" + Slots + ")"); } Game.Core.BossBar.SendName(newPlayer, Game.Prefix); Game.Core.BossBar.SendBossEventBar(newPlayer, 0); Game.onGameJoin(newPlayer, this); }
public override void GotMessage(Player player, Message m) { switch (m.Type) { case "PlayerJoined": Broadcast("PlayerJoined", Players.Count()); break; case "SetUnitDestination": foreach (Player pl in Players) { if (pl.ConnectUserId != player.ConnectUserId) { pl.Send("SetUnitDestination", m.GetInt(0), m.GetFloat(1), m.GetFloat(2), m.GetFloat(3)); } } break; case "SetUnitTarget": foreach (Player pl in Players) { if (pl.ConnectUserId != player.ConnectUserId) { pl.Send("SetUnitTarget", m.GetInt(0), m.GetInt(1)); } } break; case "SpawnUnit": foreach (Player pl in Players) { if (pl.ConnectUserId != player.ConnectUserId) { pl.Send("SpawnUnit", m.GetInt(0), m.GetFloat(1), m.GetFloat(2), m.GetFloat(3), m.GetInt(4)); } } break; case "DestroyUnit": foreach (Player pl in Players) { if (pl.ConnectUserId != player.ConnectUserId) { pl.Send("DestroyUnit", m.GetInt(0)); } } break; case "UpdateHealth": foreach (Player pl in Players) { if (pl.ConnectUserId != player.ConnectUserId) { pl.Send("UpdateHealth", m.GetInt(0), m.GetInt(1)); } } break; } }
protected override bool TryToResolve(User user) { if (readyMarks.Count() == Players.Count() && readyMarks.Values.All(m => true)) { return(base.TryToResolve(user)); } return(false); }
public override void PlayerDeathAction(BasePlayer sender, EventArgs args) { // We check if the round is finished if (Players.Count(p => p.IsAlive) == GameConfiguration.AlivePlayerRemaining) GameEventManager.OnRoundEnd(); base.PlayerDeathAction(sender, args); }
void RandomTurnTaking() { var random = new Random(); int index = random.Next(Players.Count()); var first = Players.ElementAt(index); FirstAtNextTurn(first); }
public void Inc() { currentPlayer++; if (currentPlayer == players.Count()) { currentPlayer = 0; } }
/// <summary> /// Updates the ObjectManager, obtaining all player entities from the game and adding them to the Players list. /// </summary> /// <exception cref="System.InvalidOperationException"> /// Can not update the ObjectManager when it's not properly initialized! /// Are you sure BaseAddress is valid? /// </exception> public void Update() { if (!IsValid) { throw new InvalidOperationException( "Can not update the ObjectManager when it's not properly initialized! Are you sure BaseAddress is valid?"); } var timeStamp = MonotonicTimer.GetTimeStamp(); // Throttle the updates a little - entities won't be changing that frequently. // Realistically we don't need to call this very often at all, as we only keep references to the actual // entities in the game, and only resolve their members when they're actually required. if (timeStamp - _lastUpdate < TimeSpan.FromMilliseconds(1000.0 / _ticksPerSecond)) { return; } _lastUpdate = timeStamp; if (!Orion.Client.InGame) { // No point in updating if we're not in game - we'd end up reading garbage. // Do set the last update time though, we especially don't want to tick too often in menu. return; } // Prevent duplicate entries - more efficient would be maintaining a dictionary and updating entities. // Then again, this is significantly less code, and performance wise not too big an impact. Leave it be for now, // but consider updating this in the future. _players.Clear(); IntPtr localPlayerPtr = Orion.Memory.Read <IntPtr>(Orion.ClientBase + (int)BaseOffsets.LocalPlayer); LocalPlayer = new LocalPlayer(localPlayerPtr); var dwAddress = BaseAddress; EntityEntry entry; while ((int)dwAddress != 0) { entry = Orion.Memory.Read <EntityEntry>(dwAddress); dwAddress = entry.m_pNext; if (entry.m_pNext == entry.m_pPrevious) { break; } if ((int)entry.m_pEntity == 0) { continue; } _players.Add(new BaseEntity(entry.m_pEntity)); } Trace.WriteLine($"[EntityManager] Update complete. {Players.Count(s => s.IsValid)} valid entries found."); _lastUpdate = timeStamp; }
/// <summary> /// Generate match records for the next round /// </summary> /// <exception cref="InvalidOperationException">Error while generating match records</exception> public async Task GenerateMatchesForNextRound() { await using var transaction = await Database.BeginTransactionAsync(); try { if (Matches.Any(m => m.Winner == null)) { throw new InvalidOperationException("Match in DB has no winner"); } if (Players.Count() != 32) { throw new InvalidOperationException("Not 32 players in DB"); } int nextRound; switch (Matches.Count()) { case 0: nextRound = 1; break; case 16: nextRound = 2; break; case 24: nextRound = 3; break; case 28: nextRound = 4; break; case 30: nextRound = 5; break; default: throw new InvalidOperationException("Invalid amount of matches in DB"); } var availablePlayers = nextRound == 1 ? await Players.ToListAsync() : await Matches.Where(m => m.Winner != null && m.Round == nextRound - 1).Select(m => m.Winner).ToListAsync(); Random random = new Random(); int matches = availablePlayers.Count / 2; for (int i = 0; i < matches; i++) { Player player1 = Players.ToList()[random.Next(0, availablePlayers.Count)]; availablePlayers.Remove(player1); Player player2 = Players.ToList()[random.Next(0, availablePlayers.Count)]; availablePlayers.Remove(player2); await AddMatch(player1.ID, player2.ID, nextRound); } await SaveChangesAsync(); await transaction.CommitAsync(); } catch (SqlException ex) { await transaction.RollbackAsync(); } }
public int GetNextFinishPosition() { if (Players == null || Players.Count == 0) { throw new ArgumentException("No Players created"); } return(Players.Count(p => p.Value.Position > 0) + 1); }
public override void GotMessage(Player player, Message m) { switch (m.Type) { case "PlayerJoined": Broadcast("PlayerJoined", Players.Count()); break; } }
public bool RegisterPlayer(string name, out IPlayer player) { player = PlayerFactory.GetPlayer(name); if (Players.Count() < MaxPlayerCount) { Players.Add(player); return(true); } return(false); }
/// <summary> /// 查找每轮第一个下注的玩家 /// </summary> /// <param name="index"></param> /// <returns></returns> private int GetFirstIndex(int index) { if (this.Players[index].Status != GamePlayerStatus.Fold) { return(index); } index++; index = index % Players.Count(); return(GetFirstIndex(index)); }