📄 game.java
字号:
private int cmdr[][] = new int[8][8];// 8*8格物品栏,第一项代表当前是第几页,第二项代表每页的8个格子,数值代表拥有那种物品,空的时候不拥有任何物品,为-1;
// 这里响应按键
/**
* 簡化,不管空不空,直接沖頭開是排列,依照主角身上擁有的物品,依次放進去;明天实现; 可以利用翻页,来代表有无数个物品格子;
* 画物品栏全部弄好,可以自由放入東西了,包括武器等等;
*/
/**
* 完成了
*
*/
void drawItem() {
putItem();
for (int i = 0; i < cmdr[currentCmdr].length; i++) {
if (cmdr[currentCmdr][i] >= 0 && cmdr[currentCmdr][i] < 10)
{
charBuffg.drawImage(Const.Item[cmdr[currentCmdr][i]],
cmdright[i][0], cmdright[i][1], 20);
charBuffg.drawString("X" + lin.item[cmdr[currentCmdr][i]],
Const.Item[cmdr[currentCmdr][i]].getWidth()
+ cmdright[i][0], cmdright[i][1], 20);
}
try {
if (cmdr[currentCmdr][i] >= 10
&& cmdr[currentCmdr][i] < 10 + Const.armStr.length) {
Const.drawString(charBuffg,
Const.armStr[cmdr[currentCmdr][i] - 10].substring(
1, 4)
+ "X" + lin.item[cmdr[currentCmdr][i]],
cmdright[i][0], cmdright[i][1], cmdrightw,
cmdrighth, false, Font.SIZE_MEDIUM, 5, 10, false);
}
} catch (Exception e) {
System.out.println("发生异常程序死锁");
}
}
int i = listIndex - 4;
if (i == -5 || i == -2) {
Const.drawString(charBuffg,
"第" + (currentCmdr + 1) + "层包裹 ,中间鍵到下一层" + "当前金钱:"
+ lin.gold,// 解说;
cmdrd[0], cmdrd[1], cmdrdw, cmdrdh, false,
Font.SIZE_MEDIUM, 15, 10, true);
}
if (i >= 0 && i < 8) {
if (cmdr[currentCmdr][i] >= 0 && cmdr[currentCmdr][i] < 10)
{
Const.drawString(charBuffg,
Const.ItemStr[cmdr[currentCmdr][i]] + " 中间键使用或者卖出",// 解说;
cmdrd[0], cmdrd[1], cmdrdw, cmdrdh, false,
Font.SIZE_MEDIUM, 15, 10, true);
charBuffg.drawImage(showCmd(Const.Item[cmdr[currentCmdr][i]],
lin.item[cmdr[currentCmdr][i]], cmdrightw, cmdrighth,
Font.SIZE_MEDIUM), cmdright[i][0], cmdright[i][1], 20);
}
if (cmdr[currentCmdr][i] >= 10 && cmdr[currentCmdr][i] < 34) {
Const.drawString(charBuffg,
Const.armStr[cmdr[currentCmdr][i] - 10].substring(1, 4)
+ "X" + lin.item[cmdr[currentCmdr][i]],
cmdright[i][0], cmdright[i][1], cmdrightw, cmdrighth,
false, Font.SIZE_MEDIUM, 5, 10, true);
Const.drawString(
charBuffg,
Const.armStr[cmdr[currentCmdr][i] - 10] + " 中间键装备或者卖出",// 解说;
cmdrd[0], cmdrd[1], cmdrdw, cmdrdh, false,
Font.SIZE_MEDIUM, 15, 10, true);
}
}
try {
if (bSell) {
Const.drawString(charBuffg, "您卖出了"
+ Const.ItemAndArmStr[itemId].substring(0, 5),
this.charaBuff.getWidth() / 2, this.charaBuff
.getHeight() / 3, 100, 30, false,
Font.SIZE_MEDIUM, 15, 10, true);
return;
}
} catch (Exception e) {
System.out.println("发生异常程序中断");
}
}
/**
* 根据主角身上的物品显示到相应的格子里;
*/
void putItem() {
int i = 0;
for (int page = 0; page < cmdr.length; page++)
for (int j = 0; j < cmdr[page].length; j++)
cmdr[page][j] = -1;// 每次重放都清空所有的格子,然后重新放置;
for (int page = 0; page < cmdr.length; page++)
for (int j = 0; j < cmdr[page].length; j++) {
{
while (i < lin.item.length) {
if (lin.item[i] > 0) {
cmdr[page][j] = i;
i++;
break;
}
i++;
if (i >= lin.item.length) {
return;
}
}
}
}
}
/**
* 裝備界面命令处理;卸下装备;但要装备只能去物品栏里找;
*/
void charArmInput(int key) {
int i = listIndex - 4;
if (i >= 0 && i < 8)
lin.arm[i] = -1;
}
/**
* 可以利用翻页,来代表有多少个物品格子; 画武器栏;根据主角是否拥有该武器来装备 是否装备状态,区别就是武器可以装备,
* 并且显示攻击力如何,而且是在固定的为止;卸除包括;等等;扩展,装备的武器放在物品栏里,
*
*/
void drawArm() {
for (int i = 0; i < cmdright.length; i++)
if (lin.arm[i] != -1) {
charBuffg.drawString(Const.armStr[lin.arm[i] - 10].substring(0,
4), cmdright[i][0], cmdright[i][1], 20);
} else {
charBuffg.drawString("未装备", cmdright[i][0], cmdright[i][1], 20);
}
int i = listIndex - 4;
if (i == -1) {
Const.drawString(charBuffg, Const.gameExplain[3][9], cmdrd[0],
cmdrd[1], cmdrdw, cmdrdh, false, Font.SIZE_MEDIUM, 15, 10,
true);
}
if (i >= 0 && i < 8) {
if (lin.arm[i] != -1) {
charBuffg.drawImage(showCmd(cmdrightw, cmdrighth,
Const.armStr[i].substring(0, 4), Font.SIZE_MEDIUM),
cmdright[i][0], cmdright[i][1], 20);// 高亮显示;
Const.drawString(charBuffg,
Const.armStr[lin.arm[i] - 10] + " fire键卸除",// 解说;
cmdrd[0], cmdrd[1], cmdrdw, cmdrdh, false,
Font.SIZE_MEDIUM, 15, 10, true);
} else {
charBuffg.drawImage(showCmd(cmdrightw, cmdrighth, "未装备",
Font.SIZE_MEDIUM), cmdright[i][0], cmdright[i][1], 20);
Const.drawString(charBuffg,
Const.gameExplain[3][i],// 解说;
cmdrd[0], cmdrd[1], cmdrdw, cmdrdh, false,
Font.SIZE_MEDIUM, 15, 10, true);
}
}
}
/**
* 绘制主角角色界面;实现方法,用一张图和一个图标,以圖片區域碰撞来判断他们之间的关系,显示哪些图片, 依靠主角的状态来判断哪些可见;哪些不可见
*/
void drawCharcter() {
charSelect();// 判断指针到底指向了哪儿
charBuffg.setClip(0, 0, charaBuff.getWidth(), charaBuff.getHeight());
try {
charBuffg.drawImage(chara, 0, 0, 20);// 把主角图片绘制到缓冲区的零零点开始;
if (charState < 4) {
Image im = showCmd(cmdw, cmdh, str[charState], Font.SIZE_LARGE);
charBuffg.drawImage(im, cmd[charState][0], cmd[charState][1],
20);
}
switch (charState) {// 这段要做的就是当标签指到一个命令上,直接显示当前的内容;
case SELECT:
break;
case ATRBUT:// 根据不同属性显示不同的内容;
drawAtrbut();
break;
case SKILL:
drawSkill();
break;
case ITEM:
drawItem();
break;
case ARM:
drawArm();
break;
}
charBuffg.drawImage(ind, indexX, indexY, 20);
charBX = 10;
g.drawImage(charaBuff, charBX, charBY, 20);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @param key
* 处理任务界面的转换,主要就是一个按页输出,明白了,就是一个用几页来控制就是一个包裹类型;
*
* 测试一下,用两个人的超长对话,搞定;
*/
void taskInput(int key) {
switch (key) {
case FIRE_PRESSED:
pageTask++;
offset = 0;
if (pageTask >= 15)
pageTask = 0;
break;
case DOWN_PRESSED:
String s = "page" + (pageTask + 1) + " " + Const.task[pageTask]
+ "已经完成";
if (Const.task[pageTask].length() > 60)
offset += 20;// 下拉
if (offset + 80 > s.length())
offset = s.length() - 80;
s = null;
break;
case UP_PRESSED:
if (Const.task[pageTask].length() > 60)
offset = 0;
break;
case GAME_A_PRESSED:
GAMESTATE = Const.GAME_SYSTEM;
pageTask = 0;
offset = 0;
break;
}
}
private int pageTask = 0;// 不同的任务分页;
private int offset = 0;
/**
* 绘制任务窗口;
*/
void drawTask() {
g.drawImage(loadImage("/back.png"), 0, 0, 20);
// 遍历主角任务状态,来构造任务提示字符串;
switch (lin.task[pageTask]) {
case -1:
Const.drawString(g, "page" + (pageTask + 1) + " " + "您没有接到该任务",
offset, 60, Const.Alert[0], Const.Alert[1], Const.Alert[2],
Const.Alert[3], true, Font.SIZE_LARGE, 20, 15, true);
break;
case 0:
Const.drawString(g, "任务" + (pageTask + 1) + "未完成 :"
+ Const.task[pageTask], offset, 84, Const.Alert[0],
Const.Alert[1], Const.Alert[2], Const.Alert[3], true,
Font.SIZE_LARGE, 20, 15, true);
break;
case 1:
Const.drawString(g, "任务" + (pageTask + 1) + "已经完成: "
+ Const.task[pageTask], offset, 84, Const.Alert[0],
Const.Alert[1], Const.Alert[2], Const.Alert[3], true,
Font.SIZE_LARGE, 20, 15, true);
break;
}
}
private static Image fightBuffer = null;// 这个也是通用不变的在各个游戏对象中;
private static Graphics fightBufferg = null;
private int fightCmdIndex = 0;// 四个命令按键;
private static int cmdFight[][] = new int[4][2];
private static String cmdFightStr[] = new String[4];
private static final int cmdFightw = 30, cmdFighth = 20;
static {
fightBuffer = Image.createImage(50, 40);
fightBufferg = fightBuffer.getGraphics();
cmdFight[0][0] = 5;
cmdFight[0][1] = 5;
cmdFight[1][0] = 30;
cmdFight[1][1] = 5;
cmdFight[2][0] = 5;
cmdFight[2][1] = 25;
cmdFight[3][0] = 30;
cmdFight[3][1] = 25;
cmdFightStr[0] = "攻击";
cmdFightStr[1] = "状态";
cmdFightStr[2] = "防御";
cmdFightStr[3] = "逃跑";
}
private Npc npcPrince = null, npcSchoolMaster = null, npcMoprince = null,
npcFeina = null, npcFeng = null, npcEnemyGuard = null,
npcWendini = null, npcBox = null, npcBox2 = null;
private Npc currentNpc = null;
private int fightPlayerState = 0;// 1代表攻击敌人,2到9代表技能攻击敌人,10代表逃跑;
private int fightNpcState = 0;//
boolean fightInput = false;
private int boxInfolen = 0;
boolean closed = true;// 箱子处于关闭的状态;
/**
* fight的按键处理;
*
* @param key
*/
void fightInput(int key) {
switch (key) {
case FIRE_PRESSED: {// 只有按键战斗才会结束;
if (this.currentNpc == this.npcPrince && infoLen >= 4 && vic) {
pagedown = true;
vic = false;
this.GAMESTATE = Const.GAME_DIALOGTASK;
fightInput = false;
lin.diagState = 4;
return;
}
if (this.currentNpc != this.npcPrince && infoLen >= 4 && vic) {
this.GAMESTATE = Const.GAME_RUNNING;
this.currentNpc.setVisible(false);//
vic = false;
fightInput = false;
return;
}
if (lin.atr[0] <= 0 && this.currentNpc == this.npcPrince
&& lin.trait == 2 && dlen >= 2) {
fb = true;
for (int i = 0; i < lin.atr.length; i++) {
lin.atr[i] *= 2;
lin.judgeAd();
}
lin.judgeMaxhpMp();
lin.atr[0] = lin.maxHp;
return;
}
if (lin.atr[0] <= 0) {
dlen++;
return;// 当处于零的时候封锁按键 ;
}
if (vic) {
infoLen++;
return;
}
if (preOpen) {
preOpen = false;
openBox = true;
closed = false;
return;
}//
if (boxInfolen >= 1 && closed) {
s = null;
openBox = false;
closed = true;
boxInfolen = 0;
this.GAMESTATE = Const.GAME_RUNNING;
return;
}
if (openBox) {
boxInfolen++;
return;
}
switch (fightCmdIndex) {
case 0:
fightPlayerState = 1;
// 攻击
break;
case 1:
GAMESTATE = Const.GAME_CHARCTERSTATUE;
charState = ATRBUT;
fightInput = true;
listIndex = 0;
indexX = cmd[listIndex][0];
indexY = cmd[listIndex][1];
// 状态这里直接跳转到主角界面去
break;
case 2:
// 防御;
fightPlayerState = 10;// 玩家处于防御状态
break;
case 3:
// 逃跑,判断目前处于那些阶段;
if (this.currentNpc != this.npcPrince) {
this.GAMESTATE = Const.GAME_RUNNING;
lin.move(-lin.hdx, -lin.hdy);
vic = false;
return;
}
break;
}
}
break;
case UP_PRESSED:
this.fightCmdIndex -= 2;
if (fightCmdIndex == -2)
fightCmdIndex = 2;
if (fightCmdIndex == -1)
fightCmdIndex = 3;
break;
case DOWN_PRESSED:
this.fightCmdIndex += 2;
if (fightCmdIndex == 4)
fightCmdIndex = 0;
if (fightCmdIndex == 5)
fightCmdIndex = 1;
break;
case LEFT_PRESSED:
this.fightCmdIndex--;
if (fightCmdIndex < 0)
fightCmdIndex = 3;
break;
case RIGHT_PRESSED:
this.fightCmdIndex++;
if (fightCmdIndex > 3)
fightCmdIndex = 0;
break;
}
}
boolean vic = false;
boolean escape = false;
LayerManager currentLayer = null;
String s = null;
/*
* 画战斗场景
*/
void drawFight() {
if (openBox == true && !closed) {
closed = true;
boxInfolen = 0;
if (this.currentNpc == npcBox || this.currentNpc == npcBox2) {
Random r2 = new Random();
try {
int itemid = r2.nextInt(this.currentNpc.station);
lin.item[itemid]++;
lin.judgeSuit();
s = "希洛得到了" + Const.ItemAndArmStr[itemid].substring(0, 5);
this.currentNpc.setVisible(false);
return;
} catch (Exception e) {
}
}
}
if (boxInfolen <= 1 && s != null) {
Const.drawString(g, s, 20, 40, 100, 40, true, Font.SIZE_LARGE, 15,
15, true);
return;
}
if (this.currentNpc != npcBox && this.currentNpc != npcBox2)
fight(this.currentNpc);
}
private int infoLen = 0;
private String infos[] = new String[4];
private int cfx = 0, cfy = 0;
boolean fb = false;
private int texiaolen = 0;
private int eneatclen = 5;
private byte pMX = 0;
private byte pM
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -