1.项目简介 计算机产生随机数,猜中即胜,猜不中,提示是大了还是小了,继续猜,直至猜到,给出所用时间。保留用户测试成绩,做出成绩排行榜。排行榜存放到文件中。 2.实现功能:系统生成随机数;玩家输入数字;输出排行榜;计时。 3.功能架构图 4.详细代码 GameView.java import javax.swing.*; import java.awt.*; import java.util.ArrayList; import java.util.List; import java.util.Random; public class GameView extends JFrame { //开始界面组件 JLabel welcome; JButton about,instructions,gaming,hardSet; JPanel panelStart,panelGame; Font font = new Font("华文琥珀",Font.BOLD,56); //游戏界面组件 JTextField input ; JLabel used,left; JButton submit; //答案 int answer; // 答案 Listener listener = new Listener(); GameView() { //创建窗口 this.setTitle("猜数字游戏"); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); gameStart(); this.setLocation(300, 300); this.setSize(450,300); this.setVisible(true); listener.setView(this); } public void gameStart() { //初始化开始界面 welcome = new JLabel(" 开始游戏 "); welcome.setPreferredSize(new Dimension(200,200)); welcome.setFont(font); about = new JButton("排行榜"); about.setBackground(Color.LIGHT_GRAY); instructions = new JButton("说明"); instructions.setBackground(Color.LIGHT_GRAY); gaming = new JButton("开始游戏"); gaming.setBackground(Color.pink); hardSet = new JButton(); Box boxNorth = Box.createHorizontalBox(); boxNorth.add(about); boxNorth.add(instructions); this.add(boxNorth,BorderLayout.NORTH); this.add(welcome,"Center"); this.add(gaming,"South"); gaming.addActionListener(listener); about.addActionListener(listener); instructions.addActionListener(listener); hardSet.addActionLi
项目:猜数游戏
于 2022-06-17 14:01:43 首次发布
这是一个使用Java Swing编写的猜数字游戏,游戏中系统生成0-100的随机数,玩家通过输入猜测并获取提示,直到猜中为止。游戏记录玩家的用时,并生成排行榜,排行榜数据存储在文本文件中。代码包括GameView类用于界面展示和交互,Listener类用于监听按钮事件,Leaderboard类用于存储玩家成绩。
摘要由CSDN通过智能技术生成