Can't get my class to work :(
in
Programming Questions
•
1 year ago
I've been trying for hours to get my grid code below to work with a class Grid. It's really doing my head in because it's only the start of what I really need.
This is what I know I need:
class Grid {
variables here
Grid() {
height/width
position
color etc
}
methods to display here
}
I've tried arranging the code below into that but then I go to initialise it in setup and draw and it doesn't work. Any help would be amazing thanks. :)
- final int CELL_SIZE = 50;
- final int NUM_ROW = 10;
- final int NUM_COL = 10;
- char[][] letters = new char[NUM_ROW][NUM_COL];
- PFont letterFont;
- void setup()
- {
- size(NUM_ROW * CELL_SIZE, NUM_COL * CELL_SIZE);
- }
- void draw()
- {
- background(255);
- drawGrid();
- }
- void drawCell(int row, int col, char letter)
- {
- stroke(0);
- noFill();
- rect(col * CELL_SIZE, row * CELL_SIZE, CELL_SIZE, CELL_SIZE);
- fill(0);
- text(letter, col * CELL_SIZE + CELL_SIZE/2, row * CELL_SIZE + CELL_SIZE/2);
- }
- void drawGrid()
- {
- for (int i = 0; i < letters.length; i++)
- {
- for (int j = 0; j < letters[0].length; j++)
- {
- drawCell(i, j, letters[i][j]);
- }
- }
- }
1