当前位置: 首页 > news >正文

java面向对象实验——扫雷+24点

扫雷

窗口绘制:

GameWin

package com.sxt;import javax.swing.*;public class GameWin extends JFrame {void launch(){this.setVisible(true);this.setSize(500, 500);this.setLocationRelativeTo(null);this.setTitle("SWE23070扫雷游戏");this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public static void main(String[] args) {GameWin gameWin = new GameWin();gameWin.launch();}
}
//窗口绘制

雷区绘制: 

GameWin

package com.sxt;import javax.swing.*;
import java.awt.*;public class GameWin extends JFrame {MapBottom mapBottom = new MapBottom();void launch(){this.setVisible(true);this.setSize(500, 500);this.setLocationRelativeTo(null);this.setTitle("SWE23070扫雷游戏");this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}@Overridepublic void paint(Graphics g) {mapBottom.paintSelf(g);}public static void main(String[] args) {GameWin gameWin = new GameWin();gameWin.launch();}
}

MapBottom 

package com.sxt;import java.awt.*;public class MapBottom {void paintSelf(Graphics g){for (int i = 0; i < 500; i=i+50) {g.setColor(Color.red);g.drawLine(0,i,500,i);g.drawLine(i,0,i,500);}}
}

界面规划:

GameWin

package com.sxt;import javax.swing.*;
import java.awt.*;public class GameWin extends JFrame {int width = 2*GameUtil.OFFSET+GameUtil.MAP_W*GameUtil.SQUARE_LENGTH;int height = 4*GameUtil.OFFSET+GameUtil.MAP_H*GameUtil.SQUARE_LENGTH;MapBottom mapBottom = new MapBottom();void launch(){this.setVisible(true);this.setSize(width, height);this.setLocationRelativeTo(null);this.setTitle("SWE23070扫雷游戏");this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}@Overridepublic void paint(Graphics g) {mapBottom.paintSelf(g);}public static void main(String[] args) {GameWin gameWin = new GameWin();gameWin.launch();}
}

MapBottom

package com.sxt;import java.awt.*;public class MapBottom {void paintSelf(Graphics g){g.setColor(Color.red);//画竖线for(int i = 0; i<= GameUtil.MAP_W; i++){g.drawLine(GameUtil.OFFSET+i*GameUtil.SQUARE_LENGTH,3*GameUtil.OFFSET,GameUtil.OFFSET+i*GameUtil.SQUARE_LENGTH,3*GameUtil.OFFSET+GameUtil.MAP_H*GameUtil.SQUARE_LENGTH);}//画横线for(int i = 0; i<= GameUtil.MAP_H; i++){g.drawLine(GameUtil.OFFSET,3*GameUtil.OFFSET+i*GameUtil.SQUARE_LENGTH,GameUtil.OFFSET+GameUtil.MAP_W*GameUtil.SQUARE_LENGTH,3*GameUtil.OFFSET+i*GameUtil.SQUARE_LENGTH);}}
}

GameUtil

package com.sxt;public class GameUtil {//地图的宽static int MAP_W = 11;//地图的高static int MAP_H = 11;//雷区偏移量static int OFFSET = 45;//格子边长static int SQUARE_LENGTH = 50;
}

底层地图:

GameWin

package com.sxt;import javax.swing.*;
import java.awt.*;public class GameWin extends JFrame {int width = 2*GameUtil.OFFSET+GameUtil.MAP_W*GameUtil.SQUARE_LENGTH;int height = 4*GameUtil.OFFSET+GameUtil.MAP_H*GameUtil.SQUARE_LENGTH;MapBottom mapBottom = new MapBottom();void launch(){this.setVisible(true);this.setSize(width, height);this.setLocationRelativeTo(null);this.setTitle("SWE23070扫雷游戏");this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}@Overridepublic void paint(Graphics g) {mapBottom.paintSelf(g);}public static void main(String[] args) {GameWin gameWin = new GameWin();gameWin.launch();}
}

MapBottom

package com.sxt;import java.awt.*;public class MapBottom {void paintSelf(Graphics g){g.setColor(Color.red);//画竖线for(int i = 0; i<= GameUtil.MAP_W; i++){g.drawLine(GameUtil.OFFSET+i*GameUtil.SQUARE_LENGTH,3*GameUtil.OFFSET,GameUtil.OFFSET+i*GameUtil.SQUARE_LENGTH,3*GameUtil.OFFSET+GameUtil.MAP_H*GameUtil.SQUARE_LENGTH);}//画横线for(int i = 0; i<= GameUtil.MAP_H; i++){g.drawLine(GameUtil.OFFSET,3*GameUtil.OFFSET+i*GameUtil.SQUARE_LENGTH,GameUtil.OFFSET+GameUtil.MAP_W*GameUtil.SQUARE_LENGTH,3*GameUtil.OFFSET+i*GameUtil.SQUARE_LENGTH);}for(int i = 1; i<= GameUtil.MAP_W; i++){for(int j = 1; j<= GameUtil.MAP_H; j++){g.drawImage(GameUtil.lei,GameUtil.OFFSET+(i-1)*GameUtil.SQUARE_LENGTH+1,GameUtil.OFFSET*3+(j-1)*GameUtil.SQUARE_LENGTH+1,GameUtil.SQUARE_LENGTH-2,GameUtil.SQUARE_LENGTH-2,null);}}}
}

GameUtil

package com.sxt;import java.awt.*;public class GameUtil {//地图的宽static int MAP_W = 11;//地图的高static int MAP_H = 11;//雷区偏移量static int OFFSET = 45;//格子边长static int SQUARE_LENGTH = 50;//底层元素 -1 雷 0 空 1-8 表示对应数字static int[][] MAP_BOTTOM = new int[MAP_W+2][MAP_H+2];//载入图片static Image lei = Toolkit.getDefaultToolkit().getImage("imgs/lei.png");}

 


http://www.mrgr.cn/news/79364.html

相关文章:

  • C语言——实现并求出两个数的最大公约数
  • python学习笔记—7—变量拼接
  • Java 设计模式~工厂模式
  • C++中多态性在实际项目中的应用场景;C++中面向对象编程实现数据隐藏的方法
  • 定时/延时任务-Netty时间轮源码分析
  • MySQL锁的类型有哪些
  • windsurf简介
  • [软件工程]九.可依赖系统(Dependable Systems)
  • 多层感知机imdb情感分析分块第一部分
  • 大型网站演化实例
  • Java---每日小题
  • 【网盘系统】递归删除批量文件、从回收站恢复文件、彻底删除文件
  • PS核心知识点
  • 【组件封装】uniapp vue3 封装一个完整的Tabs(标签页)组件教程,功能由简到杂实现讲解。
  • Python实现BBS论坛自动签到【steamtools论坛】
  • 2023 年“泰迪杯”数据分析技能赛B 题企业财务数据分析与造假识别
  • Java后端面试模板(技术面)
  • [软件工程]十.可靠性工程(reliable engineering)
  • android studio 读写文件操作(应用场景二)
  • 代码随想录-算法训练营day41(动态规划04:01背包,01背包滚动数组,分割等和子集)
  • 信奥常考点:二叉树的构建(已知中序和 前序或后序 的情况下)
  • 网络原理之 TCP 协议
  • pubmed关键词搜索技能1:待更新
  • No APK Signature Scheme v2 signature in package
  • T C P
  • 删除asmlib磁盘导致磁盘组故障恢复---惜分飞