Advertisement
dawdadwg

Untitled

Oct 14th, 2019
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import java.awt.Color;
  2.  
  3. import balaji.shapes.Rectangle;
  4. import processing.core.PApplet;
  5.  
  6. public class Board {
  7.  
  8.     Tile[][] board = new Tile[8][8];
  9.    
  10.     public Board()
  11.     {
  12.         int y = 0;
  13.         boolean black = false;
  14.         for(int i = 0; i < 8; i++)
  15.         {
  16.             black = !black;
  17.             int x = 0;
  18.             for (int j = 0; j < 8; j++)
  19.             {
  20.                
  21.                 board[i][j] = new Tile(x, y, null);
  22.                 x += 50;
  23.             }
  24.             y += 50;
  25.         }
  26.     }
  27.    
  28.     public void draw(PApplet drawer)
  29.     {
  30.         for(int i = 0; i < 8; i++)
  31.         {
  32.             for (int j = 0; j < 8; j++)
  33.             {
  34.                 if (i%2 == 0)
  35.                 {
  36.                     if (j%2 == 0)
  37.                     {
  38.                         board[i][j].setFillColor(Color.BLACK);
  39.                     } else
  40.                     {
  41.                         board[i][j].setFillColor(Color.WHITE);
  42.                     }
  43.                 } else
  44.                 {
  45.                     if (j%2 != 0)
  46.                     {
  47.                         board[i][j].setFillColor(Color.BLACK);
  48.                     } else
  49.                     {
  50.                         board[i][j].setFillColor(Color.WHITE);
  51.                     }
  52.                 }
  53.                 board[i][j].draw(drawer);
  54.             }
  55.         }
  56.     }
  57.    
  58.     public Tile[][] getBoard()
  59.     {
  60.         return board;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement