- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 Boggle 项目存在一些逻辑错误,但无法查明它们。我唯一能做的就是退出这个令人难以置信的游戏。谁能帮我吗?在此程序中,每当单击 JMenu 项新游戏时,我需要开始一个新游戏,每次单击 Shake Dice 按钮时要随机化的字母,包含提交单词 Jbutton 以及分数和当前单词 jlabels 的 Jpanel,以及每当单击提交单词按钮并更新分数时,当前单词标签就会更新。
Boggle 用户界面代码:
package userInterface;
/**
*
* @author Zac
*/
import core.Board;
import core.Die;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
public class BoggleUi extends JFrame{
Board boggleBoard;//creating a board object
//components
private static JMenuBar menuBar;//declare menubar
private static JMenu Boggle;// declare Jmenu
private static JMenuItem game;// set menu item for game
private static JMenuItem exit;// set menu item for exit
//buttons
private static JButton Shakedice;//button for shaking the dice
private static JButton submitWord;// button to submit word
//layout of the UI
private JPanel diceButtons;//jpanel for the dice buttons
private JPanel componentLayout;//jpanel for other components
private JPanel wordPanel;// Jpanel for word related ui
private static JScrollPane scrollPane;//scrollpane
private static JTextArea textArea;//textarea
private static JLabel timeLeft;// Jlabel for countdown
private static JLabel timer;//label for above time left
private static JLabel wordsLeft;//label for words entered in text area
private static JLabel currentWord;//label for current word
private static JLabel playerScore;// label for score
private static JLabel dieButton;// label for dice button
//handlers
private GameListener gameListener;// listener for the Boggle game
private PanelListener panelListener;// listener for dice
//timer variables
int timeMili; //miliseconds
int timeMin;// minutes
int timeSec;//seconds
Timer countdownTimer;//timer
public BoggleUi(Board boggleBoard,ArrayList Readdictionary ){
this.boggleBoard = boggleBoard;//calls the boggle board
initComponents();
}
public void initComponents(){ //initialzes components
this.setSize(800,800);//set size of JFrame
this.setDefaultCloseOperation(EXIT_ON_CLOSE);//remove window if closed
menuBar = new JMenuBar();//creates a menu bar
Boggle = new JMenu("Boggle");
game = new JMenuItem("New Game");// menu item for new game
exit = new JMenuItem("Exit");// menu item for exiting the game
exit.addActionListener(new ExitListener());//adding an action listener to the exit menu item
Boggle.add(game);
Boggle.add(exit);
menuBar.add(Boggle);
this.setJMenuBar(menuBar);
//actionlistener
gameListener = new GameListener();//make a new game listener
game.addActionListener(gameListener);//add game listener
panelListener = new PanelListener();//make new panel listener
Boggle.addActionListener(panelListener);// add panel listener
Shakedice = new JButton("Shake Dice");
Shakedice.addActionListener(new ShakeListener());// make shake listener
submitWord = new JButton("Submit Word");
submitWord.addActionListener(new SubmitWordListener());// make submit listener
//inititialize timer and listener
countdownTimer = new Timer(1000, new TimerListener());//setting timer and listener
countdownTimer.start();// start timer
//set up textarea and jscroll pane and other components
Dicepanels();//set up for panels and components
textArea = new JTextArea();//creates new text area
textArea.setLineWrap(true);//wraps text
scrollPane = new JScrollPane(textArea);//creates new scroll pane
scrollPane.setMinimumSize(new Dimension(200, 300));// set minimum size
scrollPane.setPreferredSize(new Dimension(200, 300));// preferred size of scroll pane
scrollPane.setMaximumSize(new Dimension(400, 600));//set max size
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);//never allows horizontal bar
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);//calls for vertical bar
componentLayout.setLayout(new BoxLayout(componentLayout,BoxLayout.Y_AXIS));//sets to y axis
componentLayout.add(wordsLeft);
componentLayout.add(scrollPane);//appears after a certain amount of lines are entered
componentLayout.add(timer);// adds time left label
componentLayout.add(timeLeft);//adds time label
componentLayout.add(Shakedice);//adds shake dice button
this.add(diceButtons);//adds dice buttons
this.add(componentLayout,BorderLayout.EAST);//adds the components
this.add(wordPanel,BorderLayout.SOUTH);//adds word panel
this.setVisible(true);// makes the entire jframe visible
}
private JFrame getThisParent(){// method to retrieve the JFrame
return this;
}
//code for text area
public void updateText(String boggleData){//method to update the text
textArea.append(boggleData+ "\n");
textArea.setCaretPosition(textArea.getDocument().getLength());
}
//area to place dice buttons and other components
private void Dicepanels() {
//setup dice buttons
diceButtons = new JPanel(new GridLayout(4, 4));// set buttons in a 4x4 grid
diceButtons.setMinimumSize(new Dimension(400, 400));//set minimum size
diceButtons.setPreferredSize(new Dimension(400, 400));//set preferred size
//setup components
componentLayout = new JPanel();
wordsLeft = new JLabel("Enter Words Found");
timer = new JLabel("Time Left");
timeLeft = new JLabel("3:00");//JLabel for timer
timeLeft.setMinimumSize(new Dimension(500,500));//sets size for label
Shakedice = new JButton("Shake Dice");
//dimensions for the shake dice button
Shakedice.setMinimumSize(new Dimension(120, 60));
Shakedice.setPreferredSize(new Dimension(120, 60));
Shakedice.setMaximumSize(new Dimension(120, 60));
Shakedice.setFont(null);//font size
//setup Word panel
wordPanel = new JPanel();
currentWord = new JLabel();// label to show current word
playerScore = new JLabel("Score:" + "0");// label that shows the player's score
submitWord = new JButton("Submit Word");
//dimensions for the submit word button
submitWord.setMinimumSize(new Dimension(100, 50));
submitWord.setPreferredSize(new Dimension(100, 50));
submitWord.setMaximumSize(new Dimension(100, 50));
submitWord.setFont(null);//font size
//JButton ArrayList
ArrayList <Die> dice = boggleBoard.shakeDice();
int counter = 0;
for(int row = 0; row < 4; row++){
for(int col = 0; col < 4; col++){
Die die = dice.get(counter);
JButton button = new JButton();
button.setText(die.getLetter());
button.putClientProperty("letter",die.getLetter());
button.putClientProperty("row",row);
button.putClientProperty("col",col);
diceButtons.add(button);
diceButtons.setFont(null);
counter++;
}
}
}
private class ExitListener implements ActionListener { //action for exiting
public void actionPerformed(ActionEvent e)
{
//dialogue to confirm quiting the game
int response = JOptionPane.showConfirmDialog(null, "Confirm to exit Boggle?",
"Exit?", JOptionPane.YES_NO_OPTION);
if (response == JOptionPane.YES_OPTION)
System.exit(0);//exit game
}
}
private class GameListener implements ActionListener{//implement actionlistener for game
public void actionPerformed(ActionEvent e){
textArea.revalidate();//revailidate text area
timeLeft.repaint(); //repaint time left Jpanel
Shakedice.setEnabled(true);//reenable shake dice button
}
}
private class ShakeListener implements ActionListener{
public void actionPerformed(ActionEvent e){
boggleBoard.shakeDice();//call shake dice method into shake listener
//Random randomDie = new Random();//new radomization
//String placement = randomDie.(diceButtons);
diceButtons.revalidate();// revalidates dice buttons
playerScore.repaint();//reset score
playerScore.setText("Score:" + "0");// set to 0
currentWord.repaint();// reset current word
timeLeft.repaint();// reset timer
Shakedice.setEnabled(false);//disable shake dice button
}
}
private class SubmitWordListener implements ActionListener{
boolean wordValidate = false;
public void actionPerformed(ActionEvent e){
if(wordValidate = true){
System.out.println("TemporaryDictionary.txt");
textArea.append("" + currentWord);
currentWord.revalidate();//update current word j label
}
}
}
private class PanelListener implements ActionListener{
public void actionPerformed(ActionEvent e){
ArrayList <JButton> buttons = new ArrayList<JButton>();
if(e.getSource()instanceof JButton){
//create Jbutton with get properties
JButton button = (JButton)e.getSource();
String letter = button.getClientProperty("letter").toString();
int rowClick = (int) button.getClientProperty("row");
int colClick = (int) button.getClientProperty("col");
//get text in label
String word = currentWord.getText();
currentWord.setText(word + letter);
int MIN_INDEX = 0;// minimum index
int MAX_INDEX = 3;// maximum index
// enable/disable the buttons
int count = 0;
for(int row = 0; row < 4;)
for(int col = 0; col < 4;){
if(row == rowClick && col == colClick)
button.setEnabled(false);
if(colClick > MIN_INDEX && colClick < MAX_INDEX && rowClick > MIN_INDEX && rowClick < MAX_INDEX){
buttons.get(count).setEnabled(true);
count++;
}
}
}
}
}
private class TimerListener implements ActionListener{
public void actionPerformed(ActionEvent e){
timeMili -= 1000;
//conversion into minutes and seconds
if(timeSec == 0){
timeSec = 59;
timeMin --;
}
else{
timeSec --;
}
timeLeft.setText("3:00");//enable time left to start countdown
}
}
}
最佳答案
如果您在 Eclipse 等 IDE 中运行此程序,则可以放置 breakpoint ,然后运行您的应用程序并单步调试它,看看您的代码到底在做什么。
如果您无法访问调试器,您可以简单地使用 System.out.println()
调用来报告程序的当前状态 - 它并不优雅,但它可以工作。
关于java - 如何查明 Boggle 游戏中的逻辑错误以及如何修复它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31552159/
当我尝试加载库 Raster 时,我收到如下错误: 错误:inDL(x, as.logic(local), as.logic(now), ...) 中的“raster”的包或命名空间加载失败:无法加载
当我尝试加载库 Raster 时,我收到如下错误: 错误:inDL(x, as.logic(local), as.logic(now), ...) 中的“raster”的包或命名空间加载失败:无法加载
望着help section about_Comparison_Operators of PowerShell我是这样理解的: PS C:\> $false,$false -eq $true PS C
我刚刚修改了旧代码,现在似乎没有任何效果。请您指导我哪里出错了。 一些不起作用的事情是: 以前,焦点始终停留在屏幕上唯一的输入字段上。 (现在不行了),代码中的 if else 条件也不起作用。 On
请帮我找到一个使用普通 'ol javascript 的解决方案(我无法使用外部框架)。此外,CSS :hover 选择器不适用于现实世界的实现。 注册事件发生的事情设置所有调用最后注册事件数组项。
我想创建一个软件来为残障 child 交通规划公交路线(及其最佳载客量)。 这些总线具有以下规范: m 个座位(最多 7 个 - 因为有司机和助理) o 轮椅“座位”(最多 4 个) 固定的最大负载量
有人能帮我吗?似乎我的 for 逻辑根本不起作用,因为它一直在上午 12:00 返回我的开始时间 这是我的代码 Sub forlogic() Dim i As Single Dim t
我正在尝试设置 OR两个切片器过滤器之间的逻辑。两个切片器来自相同的数据集。以下是更多详细信息: 我的源表: 带切片器的视觉效果: 我的目标是,如果我从切片器 1 和切片器 2 中选择任何值,我的视觉
我有以下 C 语句: int res = x & (x ^ y); 有没有办法做同样的事情,但每次只使用一次x和y? 例如: x | (~x & y) == x | y 最佳答案 是的,通过扩展 xo
我正在创建 Azure 逻辑应用程序以将新的 Sharepoint 文件添加到 Azure Blob。 Sharepoint 由我的公司运行,我使用我的凭据登录来为逻辑应用程序创建 Sharepoin
我有一个问题要求为给定函数合成最简单的乘积表达式总和。基本上,如果 AB == CD,则函数为 1,否则为 0,结果如下: (!A && !B && !C && !D) || (!A && B &&
我正在尝试确定是否可以在不溢出的情况下计算两个 32 位整数的总和,同时仅使用某些按位运算符和其他运算符。因此,如果整数 x 和 y 可以相加而不会溢出,则以下代码应返回 1,否则返回 0。 ((((
处理乍一看需要许多嵌套 if 语句的复杂业务逻辑的好方法是什么? 例子: 折扣券。可能: 1a) 超值折扣 1b) 百分比折扣 2a) 正常折扣 2b) 累进折扣 3a) 需要访问优惠券 3b) 不需
假设我有一个“numbers”对象数组,其中包含“startNo”整数和“endNo”整数。 数组中可以有多个“数字”,我想获取一个包含修改对象的新数组,该数组仅具有不重叠的范围。 例如:如果数组有:
我在这个问题上遇到了困难。我正在使用 JavaScript。 我有一个文本区域,用于检测 @ 输入并将其位置存储在数组中。 var input = "@a @b @c" //textarea var
默认 IN 使用 OR 基本逻辑。有没有办法在范围内使用 AND 基本逻辑。 例如下面的查询 SELECT ItemId,CategoryID FROM ItemCategories WHERE Ca
我想在您将鼠标悬停在网站图像上时添加叠加层。我在这里实现了这个,它工作正常http://jsfiddle.net/stujLbjh/ 这是js代码: var divs = document.query
这个问题在这里已经有了答案: Which is faster: x>2 是否比 x>>31 快?换句话说,sar x, 2 是否比 sar x, 31 快?我做了一些简单的测试,他们似乎有相同的速度
我有grails criteriaQuery,我在这里再次检查OR逻辑,就像这样一个状态变量: or { eq("status", Status.ONE) eq("status",
我有grails criteriaQuery,我在这里再次检查OR逻辑,就像这样一个状态变量: or { eq("status", Status.ONE) eq("status",
我是一名优秀的程序员,十分优秀!