// Piece move animation void Update() { if (Input.GetKeyUp(KeyCode.Escape)) { if (m_paused) { Resume(); } else { Pause(); } } if (m_move != null) { m_move.phase += Time.deltaTime; float jumpPercent = m_move.phase / m_jumpLength; Vector3 pos = m_move.target; if (jumpPercent < 1.0f) { pos = m_move.start + (m_move.target - m_move.start) * jumpPercent; pos.y = (float)Math.Sin(Math.PI * jumpPercent); m_move.piece.transform.parent.position = pos; } else { // jumping is done m_move.piece.transform.parent.position = m_move.target; m_move = null; } } }
private void SpawnPiece() { int xPos; int yPos = Random.Range(0, searchHeight); bool spawnLeft = Random.value > 0.5f; DirectionType moveDirection; if (spawnLeft) { xPos = 0; moveDirection = DirectionType.RIGHT; } else { xPos = rightSpawnIndex; moveDirection = DirectionType.LEFT; } Vector2Int gridSpawnPos = new Vector2Int(xPos, yPos); bool canSpawn = gameGrid.IsTileEmpty(gridSpawnPos); if (!canSpawn) { if (searchHeight > 3) { SpawnPiece(); } return; } MovingPiece newPiece = Instantiate(movingPiecePrefab); newPiece.Initialize(gridSpawnPos, moveDirection); }
private string GetMoveAsString() { string moveString; List <Square> column = MovingPiece.FindCurrentColumn(Grid, EndSquare); int indexOfColumn = Array.IndexOf(Grid.Columns, column); int indexOfSquare = column.IndexOf(EndSquare); if (MovingPiece.TypeOfPiece == Piece.PieceType.Pawn) { if (CapturedPiece != null) { moveString = string.Format("x{0}{1}", ColumnConversionPairs[indexOfColumn], indexOfSquare + 1); } else { moveString = string.Format("{0}{1}", ColumnConversionPairs[indexOfColumn], indexOfSquare + 1); } } else { if (CapturedPiece != null) { moveString = string.Format("{0}x{1}{2}", PieceConversionPairs[MovingPiece.TypeOfPiece], ColumnConversionPairs[indexOfColumn], indexOfSquare + 1); } else { moveString = string.Format("{0}{1}{2}", PieceConversionPairs[MovingPiece.TypeOfPiece], ColumnConversionPairs[indexOfColumn], indexOfSquare + 1); } } return(moveString); }
public void UnresolveMove() { MovingPiece.UnMakeMove(this); if (MoveCapturesPiece) { CapturedPiece.Captured = false; } }
public void ResolveMove() { MovingPiece.MakeMove(this); if (MoveCapturesPiece) { CapturedPiece.Captured = true; } }
IEnumerator PieceMove(GameLogic.Move move) { var piece = m_pieces[move.pieceNr]; Vector3 newCoords; if (move.toPos < GameLogic.BoardSize) { newCoords = BoardCoords.getPositionCoords(move.toPos); } else { newCoords = BoardCoords.getTargetCoords(m_gameLogic.CurrentPlayer, move.toPos % 1000); } GameObject bumpedPiece = null; Vector3? bumpTargetPos = null; if (move.pieceOnTargetPos.HasValue) { var bumpedPieceIdx = move.pieceOnTargetPos.Value; var bumpedOwner = m_gameLogic.WhosePlayerIsPiece(bumpedPieceIdx); var bumpHomePos = (-m_gameLogic.FindFreeHomePos(bumpedOwner)) - 1; bumpedPiece = m_pieces[bumpedPieceIdx]; bumpTargetPos = BoardCoords.getHomeCoords(bumpedOwner, bumpHomePos); } m_move = new MovingPiece() { piece = piece, start = piece.transform.parent.position, target = newCoords, phase = 0f }; yield return(new WaitForSeconds(m_jumpLength)); if (bumpedPiece != null) { bumpedPiece.transform.parent.position = bumpTargetPos.Value; } var result = m_gameLogic.ExecuteMove(move); if (result.gameOver != null) { Debug.Log("Game over"); GameOver(); } else { StartCoroutine(NextPlayer()); } }
/// <summary> /// Shifts the moving piece 1 square right, if possible /// </summary> private void MovePieceRight() { List <Square> squares = MovingPiece.OccupiedSquares; // Can't move out of bounds if (squares.Any(ms => ms.X == Width - 1)) { return; } // Can't move into an already occupied square else if (FixedPieces.Any(fp => fp.OccupiedSquares.Any(fs => squares.Any(ms => ms.X + 1 == fs.X && ms.Y == fs.Y)))) { return; } MovingPiece.MoveRight(); }
/// <summary> /// Rotates the moving piece /// </summary> private void RotatePiece() { List <Square> afterRotation = MovingPiece.SimulateRotation(); // Can't move out of bounds if (afterRotation.Any(ms => ms.X < 0) || afterRotation.Any(ms => ms.X >= Width) || afterRotation.Any(ms => ms.Y < 0) || afterRotation.Any(ms => ms.Y >= Height)) { return; } // Can't move into an already occupied square if (FixedPieces.Any(fp => fp.OccupiedSquares.Any(fs => afterRotation.Any(rs => rs.X == fs.X && rs.Y == fs.Y)))) { return; } MovingPiece.Rotate(); }
protected virtual void OnMovingPiece(MovingPieceEventArgs e) => MovingPiece?.Invoke(this, e);