📄 mycan.java
字号:
package Kidfishing;
import java.io.IOException;
import java.util.Random;
import java.util.Vector;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreNotOpenException;
import tool.Tools;
public class Mycan extends Canvas implements Runnable {
private Mymid mymid;
byte gamestate;
static final int WID = 176;
static final int HIG = 208;
static final int NW = 14;// 方框长
static final byte LOG = 0;// logo
static final byte MENU = 1;// 游戏菜单
static final byte LOGOG = 2;// 载入游戏
static final byte RUN = 3;// 新游戏
static final byte PAUSE = 10;// 暂停游戏
static final byte GAMEOVER = 4;// 游戏失败
static final byte HELP = 5;// 帮助
static final byte RANK = 6;// 排行
static final byte EXIT = 7;// 游戏退出
static final byte SHOP = 8;// 商店
static final byte WRITE = 9;// 留名
Image log1, log2, title, help, wordres, logogame, over, write, rank, stop;
// 移动,游戏学院,游戏海报,帮助,菜单字符,字背景,游戏失败,写名字,排行榜,数字
Image fishimage[][];
Image word[];// 菜单字符数组.
Image num[];// 数字数组
Image helptwo[][];// 帮助装饰
Image p[], blank[];// 道具栏,空白
int count, frame, log, level, money;// 计数器
int namenum = 'A';// 字母计数器
int kx = 25, ky = 116;// 框起始坐标
boolean fire;
boolean drawrank;
// -------------------------------------------
StringBuffer winname = new StringBuffer();
int playgoal;
// -------------------------------------------
Map m;
Shark sk;
Play player;
Shop shop;
// ------------------------------------------------
Winner w[];
Random rand;
Vector npc;
public Mycan(Mymid mymid) {
this.mymid = mymid;
setFullScreenMode(true);
try {
log1 = Image.createImage("/logo1.png");
log2 = Image.createImage("/logo2.png");
title = Image.createImage("/menu.png");
help = Image.createImage("/help.png");
logogame = Image.createImage("/togame.png");
over = Image.createImage("/gameover.png");
write = Image.createImage("/writename.png");
rank = Image.createImage("/rank.png");
stop = Image.createImage("/stop.png");
// -------------------------------------------
helptwo = new Image[2][];
Image aaa = Image.createImage("/helptwo.png");
helptwo[0] = Tools.getAnmi(aaa, 0, 0, 2, 1, 52, 28);// 螃蟹
helptwo[1] = Tools.getAnmi(aaa, 52, 0, 2, 1, 19, 28);// 水草
// ---------------------------------------
wordres = Image.createImage("/word.png");
word = Tools.getAnmi(wordres, 0, 0, 1, 5, 50, 20);
// --------------------------------------------
Image pr = Image.createImage("/prop.png");
p = Tools.getAnmi(pr, 0, 0, 1, 1, 54, 18);
blank = Tools.getAnmi(pr, 54, 0, 1, 1, 18, 18);
// --------------------------------------------
Image numm = Image.createImage("/number.png");
num = Tools.getAnmi(numm, 0, 0, 1, 10, 9, 13);
// ---------------------------------------------鱼
fishimage = new Image[6][];
Image rees = Image.createImage("/smallfish.png");
// -------------------------------------------
Image rres = Image.createImage("/middlefish.png");
// -----------------------------------------------
Image rrres = Image.createImage("/bigfish.png");
// ------------------------------------------------
Image upfish = Image.createImage("/upfish.png");
// -------------------------------------------------小鱼
fishimage[0] = Tools.getAnmi(rees, 0, 0, 1, 6, 24, 11);
fishimage[1] = Tools.getAnmi(upfish, 0, 0, 1, 2, 13, 30);
// ---------------------------------------------------中鱼
fishimage[2] = Tools.getAnmi(rres, 0, 0, 1, 6, 27, 11);
fishimage[3] = Tools.getAnmi(upfish, 0, 30, 1, 2, 13, 30);
// -----------------------------------------------大鱼
fishimage[4] = Tools.getAnmi(rrres, 0, 0, 1, 6, 30, 13);
fishimage[5] = Tools.getAnmi(upfish, 0, 60, 1, 2, 13, 30);
} catch (IOException e) {
e.printStackTrace();
}
// --------------------------------------------------------
}
// 初始化地图
void initializeMap() {
m = new Map();
shop = new Shop();
npc = new Vector();
rand = new Random();
sk = new Shark();
m.level = level;
m.count = 0;
addNpc();
player.setdirect(174);
}
// 添加鲨鱼
void addSk() {
sk.x = -50;
sk.y = 70 + rand.nextInt(100);
sk.iscome = true;
}
// 添加鱼
void addNpc() {
int a = 150 - m.level * 5;
if (a <= 100) {
a = 100;
}
if (m.count % a == 0) {
Fish temp = null;
int rannum = (rand.nextInt() >>> 1) % 10;
int randy = (rand.nextInt() >>> 1) % 120;
if (rannum >= 0 && rannum < 5) {
temp = new Fish(fishimage[0], fishimage[1], 140, 70 + randy, 1,
10, Fish._LEFT);
}
if (rannum >= 5 && rannum < 8) {
temp = new Fish(fishimage[2], fishimage[3], 140,
100 + randy / 3, 1, 20, Fish._LEFT);
}
if (rannum >= 8 && rannum < 10) {
temp = new Fish(fishimage[4], fishimage[5], 140,
150 + randy / 4, 1, 30, Fish._LEFT);
}
npc.addElement(temp);
}
}
// 转到菜单
void turnM() {
if (count > 119) {
gamestate = 1;
countUp(false);
}
}
// 转到游戏
void turnR() {
log = 0;
countUp(false);
gamestate = 3;
}
// 转到帮助
void turnH() {
countUp(false);
gamestate = 5;
}
// 是否过关
boolean isOver() {
if (playgoal >= m.tollgate()) {
return true;
}
return false;
}
// 总绘画
protected void paint(Graphics g) {
switch (gamestate) {
case LOG:
drawLog(g);
break;
case MENU:
drawMenu(g);
break;
case LOGOG:
drawLogogame(g);
break;
case PAUSE:
case RUN:
m.drawMap(g);
sk.drawShark(g);
drawBub(g);
drawProp(g);
drawPlaygoals(g);
// -----------------------------------
drawPlayer(g);
drawNPC(g);
shop.drawBox(g);
if (fire) {
shop.drawDeto(g);
}
if (gamestate == PAUSE) {
g.drawImage(stop, 38, 54, Graphics.TOP | Graphics.LEFT);
}
break;
case SHOP:
shop.drawShop(g);
darwShop(g);
break;
case GAMEOVER:
g.drawImage(over, 0, 0, Graphics.TOP | Graphics.LEFT);
break;
case WRITE:
g.drawImage(write, 0, 0, Graphics.TOP | Graphics.LEFT);
drawNK(g);
break;
case RANK:
g.drawImage(rank, 0, 0, Graphics.TOP | Graphics.LEFT);
if (drawrank) {
Myrms mrs = new Myrms();
w = mrs.displayall();
mrs.close();
drawrank = false;
}
drawGood(g, w);
break;
case HELP:
drawHelp(g);
break;
}
}
// 画高手
void drawGood(Graphics g, Winner w[]) {
for (int i = 0; i < w.length; i++) {
if (w[i] != null) {
g.setColor(0x0 + i + i + i + i + i + i);
g.drawString(w[i].name, 50, 50 + i * 10, Graphics.TOP
| Graphics.LEFT);
String a = "" + w[i].count;
g.drawString(a, 100, 50 + i * 10, Graphics.TOP | Graphics.LEFT);
}
}
}
// 画NPC
void drawNPC(Graphics g) {
for (int i = 0; i < npc.size(); i++) {
Fish temp = (Fish) npc.elementAt(i);
temp.drawFish(g);
}
}
// 画玩家
void drawPlayer(Graphics g) {
player.drawPlayer(g);
player.drawFishline(g);
player.stillMove();
if (player.isdown && !player.isfish) {
player.stillDown();
}
if (player.isback) {
player.stillUp(money);
}
}
// 画水泡
void drawBub(Graphics g) {
g.setColor(0xffffff);
countUp(true);
for (int i = 0; i < 3; i++) {
if (count % 113 > 0 + i * 10 && count % 113 < 10 + i * 10) {
g.drawArc(30 + i * 5, 190 - i * 10, 3 + i, 3 + i, 0, 360);
}
if (count % 203 > 0 + i * 10 && count % 113 < 10 + i * 10) {
g.drawArc(130 + i * 5, 190 - i * 10, 3 + i, 3 + i, 0, 360);
}
}
}
// 画道具栏
void drawProp(Graphics g) {
g.drawImage(p[0], 100, 0, Graphics.TOP | Graphics.LEFT);
int temp[] = player.isProp();
for (int i = 0; i < 3; i++) {
if (temp[i] == 0) {
g.drawImage(blank[0], 100 + i * 18, 0, Graphics.TOP
| Graphics.LEFT);
}
}
}
// 画得分
void drawPlaygoals(Graphics g) {
int a = playgoal;
drawNum(g, a / 1000, 33, 18);
drawNum(g, (a % 1000) / 100, 42, 18);
drawNum(g, (a % 100) / 10, 51, 18);
drawNum(g, 0, 60, 18);
// ------------------------目标
int d = m.tollgate();
drawNum(g, d / 1000, 32, 32);
drawNum(g, (d % 1000) / 100, 41, 32);
drawNum(g, (d % 100) / 10, 50, 32);
drawNum(g, 0, 59, 32);
}
// 画数字
public void drawNum(Graphics g, int a, int x, int y) {
for (int i = 0; i < 10; i++) {
if (a == i) {
g.drawImage(num[i], x, y, Graphics.TOP | Graphics.LEFT);
}
}
}
// 画字符
void drawWord(Graphics g) {
g.drawImage(word[frame], 63, 170, Graphics.TOP | Graphics.LEFT);
}
// 画菜单,方框
void drawMenu(Graphics g) {
g.drawImage(title, 0, 0, Graphics.TOP | Graphics.LEFT);
countUp(true);
if (count > 0 && count <= 10) {
g.setColor(0xff0000);
}
if (count > 10 && count <= 20) {
g.setColor(0xff00ff);
}
if (count > 20 && count <= 30) {
g.setColor(0xffff00);
}
if (count > 30 && count <= 40) {
g.setColor(0x00ffff);
}
if (count > 40 && count <= 50) {
g.setColor(0x0000ff);
}
if (count == 50) {
count = 0;
}
g.drawRect(62, 169, 51, 21);
drawWord(g);
}
// 画logo
void drawLog(Graphics g) {
countUp(true);
if (count == 0 || log == 0) {
g.drawImage(log1, 0, 0, Graphics.TOP | Graphics.LEFT);
}
if (count == 60 || log == 1) {
g.drawImage(log2, 0, 0, Graphics.TOP | Graphics.LEFT);
}
turnM();
}
// 画logogame
void drawLogogame(Graphics g) {
g.drawImage(logogame, 0, 0, Graphics.TOP | Graphics.LEFT);
g.setColor(0x000000);
int a = 150 + (level) * 150 + (level / 2) * 200 + (level / 3) * 250;
g.drawString("" + a, 77, 107, Graphics.TOP | Graphics.LEFT);
// ----------------------------------------------------------
for (int i = 0; i < 6; i++) {
if (i >= 0 && i <= 1) {
g.setColor(0xff0000);
} else if (i >= 1 && i <= 3) {
g.setColor(0xff00ff);
} else if (i >= 3 && i <= 5) {
g.setColor(0xffff00);
}
if (log % 60 > 0 + 10 * i && log % 60 < 10 + 10 * i) {
g.drawArc(50 + 15 * i, 150 - i * 5, 4 + i, 4 + i, 0, 360);
}
}
}
// 画留名方框
void drawNK(Graphics g) {
g.setColor(0xffff00);
g.drawRect(kx, ky, NW, NW);
if (winname != null) {
g.setColor(0x000000);
// ----------------------
String a = "";
for (int i = 0; i < winname.length(); i++) {
a = winname.toString();
}
g.drawString(a, 60, 80, Graphics.TOP | Graphics.LEFT);
}
}
// 画商店
void darwShop(Graphics g) {
g.setColor(0xffffff);
switch (shop.ly) {
case 27:
g.drawString("鲨鱼药水", 105, 26, Graphics.TOP | Graphics.LEFT);
g.drawString("100", 107, 41, Graphics.TOP | Graphics.LEFT);
g.drawString("钓到鲨鱼", 105, 56, Graphics.TOP | Graphics.LEFT);
g.drawString("使它离开.", 105, 66, Graphics.TOP | Graphics.LEFT);
g.drawString("(自动使用)", 105, 76, Graphics.TOP | Graphics.LEFT);
break;
case 52:
g.drawString("小炸药", 105, 26, Graphics.TOP | Graphics.LEFT);
g.drawString("200", 107, 41, Graphics.TOP | Graphics.LEFT);
g.drawString("15秒钟内", 105, 56, Graphics.TOP | Graphics.LEFT);
g.drawString("使鱼不移动.", 105, 66, Graphics.TOP | Graphics.LEFT);
break;
case 77:
g.drawString("钥匙", 105, 26, Graphics.TOP | Graphics.LEFT);
g.drawString("300", 107, 41, Graphics.TOP | Graphics.LEFT);
g.drawString("打开宝箱", 105, 56, Graphics.TOP | Graphics.LEFT);
g.drawString("之必备.", 105, 66, Graphics.TOP | Graphics.LEFT);
g.drawString("(自动使用)", 105, 76, Graphics.TOP | Graphics.LEFT);
break;
}
}
// 画帮助
void drawHelp(Graphics g) {
g.drawImage(help, 0, 0, Graphics.TOP | Graphics.LEFT);
// ---------------------------------------------------
countUp(true);
if (count % 5 >= 0 && count % 5 <= 5) {
g.drawImage(helptwo[0][0], 5, 0, Graphics.TOP | Graphics.LEFT);
g.drawImage(helptwo[0][0], 115, 0, Graphics.TOP | Graphics.LEFT);
g.drawImage(helptwo[1][0], 97, 175, Graphics.TOP | Graphics.LEFT);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -