推荐一个打字游戏typespeed

typespeed是一个终端下的打字程序。

http://typespeed.sourceforge.net/

界面还是比较粗糙的,但是可以接受。

他内设有多个单词列表,尤其是有CSharp Keywords,非常适合程序员练手用。

单词列表可以编辑(/usr/share/typespeed/words)

每次打完可以看到一个rank。一般来说,正常人能够打到Average,而稍微练习一下,打到Good不难。

但要是想打到VeryGood、Pro、3133t,可就难上加难了。

转载于:https://www.cnblogs.com/fanhqme/archive/2012/05/22/2513814.html

好的,这里是一个简单的打字游戏示例,使用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、付费专栏及课程。

余额充值