/// <summary> /// Respond to a penguin click /// </summary> /// <remarks> /// CALLED BY: GamePenguin::OnMouseDown() /// </remarks> /// public void OnPenguinSelected(GamePenguin penguin) { // Unselect any currently selected penguin // UnselectPenguin(); m_currentState.OnPenguinClicked(penguin); }
/// <summary> /// Give player a penguin /// </summary> /// /// <remarks> /// CALLED BY: SpawnNewPenguin() /// </remarks> /// public void AddPenguin(GameManager gm, GameTile placePenguinHere, bool bAI) { GamePenguin newPenguin = gm.CreatePenguin(placePenguinHere, Color, bAI); // Add new penguin to player's penguin list // m_myPenguins.Add(newPenguin); // Tell AIBoard to add the penguin // GameManager.GetGameManager().SendMessage("OnAddPenguinAIBoard", newPenguin); }
/// <summary> /// If player selects a penguin, highlight it, if another one was previously clicked, clear its selection /// </summary> /// <param name="newPenguin"></param> /// void ChangePenguin(GamePenguin newPenguin) { if (m_currentPenguin) { m_currentPenguin.OnSelectOff(); // Unselect currently selected } m_currentPenguin = newPenguin; // New selection // Set Selected flag on new penguin // m_currentPenguin.OnSelect(); }
/* * /// <summary> * /// Player takes all the cumulative fish on multiple tiles! * /// </summary> * /// <param name="allMyFish">Total score from previously evaluated tiles</param> * /// * public void WinAll(int fishScoreValue) * { * AddFish(fishScoreValue); * } * * Old Version * public void WinAll(List<GameTile> allMyFish) * { * foreach(GameTile tile in allMyFish) * { * AddFish(tile.FishScoreValue); * } * } */ /// <summary> /// Do I own input penguin? /// </summary> /// <param name="penguin">Penguin to test</param> /// public virtual bool IsMyPenguin(GamePenguin penguin) { foreach (GamePenguin p in m_myPenguins) { if (p == penguin) { return(true); // Penguin found in list! } } return(false); }
/// <summary> /// After AI selects move and updates the internal board, then animate the move on the Game Board /// </summary> /// <param name="tile">Destination tile</param> /// <remarks>FLOW: AIBrain::MakeMove_***() -> OnExeAIMove() -> ExecuteAIMove() /// </remarks> /// public void ExecuteAIMove(Command.GameMove move) { ExecuteMove_Internal(move); // Simulate a penguin click from AI move // GamePenguin penguin = m_refTileMgr.tileTable[move.fromTile].CurrentPenguin; // Simulate a destination tile click from AI move // GameTile tile = m_refTileMgr.tileTable[move.toTile]; // Execute move onscreen // ExecuteMove_GameWorld(penguin, tile); }
/// <summary> /// Let AI place its penguin on an optimal tile /// </summary> /// public void PlacePenguinAI(Player current) { const float MinDist = 3.0f; m_refAIBoard.UpdateHeuristicMap(); List <VTile> allTiles = new List <VTile>(m_refAIBoard.tileTable.Values); AIBoardSim.SortVTiles(allTiles); int length = allTiles.Count; VTile vtile = null; GameTile tile = null; GamePenguin lastPen = current.lastAddedPenguin; // Scan highest scored tiles for first available one-fish tile // for (int index = 0; index < length; index++) { vtile = allTiles[index]; tile = m_refTileMgr.tileTable[vtile.tileID]; if (lastPen != null) { // Try not to place AI's penguins too close together, or it will be too easy for the // other players to "gang up" on them. // if (TileManager.Distance(tile, lastPen.CurrentTile) < MinDist) { continue; } } if (tile.numFish == 1 && !tile.IsPenguinHere) { break; // Appropriate tile found -- Loop ends } } // Place penguin on that tile // current.AddPenguin(this, tile, true); }
/// <summary> /// Delete the penguin, from player list and from scene /// </summary> /// <param name="penguin">Penguin to delete</param> /// <param name="partprefan">Particle system to mark penguin's disappearence</param> /// <remarks> /// CALLED BY: RemovePenguin(), RemoveUnmovablePenguin() /// </remarks> /// public void ExpungePenguin(GamePenguin penguin, ParticleSystem partPrefab) { CurrentPlayer.RemovePenguin(penguin); // Remove penguin from player's list // Start "disappear" effect // Instantiate(partPrefab, penguin.transform.position, Quaternion.identity); // Eliminate penguin // Destroy(penguin.gameObject); if (CurrentPlayer.NumPenguins == 0) { Resign(); // If player has no penguins left, remove from game play } }
/// <summary> /// Let AI place its penguin on a random (but still one-fish) tile /// </summary> /// public void PlacePenguinAIRnd(Player current) { const float MinDist = 3.0f; Dictionary <string, GameTile> .ValueCollection allTiles = m_refTileMgr.tileTable.Values; int length = allTiles.Count; GameTile [] arrTiles = new GameTile[length]; allTiles.CopyTo(arrTiles, 0); GameTile tile = null, tempTile; GamePenguin lastPen = current.lastAddedPenguin; do // Find a random available one-fish tile with highest heuristic value { int index = Random.Range(0, length); tempTile = arrTiles[index]; if (lastPen != null) { // Don't place AI's penguins too close together, or it will be too easy for the // other players to "gang up" on them. // if (TileManager.Distance(tempTile, lastPen.CurrentTile) < MinDist) { continue; } } if (tempTile.numFish == 1 && !tempTile.IsPenguinHere) { // tile = arrTiles[index]; } } while (tile == null); // Place penguin on that tile (TODO: Special prefab for AI) // current.AddPenguin(this, tile, true); }
/// <summary> /// Apply a move to the penguins and board in Game World /// </summary> /// <param name="penguin">Penguin to move</param> /// <param name="tile">Destination tile</param> /// <remarks> /// CALLED BY: ExecuteHumanMove(), ExecuteAIMove() /// </remarks> /// void ExecuteMove_GameWorld(GamePenguin penguin, GameTile tile) { GameTile startTile = penguin.CurrentTile; if (penguin.MoveTo(tile)) // If a legal move was selected, start animating the penguin's move { // Player acquires this tile's fish // CurrentPlayer.AddFish(startTile.FishScoreValue); // Set flag for tile just departed to sink (not until penguin has left it, else it will look like // it's "walking on water"! // m_condemnedTile = startTile; // Go to "MovePending" state until all animations complete // StartAnimateMove(); } }
/// <summary> /// Respond to player clicking on a penguin they want to move /// </summary> /// <param name="penguin"></param> /// public override void OnPenguinClicked(GamePenguin penguin) { // If a penguin is already selected, unselect it // if (s_refGM.CurrentPenguin) { s_refGM.ClearPenguinCurrent(); } // Evaluate clicked penguin // if (s_refGM.CurrentPlayer.IsMyPenguin(penguin)) { // Compute valid moves // s_refGM.FindLegalMoves(penguin); // If there are no valid moves, remove penguin // if (penguin.ValidMoveList.Count == 0) { s_refGM.RemoveUnmovablePenguin(penguin); } else // Make clicked penguin the current penguin { s_refGM.MakePenguinCurrent(penguin); // Check if penguin is alone on an "island" of tiles and remove it if it is // bool bPenguinRemoved = s_refGM.TryRemovePenguin(); if (!bPenguinRemoved) { penguin.OnSelect(); // If penguin not removed, visually highlight it and wait for player to move } } } }
public override void OnPenguinClicked(GameManager gm, GamePenguin penguin) { // If a penguin is already selected, unselect it // if (gm.CurrentPenguin) { gm.UnselectPenguin(); } // Evaluate clicked penguin // if (gm.CurrentPlayer.IsMyPenguin(penguin)) { // Compute valid moves // gm.FindLegalMoves(penguin); // If there are no valid moves, remove penguin // if (penguin.ValidMoveList.Count == 0) { gm.CurrentPlayer.AddFish(penguin.CurrentTile.FishScoreValue); // Take fish on this tile penguin.CurrentTile.Sink(); // Remove tile // gm.OnExpungePenguin() // Remove Penguin // gm.NextPlayer(); // Go to next player } else // Make clicked penguin the current penguin { gm.CurrentPenguin = penguin; gm.CurrentTile = penguin.CurrentTile; penguin.OnSelect(); } } }
/// <summary> /// Find penguin's current legal moves and put them in a list /// </summary> /// <param name="penguin">Current penguin</param> /// public void FindLegalMoves(GamePenguin penguin) { m_refTileMgr.FindValidTiles(penguin.CurrentTile, penguin.ValidMoveList); }
/// <summary> /// Set the current penguin -- Necessary before calling GamePenguin::MoveTo() /// </summary> /// <param name="penguin"></param> /// <remarks> /// This is called either when the player clicks on a penguin (State_Move_Human::OnPenguinClicked()), /// or when the AI has found a move and is ready to move the GamePenguin on the board. /// </remarks> /// public void MakePenguinCurrent(GamePenguin penguin) { CurrentPenguin = penguin; CurrentTile = penguin.CurrentTile; }
/// <summary> /// Start AI finding a move /// </summary> /// <remarks> /// FLOW: Game_State_Play::OnAI() -> AIBrain::OnLaunchAIThread() /// Or: Game_State_Init::OnAI() -> GameMgr::PlacePenguinAIRnd() /// </remarks> /* * public override IEnumerator WaitTurn() * { * m_refGM.CurrentState.OnAI(m_refGM, this); // Launch AI making a move * * yield return base.WaitTurn(); * } */ // Disallow user clicking on computer AI's penguins // public override bool IsMyPenguin(GamePenguin penguin) { return(false); }
/// <summary> /// Determine if a penguin is alone on an "island" with no other penguins /// </summary> /// <param name="tm">Ref to TileManager</param> /// <param name="penguin">Penguin to evaluate</param> /// <returns>TRUE if no other penguins</returns> /// public static bool IsAlone(GamePenguin penguin, TileManager tm) { return(TileManager.CheckForIsland(tm, penguin.CurrentTile, tm.workTiles, true) >= 0); }
// When user clicks on a penguin // public virtual void OnPenguinClicked(GamePenguin penguin) { // Disable click }
public override void OnPenguinClicked(GameManager gm, GamePenguin penguin) { }
// When user clicks on a penguin // public abstract void OnPenguinClicked(GameManager gm, GamePenguin penguin);
GamePenguin m_thisPenguin; // The penguin affected by this controller // Create a link to the penguin // override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { m_thisPenguin = animator.GetComponent <GamePenguin>(); }
// When the "R" (Remove penguin) key is pressed // public virtual void OnPenguinRemove(GamePenguin penguin) { // Disable key }
/// <summary> /// Place/Remove penguin from this tile /// </summary> /// <param name="penguin"></param> /// public void PlacePenguin(GamePenguin penguin) { CurrentPenguin = penguin; // Needed to apply an AI move to Game World IsPenguinHere = true; // Needed for path traversal }