public void KillPieceAtPosition(Position position, AbstractPiece movingPiece) { AbstractPiece foundPiece = null; foreach (AbstractPiece piece in this.activePieces) { if (position.Equals(piece.GetCurrentPosition())) { foundPiece = piece; Side side = foundPiece.side; if (side == Side.Black) { this.blackPieceLocations.FlipPosition(position); } else { this.whitePieceLocations.FlipPosition(position); } this.activePieces.Remove(piece); break; } } }
private static void TryAnimateEnPassantCapture(Move move) { Position enPassantPosition; if (move.getPiece().side == Side.Black) { enPassantPosition = new Position(move.getPosition().GetColumn(), move.getPosition().GetRow() + 1); } else { enPassantPosition = new Position(move.getPosition().GetColumn(), move.getPosition().GetRow() - 1); } AbstractPiece pieceAtEnPassantPosition = GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>().chessBoard.GetPieceAtPosition(enPassantPosition); Pawn dyingPawn = null; if (pieceAtEnPassantPosition != null && pieceAtEnPassantPosition.GetType().Name == Constants.PieceClassNames.Pawn && pieceAtEnPassantPosition.side != move.getPiece().side&& ((Pawn)pieceAtEnPassantPosition).allowEnPassantCapture) { dyingPawn = (Pawn)pieceAtEnPassantPosition; } if (dyingPawn != null) { GameObject.Find(Constants.ActionCameraObject).GetComponent <ActionCamera>().EnableActionCamera(move.getPiece(), dyingPawn); GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>().DestroyPiece(GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>().GetGameObjectFromPiece(dyingPawn).GetComponent <PieceBehaviour>()); } }
private void OnPieceReleased(object sender, EventArgs e) { if (_board.PutPiece(_draggedPiece)) { _board.ClearCurrentPiece(); int idPos = GetPieceSlotId(_draggedPiece as Piece); CleanDestroyPiece(_draggedPiece); Piece newPiece = GetNewPiece(_piecePositions[idPos]); _pieceSlots[idPos] = newPiece; if (_board.lastNumberValidatedLines > 1) { _shuffleCount += _board.lastNumberValidatedLines - 1; } ComputeScore(); ComputeQuest(); UpdateUI(); ManageGameOver(); } else { _draggedPiece.transform.position = _piecePositions[GetPieceSlotId(_draggedPiece as Piece)]; } _draggedPiece = null; _board.ClearCurrentPiece(); ResetHelpTimer(); }
/// <summary> /// Puts the piece on the board /// </summary> /// <param name="piece">The piece to put</param> /// <returns>True if the piece is really put, false else</returns> public bool PutPiece(AbstractPiece piece) { //Shape hoveredShape = GetShapeAtPos(piece.transform.position, false); Shape playableShape = GetClosestPlayableShape(); if (playableShape != null) { IEnumerable <Shape> addedShapes = GetNecessaryShapesForPieceWithFirstShape(playableShape, piece, _shapes); if (piece is Piece) { Color pColor = piece.PieceColor; addedShapes.ToList().ForEach(s => s.isFilled = true); addedShapes.ToList().ForEach(s => s.IsVisuallyFilled = true); addedShapes.ToList().ForEach(s => s.FilledColor = pColor); ValidateUniqueLines(addedShapes); } else if (piece is PieceBonusDestroy) { addedShapes.ToList().ForEach(s => s.isFilled = false); addedShapes.ToList().ForEach(s => s.IsVisuallyFilled = false); } return(true); } return(false); }
private void OnPieceDragged(object sender, EventArgs e) { _draggedPiece = sender as AbstractPiece; _board.currentDraggedPiece = _draggedPiece; _board.FindPlayableShapes(_draggedPiece); ResetHelpTimer(); }
public void DisplayPieceOnShape(AbstractPiece piece, Shape sh) { IEnumerable <Shape> hoveredShapes = GetNecessaryShapesForPieceWithFirstShape(sh, piece, _shapes); hoveredShapes.ToList().ForEach(s => s.isPlayable = true); hoveredShapes.ToList().ForEach(s => s.HoveredColor = piece.PieceColor); }
protected override void Execute(Map map) { AbstractField position = map.GetPlayerById(_agentId).Position; AbstractPiece piece = map.GetPlayerById(_agentId).Holding; PutPieceAt(piece, position, map); }
/* * public void GenerateNewBoard() { * ResetBoard(); * foreach(Shape s in _shapes) { * Destroy(s.gameObject); * } * _shapes.Clear(); * ClearCurrentPiece(); * SelectBoard(2); * } * * private void CreateBoardFromArray(int[,] data) { * for (int j = 0; j < data.GetLength(1); j++) { * for (int i = 0; i < data.GetLength(0); i++) * { * if (data[i,j] == 1){ * CreateBoardShape(j, i); * } * } * } * ComputeBoardDimensions(data.GetLength(1), data.GetLength(0)); * AdjustBoardPosition(); * }*/ /// <summary> /// Returns all playable shapes for the current piece /// </summary> /// <param name="piece">The currently selected piece</param> /// <returns></returns> public IEnumerable <Shape> FindPlayableShapes(AbstractPiece piece) { IEnumerable <Shape> resShapes = new List <Shape>(); resShapes = _shapes.Where(s => IsPiecePlayableOnShape(s, piece)); return(resShapes); }
public void EnableActionCamera(AbstractPiece movingPiece, AbstractPiece dyingPiece) { // The action camera will always point towards a dying object from the initial position of the object destroying it GameKeeper gameKeeper = GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>(); if (movingPiece.side == Side.White) { // Positive music this.deathAudioSource.clip = (AudioClip)Resources.Load(Constants.AudioClipNames.AudioDirectory + Constants.AudioClipNames.RebelAttack, typeof(AudioClip)); } if (movingPiece.side == Side.Black) { // Badass music this.deathAudioSource.clip = (AudioClip)Resources.Load(Constants.AudioClipNames.AudioDirectory + Constants.AudioClipNames.ImperialMarch, typeof(AudioClip)); } StartCoroutine(this.PlayDeathMusic()); Vector3 forward = gameKeeper.GetTransformFromPosition(movingPiece.GetCurrentPosition()) - gameKeeper.GetTransformFromPosition(dyingPiece.GetCurrentPosition()); Vector3 up = new Vector3(0, 1, 0); Vector3 cameraPosition = gameKeeper.GetTransformFromPosition(dyingPiece.GetCurrentPosition()) - 2 * gameKeeper.GetSquareSpacing() * forward.normalized; cameraPosition.y = 1; this.gameObject.GetComponent <Transform>().position = cameraPosition; this.gameObject.GetComponent <Transform>().rotation = Quaternion.LookRotation(forward, up); GameObject.Find(Constants.MainCameraObject).GetComponent <Camera>().enabled = false; this.gameObject.GetComponent <Camera>().enabled = true; }
public BasicChessModel(Game game, AbstractPiece logicalPieceRef, ModelProvider modelProvider) : base(game, logicalPieceRef, modelProvider) { createModel(); maxModelHeight = 1.2f; prefferedModelHeight = 0.9f; }
private void CleanDestroyPiece(AbstractPiece piece) { _board.ClearCurrentPiece(); piece.PieceDraggedHandler -= OnPieceDragged; piece.PieceReleasedHandler -= OnPieceReleased; piece.PieceCollidingHandler -= OnPieceCollision; piece.PieceExitCollisionHandler -= OnPieceExitCollision; piece.DestroyPiece(); }
public override AbstractPiece CopyPiece(AbstractPiece pieceToCopy) { pieceToCopy = base.CopyPiece(pieceToCopy); Rook rookToCopy = (Rook)pieceToCopy; rookToCopy.canCastle = this.canCastle; return(rookToCopy); }
public virtual AbstractPiece CopyPiece(AbstractPiece pieceToCopy) { pieceToCopy.side = this.side; pieceToCopy.currentPosition = this.currentPosition; // Don't copy the chessboard as this function is mostly called when a new chessboard has to be created pieceToCopy.moves = this.moves; return(pieceToCopy); }
public override AbstractPiece CopyPiece(AbstractPiece pieceToCopy) { pieceToCopy = base.CopyPiece(pieceToCopy); King kingToCopy = (King)pieceToCopy; kingToCopy.canCastle = this.canCastle; return(kingToCopy); }
private void PutPieceInGoalArea(AbstractPiece piece, AbstractField position, Map map) { if (piece.IsSham()) { PutShamInGoalArea(piece, position); } else { PutNonShamInGoalArea(piece, position, map); } }
private static void TryPlayDeathAnimation(Move move) { AbstractPiece pieceAtMovePosition = GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>().chessBoard.GetPieceAtPosition(move.getPosition()); if (pieceAtMovePosition != null) // Switch to action cam for some awesomeness { GameObject.Find(Constants.ActionCameraObject).GetComponent <ActionCamera>().EnableActionCamera(move.getPiece(), pieceAtMovePosition); GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>().DestroyPiece(GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>().GetGameObjectFromPiece(pieceAtMovePosition).GetComponent <PieceBehaviour>()); } }
public override AbstractPiece CopyPiece(AbstractPiece pieceToCopy) { pieceToCopy = base.CopyPiece(pieceToCopy); Pawn pawnToCopy = (Pawn)pieceToCopy; pawnToCopy.allowEnPassantCapture = this.allowEnPassantCapture; pawnToCopy.initialPosition = this.initialPosition; return(pawnToCopy); }
private void PutNonShamInGoalArea(AbstractPiece piece, AbstractField position, Map map) { position.Discover(); if (position.IsGoalField) { PutNonShamOnGoal(piece, position, map); } else { PutNormalOnNonGoal(piece, position); } }
public override (PutEvent putEvent, bool wasPieceRemoved) Put(AbstractPiece piece) { if (piece.CheckForSham() == false) { Pieces.Add(piece); return(PutEvent.NormalOnNonGoalField, true); } else { Pieces.Add(piece); return(PutEvent.ShamOnGoalArea, true); } }
private void PutPieceAt(AbstractPiece piece, AbstractField position, Map map) { map.GetPlayerById(_agentId).Holding = null; if (map.IsInGoalArea(position)) { map.AddPiece(); PutPieceInGoalArea(piece, position, map); } else { PutPieceOutsideGoalArea(piece, position); } }
public GameObject GetGameObjectFromPiece(AbstractPiece piece) { GameObject gameObjectOfPiece = null; foreach (GameObject pieceGameObject in GameObject.FindGameObjectsWithTag(Constants.PieceTag)) { if (pieceGameObject.GetComponent <PieceBehaviour>().getPiece().Equals(piece)) { gameObjectOfPiece = pieceGameObject; } } return(gameObjectOfPiece); }
public static Chessboard MakeCopyOfChessboard(Chessboard chessboardToCopy) { Chessboard newChessboard = new Chessboard(); newChessboard.blackPieceLocations = new Bitboard(); newChessboard.whitePieceLocations = new Bitboard(); newChessboard.blackPieceLocations = chessboardToCopy.blackPieceLocations.IntersectBitboard(newChessboard.blackPieceLocations); newChessboard.whitePieceLocations = chessboardToCopy.whitePieceLocations.IntersectBitboard(newChessboard.whitePieceLocations); newChessboard.movingSide = chessboardToCopy.movingSide; foreach (AbstractPiece piece in chessboardToCopy.activePieces) { System.Type pieceType = piece.GetType(); AbstractPiece newPiece = null; if (pieceType == typeof(Pawn)) { newPiece = new Pawn(piece.GetCurrentPosition()); } else if (pieceType == typeof(Rook)) { newPiece = new Rook(piece.GetCurrentPosition()); } else if (pieceType == typeof(Bishop)) { newPiece = new Bishop(piece.GetCurrentPosition()); } else if (pieceType == typeof(Knight)) { newPiece = new Knight(piece.GetCurrentPosition()); } else if (pieceType == typeof(Queen)) { newPiece = new Queen(piece.GetCurrentPosition()); } else if (pieceType == typeof(King)) { newPiece = new King(piece.GetCurrentPosition()); } if (newPiece != null) { newPiece = piece.CopyPiece(newPiece); newPiece.SetChessboard(newChessboard); newChessboard.activePieces.Add(newPiece); } } return(newChessboard); }
public AbstractPiece GetPieceAtPosition(Position position) { AbstractPiece foundPiece = null; foreach (AbstractPiece piece in this.activePieces) { if (position.Equals(piece.GetCurrentPosition())) { foundPiece = piece; } } return(foundPiece); }
private static bool willMoveCheckmateOpponent(Move move) { bool willCheckmateOpponent = false; Chessboard gameStateAfterMove = Chessboard.MakeCopyOfChessboard(move.getPiece().GetChessboard()); AbstractPiece correspondingMovingPiece = gameStateAfterMove.GetPieceAtPosition(move.getPiece().GetCurrentPosition()); gameStateAfterMove.MoveTo(correspondingMovingPiece, move.getPosition()); if (gameStateAfterMove.IsKingInCheckmate(gameStateAfterMove.CurrentMovingSide())) { willCheckmateOpponent = true; } return(willCheckmateOpponent); }
/// <summary> /// Returns the list of shapes necessary to fit the piece, starting with the current shape /// /!\ You probably want to use GetNecessaryShapesForPieceWithFirstShape /// </summary> /// <param name="shape">The base shape to create the piece</param> /// <param name="piece">The piece to fit</param> /// <param name="shapeList">The list of shapes in which to pick</param> /// <returns>A (possibly incomplete) list of shapes fitting the piece</returns> private IEnumerable <Shape> GetNecessaryShapesForPiece(Shape shape, AbstractPiece piece, IEnumerable <Shape> shapeList) { List <Shape> necessaryShapes = new List <Shape>(); foreach (Shape s in piece.pieceShapes) { Vector2 searchPos = s.PosXY + shape.PosXY; IEnumerable <Shape> found = shapeList.Where(us => us.PosXY == searchPos && us.IsUpsideDown == s.IsUpsideDown); if (found.Count() != 0) { necessaryShapes.Add(found.First()); } } return(necessaryShapes); }
/// <summary> /// Determines whether the piece can be played on a particular shape /// </summary> /// <param name="shape"></param> /// <param name="piece"></param> /// <returns></returns> public bool IsPiecePlayableOnShape(Shape shape, AbstractPiece piece) { IEnumerable <Shape> listShapes; if (piece is Piece) { listShapes = _shapes.Where(s => !s.isFilled); } else { // Probably for DetroyPiece, to check with Jade listShapes = _shapes; } IEnumerable <Shape> necessaryShapes = GetNecessaryShapesForPieceWithFirstShape(shape, piece, listShapes); return(necessaryShapes.Count() == piece.pieceShapes.Count); }
public static void TriggerNextStartAnimation(AbstractPiece piece) { if (piece.GetType().Name == Constants.PieceClassNames.Pawn) { EventManager.TriggerEvent(Constants.EventNames.PawnsLanded); } else if (piece.GetType().Name == Constants.PieceClassNames.Bishop) { EventManager.TriggerEvent(Constants.EventNames.BishopsLanded); } else if (piece.GetType().Name == Constants.PieceClassNames.Knight) { EventManager.TriggerEvent(Constants.EventNames.KnightsLanded); } else if (piece.GetType().Name == Constants.PieceClassNames.Rook) { EventManager.TriggerEvent(Constants.EventNames.RooksLanded); } }
//Maybe we should add later some methods like: Highlight, Select, and Reset. Just like the checker. //But that needs extra handling using dedicated Effect. public ChessModel(Game game, AbstractPiece logicalPieceRef, ModelProvider modelProvider) : base(game) { this.logicalPieceRef = logicalPieceRef; this.modelProvider = modelProvider; // ModelEffect = new PhongEffect(game, logicalPieceRef); ModelEffect = new BasicEffect(game.GraphicsDevice, null); //System.Console.WriteLine(ModelEffect.Effect.GetHashCode()); // ModelEffect.setOtherParams(); if (logicalPieceRef.player is Player1) { fireParticles = new FireParticleSystem(game, Tint.Dark); } else { fireParticles = new FireParticleSystem(game, Tint.Light); } fireParticles.DrawOrder = 500; cam = (GameCamera)game.Services.GetService(typeof(BasicCamera)); Game.Components.Add(fireParticles); shadowPlane = new Plane(new Vector3(-5, 0, -5), new Vector3(5, 0, -5), new Vector3(5, 0, 5)); shadowPlane.Normal = new Vector3(0, -8, 0); shadowLightDir = new Vector3(-2.1f, -2f, -2.1f); shadow = Matrix.CreateShadow(shadowLightDir, shadowPlane); modelEffect.LightingEnabled = true; modelEffect.TextureEnabled = true; modelEffect.EnableDefaultLighting(); if (logicalPieceRef.player is Player1) { texture = game.Content.Load <Texture2D>("White"); } else { texture = game.Content.Load <Texture2D>("Black"); } //game.Components.Add(fireParticles); }
private static Type isMoveAnOpponentCapture(Move move) { Type capturedPieceType = typeof(AbstractPiece); Chessboard gameState = move.getPiece().GetChessboard(); AbstractPiece pieceAtMovePosition = gameState.GetPieceAtPosition(move.getPosition()); //TODO: Make it easier to get en passant positions Position enPassantPosition; AbstractPiece pieceAtEnPassantPosition = null; if (move.getPiece().GetType() == typeof(Pawn)) { if (move.getPiece().side == Side.Black) { enPassantPosition = new Position(move.getPosition().GetColumn(), move.getPosition().GetRow() + 1); } else { enPassantPosition = new Position(move.getPosition().GetColumn(), move.getPosition().GetRow() - 1); } pieceAtEnPassantPosition = gameState.GetPieceAtPosition(enPassantPosition); if (pieceAtEnPassantPosition != null && (pieceAtEnPassantPosition.GetType() != typeof(Pawn) || pieceAtEnPassantPosition.side == move.getPiece().side)) { pieceAtEnPassantPosition = null; } } // Normal captures if (pieceAtMovePosition != null && pieceAtMovePosition.side != move.getPiece().side) { capturedPieceType = pieceAtMovePosition.GetType(); } //En passant capture else if (pieceAtEnPassantPosition != null && ((Pawn)pieceAtEnPassantPosition).allowEnPassantCapture) { capturedPieceType = pieceAtEnPassantPosition.GetType(); } return(capturedPieceType); }
public static bool isSpaceship(AbstractPiece piece) { // The pieces that are represented as spaceships will have different animations, sound effects, etc. List <string> spaceshipPieceClassNames = new List <string> { Constants.PieceClassNames.Pawn, Constants.PieceClassNames.Rook, Constants.PieceClassNames.Bishop, Constants.PieceClassNames.Knight }; if (spaceshipPieceClassNames.Contains(piece.GetType().Name)) { return(true); } else { return(false); } }