public CocoPiece Build(Piece piece) { var strColor = piece.Color == PieceColor.White ? "w" : "b"; var spriteName = strColor + "_" + Enum.GetName(typeof(PieceType), piece.Type).ToLower() + ".png"; var cocoPiece = new CocoPiece(piece, cache[spriteName]); return cocoPiece; }
public CocoPiece(Piece piece, CCSpriteFrame cCSpriteFrame) : base(cCSpriteFrame) { this.ScaleX = 118 / cCSpriteFrame.Texture.ContentSizeInPixels.Width + 0.1f; this.ScaleY = 118 / cCSpriteFrame.Texture.ContentSizeInPixels.Width + 0.1f; this.piece = piece; this.piece.PieceTaken += OnPieceTaken; this.piece.PositionUpdated += (s, p) => { this.Position = p.GetPoint(this.piece.Board.Size); }; AnchorPoint = CCPoint.AnchorMiddle; Position = this.GetPosition(); touchListener = new CCEventListenerTouchOneByOne(); touchListener.OnTouchMoved = Touch; touchListener.OnTouchBegan = ToucheBegan; touchListener.OnTouchEnded = TouchEnded; touchListener.OnTouchCancelled = TouchCanceled; AddEventListener(touchListener, this); }
private void FirePieceMoved(Square oldPosition, Piece piece) { if (this.PieceMoved != null) { var move = new Move() { Color = piece.Color, OriginalSquare = oldPosition, TargetSquare = piece.Position, Piece = piece.Type }; this.PieceMoved(this, move); } }
internal void MakeMove(Square targetSquare, Piece pieceToMove) { this.PutPiece(targetSquare, pieceToMove, false); }
public void PutPiece(Square square, Piece piece, bool notifyPieceMoved = true) { if (this.squares[square] != null) { this.squares[square].TakePiece(); } // Put piece in a new position var oldPosition = piece.Position; this.squares[oldPosition] = null; this.squares[square] = piece; piece.Position = square; // Now it's opposite color to move this.IsWhiteMove = !this.IsWhiteMove; if (notifyPieceMoved) { this.FirePieceMoved(oldPosition, piece); } }