0
我想製作一個程序,在點擊「Roll」的矩形後單擊顯示骰子的面部,但是當我點擊時,沒有任何反應。試圖在Processing中創建一個骰子,但點擊不會觸發它
有人可以解釋我做錯了什麼嗎?
import java.util.Random;
public Random random = new Random();
public color purple = #B507F5;
public int diceChoose = random.nextInt(6);
public int x = mouseX;
public int y = mouseY;
public void setup() {
size(750, 900);
background(255);
}
public void draw() {
strokeWeight(3);
//dice roll button
rect(100, 700, 550, 150);
textSize(100);
fill(purple);
text("Roll", 280, 815);
noFill();
//dice face
rect(100, 100, 550, 550);
roll();
}
public void one() {
fill(0);
ellipse(375, 375, 100, 100);
noFill();
}
public void two() {
fill(0);
ellipse(525, 225, 100, 100);
ellipse(225, 525, 100, 100);
noFill();
}
public void three() {
fill(0);
ellipse(375, 375, 100, 100);
ellipse(525, 225, 100, 100);
ellipse(225, 525, 100, 100);
noFill();
}
public void four() {
fill(0);
ellipse(525, 225, 100, 100);
ellipse(225, 525, 100, 100);
ellipse(525, 525, 100, 100);
ellipse(225, 225, 100, 100);
noFill();
}
public void five() {
fill(0);
ellipse(375, 375, 100, 100);
ellipse(525, 225, 100, 100);
ellipse(225, 525, 100, 100);
ellipse(525, 525, 100, 100);
ellipse(225, 225, 100, 100);
noFill();
}
public void six() {
fill(0);
ellipse(525, 225, 100, 100);
ellipse(225, 525, 100, 100);
ellipse(525, 525, 100, 100);
ellipse(225, 225, 100, 100);
ellipse(525, 375, 100, 100);
ellipse(225, 375, 100, 100);
noFill();
}
public void roll() {
if (mousePressed && x > 100 && x < 650 && y > 700 && y < 850) {
diceChoose = random.nextInt(6);
if (diceChoose == 0) {
one();
}
else if (diceChoose == 1) {
two();
}
else if (diceChoose == 2) {
three();
}
else if (diceChoose == 3) {
four();
}
else if (diceChoose == 4) {
five();
}
else if (diceChoose == 5) {
six();
}
}
}
你是什麼意思,它有什麼有點不對? –
我沒有意識到我可以在發佈評論前編輯帖子。 –