public override void _Process(float delta) { if (gamePaused) { return; } if (currentGameTurnState != GameTurnState.ANIMATING_PLAYER && onCooldown && coolDownTimer > 0) { coolDownTimer -= delta; if (coolDownTimer <= 0) { onCooldown = false; } } if (currentGameTurnState == GameTurnState.TICKING_ENTITIES) { ProcessTickingEntities(delta); if (tickingEntities.Count == 0) { GD.Print($"{TAG} - Player's Turn Has Started"); currentGameTurnState = GameTurnState.WAITING_ON_PLAYER; } } }
public void GameOverState() { DisablePieces(); DisableTiles(); if (!model.isGameTied) { Debug.Log((IsPlayerTurn ? "Player" : "Opponent") + " Has Won"); if (IsPlayerTurn) { CurrentTurn = GameTurnState.PLAYERWON; } else { CurrentTurn = GameTurnState.OPPONENTWON; } } else { Debug.Log("GAME HAS TIED"); CurrentTurn = GameTurnState.GAMETIED; } GameOver?.Invoke(); }
void ResetGame() { model.NewGame(); DisableTiles(); DisablePieces(); CurrentTurn = GameTurnState.NONE; OnDeckPiece = NOSELECTION; LastTileClicked = NOSELECTION; }
private void HandleOnPlayerActionCompleted() { GD.Print($"{TAG} - Player Action Completed"); if (currentTimingState == GameTimingState.TURN_BASED) { currentGameTurnState = GameTurnState.TICKING_ENTITIES; InitializeTickingEntities(); } }
public void SelectTile(string tileName) { Debug.Log("Attempting to make move - " + OnDeckPiece + " to " + tileName); DisableTiles(); EnablePieces(); model.Move(tileName, OnDeckPiece); LastTileClicked = tileName; OnDeckPiece = NOSELECTION; CurrentTurn = GameTurnState.PLAYERCHOOSEPIECE; }
public void SwapTurn() { if (IsGameOver) { return; } CurrentTurn = (IsPlayerTurn ? GameTurnState.OPPONENT : GameTurnState.PLAYER); Debug.Log((IsPlayerTurn ? "Player" : "Opponent") + "'s Turn"); }
private void NextPlayerTurn() { currentPlayer += 1; if (currentPlayer == roomCapacity) { currentPlayer = 0; } turnState = GameTurnState.PlayCard; TurnStarted(currentPlayer); }
private void HandleOnPlayerActionStarted() { GD.Print($"{TAG} - Player Action Started"); if (currentTimingState == GameTimingState.TURN_BASED) { currentGameTurnState = GameTurnState.ANIMATING_PLAYER; coolDownTimer = playerTurnCooldown; onCooldown = true; } }
/// <summary> /// 结束指定玩家的回合 /// </summary> /// <param name="playerIndex">指定玩家下标</param> /// <returns>结束回合是否成功</returns> /// <remarks>回合是自动开始的</remarks> public bool EndMyTurn(int playerIndex) { if (currentPlayer != playerIndex || turnState != GameTurnState.PlayCard) { return(false); } turnState = GameTurnState.End; TurnEnded(playerIndex); NextPlayerTurn(); return(true); }
IEnumerator PlayerTurn() { Debug.Log("Enabling tiles for player and waiting for input"); EnableTiles(); DisablePieces(); CurrentTurn = GameTurnState.PLAYERCHOOSETILE; while (!IsPlayerDone) { yield return(null); } Opponent.SendMove(); }
IEnumerator PlayerFirstTurn() { Debug.Log("Player picking first piece"); EnablePieces(); DisableTiles(); CurrentTurn = GameTurnState.PLAYERCHOOSEPIECE; while (!IsPlayerDone) { yield return(null); } Opponent.SendFirstMove(); }
/// <summary> /// If previous player is player1, then change the state to Player2Turn, vice versa. /// </summary> /// <param name="previousPlayer"></param> private void ToggleGameState(Player previousPlayer) { if (!PlayerChecker.GetVictoryPlayer()) { switch (previousPlayer.playerIndex) { case 1: gameTurnState = GameTurnState.Player2Turn; break; case 2: gameTurnState = GameTurnState.Player3Turn; break; case 3: gameTurnState = GameTurnState.Player4Turn; break; case 4: gameTurnState = GameTurnState.Player1Turn; break; } } else // There is a player winning { gameState = GameState.GameOver; if (PlayerChecker.IsPlayerWin(players[0])) { print("Player 1 won"); } if (PlayerChecker.IsPlayerWin(players[1])) { print("Player 2 won"); } if (PlayerChecker.IsPlayerWin(players[2])) { print("Player 3 won"); } if (PlayerChecker.IsPlayerWin(players[3])) { print("Player 4 won"); } } }
private IEnumerator PickFirstTurn() { if (Opponent.IsMaster) { // Wait for Opponent to communicate the first turn Debug.Log("Opponent is picking first turn"); while (CurrentTurn == GameTurnState.NONE) { yield return(null); } } else { Debug.Log("Picking first turn"); System.Random rand = new System.Random(); CurrentTurn = rand.Next(0, 2) == 1 ? GameTurnState.PLAYER : GameTurnState.OPPONENT; Debug.Log((IsPlayerTurn ? "Player" : "Opponent") + "'s Turn"); Opponent.SendFirstTurn((IsPlayerTurn ? GameTurnState.OPPONENT : GameTurnState.PLAYER)); } }
/// <summary> /// 结束当前玩家的回合 /// </summary> public void EndCurrentPlayerTurn() { turnState = GameTurnState.End; TurnEnded(currentPlayer); NextPlayerTurn(); }
/// <summary> /// 强制跳到指定玩家的回合 /// </summary> /// <param name="playerIndex"></param> public void SwitchPlayer(int playerIndex) { currentPlayer = playerIndex; turnState = GameTurnState.PlayCard; TurnStarted(currentPlayer); }
public void Forfeit() { Opponent.SendForfeit(); CurrentTurn = GameTurnState.PLAYERFORFEIT; }
public void SelectPiece(string pieceName) { Debug.Log("Piece selected - " + pieceName); OnDeckPiece = pieceName; CurrentTurn = GameTurnState.PLAYERDONE; }
/// <summary> /// 重置至游戏开始状态 /// </summary> public void Reset() { currentPlayer = 0; turnState = GameTurnState.End; //只有这个状态才能开始回合 TurnPhase = GameTurnPhase.GrabLandlord; }
public IEnumerator PlayGame(bool playerGoesFirst) { CurrentTurn = (playerGoesFirst) ? GameTurnState.PLAYER : GameTurnState.OPPONENT; return(PlayGame()); }
/// <summary> /// This is used in the beginning of the GameManager to load game information to put players in place /// If there is no game progress, meaning that the player hasn't started the game, then load all the player to the first tile /// </summary> /// <returns></returns> private bool LoadGameProgress() { MainGameData mainGameData = SaveSystem.LoadMainGameData(); if (mainGameData == null) { Debug.LogError("There is no main game data"); // Player hasn't save anything yet return(false); } gameMode = (GameMode)(mainGameData.playerNum - 1); players = new Player[4]; for (int i = 0; i < players.Length; i++) { GameObject player = Instantiate(ResourceManager.Instance.players[i], gameBoard.wayPoints[mainGameData.playersPositionsIndexes[i]].position, Quaternion.identity); players[i] = player.GetComponent <Player>(); players[i].PositionIndex = mainGameData.playersPositionsIndexes[i]; } switch (mainGameData.playerTurnIndex) { case 0: gameTurnState = GameTurnState.Player1Turn; break; case 1: gameTurnState = GameTurnState.Player2Turn; break; case 2: gameTurnState = GameTurnState.Player3Turn; break; case 3: gameTurnState = GameTurnState.Player4Turn; break; } for (int i = 0; i < players.Length; i++) { players[i].playerIndex = i + 1; } foreach (var player in players) { player.onPlayerMovementFinished += ToggleGameState; player.onPlayerMovementFinished += AiBeginMoving; } MiniGameData miniGameData = SaveSystem.LoadMiniGameData(); if (miniGameData != null) // If the player comes back from the mini game { switch (miniGameData.playerIndex) { case 1: gameTurnState = GameTurnState.Player1Turn; break; case 2: gameTurnState = GameTurnState.Player2Turn; break; case 3: gameTurnState = GameTurnState.Player3Turn; break; case 4: gameTurnState = GameTurnState.Player4Turn; break; } if (miniGameData.state == 1) // Success { GetPlayerInTurn().MoveTiles(miniGameData.tileNum); } else if (miniGameData.state == 2) // Failure { GetPlayerInTurn().MoveTiles(-miniGameData.tileNum); } } else { Debug.LogWarning("There is no mini game data yet (Ignore it if this shows in the beginning of the game)"); } return(true); }