internal static void ChangeDiscsColor(Board io_OthelloBoard, Board.Point i_CurrentPoint, int i_LongtitudeVal, int i_LatitudeVal, int i_NumberOfRivalDiscsToChange) { int startLongtitude = i_CurrentPoint.M_Longtitude - 1; int startLatitude = i_CurrentPoint.M_Latitude - 'A'; for (int i = 1; i <= i_NumberOfRivalDiscsToChange; i++) { io_OthelloBoard.M_OthelloBoard[startLongtitude + (i * i_LongtitudeVal), startLatitude + (i * i_LatitudeVal)].M_CellValue = i_CurrentPoint.M_CellValue; } }
internal static void UpdateBoardAfterDiscPlacement(Board io_OthelloBoard, Board.Point i_UserPointChosen) { int numberOfDiscsToChange = 0; List <Board.Point> emptyList = new List <Board.Point>(); for (eDirection direction = eDirection.Up; direction <= eDirection.UpLeft; direction++) { EightWayCellsCheckAndUpdateValidityOrChangeCellsColor(io_OthelloBoard, i_UserPointChosen, direction, k_ChangeRivalDiscsCellsColor, emptyList, ref numberOfDiscsToChange); numberOfDiscsToChange = 0; } }
public static bool IsRivalDiscChangeNeeded(Board io_OthelloBoard, Board.Point i_CurrentPoint, int i_LongtitudeValue, int i_LatitudeValue, ref int io_NumberOfRivalDiscsToChange) { int latitude = (i_CurrentPoint.M_Latitude - 'A') + i_LatitudeValue; int longtitude = i_CurrentPoint.M_Longtitude - 1 + i_LongtitudeValue; bool isChangeOfDiscsNeeded = false; while (IsPointOnBoardAndRivalDisc(io_OthelloBoard, longtitude, latitude, i_CurrentPoint.M_CellValue) == true) { longtitude += i_LongtitudeValue; latitude += i_LatitudeValue; io_NumberOfRivalDiscsToChange += 1; isChangeOfDiscsNeeded = true; } if (latitude < 0 || latitude >= io_OthelloBoard.M_BoardSize || longtitude < 0 || longtitude >= io_OthelloBoard.M_BoardSize || isChangeOfDiscsNeeded == false || io_OthelloBoard.M_OthelloBoard[longtitude, latitude].M_CellValue != i_CurrentPoint.M_CellValue) { isChangeOfDiscsNeeded = false; io_NumberOfRivalDiscsToChange = 0; } return(isChangeOfDiscsNeeded); }
public static void UpdateCellsValidity(Board io_OthelloBoard, Board.Point i_CurrentPoint, int i_LongtitudeValue, int i_LatitudeValue, List <Board.Point> io_ValidPointsToChooseFrom) { int latitude = (i_CurrentPoint.M_Latitude - 'A') + i_LatitudeValue; int longtitude = i_CurrentPoint.M_Longtitude - 1 + i_LongtitudeValue; bool isPotentialValidPoint = false; while (IsPointOnBoardAndRivalDisc(io_OthelloBoard, longtitude, latitude, i_CurrentPoint.M_CellValue) == true) { longtitude += i_LongtitudeValue; latitude += i_LatitudeValue; isPotentialValidPoint = true; } if (latitude >= 0 && latitude < io_OthelloBoard.M_BoardSize && longtitude >= 0 && longtitude < io_OthelloBoard.M_BoardSize && isPotentialValidPoint == true && io_OthelloBoard.M_OthelloBoard[longtitude, latitude].M_CellValue == Board.Point.k_Empty) { if (io_OthelloBoard.M_OthelloBoard[longtitude, latitude].M_IsAvailableCell == false) { io_OthelloBoard.M_OthelloBoard[longtitude, latitude].M_IsAvailableCell = true; io_ValidPointsToChooseFrom.Add(io_OthelloBoard.M_OthelloBoard[longtitude, latitude]); } } }
/// <summary> /// This method is used for magnet power-up move. /// </summary> /// <param name="p">P is the clicked shape point.</param> public static void MagnetPowerUpMove(Board.Point p) { Board board = GameObject.Find("Board").GetComponent <Board> (); GameObject magnetButton = GameObject.Find("Magnet Power-Up"); int type = board.map [p.x, p.y].GetComponent <Shape> ().Type; List <Board.Point> sameType = new List <Board.Point> (); for (int i = 0; i < Board.Size; i++) { for (int j = 0; j < Board.Size; j++) { if (board.map [i, j].GetComponent <Shape> ().Type == type) { Board.Point point; point.x = i; point.y = j; sameType.Add(point); } } } board.DestroyShape(sameType); turnLeft--; tileLeft -= sameType.Count; DestroyTurn(); if (!board.IsPossibleMove()) { board.ShuffleBoard(); } magnetButton.GetComponent <Image> ().enabled = false; magnetButton.GetComponent <Button> ().enabled = false; isMagnetClicked = false; }
public static void EightWayCellsCheckAndUpdateValidityOrChangeCellsColor(Board io_OthelloBoard, Board.Point i_CurrentPoint, eDirection i_Direction, string i_UpdateValidityOrChangeColor, List <Board.Point> io_ValidPointsToChooseFrom, ref int io_NumberOfRivalDiscsToChangeIfNeeded) { switch (i_Direction) { case eDirection.Up: if (i_UpdateValidityOrChangeColor == k_UpdateValidity) { UpdateCellsValidity(io_OthelloBoard, i_CurrentPoint, k_Decrease, k_DontMove, io_ValidPointsToChooseFrom); } else { if (IsRivalDiscChangeNeeded(io_OthelloBoard, i_CurrentPoint, k_Decrease, k_DontMove, ref io_NumberOfRivalDiscsToChangeIfNeeded)) { ChangeDiscsColor(io_OthelloBoard, i_CurrentPoint, k_Decrease, k_DontMove, io_NumberOfRivalDiscsToChangeIfNeeded); } } break; case eDirection.UpRight: if (i_UpdateValidityOrChangeColor == k_UpdateValidity) { UpdateCellsValidity(io_OthelloBoard, i_CurrentPoint, k_Decrease, k_Increase, io_ValidPointsToChooseFrom); } else { if (IsRivalDiscChangeNeeded(io_OthelloBoard, i_CurrentPoint, k_Decrease, k_Increase, ref io_NumberOfRivalDiscsToChangeIfNeeded)) { ChangeDiscsColor(io_OthelloBoard, i_CurrentPoint, k_Decrease, k_Increase, io_NumberOfRivalDiscsToChangeIfNeeded); } } break; case eDirection.Right: if (i_UpdateValidityOrChangeColor == k_UpdateValidity) { UpdateCellsValidity(io_OthelloBoard, i_CurrentPoint, k_DontMove, k_Increase, io_ValidPointsToChooseFrom); } else { if (IsRivalDiscChangeNeeded(io_OthelloBoard, i_CurrentPoint, k_DontMove, k_Increase, ref io_NumberOfRivalDiscsToChangeIfNeeded)) { ChangeDiscsColor(io_OthelloBoard, i_CurrentPoint, k_DontMove, k_Increase, io_NumberOfRivalDiscsToChangeIfNeeded); } } break; case eDirection.DownRight: if (i_UpdateValidityOrChangeColor == k_UpdateValidity) { UpdateCellsValidity(io_OthelloBoard, i_CurrentPoint, k_Increase, k_Increase, io_ValidPointsToChooseFrom); } else { if (IsRivalDiscChangeNeeded(io_OthelloBoard, i_CurrentPoint, k_Increase, k_Increase, ref io_NumberOfRivalDiscsToChangeIfNeeded)) { ChangeDiscsColor(io_OthelloBoard, i_CurrentPoint, k_Increase, k_Increase, io_NumberOfRivalDiscsToChangeIfNeeded); } } break; case eDirection.Down: if (i_UpdateValidityOrChangeColor == k_UpdateValidity) { UpdateCellsValidity(io_OthelloBoard, i_CurrentPoint, k_Increase, k_DontMove, io_ValidPointsToChooseFrom); } else { if (IsRivalDiscChangeNeeded(io_OthelloBoard, i_CurrentPoint, k_Increase, k_DontMove, ref io_NumberOfRivalDiscsToChangeIfNeeded)) { ChangeDiscsColor(io_OthelloBoard, i_CurrentPoint, k_Increase, k_DontMove, io_NumberOfRivalDiscsToChangeIfNeeded); } } break; case eDirection.DownLeft: if (i_UpdateValidityOrChangeColor == k_UpdateValidity) { UpdateCellsValidity(io_OthelloBoard, i_CurrentPoint, k_Increase, k_Decrease, io_ValidPointsToChooseFrom); } else { if (IsRivalDiscChangeNeeded(io_OthelloBoard, i_CurrentPoint, k_Increase, k_Decrease, ref io_NumberOfRivalDiscsToChangeIfNeeded)) { ChangeDiscsColor(io_OthelloBoard, i_CurrentPoint, k_Increase, k_Decrease, io_NumberOfRivalDiscsToChangeIfNeeded); } } break; case eDirection.Left: if (i_UpdateValidityOrChangeColor == k_UpdateValidity) { UpdateCellsValidity(io_OthelloBoard, i_CurrentPoint, k_DontMove, k_Decrease, io_ValidPointsToChooseFrom); } else { if (IsRivalDiscChangeNeeded(io_OthelloBoard, i_CurrentPoint, k_DontMove, k_Decrease, ref io_NumberOfRivalDiscsToChangeIfNeeded)) { ChangeDiscsColor(io_OthelloBoard, i_CurrentPoint, k_DontMove, k_Decrease, io_NumberOfRivalDiscsToChangeIfNeeded); } } break; case eDirection.UpLeft: if (i_UpdateValidityOrChangeColor == k_UpdateValidity) { UpdateCellsValidity(io_OthelloBoard, i_CurrentPoint, k_Decrease, k_Decrease, io_ValidPointsToChooseFrom); } else { if (IsRivalDiscChangeNeeded(io_OthelloBoard, i_CurrentPoint, k_Decrease, k_Decrease, ref io_NumberOfRivalDiscsToChangeIfNeeded)) { ChangeDiscsColor(io_OthelloBoard, i_CurrentPoint, k_Decrease, k_Decrease, io_NumberOfRivalDiscsToChangeIfNeeded); } } break; } }