/// <summary> /// Automatically moves a checker from and to the specified points. /// </summary> /// <param name="startPoint"></param> /// <param name="endPoint"></param> private MoveResult MoveChecker(Point startPoint, Point endPoint) { BGMove move = MoveOptions.GetMove(startPoint.ID, endPoint.ID); if (move != null && DiceRoll.Use(move)) { if (move.IsHit) { JailChecker(endPoint.PickUp()); } endPoint.GetCheckerFrom(startPoint); m_MovesMade.Push(move); MoveOptions = new BGMoveOptions(CurrentPlayer.ID, Board.GetBoardMap(), DiceRoll); EventHelper.Raise(this, MoveOptionsUpdated); EventHelper.Raise(this, CheckerMoved); if (CheckForWin(CurrentPlayer)) { return(CurrentPlayer.ID == BGPlayerID.Player1 ? MoveResult.Player1Win : MoveResult.Player2Win); } else { return(MoveResult.Success); } } else { return(MoveResult.Invalid); } }
/// <summary> /// Fills the Backgammon board with place checker indicators. /// </summary> protected override void Fill() { if (BackgammonGame.Instance.SelectedChecker != null) { Point point = BackgammonGame.Instance.SelectedChecker.Point; for (int diceRoll = 1; diceRoll <= 6; diceRoll++) { BGMove move = BackgammonGame.Instance.MoveOptions.GetMoveFrom(point.ID, diceRoll); if (move != null) { Vector3 position = BackgammonGame.Instance.Board.GetPoint(move.EndPointID).transform.position; position.y += 0.075f; GameObject indicatorObject = Add(); indicatorObject.transform.position = position; SimpleDie simpleDie = indicatorObject.GetComponentInChildren <SimpleDie>(); if (simpleDie != null) { simpleDie.Number = move.DiceRoll; } } } } }
/// <summary> /// Applies the specified move to the board map. /// Returns whether the move has been applied successfully, resulting in the board map being changed. /// </summary> /// <param name="move"></param> /// <returns></returns> public bool Use(BGMove move) { BGPoint startPoint = GetPoint(move.StartPointID); BGPoint endPoint = GetPoint(move.EndPointID); // Return immediately if the move is invalid. if (startPoint.Count == 0) { return(false); } // Case 1: The endpoint does not have any checkers. // Case 2: The endpoint is occupied by the same player occupying the start point. if (endPoint.Player == BGPlayerID.None || startPoint.Player == endPoint.Player) { startPoint.Count--; endPoint.Count++; endPoint.Player = startPoint.Player; if (startPoint.Count == 0) { startPoint.Player = BGPlayerID.None; } return(true); } // Case 3: The endpoint is occupied by the opponent of the player occupying the start point and is vulnerable. else if (endPoint.Player != startPoint.Player && endPoint.Count == 1) { GetJail(endPoint.Player).Count++; startPoint.Count--; endPoint.Player = startPoint.Player; if (startPoint.Count == 0) { startPoint.Player = BGPlayerID.None; } return(true); } return(false); }
IEnumerator Coroutine_Start() { Character.SetBool("IsStop", true); BGMove bg1 = BG[0].GetComponent <BGMove>(); BGMove bg2 = BG[1].GetComponent <BGMove>(); for (int i = 0; i < 10; i++) { yield return(new WaitForSeconds(0.1f)); bg1.currentSpeed -= bg1.speed * 0.1f; bg2.currentSpeed -= bg2.speed * 0.1f; } yield return(new WaitForSeconds(1.3f)); SceneMove.Instance.Move("InGame"); }
/// <summary> /// Places the current selected checker on the specified point. /// </summary> private void PlaceChecker(Point point) { if (SelectedChecker == null) { return; } else if (SelectedChecker.Point == point) { point.Place(SelectedChecker); SelectedChecker = null; EventHelper.Raise(this, CheckerReturned); } else { BGMove move = MoveOptions.GetMove(SelectedChecker.Point.ID, point.ID); if (move != null && DiceRoll.Use(move)) { if (move.IsHit) { JailChecker(point.PickUp()); } point.Place(SelectedChecker); SelectedChecker = null; m_MovesMade.Push(move); MoveOptions = new BGMoveOptions(CurrentPlayer.ID, Board.GetBoardMap(), DiceRoll); EventHelper.Raise(this, MoveOptionsUpdated); EventHelper.Raise(this, CheckerMoved); } } // Check if the move results in a win. if (SelectedChecker == null) { CheckForWin(CurrentPlayer); } }
/// <summary> /// Undos the last move made. /// </summary> public void Undo() { if (SelectedChecker != null) { ReturnChecker(); } else if (m_MovesMade.Count > 0) { BGMove move = m_MovesMade.Pop(); Board.GetPoint(move.StartPointID).PlaceInstantly(Board.GetPoint(move.EndPointID).PickUp()); if (move.IsHit) { Point jail = Board.GetJail(GetOpponent(CurrentPlayer)); Board.GetPoint(move.EndPointID).PlaceInstantly(jail.PickUp()); } DiceRoll.Restore(move); MoveOptions = new BGMoveOptions(CurrentPlayer.ID, Board.GetBoardMap(), DiceRoll); EventHelper.Raise(this, MoveOptionsUpdated); EventHelper.Raise(this, CheckerMoved); } }
/// <summary> /// Automatically moves a checker using the specified move. /// </summary> /// <param name="move"></param> public MoveResult MoveChecker(BGMove move) { return(MoveChecker(move.StartPointID, move.EndPointID)); }
/// <summary> /// Restores the specified move. Returns whether the move was restored successfully. /// </summary> /// <param name="move"></param> /// <returns></returns> public bool Restore(BGMove move) { return(Restore(move.DiceRoll)); }
/// <summary> /// Uses the specified move. Returns whether the move was used successfully. /// </summary> /// <param name="move"></param> /// <returns></returns> public bool Use(BGMove move) { return(Use(move.DiceRoll)); }
/// <summary> /// Gets whether the specified move can be used. /// </summary> /// <param name="move"></param> /// <returns></returns> public bool CanUse(BGMove move) { return(CanUse(move.DiceRoll)); }