类Main.java
public class classMain
{
public static classCall classCallObject;
public static void main(String[] args)
{
classCallObject = new classCall();
classCallObject.calling();
}
}
类调用.java
import java.awt.CardLayout;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class classCall extends JFrame
{
public JFrame frame;
public JPanel cards;
public CardLayout cardlayout = new CardLayout();
public static classEngine engObject = new classEngine();
public void calling()
{
frame = new JFrame();
frame.setVisible(true);
frame.setLayout(new FlowLayout());
frame.setTitle("Cricket Game 2012");
frame.setSize(1024, 740);
frame.setResizable(false);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
gui guiObject = new gui();
frame.add(guiObject.totalScore);
}
}
gui.java
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class gui extends JFrame
{
public JLabel totalScore;
public gui()
{
classCall.engObject.gameEngine();
totalScore = new JLabel(String.format("Total is %d - %d", classCall.engObject.getTotal(), classCall.engObject.getWickets()));
totalScore.setLayout(new FlowLayout());
}
}
类引擎.java
import java.util.Random;
public class classEngine
{
public int[][] Overs = new int[20][6];
public static int total=0;
public static int wickets=0;
public void gameEngine()
{
for (int over=1; over<Overs.length;over++)
{
for (int ball=1; ball<Overs[over].length; ball++)
{
Overs[over][ball] = batsmanNormalNormal();
total=total + Overs[over][ball];
}
}
}
public int batsmanNormalNormal()
{
int x=0;
int randomNumber = 0;
Random randomObject = new Random();
randomNumber=randomObject.nextInt(100)+1;
if (randomNumber<=1 && randomNumber>=10)
x=4;
else if (randomNumber<=11 && randomNumber>=13)
{
x=0;
wickets++;
}
else if (randomNumber<=14 && randomNumber>=17)
x=1;
else if (randomNumber<=18 && randomNumber>=19)
x=1;
else if (randomNumber<=20 && randomNumber>=30)
x=2;
else if (randomNumber<=31 && randomNumber>=55)
x=1;
else if (randomNumber<=56 && randomNumber>=96)
x=0;
else if (randomNumber<=97 && randomNumber>=98)
x=6;
else if (randomNumber<=99 && randomNumber>=100)
x=3;
return x;
}
public int getTotal()
{
return total;
}
public int getWickets()
{
return wickets;
}
}
我试图创建一个刺激板球比赛的java代码。我知道你们很多人可能不知道这个游戏。基本上,我想做的是随机生成数字(加权概率 - 不是完全随机的)并将它们添加到一个名为 total 的静态 int 中。我想使用 JLabel 显示总计。
但是由于某种原因,总数没有更新。它说0-0。它应该给出其他结果,例如 140 或 200,因为我已经对其进行了编码,以将随机生成的数字添加到总数中。120 次。
我想我可能会遗漏一些东西。
我认为我的空白大脑无法读取 atm 是显而易见的。有人可以帮我吗?谢谢