private void CheckGameStatus() { CheckMateLabel.Visible = false; if (_game.IsGameOver() || _game.IsGameDraw()) { TurnTimer.Stop(); ChessBoard.Enabled = false; BoardStateHistory.Enabled = false; Message.Location = new Point(413, 150); if (_game.IsGameDraw()) { Message.Text = drawMessage; } else { Message.Text = _currentPlayerName + winMessage; } } else { _currentPlayerTurn = _currentPlayerTurn == PlayerName.PlayerOne ? PlayerName.PlayerTwo : PlayerName.PlayerOne; _currentPlayerName = _currentPlayerTurn == PlayerName.PlayerOne ? playerOne : playerTwo; if (_game.IsCheck()) { CheckMateLabel.Text = _currentPlayerName + checkMateText; CheckMateLabel.Visible = true; } } }
public void ChangeTurn() { _playerIndex++; if (_playerIndex >= AllPlayers.Length) { _playerIndex = 0; } ActivePlayer.StartTurn(); TurnTimer.Stop(); TurnTimer.Reset(); TurnTimer.StartTimer(); OnTurnChanged(); }
} // Timerları yavaşlatma işlemini gerçekleştiren buton private void turnTimerControl_Click(object sender, EventArgs e) { if (btnPlayStop.AccessibleName == "1") { TurnTimer.Stop(); btnPlayStop.AccessibleName = "2"; btnPlayStop.Image = Properties.Resources.playButton; } else { TurnTimer.Start(); btnPlayStop.AccessibleName = "1"; btnPlayStop.Image = Properties.Resources.pauseButton; } } // Timerları durdurup , başlatma işlemini gerçekleştiren buton
private void TurnTimer_Tick(object sender, EventArgs e) { if (MyTurn == false) { TurnTimer.Stop(); Cursor = Cursors.Default; Random random = new Random(); int choise = random.Next(1, 2); if (choise == 1) { currentCountOfStones = currentCountOfStones * Times; labelCurrentCountOfStones.Text = currentCountOfStones.ToString(); } else { currentCountOfStones += Plus; labelCurrentCountOfStones.Text = currentCountOfStones.ToString(); } if (currentCountOfStones == totalCountOfStones) { GameTimer.Stop(); this.Hide(); LoserForm loseForm = new LoserForm(form, minutes, seconds, form); loseForm.ShowDialog(); this.Close(); } if (currentCountOfStones > totalCountOfStones) { GameTimer.Stop(); this.Hide(); WinnerForm winnerForm = new WinnerForm(form, minutes, seconds, form); winnerForm.ShowDialog(); this.Close(); } labelWhosTurn.Text = "ВАШ ХОД"; labelWhosTurn.ForeColor = Color.LimeGreen; MyTurn = true; } }
public void GameUserLeave(ClaimsPrincipal userLeaving, Action <long> onTurnTimeout, Action <long> onGameFinish) { lock (gameLogicLock) { var user = GameUsers .Where((i) => i.UserPrincipal.GetUserLoginID() == userLeaving.GetUserLoginID()) .FirstOrDefault(); if (GetCurrentPlayerTurn().UserPrincipal.GetUserLoginID() == user.UserPrincipal.GetUserLoginID() && CurrentGamePhase == GamePhase.TurnPhase) { TurnTimer.Stop(); onTurnTimeout(GameLobbyID); } user.State = GameUserState.Disconnected; var rankToCountMappings = new Dictionary <string, int>(); user.Hand.Select((i) => i.Value).ToList().ForEach((value) => { if (rankToCountMappings.ContainsKey(value.Rank)) { rankToCountMappings[value.Rank] = rankToCountMappings[value.Rank] + 1; } else { rankToCountMappings[value.Rank] = 1; } }); var handList = new List <string>(); foreach (var pair in rankToCountMappings) { handList.Add($"×{pair.Value} {pair.Key}"); } ActionHistory.Add($"{user.UserPrincipal.GetUserName()} has left. His cards are out of play: {String.Join(",", handList)}"); if (IsVictory()) { onGameFinish(GameLobbyID); } } }
} // Static değişkenler bu fonksiyonda set ediliyor. private void CreateGame() { pnlBoard.Controls.Clear(); if (MoveTimer.Enabled == true) { MoveTimer.Stop(); } if (TurnTimer.Enabled == true) { TurnTimer.Stop(); } goldList.Clear(); playerList.Clear(); btnPlayStop.AccessibleName = "2"; btnPlayStop.Image = Properties.Resources.playButton; turnMoveTEMP = 1; playerTurn = 1; countLivePlayers = 4; logNum = 0; textPlayerACoin.Text = "200"; textPlayerBCoin.Text = "200"; textPlayerCCoin.Text = "200"; textPlayerDCoin.Text = "200"; int areaTotalSize = areaXSize * areaYSize; // Oyun alanında ki toplam kare sayısı int cellWidth = Convert.ToInt32(Math.Floor(Convert.ToDouble(pnlBoard.Width) / areaXSize)); // Alandaki Bir karenin genişliği int cellHeight = Convert.ToInt32(Math.Floor(Convert.ToDouble(pnlBoard.Height) / areaYSize)); // Alandaki Bir karenin uzunluğu int playerAFirstSpawn = 1; int playerBFirstSpawn = areaXSize; int playerCFirstSpawn = areaTotalSize; int playerDFirstSpawn = areaTotalSize - (areaXSize - 1); GenerateGolds(areaTotalSize, playerAFirstSpawn, playerBFirstSpawn, playerCFirstSpawn, playerDFirstSpawn); GenerateMap(areaTotalSize, cellWidth, cellHeight); GeneratePlayers(cellWidth, cellHeight, playerAFirstSpawn, playerBFirstSpawn, playerCFirstSpawn, playerDFirstSpawn); } // Oyunu oluşturan fonksiyon
} // Sonraki hamleyi gerçekleştiren fonksiyon private void TurnSystem() { if (MoveTimer.Enabled == false) { if (playerTurn > 4) { playerTurn = 1; } turnMoveTEMP = 1; Player player = playerList.Where(p => p.playerdID == playerTurn).SingleOrDefault(); int remainingGold = goldList.Where(p => p.isTaken == false && p.isSecret == false).Count(); int remainingSecretGold = goldList.Where(p => p.isTaken == false).Count(); Player playerC = playerList.Where(p => p.playerdID == 3).Single(); int eliminatedPlayerNumber = playerList.Where(p => p.stat != 5).Count(); if (remainingGold == 0 && playerC.playerGold < findTargetCost[2] || remainingGold == 0 && remainingSecretGold == 0 || eliminatedPlayerNumber == 4) { TurnTimer.Stop(); Player winnerPlayer = playerList.Where(t => t.playerGold == playerList.Select(p => p.playerGold).Max()).FirstOrDefault(); ScoreBoard scr = new ScoreBoard(playerList); scr.ShowDialog(); WriteText(); } else { if (player.target != 0 && player.playerGold > turnCost[playerTurn - 1]) { player.playerGold -= turnCost[playerTurn - 1]; player.spentGold += turnCost[playerTurn - 1]; addLog(player.playerName + " Oyuncusu hamle yapmak için " + turnCost[player.playerdID - 1] + " Altın ödedi"); MoveTimer.Start(); } else if (player.target == 0 && player.playerGold >= findTargetCost[playerTurn - 1] && player.playerGold > turnCost[playerTurn - 1]) { FindNextTarget(player); if (player.target != 0) { addLog(player.playerName + " Oyuncusu hedef olarak " + player.target + ". kareyi belirledi ve bunun için " + turnCost[player.playerdID - 1] + " Altın Harcadı "); addLog(player.playerName + " Oyuncusu hamle yapmak için " + turnCost[player.playerdID - 1] + " Altın ödedi"); player.playerGold -= findTargetCost[playerTurn - 1]; player.playerGold -= turnCost[playerTurn - 1]; player.spentGold += findTargetCost[playerTurn - 1] + turnCost[playerTurn - 1]; MoveTimer.Start(); } else { playerTurn++; } } else { if (player.stat == 5) { player.stat = countLivePlayers; addLog(player.playerName + " Oyuncusunun oynamak için yeterli altını kalmadı ve oyunu " + player.stat + ". olarak tamamladı"); countLivePlayers--; } playerTurn++; } (pictureBox2.Controls["textPlayer" + player.playerName + "Coin"] as Label).Text = player.playerGold.ToString(); } } } // Oyun sırasını belirleyen fonksiyon
private void TurnTimer_Tick(object sender, EventArgs e) { Cursor = Cursors.Default; TurnTimer.Stop(); if (MyTurn == false) { Cursor = Cursors.Default; Random random = new Random(); int choise = random.Next(1, 4); int choiseOfHeap = random.Next(1, 3); if (choise == 1) { if (choiseOfHeap == 1) { currentCountOfStonesInFirstHeap += Plus; labelCurrentCountOfStonesInFirstHeap.Text = currentCountOfStonesInFirstHeap.ToString(); } else if (choiseOfHeap == 2) { currentCountOfStonesInSecondHeap += Plus; labelCurrentCountOfStonesInSecondHeap.Text = currentCountOfStonesInSecondHeap.ToString(); } else if (choiseOfHeap == 3) { currentCountOfStonesInThirdHeap += Plus; labelCurrentCountOfStonesInThirdHeap.Text = currentCountOfStonesInThirdHeap.ToString(); } } else if (choise == 2) { if (choiseOfHeap == 1) { currentCountOfStonesInFirstHeap = Times * currentCountOfStonesInFirstHeap; labelCurrentCountOfStonesInFirstHeap.Text = currentCountOfStonesInFirstHeap.ToString(); } else if (choiseOfHeap == 2) { currentCountOfStonesInSecondHeap = Times * currentCountOfStonesInSecondHeap; labelCurrentCountOfStonesInSecondHeap.Text = currentCountOfStonesInSecondHeap.ToString(); } else if (choiseOfHeap == 3) { currentCountOfStonesInThirdHeap = Times * currentCountOfStonesInThirdHeap; labelCurrentCountOfStonesInThirdHeap.Text = currentCountOfStonesInThirdHeap.ToString(); } } else if (choise == 3) { if (choiseOfHeap == 1) { if (currentCountOfStonesInFirstHeap - Minus > 2) { currentCountOfStonesInFirstHeap = currentCountOfStonesInFirstHeap - Minus; labelCurrentCountOfStonesInFirstHeap.Text = currentCountOfStonesInFirstHeap.ToString(); } else { choise = random.Next(1, 3); ChoiseOfHeapD(choise, choiseOfHeap, ref currentCountOfStonesInFirstHeap, ref currentCountOfStonesInSecondHeap); } } else if (choiseOfHeap == 2) { if (currentCountOfStonesInSecondHeap - Minus > 2) { currentCountOfStonesInSecondHeap = currentCountOfStonesInSecondHeap - Minus; labelCurrentCountOfStonesInSecondHeap.Text = currentCountOfStonesInSecondHeap.ToString(); } else { choise = random.Next(1, 3); ChoiseOfHeapD(choise, choiseOfHeap, ref currentCountOfStonesInFirstHeap, ref currentCountOfStonesInSecondHeap); } } else if (choiseOfHeap == 3) { if (currentCountOfStonesInThirdHeap - Minus > 2) { currentCountOfStonesInThirdHeap = currentCountOfStonesInThirdHeap - Minus; labelCurrentCountOfStonesInThirdHeap.Text = currentCountOfStonesInThirdHeap.ToString(); } else { choise = random.Next(1, 3); ChoiseOfHeapD(choise, choiseOfHeap, ref currentCountOfStonesInFirstHeap, ref currentCountOfStonesInSecondHeap); } } } else if (choise == 4) { if (choiseOfHeap == 1) { if (currentCountOfStonesInFirstHeap / Divide > 2) { currentCountOfStonesInFirstHeap = currentCountOfStonesInFirstHeap / Divide; labelCurrentCountOfStonesInFirstHeap.Text = currentCountOfStonesInFirstHeap.ToString(); } else { choise = random.Next(1, 3); ChoiseOfHeapM(choise, choiseOfHeap, ref currentCountOfStonesInFirstHeap, ref currentCountOfStonesInSecondHeap); } } else if (choiseOfHeap == 2) { if (currentCountOfStonesInSecondHeap / Divide > 2) { currentCountOfStonesInSecondHeap = currentCountOfStonesInSecondHeap / Divide; labelCurrentCountOfStonesInSecondHeap.Text = currentCountOfStonesInSecondHeap.ToString(); } else { choise = random.Next(1, 3); ChoiseOfHeapM(choise, choiseOfHeap, ref currentCountOfStonesInFirstHeap, ref currentCountOfStonesInSecondHeap); } } else if (choiseOfHeap == 3) { if (currentCountOfStonesInThirdHeap / Divide > 2) { currentCountOfStonesInThirdHeap = currentCountOfStonesInThirdHeap / Divide; labelCurrentCountOfStonesInThirdHeap.Text = currentCountOfStonesInThirdHeap.ToString(); } else { choise = random.Next(1, 3); ChoiseOfHeapM(choise, choiseOfHeap, ref currentCountOfStonesInFirstHeap, ref currentCountOfStonesInSecondHeap); } } } } if (currentCountOfStonesInFirstHeap + currentCountOfStonesInSecondHeap + currentCountOfStonesInThirdHeap == totalCountOfStones) { if (isCreated == false) { GameTimer.Stop(); this.Hide(); LoserForm loseForm = new LoserForm(form, minutes, seconds, form); loseForm.ShowDialog(); this.Close(); isCreated = true; } } if (currentCountOfStonesInFirstHeap + currentCountOfStonesInSecondHeap + currentCountOfStonesInThirdHeap > totalCountOfStones) { if (isCreated == false) { GameTimer.Stop(); this.Hide(); WinnerForm winnerForm = new WinnerForm(form, minutes, seconds, form); winnerForm.ShowDialog(); this.Close(); isCreated = true; } } labelWhosTurn.Text = "ВАШ ХОД"; labelWhosTurn.ForeColor = Color.LimeGreen; MyTurn = true; }
private void EndGame() { TurnTimer.Stop(); StateManager.PerformTransition(TransitionType.GameToGameOver); }
public virtual void EndTurn() { turnTimer.Stop(); RoomUserView.Manager.I.RoomUserViews[Turn].SetTurnFill(0); turnId++; }
public void SubmitClaim(ClaimsPrincipal user, List <GameCard> claims, List <GameCard> actual) { lock (gameLogicLock) { if (!IsCurrentTurn(user)) { throw new Exception("Somebody may be cheating"); } if (claims.Count != actual.Count) { throw new Exception("Somebody may be cheating"); } if (TurnTimer != null) { TurnTimer.Stop(); TurnTimer.Dispose(); } var referenceCard = claims[0]; foreach (var card in claims) { if (card.Rank != referenceCard.Rank) { throw new Exception("Somebody may be cheating"); } } if (CurrentClaims.Count > 0) { if (CurrentClaims.Last().ClaimUser.UserPrincipal.GetUserLoginID() == user.GetUserLoginID()) { throw new Exception("Somebody may be cheating"); } } if (CurrentClaims.Count > 0) { var recentClaimIndex = GameCard .Ranks .FindIndex((item) => { return(item == CurrentClaims.Last().Claims[0].Rank); }); var lowerBoundRank = GetLowerBoundRank(recentClaimIndex); var upperBoundRank = GetUpperBoundRank(recentClaimIndex); var middleBoundRank = GetMiddleBoundRank(recentClaimIndex); if ( referenceCard.Rank != lowerBoundRank && referenceCard.Rank != middleBoundRank && referenceCard.Rank != upperBoundRank) { throw new Exception("Somebody may be cheating"); } } var gameUser = GetPlayer(user); CurrentClaims.Add(new GameClaim(claims, actual, gameUser)); foreach (var card in actual) { gameUser.Hand.Remove(card); } ActionHistory.Add($"{user.GetUserName()} has submitted {claims.Count} cards, with claim {referenceCard.Rank}"); } }
public void TurnEnd() { TurnTimer.Stop(); if (this.FightState != FightStateEnum.FIGHT_STARTED) { return; } //queue message List <NetworkMessage> messages = new List <NetworkMessage>(); messages.Add(new GameFightTurnEndMessage((double)this.ActualFighter.Id)); //fin du tour messages.Add(new GameFightTurnReadyRequestMessage((double)this.ActualFighter.Id)); //reset AP/PM if (this.ActualFighter is CharacterFighter) { ((CharacterFighter)this.ActualFighter).ResetFighter(); } var aliveFighters = this.Fighters.OrderBy(x => x.TimelineOrder).ToList().FindAll(x => x.Life > 0); var nextFighter = this.Fighters.Concat(this.Defenders).OrderBy(x => x.TimelineOrder).ToList().Find(x => x.TimelineOrder > this.ActualFighter.TimelineOrder && x.Life > 0); if (aliveFighters.Count == 0) //impossible normalement car endfight plutot mais on ne sais jamais { return; } if (nextFighter == null) { this.ActualFighter = aliveFighters.First(); this.Round += 1; messages.Add(new GameFightNewRoundMessage((uint)this.Round)); } else { this.ActualFighter = nextFighter; } Console.WriteLine("FIN DU TOUR DE JEU"); Console.WriteLine("NOUVEAU TOUR POUR {0} authorId.", this.ActualFighter.Id); int nextTurnSecondes = 320; if (this.ActualFighter is MonsterFighter) { nextTurnSecondes = 150; } messages.Add(new GameFightTurnStartMessage(this.ActualFighter.Id, (uint)nextTurnSecondes)); //nouveau tour this.SendToAllFighters(messages); this.StartTurnTimer(nextTurnSecondes); if (this.ActualFighter is MonsterFighter) { //IA RUSHER EXPERIMENTAL POUR MOMENT var nearestFighter = BrainManager.Instance.AIGetNearestFighter(this, (MonsterFighter)this.ActualFighter); BrainManager.Instance.AIMoveToTarget(this, nearestFighter); BrainManager.Instance.AILaunchSpellToTarget(this, nearestFighter); this.TurnEnd(); } else { this.SynchronizeSequence((CharacterFighter)this.ActualFighter); } }