Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Cell[][] cell = new Cell[8][8];
- int w;
- Piece[] piece = new Piece[32];
- void setup(){
- size(400,400);
- w = width/8;
- textSize(w);
- for(int i = 0; i < 8; i++){
- for(int j = 0; j < 8; j++){
- cell[i][j] = new Cell(i,j,w);
- }
- }
- makePieces();
- }
- void draw(){
- backGround();
- showPieces();
- piece[0].show();
- }
- void makePieces(){
- for(int i = 0; i < 16; i++){
- if(i < 8){ //PAWNS
- piece[i] = new Piece(i, 1, 'P', true); //Black pieces
- piece[i+16] = new Piece(i, 6, 'P', false); //White Pieces
- } else if(i == 8 || i == 15){ //ROOKS
- piece[i] = new Piece(i-8, 0, 'R', true);
- piece[i+16] = new Piece(i-8, 7, 'R', false);
- } else if(i == 9 || i == 14){ //'N'IGHTS
- piece[i] = new Piece(i-8, 0, 'N', true);
- piece[i+16] = new Piece(i-8, 7, 'N', false);
- } else if(i == 10 || i == 13){ //Bishops
- piece[i] = new Piece(i-8, 0, 'B', true);
- piece[i+16] = new Piece(i-8, 7, 'B', false);
- } else if(i == 11){ //Queens
- piece[i] = new Piece(i-8, 0, 'Q', true);
- piece[i+16] = new Piece(i-8, 7, 'Q', false);
- } else { //Kings
- piece[i] = new Piece(i-8,0,'K',true);
- piece[i+16] = new Piece(i-8,7,'K',false);
- }
- }
- }
- void showPieces(){
- for(int i = 0; i < piece.length; i++){
- piece[i].show();
- }
- }
- void backGround(){
- for(int i = 0; i < 8; i++){
- for(int j = 0; j < 8; j++){
- cell[i][j].show();
- }
- }
- }
- public class Cell{
- int row;
- int column;
- int w;
- boolean hasPiece;
- boolean isSelected;
- public Cell(int i, int j, int w){
- this.row = i;
- this.column = j;
- this.hasPiece = false;
- this.isSelected = false;
- this.w = w;
- }
- public void show(){
- if((this.row + this.column)%2 == 0){
- fill(0, 0, 255);
- } else {
- fill(255,0,0);
- }
- rect(this.row*this.w, this.column*this.w, this.w, this.w);
- }
- }
- public class Piece{
- int x;
- int y;
- char ch;
- boolean onBoard;
- boolean isBlack;
- public Piece(int x, int y, char ch, boolean isBlack){
- this.x = x;
- this.y = y;
- this.ch = ch;
- this.isBlack = isBlack;
- }
- public void show(){
- if(this.isBlack){
- fill(0);
- } else {
- fill(255);
- }
- text(this.ch, (this.x+.15)*w, (this.y+.85)*w);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment