Java仿太閣立志傳5
阿新 • • 發佈:2018-11-20
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!
沒有標題寫的那麼大……真要用Java重寫太閣五不說別的,光整理原圖就夠累死我的……遊戲截圖:
只是一個太閣五中加農業水平小遊戲的再現……用本人loonframework-game包進行圖形處理,算是一個對jar包的測試程式,完整程式下載地址,僅將使用到的類和圖形打包:
原始碼如下:
TgIrrigationScript.java
package org.loon.framework.test.tg;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;
import javax.swing.JOptionPane;
import org.loon.framework.game.collection.SimpleArray;
import org.loon.framework.game.image.Bitmap;
/** */ /**
* <p>
* Title: LoonFramework
* </p>
* <p>
* Description:[太閣立志傳小遊戲Java模擬之水渠貫通]loonframework-game包由於標準類及介面未完成暫不開源(我懶……目前只完成大約45%而已|||三月沒動……)
* </p>
* <p>
* Copyright: Copyright (c) 2007
* </p>
* <p>
* Company: LoonFramework
* </p>
*
* @author chenpeng
* @email:[email protected]
* @version 0.1
*/
public class TgIrrigationScript extends Panel implements KeyListener ... {
/** *//**
*
*/
private static final long serialVersionUID = 1L;
// 生成快取用背景Image
Image _screen = new Bitmap(640, 480, 1).getImage();
//獲得畫布
Graphics _graphics = _screen.getGraphics();
final private int _rs = 6;
private int[][] _chess = null;
private int[] _obj_block = null;
// Bitmap為loonframework提供類,內部混合封裝了Image和BufferedImage,提供了通用的處理方式
// 背景圖
Bitmap _back_bitmap = null;
// 出水圖1
Bitmap _water_start = null;
// 出水圖2
Bitmap _water_start2 = null;
// 左邊框圖
Bitmap _left_box = null;
// 左側輔助框
Bitmap[] _leftnew_sprites = null;
// 磚塊地圖
Bitmap[][] _character_sprites = null;
// 游標
Bitmap _cursor = null;
Bitmap bitmap = null;
/** *//**
* 建構函式
*
*/
public TgIrrigationScript() ...{
initialize();
}
/** *//**
* 初始化
*
*/
public void initialize() ...{
setBackground(Color.BLACK);
setSize(640, 480);
_leftnew_sprites = new Bitmap[4];
_character_sprites = new Bitmap[_rs][_rs];
_back_bitmap = new Bitmap("./image/pano.png");
_water_start = new Bitmap("./image/water_start.png");
_water_start2 = new Bitmap("./image/spr16.png");
_left_box = new Bitmap("./image/left_box.png");
_cursor = new Bitmap("./image/choose_box.png");
bitmap = new Bitmap("./image/mud.png");
// 出水圖繪製座標
_water_start.setDrawXY(272, 2);
// 左邊框繪製座標
_left_box.setDrawXY(25, 20);
_water_start2.setDrawXY(308, 45);
//遊標繪製座標
_cursor.setDrawXY(308, 91);
for (int i = 0; i < _leftnew_sprites.length; i++) ...{
_leftnew_sprites[i] = new Bitmap("./image/mud.png");
_leftnew_sprites[i].setDrawXY(42, 204 - i * 56);
}
_leftnew_sprites[0].setDrawY(212);
for (int i = 0; i <_rs; i++) ...{
for (int j = 0; j < _rs; j++) ...{
_character_sprites[i][j] = new Bitmap("./image/mud.png");
_character_sprites[i][j].setDrawXY(i * 48 + 164, j * 48 + 91);
}
}
_chess = new int[_rs][_rs];
_obj_block = new int[4];
// 左側輔助欄讀取圖形
for (int i = 0; i < 4; i++) ...{
down();
}
// 設定監聽
setFocusable(true);
addKeyListener(this);
}
public void update(Graphics g) ...{
paint(g);
}
public void paint(Graphics g) ...{
// 背景繪製
_back_bitmap.draw(_graphics);
// 出水圖繪製
_water_start.draw(_graphics);
//
_water_start2.draw(_graphics);
// 左邊框圖繪製
_left_box.draw(_graphics);
// 左側輔助框繪製
for (int i = 0; i < _leftnew_sprites.length; i++) ...{
_leftnew_sprites[i].draw(_graphics);
}
// 繪製磚塊
for (int i = 0; i < _character_sprites.length; i++) ...{
for (int j = 0; j < _character_sprites[i].length; j++) ...{
_character_sprites[i][j].draw(_graphics);
}
}
// 繪製選中游標
_cursor.draw(_graphics);
g.drawImage(_screen, 0, 0, this);
}
public void down() ...{
int steps = 0;
_obj_block[0] = _obj_block[1];
_leftnew_sprites[0].setBufferedImage(_leftnew_sprites[1]
.getBufferedImage());
_obj_block[1] = _obj_block[2];
_leftnew_sprites[1].setBufferedImage(_leftnew_sprites[2]
.getBufferedImage());
_obj_block[2] = _obj_block[3];
_leftnew_sprites[2].setBufferedImage(_leftnew_sprites[3]
.getBufferedImage());
if (steps < (_rs * _rs)) ...{
// 點陣圖
int[] tmparr = new int[] ...{3,5,6,7,9,10,11,12,13,14,15};
// 隨即選取
int tmpint = tmparr[new Random().nextInt(11)];
_obj_block[3] = tmpint;
_leftnew_sprites[3].setBufferedImage(new Bitmap("./image/spr"
+ tmpint + ".png").getBufferedImage());
} else ...{
_obj_block[3] = 0;
_leftnew_sprites[3].setBufferedImage(bitmap.getBufferedImage());
}
steps += 1;
}
/** *//**
* 放下事件處理
* @param x
* @param y
*/
public void putCase(int x, int y) ...{
if (this._chess[x][y] == 0) ...{
_character_sprites[x][y].setBufferedImage(_leftnew_sprites[0]
.getBufferedImage());
_chess[x][y] = _obj_block[0];
down();
//_obj_block[0]為最後的渠道方塊,所以為0時代表資料讀完
if (_obj_block[0] == 0) ...{
endCase();
}
}
}
/** *//**
* 判斷選中圖形能否貫通
* @param x
* @param y
* @param dire
* @return
*/
public boolean crossInclude(int x, int y, int dire) ...{
boolean flag = false;
switch (dire) ...{
case 1:
flag = SimpleArray.include("3,5,7,9,11,13,15", _chess[x]