public piece(string n, tile st, Texture2D tex, Rectangle texSlice) { name = n; start = st; current = start; current.piece = this; texture = tex; textureSlice = texSlice; }
//moves piece to parameter in tile public void move(tile t) { current.piece = null; if (t.piece != null) { takePiece(t); return; } current = t; t.piece = this; }
public void takePiece(tile t) { //take piece and set fallout t.piece.current = null; t.piece = null; t.fallout = true; this.current = null; //remove 1 sq radius if (t.x < 7) { if (grid[t.x+1, t.y].piece != null) { grid[t.x+1, t.y].piece.current = null; grid[t.x+1, t.y].piece = null; } if (t.y < 7) { if (grid[t.x + 1, t.y+1].piece != null) { grid[t.x + 1, t.y+1].piece.current = null; grid[t.x + 1, t.y+1].piece = null; } } } if (t.x > 0) { if (grid[t.x-1, t.y].piece != null) { grid[t.x-1, t.y].piece.current = null; grid[t.x-1, t.y].piece = null; } if (t.y > 0) { if (grid[t.x - 1, t.y-1].piece != null) { grid[t.x - 1, t.y-1].piece.current = null; grid[t.x - 1, t.y-1].piece = null; } } } if (t.y > 0) { if (grid[t.x, t.y-1].piece != null) { grid[t.x, t.y-1].piece.current = null; grid[t.x, t.y-1].piece = null; } if (t.x < 7) { if (grid[t.x + 1, t.y-1].piece != null) { grid[t.x + 1, t.y-1].piece.current = null; grid[t.x + 1, t.y-1].piece = null; } } } if (t.y < 7) { if (grid[t.x, t.y+1].piece != null) { grid[t.x, t.y+1].piece.current = null; grid[t.x, t.y+1].piece = null; } if (t.x >0) { if (grid[t.x - 1, t.y+1].piece != null) { grid[t.x - 1, t.y+1].piece.current = null; grid[t.x - 1, t.y+1].piece = null; } } } }
public piece(string n, tile st) { name = n; start = st; current = start; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // grid = Content.Load<Texture2D>("chessboard"); pieces = Content.Load<Texture2D>("Chess_symbols"); bpixel = Content.Load<Texture2D>("BlackPixel"); wPixel = Content.Load<Texture2D>("WhitePixel"); radioactive = Content.Load<Texture2D>("Radioactive"); // TODO: use this.Content to load your game content here pixel = new Texture2D(graphics.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); pixel.SetData(new[] { Color.White }); int curx = 50; int cury = 50; bool black = false; for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { Texture2D col; if (black) { col = bpixel; } else { col = wPixel; } grid [x, y] = new tile(new Rectangle(curx, cury, 100, 100), x, y, black, col); grid [x, y].Fallout = radioactive; black = !black; cury += 100; } black = !black; cury = 50; curx += 100; } //initialize white pawns for (int i = 0; i < 8; i++) { whitepieces[i] = new piece("Pawn", grid[i,1], pieces, WPawn); } whitepieces[8] = new piece("Rook", grid[0, 0], pieces, WRook); whitepieces[9] = new piece("Rook", grid[7, 0], pieces, WRook); whitepieces[10] = new piece("Knight", grid[1, 0], pieces, WKnight); whitepieces[11] = new piece("Knight", grid[6, 0], pieces, WKnight); whitepieces[12] = new piece("Bishop", grid[2, 0], pieces, WBishop); whitepieces[13] = new piece("Bishop", grid[5, 0], pieces, WBishop); whitepieces[14] = new piece("King", grid[3, 0], pieces, WKing); whitepieces[15] = new piece("Queen", grid[4, 0], pieces, WQueen); //initialize black pawns for (int i = 0; i < 8; i++) { blackpieces[i] = new piece("Pawn", grid[i, 6], pieces, BPawn); } blackpieces[8] = new piece("Rook", grid[0, 7], pieces, BRook); blackpieces[9] = new piece("Rook", grid[7, 7], pieces, BRook); blackpieces[10] = new piece("Knight", grid[1, 7], pieces, BKnight); blackpieces[11] = new piece("Knight", grid[6, 7], pieces, BKnight); blackpieces[12] = new piece("Bishop", grid[2, 7], pieces, BBishop); blackpieces[13] = new piece("Bishop", grid[5, 7], pieces, BBishop); blackpieces[14] = new piece("King", grid[3, 7], pieces, BKing); blackpieces[15] = new piece("Queen", grid[4, 7], pieces, BQueen); //p = new piece("King", grid[2, 1], pieces, WKing); }