Python 作为一种简洁易懂且功能强大的编程语言,吸引着越来越多的初学者。当学习与游戏相结合,可以快速让同学们get到学习编程的乐趣~
下面小黄鸭给大家分享12个Java小游戏及源码,希望能更好的帮助大家上手掌握!由于篇幅限制在此展示2个游戏的部分示例,剩下的源码已经给大家打包好了 在文末,需要的可以自取嗷!
一、黄金矿工
public class GameUI extends JFrame {
public void launch(){
setSize(768,1000);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setTitle("黄金矿工v2");
setLocationRelativeTo(null);
setVisible(true);}}
- 上面是一些背景图片,保存在imgs里。
import java.awt.*;
public class Background {
Image bg=Toolkit.getDefaultToolkit().getImage("imgs/bg.jpg");
Image bg1=Toolkit.getDefaultToolkit().getImage("imgs/bg1.jpg");
Image peo=Toolkit.getDefaultToolkit().getImage("imgs/peo.png");
Image water=Toolkit.getDefaultToolkit().getImage("imgs/water.png");
public void paint(Graphics g){
g.drawImage(bg,0,200,null);
g.drawImage(bg1,0,0,null);
g.drawImage(peo,315,65,null);
g.drawImage(water,500,100,null);}}
二,羊了个羊
下面通过一个代码案例来制作一个这样的小游戏。游戏的GUI部分使用了JAVAFX来编写
部分关键代码:
<code class="language-plaintext hljs">public class FXController extends Application implements Serializable{
private static final long serialVersionUID = 1L;
private double x=0,y=0,width = 500,height = 800,jianju=18;
private volatile int img_x = -1,img_y = -1,
end_x = 50,end_y = 625,
count = 0,status = 0,
guanqia = 4,qiehuan_x = (int) (width*2);
private volatile boolean qiehuan = false,setting_show = false,play_muisc = false,
last = false;
private Canvas canvas = new Canvas(width,height);
private GraphicsContext context = canvas.getGraphicsContext2D();
private Random random = new Random();
private ExecutorService service = new ThreadPoolExecutor(10, 100, 0, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(100));
private Font font = Font.font("微软雅黑",FontWeight.BOLD,60);
//private Font wei = Font.font("微软雅黑",FontWeight.BOLD,40);
private AudioClip clip = play_music("D:\\桌面\\imagess\\button.mp3",1,false),clip2,
clip3 = play_music("D:\\桌面\\imagess\\xiaochu2.mp3",1,false);
private static List<Image> back,yuansu,buttons,icon,huiyuansu,bu,jie,setting;
private static Map<String,String> muisc;
private List<ImageInfo> info1 = new ArrayList<ImageInfo>(8);
private ImageInfo[][] images = new ImageInfo[guanqia][guanqia];
private ImageInfo[][] images2 = new ImageInfo[guanqia][guanqia];
private boolean[] muisc_is = new boolean[3];
剩下的Python小游戏游戏
桌球游戏的设计与实现
羊了个羊游戏的设计与实现
坦克大战游戏的设计与实现
扫雷游戏的设计与实现
基于JAVA的推箱子游戏
黄金矿工游戏的设计与实现
飞翔小鸟游戏的设计与实现
俄罗斯方块游戏的设计与实现
大鱼吃小鱼游戏的设计与实现
王者荣耀
超级玛丽
...
如何获取资料:
后台回复:游戏项目 获取