在这里,我创建了一个游戏,您可以在其中掷骰子并一次绘制一个错误。这是 什么卷的列表可以为您提供哪些部分以及您需要的数量。
您必须点击身体部位附近的屏幕才能显示出来。然后我们 可以计时整件事。
我使用deltaT来设置计时器,但doTime方法给我一个错误。
我想要的是让时间在屏幕的底部移动。
主程序
package dice;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.Timer;
public class Yahtzee extends JFrame implements ActionListener {
Die[] d; // array to hold the 5 dice
FourOfAKind[] f;
JPanel dicePanel; // panel to hold the dice
JPanel bugPanel;
ScoreRow[] theScores;
javax.swing.Timer time; // generates ticks that drive the animation
protected double deltaT = 0.020; // how much time for each tick
protected Object bug;
public static void main(String[] args) {
Yahtzee y = new Yahtzee();
}
public Yahtzee() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
setLayout(new BorderLayout());
time = new javax.swing.Timer((int) (1000 * deltaT), this);
time.start();
dicePanel = new JPanel();
dicePanel.setLayout(new GridLayout(5, 1));
dicePanel.setLayout(new FlowLayout());
dicePanel.setSize(new Dimension(50, 50));
add(dicePanel, BorderLayout.CENTER);
d = new Die[1];
for (int i = 0; i < 1; i++) {
d[i] = new Die(this);
dicePanel.add(d[i]);
}
bugPanel = new JPanel();
bugPanel.setLayout(new GridLayout(5, 5));
bugPanel.setLayout(new FlowLayout());
bugPanel.setSize(new Dimension(50, 50));
add(bugPanel, BorderLayout.SOUTH);
f = new FourOfAKind[1];
for (int w = 0; w < 1; w++) {
f[w] = new FourOfAKind(this);
bugPanel.add(f[w]);
}
setSize(new Dimension(715, 705));
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == time) {
doTime();
}
repaint();
}
public void setChoice(int choice) {
f[0].setChoice(choice);
}
public void drawBug() {
f[0].setChoice(d[0].getChoice());
f[0].drawBug();
}
public void doTime() {
for (int i = 0; i < blueCounter; i++) {
f[i].move(deltaT);
}
}
}