一、界面预览
1.登录页面
点击验证码可更换验证码,点击查看密码可查看输入的密码
2.注册界面
点击注册即可以新用户身份进入游戏
注:
初始用户信息为
用户名:hangman
密码:123456
点击重置即可重新输入密码账号重新注册
3.游戏界面
按下键盘上下左右即可进行移动操作并计算移动的步数.
功能预览:
点击更换图片即可变换图片进行游戏,重新登录回到登录页面,重新开始游戏步数清零打乱图片顺序继续游戏,点击关闭即可退出游戏
4.游戏胜利
游戏结束点击重新开始游戏即可继续游戏
二、 创建环境
- 文件结构
test文件夹为本人测试使用可不创建
2.资源图片结构
二、代码实现
1.主类
此类主要用来启动游戏
代码如下:
import com.PinTu.UI.Login;
public class Main {
//作为界面的启动清单
public static void main(String[] args) {
new Login();
}
}
2.登录页面
此类用来用户登录游戏并实现了新用户注册功能
1.主页面
public void initFrame(){
this.setSize(488, 430);//设置宽高
this.setTitle("登录账号");//设置标题
this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);//设置关闭模式
this.setLocationRelativeTo(null);//居中
this.setAlwaysOnTop(true);//置顶
this.setLayout(null);//取消内部默认布局
}
2.定义组件
JTextField UserjTextField = new JTextField();//用户名输入框
JPasswordField passwordField = new JPasswordField();//用户密码输入框
JTextField code = new JTextField();//验证码输入框
JButton loginButton = new JButton();//登录按钮
JButton enrollButton = new JButton();//注册按钮
JLabel seelabel = new JLabel();
//验证码区域
JLabel rightCode = new JLabel();
3.页面内容
public void initView() {
//添加用户名标签
JLabel UserjLabel = new JLabel(new ImageIcon("......\\PinTu\\image\\login\\用户名.png"));
UserjLabel.setBounds(100, 140, 47, 17);
this.getContentPane().add(UserjLabel);
//添加输入框
UserjTextField.setBounds(195, 134, 200, 30);
this.getContentPane().add(UserjTextField);
//添加密码标签
JLabel PawjLabel = new JLabel(new ImageIcon("E:\\JavaProject\\PinTu\\image\\login\\密码.png"));
PawjLabel.setBounds(110, 200, 32, 16);
this.getContentPane().add(PawjLabel);
//添加密码输入框
passwordField.setBounds(195, 195, 200, 30);
passwordField.setEchoChar('*');
this.getContentPane().add(passwordField);
//密码显示
seelabel.setIcon(new ImageIcon("......\\PinTu\\image\\login\\显示密码.png"));
seelabel.setBounds(400,195,50,30);
seelabel.addMouseListener(this);
this.getContentPane().add(seelabel);
//验证码提示
JLabel codeText = new JLabel(new ImageIcon("......\\PinTu\\image\\login\\验证码.png"));
codeText.setBounds(100, 256, 50, 30);
this.getContentPane().add(codeText);
//验证码的输入框
code.setBounds(195, 256, 100, 30);
this.getContentPane().add(code);
//生成5个随机验证码
String codeStr = CodeUtil.Create(5);
//设置内容
rightCode.setText(codeStr);
//绑定鼠标事件
rightCode.addMouseListener(this);
//位置和宽高
rightCode.setBounds(300, 256, 50, 30);
//添加到界面
this.getContentPane().add(rightCode);
//设置登录按钮
loginButton.setBounds(123, 310, 128, 47);
ImageIcon icon1 = new ImageIcon(".....\\image\\login\\登录按钮.png");
loginButton.setIcon(icon1);
//去除按钮的边框
loginButton.setBorderPainted(false);
//去除按钮的背景
loginButton.setContentAreaFilled(false);
loginButton.addMouseListener(this);
this.getContentPane().add(loginButton);
//设置注册按钮
enrollButton.setBounds(256, 310, 128, 47);
ImageIcon icon2 = new ImageIcon("......\\PinTu\\image\\login\\注册按钮.png");
enrollButton.setIcon(icon2);
//去除按钮的边框
enrollButton.setBorderPainted(false);
//去除按钮的背景
enrollButton.setContentAreaFilled(false);
enrollButton.addMouseListener(this);
this.getContentPane().add(enrollButton);
//创建背景色
JLabel back = new JLabel(new ImageIcon("......\\PinTu\\image\\login\\background.png"));
back.setBounds(0, 0, 470, 390);
this.getContentPane().add(back);
}
4.弹窗设置
public void showDialog(String str){
JDialog dialog = new JDialog();
dialog.setSize(180,150);
//让弹框置顶
dialog.setAlwaysOnTop(true);
//让弹框居中
dialog.setLocationRelativeTo(null);
//弹框不关闭永远无法操作下面的界面
dialog.setModal(true);
JLabel warning = new JLabel(str);
//让显示的文字居中
warning.setHorizontalAlignment(JLabel.CENTER);
warning.setBounds(0, 0, 200, 150);
dialog.getContentPane().add(warning);
//让弹框展示出来
dialog.setVisible(true);
}
3.登录页面逻辑实现
鼠标点击监听
@Override
public void mouseClicked(MouseEvent m) {
if (m.getSource() == loginButton){
System.out.println("用户点击登录按钮");
String name = UserjTextField.getText();
String paw = passwordField.getText();
//获取验证码
String codeInput = code.getText();
UserInfo user = new UserInfo(name,paw);
System.out.println("用户输入的用户名为:"+name);
System.out.println("用户输入的密码为:"+paw);
if (codeInput.length() == 0 && name.length() !=0 && paw.length() !=0){
System.out.println("用户验证码为空!");
showDialog("验证码不能为空!");
String code = CodeUtil.Create(5);//创建一个5位长度的随机验证码
rightCode.setText(code);
}else if (name.length() ==0 || paw.length() == 0){
System.out.println( "用户名或者密码为空");
showDialog("用户名或者密码为空");
String code = CodeUtil.Create(5);
rightCode.setText(code);
//判断输入的验证码与生成的验证码是否相同
} else if (!codeInput.equalsIgnoreCase(rightCode.getText())) {
showDialog("验证码输入错误");
String code = CodeUtil.Create(5);
rightCode.setText(code);
}else if(contains(user)){
System.out.println("用户输入账号正确,登录成功!");
//关闭登陆界面
this.setVisible(false);
new Game();
}else {
System.out.println("用户名或密码错误");
showDialog("用户名或密码错误");
String code = CodeUtil.Create(5);
rightCode.setText(code);
}
}
//更换验证码
if(m.getSource() == rightCode){
System.out.println("更换验证码!");
String code = CodeUtil.Create(5);
rightCode.setText(code);
}
//进入注册页面
if(m.getSource() == enrollButton){
System.out.println("用户注册");
this.dispose();
new Register();
}
}
鼠标长按监听
//鼠标长按
@Override
public void mousePressed(MouseEvent m) {
if (m.getSource() == loginButton){
loginButton.setIcon(new ImageIcon("......\\PinTu\\image\\login\\登录按下.png"));
}else if (m.getSource() == enrollButton){
enrollButton.setIcon(new ImageIcon("......\\PinTu\\image\\login\\注册按下.png"));
} //显示查看密码
else if (m.getSource() == seelabel){
seelabel.setIcon(new ImageIcon("......\\PinTu\\image\\login\\显示密码按下.png"));
passwordField.setEchoChar((char)0);
}
}
鼠标松开监听
//松开按钮
@Override
public void mouseReleased(MouseEvent m) {
if (m.getSource() == loginButton){
loginButton.setIcon(new ImageIcon("......\\PinTu\\image\\login\\登录按钮.png"));
}else if (m.getSource() == enrollButton){
enrollButton.setIcon(new ImageIcon("......\\PinTu\\image\\login\\注册按钮.png"));
} else if (m.getSource() == seelabel){
seelabel.setIcon(new ImageIcon("......\\PinTu\\image\\login\\显示密码.png"));
passwordField.setEchoChar('*');
}
}
**
验证码生成
import java.util.Random;
public class CodeUtil {
public static String Create(int n){
String code = "";
Random r = new Random();//随机生成
for (int i = 0; i < n; i++) {
int type =r.nextInt(3);//随机生成三个数字
switch (type){
case 0:
//大写字符
//A-Z
char ch = (char)(r.nextInt(26)+65);//生成的数字加上就等于大写字符的Ascii
code += ch;
break;
case 1:
//小写字符
// a-z
char ch1 = (char)(r.nextInt(26)+97);
code += ch1;
break;
case 2:
//数字字符
code +=r.nextInt(10);
break;
}
}
return code;
}
}
4.用户信息
1.存储用户信息
public static ArrayList<UserInfo> userInfoArrayList = new ArrayList<>();
{
userInfoArrayList.add(new UserInfo("hangman","123456"));
for (UserInfo userInfo : userInfoArrayList) {
System.out.println("用户信息:"+userInfo.getName()+" "+userInfo.getPaw());
System.out.println("--------------------------------------------");
}
}
2.核对用户信息
public boolean contains(UserInfo userInfo){
//for增强
for (UserInfo rightuser : userInfoArrayList) {
//集合user
if (userInfo.getName().equals(rightuser.getName()) && userInfo.getPaw().equals(rightuser.getPaw())) {
//相同则通过进行下一步
return true;
}
}
return false;
}
3.用户信息类
public class UserInfo {
private String name;
private String paw;
public UserInfo(String name, String paw) {
this.name = name;
this.paw = paw;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPaw() {
return paw;
}
public void setPaw(String paw) {
this.paw = paw;
}
}
6.游戏界面
import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;
public class Game extends JFrame implements KeyListener,ActionListener {
String path = "......\\PinTu\\image\\animal\\animal3\\";
//定义图片的类型
int[][] data = new int[4][4];
//记录白色方块的位置
int x = 0,y = 0;
//计算移动的步数
int count = 0;
//单个功能下的再功能
JMenuItem girl = new JMenuItem("女生");
JMenuItem animal = new JMenuItem("动物");
JMenuItem sport = new JMenuItem("运动");
JMenuItem replayItem = new JMenuItem("重新游戏" );
JMenuItem reLoginItem = new JMenuItem("重新登录");
JMenuItem nameItem = new JMenuItem("联系方式");
JMenuItem CloseItem = new JMenuItem("关闭游戏");
int[][] win = new int[][]{
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16}
};
public Game() {
//主界面
super();
initJFrame();
//初始化菜单
initJMenuBar();
//初始化主要数据
initData();
//初始化图片
initImage();
this.setVisible(true);
}
//随机打乱数组
private void initData(){
int[] tempArr = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
Random r = new Random();
for (int i = 0; i < tempArr.length; i++) {
//获取到随机索引
int index = r.nextInt(tempArr.length);
int temp = tempArr[i];
tempArr[i] = tempArr[index];
tempArr[index] = temp;
}
for (int i = 0; i < tempArr.length; i++) {
if (tempArr[i] == 0){
x = i / 4;
y = i % 4;
}else {
data[i / 4][i % 4] = tempArr[i];
}
}
}
//使用二维数组中的数据添加管理
private void initImage(){
//清除已经出现的图片
this.getContentPane().removeAll();
//如果拼图完成则出现成功的界面
if(Win()){
JLabel win = new JLabel(new ImageIcon("......\\PinTu\\image\\win.png"));
win.setBounds(203,283,197,73);
this.getContentPane().add(win);
}
JLabel countable = new JLabel("步数:"+count);
countable.setBounds(80,40,100,100);
this.getContentPane().add(countable);
//for方法循环放置快速拼接图片
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
int num = data[i][j];
//管理容器
JLabel jLabel = new JLabel(new ImageIcon(path + num + ".jpg"));
//添加到指定的位置
jLabel.setBounds(105 * j + 83,105 * i + 123,105,105);
jLabel.setBorder(new BevelBorder(BevelBorder.LOWERED));//加边框美化
this.getContentPane().add(jLabel);
}
}
JLabel back = new JLabel(new ImageIcon("......\\PinTu\\image\\background.png"));
back.setBounds(40,30,508,560);
this.getContentPane().add(back);
//刷新界面
this.getContentPane().repaint();
}
private void initJMenuBar(){
//整个菜单
JMenuBar jMenuBar = new JMenuBar();
//创建菜单的单个功能
JMenu functionMenu = new JMenu("功能");
JMenu aboutMenu = new JMenu("关于我们");
JMenu changeImage = new JMenu("更换图片");
//将功能加入到选项下方
functionMenu.add(changeImage);
functionMenu.add(replayItem);
functionMenu.add(reLoginItem);
functionMenu.add(CloseItem);
changeImage.add(girl);
changeImage.add(animal);
changeImage.add(sport);
aboutMenu.add(aboutMenu);
aboutMenu.add(nameItem);
jMenuBar.add(functionMenu);
jMenuBar.add(aboutMenu);
replayItem.addActionListener(this);
reLoginItem.addActionListener(this);
nameItem.addActionListener(this);
CloseItem.addActionListener(this);
//更换图片添加监听器
girl.addActionListener(this);
animal.addActionListener(this);
sport.addActionListener(this);
this.setJMenuBar(jMenuBar);
}
private void initJFrame(){
this.setSize(603,680);
this.setTitle("拼图单机版 v1.0");
this.setAlwaysOnTop(true);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.addKeyListener(this);
}
/*
* case 37:
return Toolkit.getProperty("AWT.left", "Left");
case 38:
return Toolkit.getProperty("AWT.up", "Up");
case 39:
return Toolkit.getProperty("AWT.right", "Right");
case 40:
return Toolkit.getProperty("AWT.down", "Down");
* */
@Override
public void keyTyped(KeyEvent e) {
}
// 按下不松手时调用该方法
@Override
public void keyPressed(KeyEvent e) {
int code = e.getKeyCode();
if(code == 65){
//清除界面的所有图片
this.getContentPane().removeAll();
//加载第一张完整的图片
JLabel all = new JLabel(new ImageIcon(path + "all.jpg"));
all.setBounds(83,125,420,420);
this.getContentPane().add(all);
JLabel back = new JLabel(new ImageIcon("......\\PinTu\\image\\background.png"));
back.setBounds(40,30,508,560);
this.getContentPane().add(back);
//刷新界面
this.getContentPane().repaint();
}
}
@Override
public void keyReleased(KeyEvent e) {
// System.out.println(e.getKeyCode());
//对上下左右进行判断
//移动方法相对于白色方块所设定图片向左即白块向右
//上下与左右同理
int code = e.getKeyCode();
//code码如上
if(code == 37){
System.out.println(e.getKeyCode());
System.out.println("向左移动!");
if (y == 3){
return;
}
data[x][y] = data[x][y+1];
data[x][y+1] = 0;
y++;
count++;
initImage();
} else if (code == 39) {
System.out.println(e.getKeyCode());
System.out.println("向右移动!");
if (y == 0){
return;
}
data[x][y] = data[x][y-1];
data[x][y-1] = 0;
y--;
count++;
initImage();
} else if (code == 38) {
System.out.println(e.getKeyCode());
System.out.println("向上移动!");
//空白方块已经在最上面了
if (x == 3){
return;
}
data[x][y] = data[x+1][y];
data[x+1][y] = 0;
x++;
count++;
initImage();
} else if (code == 40) {
System.out.println(e.getKeyCode());
System.out.println("向下移动!");
if(x == 0){
return;
}
data[x][y] = data[x-1][y];
data[x-1][y] = 0;
x--;
count++;
initImage();
//松开A键后重新进入拼图状态
} else if (code == 65) {
initImage();
//作弊码
//点击“Ctrl+C 组合键直接获得游戏胜利”
} else if (e.isControlDown()) {
data = new int[][]{
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16}
};
initImage();
}
}
//该方法判断data中的数组顺序与win是否一致
//游戏胜利判断
public boolean Win(){
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data[i].length; j++) {
if(data[i][j] != win[i][j]){
return false;
}
}
}
//如果都一样则返回true
return true;
}
//获取鼠标事件
@Override
public void actionPerformed(ActionEvent e) {
Object obj = e.getSource();
if (obj == replayItem){
//点击重新开始游戏后出现弹窗
JDialog dialog = new JDialog();
JLabel jl = new JLabel("是否重新开始游戏");
jl.setBounds(90,10,100,100);
dialog.setTitle("警告");
dialog.setAlwaysOnTop(true);
dialog.setSize(300,220);
dialog.setLocationRelativeTo(null);
jl.setVisible(true);
dialog.setVisible(true);
//设置按钮
JButton jb1 = new JButton();
JButton jb2 = new JButton();
jb1.setText("是");
jb2.setText("否");
jb1.setBounds(80,80,50,30);
jb2.setBounds(140,80,50,30);
//监听”是“按钮
jb1.addActionListener(actionEvent -> {
//步数清零
count = 0;
//重新打乱图片顺序
initData();
//重新加载图片
initImage();
dialog.dispose();//点击按钮后关闭弹窗
});
//监听”否“按钮
jb2.addActionListener(actionEvent -> dialog.dispose());
dialog.getContentPane().add(jb1);
dialog.getContentPane().add(jb2);
dialog.getContentPane().add(jl);
System.out.println("重新游戏!");
} else if (obj == reLoginItem) {
System.out.println("重新登录!");
this.setVisible(false);
new Login();
} else if (obj == CloseItem) {
System.out.println("关闭游戏!");
System.exit(0);
}else if (obj == nameItem){
System.out.println("联系我们!");
//创建弹窗
JDialog jDialog =new JDialog();
JLabel jl =new JLabel(new ImageIcon("......\\PinTu\\image\\me.jpg"));
//设置大小
jl.setBounds(0,0,5,5);
jDialog.getContentPane().add(jl);
jDialog.setTitle("联系方式");
jDialog.setSize(300,380);
jDialog.setAlwaysOnTop(true);
jDialog.setLocationRelativeTo(null);
jDialog.setModal(true);
jDialog.setVisible(true);
}
//判断更换图片的点击事件
if(obj == girl){
Random r = new Random();
int num = r.nextInt(10)+1;
count = 0;
path = "......\\PinTu\\image\\girl\\girl"+num+"\\";
//随机放置图片
initData();
initImage();
}
if(obj == animal){
Random r = new Random();
int num = r.nextInt(8)+1;
count = 0;
path = "......\\PinTu\\image\\animal\\animal"+num+"\\";
//随机放置图片
initData();
initImage();
}
if(obj == sport){
Random r = new Random();
int num = r.nextInt(10)+1;
count = 0;
path = "......\\PinTu\\image\\sport\\sport"+num+"\\";
//随机放置图片
initData();
initImage();
}
}
}
7.注册界面
import com.PinTu.user.UserInfo;
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class Register extends JFrame implements MouseListener {
JTextField registeruser = new JTextField();
JPasswordField registerpaw = new JPasswordField();
JPasswordField registerpaw2 = new JPasswordField();
JButton registerbutton = new JButton();
JButton returnbutton = new JButton();
//注册界面
public Register() {
//主页面
initFrame();
//初始化页面
initview();
}
public void initview(){
JLabel registerUser = new JLabel(new ImageIcon("......\\PinTu\\image\\register\\注册用户名.png"));
registerUser.setBounds(100, 140, 80, 17);
this.getContentPane().add(registerUser);
//添加输入框
registeruser.setBounds(195, 134, 200, 30);
this.getContentPane().add(registeruser);
//添加密码标签
JLabel PawjLabel = new JLabel(new ImageIcon("......\\PinTu\\image\\register\\注册密码.png"));
PawjLabel.setBounds(100, 200, 80, 17);
this.getContentPane().add(PawjLabel);
//添加注册输入框
registerpaw.setBounds(195, 195, 200, 30);
this.getContentPane().add(registerpaw);
JLabel PawjLabel2 = new JLabel(new ImageIcon("......\\PinTu\\image\\register\\再次输入密码.png"));
PawjLabel2.setBounds(70, 255, 120, 20);
this.getContentPane().add(PawjLabel2);
//添加再次注册输入框
registerpaw2.setBounds(195, 250, 200, 30);
this.getContentPane().add(registerpaw2);
//注册按钮
registerbutton.setBounds(123, 310, 128, 47);
ImageIcon icon1 = new ImageIcon("......\\PinTu\\image\\register\\注册按钮.png");
registerbutton.setIcon(icon1);
//去除按钮的边框
registerbutton.setBorderPainted(false);
//去除按钮的背景
registerbutton.setContentAreaFilled(false);
registerbutton.addMouseListener(this);
this.getContentPane().add(registerbutton);
//设置重置按钮
returnbutton.setBounds(256, 310, 128, 47);
ImageIcon icon2 = new ImageIcon("......\\PinTu\\image\\register\\重置按钮.png");
returnbutton.setIcon(icon2);
//去除按钮的边框
returnbutton.setBorderPainted(false);
//去除按钮的背景
returnbutton.setContentAreaFilled(false);
returnbutton.addMouseListener(this);
this.getContentPane().add(returnbutton);
JLabel back = new JLabel(new ImageIcon("......\\PinTu\\image\\login\\background.png"));
back.setBounds(0, 0, 470, 390);
this.getContentPane().add(back);
}
public void initFrame(){
this.setSize(488, 430);//设置宽高
this.setTitle("注册账号");//设置标题
this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);//设置关闭模式
this.setLocationRelativeTo(null);//居中
this.setAlwaysOnTop(true);//置顶
this.setLayout(null);//取消内部默认布局
this.setVisible(true);
}
//单击鼠标
@Override
public void mouseClicked(MouseEvent m) {
if (m.getSource() == registerbutton){
if(registerpaw.getText().equals(registerpaw2.getText())) {
System.out.println("用户注册成功!");
for (UserInfo userInfo : Login.userInfoArrayList) {
System.out.println("当前用户信息:"+userInfo.getName()+" "+userInfo.getPaw());
}
String name = registeruser.getText();
String paw = registerpaw.getText();
Login.userInfoArrayList.add(new UserInfo(name, paw));
System.out.println("用户添加成功!");
this.dispose();
new Login();
} else {
JDialog dialog = new JDialog();
dialog.setSize(180,150);
//让弹框置顶
dialog.setAlwaysOnTop(true);
//让弹框居中
dialog.setLocationRelativeTo(null);
//弹框不关闭永远无法操作下面的界面
dialog.setModal(true);
JLabel warning = new JLabel("两次输入的密码不一致!");
//让显示的文字居中
warning.setHorizontalAlignment(JLabel.CENTER);
warning.setBounds(0, 0, 200, 150);
dialog.getContentPane().add(warning);
//让弹框展示出来
dialog.setVisible(true);
}
} else if (m.getSource() == returnbutton) {
System.out.println("重置用户注册信息");
registeruser.setText("");
registerpaw.setText("");
registerpaw2.setText("");
}
}
@Override
public void mousePressed(MouseEvent m) {
if (m.getSource() == registerbutton){
registerbutton.setIcon(new ImageIcon("......\\PinTu\\image\\register\\注册按下.png"));
}else if (m.getSource() == returnbutton){
returnbutton.setIcon(new ImageIcon("......\\PinTu\\image\\register\\重置按下.png"));
}
}
@Override
public void mouseReleased(MouseEvent m) {
if (m.getSource() == registerbutton){
registerbutton.setIcon(new ImageIcon("E:\\JavaProject\\PinTu\\image\\register\\注册按钮.png"));
}else if (m.getSource() == returnbutton){
returnbutton.setIcon(new ImageIcon("......\\PinTu\\image\\register\\重置按钮.png"));
}
}
@Override
public void mouseEntered(MouseEvent m) {
}
@Override
public void mouseExited(MouseEvent m) {
}
}
8. 作弊码及还原图片功能
在正常游戏的基础上加入了作弊码,以及还原图片的功能
还原图片代码如下:
public void keyPressed(KeyEvent e) {
int code = e.getKeyCode();
if(code == 65){
//清除界面的所有图片
this.getContentPane().removeAll();
//加载第一张完整的图片
JLabel all = new JLabel(new ImageIcon(path + "all.jpg"));
all.setBounds(83,125,420,420);
this.getContentPane().add(all);
JLabel back = new JLabel(new ImageIcon("......\\PinTu\\image\\background.png"));
back.setBounds(40,30,508,560);
this.getContentPane().add(back);
//刷新界面
this.getContentPane().repaint();
}
}
作弊代码如下:文章来源:https://www.toymoban.com/news/detail-490047.html
//”按下“Ctrl+C“ 组合键直接获得游戏胜利”
if (e.isControlDown()) {
data = new int[][]{
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16}
};
//重置图片
initImage();
}
三、总结
该拼图游戏实现了登录,注册功能,记录游戏步数,作弊功能,菜单功能。文章来源地址https://www.toymoban.com/news/detail-490047.html
到了这里,关于Java实现简单的登录,注册拼图游戏的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!