📄 mainpit.java
字号:
/*SLG战略实现
时间 2005年4月14日16:44
李波
小图模式
1:光标移动OK
2:滚屏OK
3:人物动作OK
4:人物移动OK
5:移动范围限定OK
6:显示菜单OK
7:多人物模式OK
8:移动完成后的攻击判断,并且根据判断绘制菜单.2005年4月14日16:44-2005/4/15/09:40!OK
9:选择菜单攻击指令后,绘制攻击范围.2005/4/15/09:42-2005/4/15/11:00!OK
10:选择攻击目标2005/4/15/11:25-12:30!OK
11:攻击过程2005/4/15/12:32-2005/4/18/11:49 !OK
12:带有地图限定的移动模式2005/4/18/12:00 - 2005/4/19/12:48 !OK
13:其它限定移动2005/4/19/13:45 -- 2005/4/19/14:22 !OK
14:整理以方便移植,除去攻击血量显示外,其余已调整完成 ,适配其它机型调整参数即可 2005/4/19/14:22 -- 2005/4/19/16:12!OK
15:开始菜单,相关其它显示内容的接口,分离光标的参数调整与绘制2005/4/19/16:12 -- 2005/4/19/18:40!OK
16:移动过程人物寻路2005/4/20/09:07 -- 2005/4/20/12/40!OK
17:全局信息读入2005/4/21/9:09 -- 2005/4/21/12/09!OK
18:加入人物参数及其相关参数导入2005/4/21/12:12 -- 2005/4/
*/
import javax.microedition.lcdui.Image;
import java.lang.Math;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import java.lang.Thread;
import java.lang.Runnable;
import java.io.InputStream;
import javax.microedition.rms.*;
import java.io.DataOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
//import com.nokia.mid.ui.FullCanvas;
//class MainPit extends FullCanvas implements Runnable
class MainPit extends Canvas implements Runnable
{
MainMid myMid;
private String mainMenuText[] =
{
"开始游戏",
"继续游戏",
"读取进度",
"帮助信息",
"结束游戏"
};
//按键
final static byte UP = -1;
final static byte DOWN = -2;
final static byte LEFT = -3;
final static byte RIGHT = -4;
final static byte OK = -5;
final static byte LCOMMAND = -6;
final static byte RCOMMAND = -7;
//状态
private int STATE = 1;
//屏幕大小
private int SCREEN_WIDTH = 128;
private int SCREEN_HEIGHT = 128;
//瓷砖大小
private int TILE_WIDTH = 16;
private int TILE_HEIGHT = 16;
private int TILE_SIZE = 16;
//屏幕单元数目最大数
private int SCREEN_MAX_WIDTH = 7;
private int SCREEN_MAX_HEIGHT = 7;
//地图单元数目
private int MAP_MAX_WIDTH = 15;
private int MAP_MAX_HEIGHT = 15;
//职业相关参数
private byte vocation[][] = {
{22,5,5,5,5,4,1},//人剑
{22,5,7,4,4,8,2},//人骑
{25,6,5,5,4,6,2},//蛮骑
{25,5,5,7,3,6,3},//蛮骑射
{20,6,2,8,4,7,3},//羽射
{20,6,6,4,4,3,1},//河洛
{28,7,7,3,3,5,1},//夸父
{20,7,2,6,5,3,1},//魅
{22,4,4,6,6,3,1}//术
};
//图片偏移系数
//人物图片偏移[人物类型][y偏移][x偏移]
private byte actorpos[][] = {
//女剑士1
//无焦点
{0,2},
{-1,1},
//有焦点
{0,1},
{2,-8},
//正面下移
{2,-1},
{2,-2},
//背面上移
{2,0},
{2,0},
//左移
{3,0},
{2,0},
//右移
{-5,0},
{-5,0},
//骑士
//无焦点
{1,-3},
{0,-6},
//有焦点
{-4,-6},
{0,-9},
//正面下移
{2,-7},
{2,-9},
//背面上移
{-1,-6},
{-1,-8},
//左移
{-2,-6},
{-2,-5},
//右移
{-5,-6},
{-7,-5}
};
//人物动作图片位置
//[人物类型][动作类型]
//人物类型0:主角1
//动作类型0:无焦点,1:有焦点,2:正面下移,3:背面上移,4:左移,5:右移
private byte actpic[][] = {
{0,2,4,6,8,10},
{12,14,16,18,20,22}
};
//红方信息
//0:类型,1:x坐标,2:y坐标,3:等级,4:五行属性,5:HP,6:ATK,7:DEF,8:DEX,9,AGI,10:MOV,11:攻击范围)
private byte redinfo[][] = new byte[9][12];
//蓝方信息
//0:类型,1:x坐标,2:y坐标,3:等级,4:五行属性,5:HP,6:ATK,7:DEF,8:DEX,9,AGI,10:MOV,11:攻击范围)
private byte blueinfo[][] = new byte[9][12];
private byte infored[][] = {//类型,坐标,等级,属性
{0,0,0,3,0},
{1,5,6,4,1},
{2,3,9,4,2},
{3,1,6,2,3},
{4,8,10,5,4},
{5,2,7,2,0},
{6,12,12,3,1},
{7,14,11,3,2},
{8,15,15,5,3}
};
//出场人物信息数组(人物类型,人物地图坐标,人物移动能力,攻击范围最小值,攻击范围最大值)
private int infoact[][] = {
{0, 0, 0, 6, 0, 1},
{1, 6, 5, 4, 0, 1},
{1, 8,10, 4, 1, 3},
{0, 1, 1, 2, 1, 4},
{1, 2, 7, 5, 0, 2}
};
//出场人物个数
private int actnum = 5;
//出场人物处理编号
private int idact[] = {0,1,2,3,4};
//红方数量
private byte rednum;
//蓝方数量
private byte bluenum;
/*//蓝方编号
private byte redindex[];
//红方编号
private byte blueindex[];
*/
//计数器
private int tally;
//光标计数器
private int cursortally;
//动作类型
//0:未得焦点
//1:得到焦点
//2:正面下移
//3:背面上移
//4:左面侧移
//5:右面侧移
//private byte motionkind[]={0,4,8,12,16,20};
//人物类型
//0:主角
//private byte actpickind[]={0,24};
//地图
private byte map[][] ={
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0},
{0,0,0,0,0,0,0,3,3,3,0,3,0,0,0,0},
{0,1,0,0,0,0,0,3,0,0,0,3,0,0,0,0},
{0,1,1,0,0,0,0,3,0,3,3,3,0,0,0,0},
{0,1,1,0,0,0,3,3,0,3,0,0,0,0,0,0},
{0,0,0,0,0,3,3,0,0,3,0,0,0,0,0,0},
{0,0,0,0,3,3,0,0,3,3,0,0,2,0,0,0},
{0,0,0,0,0,0,0,3,3,0,0,2,2,2,0,0},
{0,0,0,0,0,0,3,3,0,0,0,2,2,2,2,2},
{0,1,1,0,0,0,3,0,0,0,2,2,2,2,2,2},
{0,0,1,0,0,0,3,0,0,0,2,2,2,2,2,2},
{0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2},
{0,0,0,0,0,0,0,0,0,2,2,2,2,2,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
private String mapname[] = {"草","林","沙","山"};
//地图能力修正[防御,闪避][修正值]
private byte maprevise[][] = {
//草地,林地,沙地,建筑
{0,1,2,3},//防御
{0,20,10,30}//回避
};
//地图类型对人物移动能力的修正[地图类型][人物类型]
private byte mappos[][] = {
//剑士,骑士
{1,1},//草地
{1,2},//林地
{2,2},//沙地
{10,10}
};
//移动能力
private byte move[][] =
{
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}
};
//菜单内容
public String MenuContent[][] = {
{"终了","中断","状况","部队"},
{"待机","攻击"}
};
//菜单信息
public byte MenuInfo[] = {4, 1};
//当前菜单焦点
public int MenuFocus;
private byte CurrentMenu;//当前菜单
private byte CurrentScene;//当前场景
private boolean atkrangeshow;//显示攻击范围
private byte atktarget[] = {0,0,0,0,0,0,0,0,0,0,0};//攻击目标
private byte currentatk;//当前攻击对象
//光标在地图中位置
private int cursorMX;
private int cursorMY;
//光标在屏幕中位置
private int cursorSX;
private int cursorSY;
//屏幕左上角瓷砖在地图中位置
private byte x;
private byte y;
//光标式样
private int cursorkind;
//按键已按标记
private boolean hasPressed;
//屏幕滚动标记
private boolean rollmapflag;
//按键记忆
private int kCode;
//延时
private int hangfire;
//选中目标标记
private int currentact;
/****************************************************************************/
//选中目标参数
//选中目标类型
private int currentactkind;
//选中目标攻击范围下限
private int currentactatkmin;
//选中目标攻击范围下限
private int currentactatkmax;
//选中目标位置坐标
//屏幕中位置
private int currentactSX;
private int currentactSY;
//地图中位置
private int currentactMX;
private int currentactMY;
//选中目标状态
private int currentactstate;
//选中目标动作标记
private int currentactcg;
//选中目标移动偏移
private int currentactmovex;
private int currentactmovey;
//选中目标移动标记
private boolean moveaction;
//移动对象坐标
private int targetSX;
private int targetSY;
//选中目标状态
private int targetstate;
//选中目标移动范围
private int currentactmovearea;
//移动范围显示标记
private boolean showmovearea;
/********************************************************************************/
//文字框架颜色方案数组
private int frameColor[][] = {
{0x00c8c8d0,0x00d8d8a8,0x00003088,0x000050b0},//开始菜单
{0x00605838,0x00605838,0x00f8f8c8,0x005858c0},//游戏菜单
{0x00605838,0x00f8f8c8},//地形修正
{0x00504830,0x00f8f0c8,0x00f87079,0x00f86800},//攻击血量显示蓝方
{0x00504830,0x00f8f0c8,0x00404090,0x0010b0f8},//攻击血量显示红方
{0x00d0d8f8,0x005858a8,0x00a0a0f8}//人物基本信息蓝方
};
/************************************/
//游戏相关
//游戏章节
private byte gameChapter;
Image back_buffer;//缓存
Image static_buffer;//静态图形缓存
Image picmap[] = new Image[4];//地图
Image piccursor[] = new Image[4];//光标
Image picact[] = new Image[24];//人物
Graphics gb;
Graphics gs;
private RecordStore myStore = null;
public MainPit(MainMid Mid)
{
gameChapter = 0;
myMid = Mid;
try
{
back_buffer = Image.createImage(SCREEN_WIDTH,SCREEN_HEIGHT);
static_buffer = Image.createImage(SCREEN_WIDTH,SCREEN_HEIGHT);
//图片载入,
for(int i = 0; i < 24; i++)
{
if(i < 4)
{
piccursor[i] = Image.createImage("/pic/cursor/c" + i + ".png");
picact[i] = Image.createImage("/pic/act/m" + i + ".png");
picmap[i] = Image.createImage("/pic/map/m" + i + ".png");
}
else
{
picact[i] = Image.createImage("/pic/act/m" + i + ".png");
}
}
//readStaticInfo();
}
catch(Exception e)
{}
gb = back_buffer.getGraphics();
gs = static_buffer.getGraphics();
//System.out.println("11111111111111");
//System.out.println("22222222222");
newGame();
//System.out.println("3333333333333");
}
public void loadGameItem(byte chaper)
{
}
public void newGame()
{
//菜单焦点
MenuFocus = 0;
//计数器
tally = 0;
cursortally = 0;
CurrentScene = 1;//当前场景
//光标在地图中位置
cursorMX = 0;
cursorMY = 0;
//光标在屏幕中位置
cursorSX = 0;
cursorSY = 0;
//屏幕左上角瓷砖在地图中位置
x = 0;
y = 0;
//光标式样
tally = 0;
//按键已按标记
hasPressed = false;
//屏幕滚动标记
rollmapflag = false;
//按键记忆
kCode = 0;
//延时
hangfire = 0;
//选中目标标记
currentact = -1;
/****************************************************************************/
//选中目标参数
//选中目标位置坐标
//屏幕中位置
currentactSX = -1;
currentactSY = -1;
//地图中位置
currentactMX = -1;
currentactMY = -1;
//选中目标状态
currentactstate = 0;
//选中目标动作标记
currentactcg = -1;
//选中目标移动偏移
currentactmovex = 0;
currentactmovey = 0;
//选中目标移动标记
moveaction = false;
//移动对象坐标
targetSX = -1;
targetSY = -1;
//选中目标状态
targetstate = 0;
//选中目标移动范围
currentactmovearea = 0;
//移动范围显示标记
showmovearea = false;
//System.out.println("444444444444444");
//readChapterInfo(gameChapter);
DrawStaticPic(gs);
//System.out.println("end");
}
public void paint(Graphics g)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -