Random letters. help.
in
Programming Questions
•
1 year ago
Basically, what I'm trying to do is make my grid a class which I'm not sure how to configure my code to do so.
Also, I've got random letter in the grids. Would anyone know how to make it so only some cells have random letter and the ability to right click and input a letter into any cell, I need to make it so I can drag letter too but I don't want to get a head of myself. Any help would be great!
int cell= 50;
int row=11;
int column=11;
char[][]letters= new char[row][column];
int code;
PFont letterFont;
void setup()
{
initLetters(letters);
displayLetters(letters);
size(row*cell,column*cell);
letterFont = createFont("TimesNewRoman",cell*0.4);
textFont(letterFont);
textAlign(CENTER);
}
void draw()
{
background(255);
drawGrid();
}
void initLetters(char[][]a)
{
for (int i=0;i<a.length;i++)
{
for (int j=0;j<a[0].length; j++)
{
code=(int)random(0,10);
a[i][j]=(char)('A'+code);
}
}
}
void displayLetters(char[][] a)
{
for (int i=0;i<a.length;i++)
{
for (int j=0;j< a[0].length;j++)
{
print(a[i][j]);
}
println();
}
}
void drawCell(int row,int column,char letter)
{
stroke(0);
noFill();
rect(column*cell,row*cell,cell,cell);
fill(0);
text(letter,column*cell+cell/2,row*cell+cell/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