为女儿认识英文写的一款Flash游戏(简易打字)

运行截图:
这里写图片描述

游戏简介:
游戏运行后,其界面上会随机出现英文字母(区分大小写),游戏者需要按下与该字母相对应的键盘键(支持组合键)。软件下方将显示用户按键操作的正确与错误次数。
设计手稿:
这里写图片描述
源代码:
http://download.csdn.net/detail/jiller/8900587

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这里是一个简单的打字游戏示例,使用Java Swing编。 ```java import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.Timer; public class TypingGame extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; private static final int WIDTH = 600; private static final int HEIGHT = 400; private JLabel scoreLabel; private JLabel timeLabel; private JTextField textField; private JPanel gamePanel; private int score; private int timeLeft; private Timer timer; private Random random; private String[] words = { "java", "programming", "computer", "language", "algorithm", "software" }; public TypingGame() { super("Typing Game"); setPreferredSize(new Dimension(WIDTH, HEIGHT)); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel mainPanel = new JPanel(new BorderLayout()); scoreLabel = new JLabel("Score: 0"); scoreLabel.setFont(new Font("Arial", Font.BOLD, 16)); scoreLabel.setForeground(Color.BLUE); mainPanel.add(scoreLabel, BorderLayout.NORTH); gamePanel = new JPanel(); gamePanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); mainPanel.add(gamePanel, BorderLayout.CENTER); timeLabel = new JLabel("Time left: 30"); timeLabel.setFont(new Font("Arial", Font.BOLD, 16)); timeLabel.setForeground(Color.RED); mainPanel.add(timeLabel, BorderLayout.SOUTH); textField = new JTextField(20); textField.setFont(new Font("Arial", Font.PLAIN, 16)); textField.addActionListener(this); gamePanel.add(textField); add(mainPanel); pack(); setLocationRelativeTo(null); score = 0; timeLeft = 30; random = new Random(); timer = new Timer(1000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { timeLeft--; timeLabel.setText("Time left: " + timeLeft); if (timeLeft == 0) { endGame(); } } }); timer.start(); newWord(); } private void newWord() { String word = words[random.nextInt(words.length)]; gamePanel.removeAll(); gamePanel.add(new JLabel(word)); textField.setText(""); pack(); } private void endGame() { timer.stop(); textField.setEnabled(false); gamePanel.removeAll(); gamePanel.add(new JLabel("Game over!")); pack(); } @Override public void actionPerformed(ActionEvent e) { String input = textField.getText().trim(); String word = ((JLabel) gamePanel.getComponent(0)).getText(); if (input.equals(word)) { score++; scoreLabel.setText("Score: " + score); newWord(); } else { textField.setText(""); } } public static void main(String[] args) { TypingGame game = new TypingGame(); game.setVisible(true); } } ``` 这个游戏有一个单词列表,每次随机选择一个单词并将其显示在屏幕上。玩家必须在文本框中输入正确的单词,以赚取分数。游戏时间为30秒,计时器会在游戏结束时停止。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值