我写的个贴子被移动到了非技术区,刚才发不小心自己也发到了非技术区,现在重发,请管理员把非技术区我的帖子删除。
为了让更多同行得到原代码,再开贴,希望管理员不要移动,那样看到的人很少,不利大家共同进步。
我以前写的商业游戏原代码,原来在国外SP使用,似乎国内一直没有用,部分被重写(有些原公司不让公开),如果是BIG5版本的大家找个东东翻译一下好了,呵呵
需要的可以去下面网址看样本 ,更多代码到群里去下,这里只能发代码段不能发完整的带图片的整个程序
QQ群:8294554
龙王J2ME游戏制作,交流技术,共同进步
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.*;
import com.nokia.mid.ui.*;
import com.nokia.mid.sound.*;
public class csbw extends MIDlet
{
private Display dp;
//re1,rz2是人质,dr1,dr2是敌人,xue1:血条值,qiang1:枪,qiang2;枪(太久或雷,我忘了);yyx1也忘了
Image ftu,rz1,rz2,dr1,dr2,xue1,qiang1,qiang2,yyx1;
Timer tm,tm2;
private Fca fca;
//声音单音
Sound s = new Sound(800, 120);
Sound s1 = new Sound(1200, 150);
Sound s2 = new Sound(1000, 100);
Sound s3 = new Sound(1500, 180);
DateField dtime;
//图片显示位置数组
int X[]={19,52,90,19,52,90,19,52,90};
int Y[]={32,32,32,64,64,64,96,96,96};
//gm,gmgd,和过关和结束有关,我也忘了
private boolean gm,gmgd,yn=true,leif;
public String keys;//="axzxvz";
public int jf,z,sd=18,w,ds=8,xu=92,guan=1,dtm,j0,yyx2;
public byte rets,j,k,kkk,a,x,y,X1,Y1,kq,lei=3,tsx,i,mm,kd,dz,xz,xzjx=1;
public csbw()
{fca =new Fca();
dp=Display.getDisplay(this);
}
protected void startApp( ) throws MIDletStateChangeException
{
dp.setCurrent(fca);
//gtimer(5000);
}
protected void pauseApp( )
{
}
protected void destroyApp( boolean b )
{
}
class Fca extends FullCanvas
{ int gg1,gg2,rr1,gg,rr3, gg3,rr2,rr,a4,a5;
byte ht2,HT;
boolean helps;
public void paint(Graphics g)
{
if(helps){
//退出
g.setColor(0, 0,0);
g.fillRect(0,0,128,128);
g.setColor(0,255,0);
g.drawString("Operation note", getWidth()/2, 5 , Graphics.TOP | Graphics.HCENTER);
g.setFont ( Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
g.setColor(100,100,255);
g.drawString(" Open fire:1-9", 0, 30 , Graphics.TOP |Graphics.LEFT);
g.drawString(" corresponding the place", 0, 40 , Graphics.TOP |Graphics.LEFT);
g.drawString(" of enemy on screen. ", 0, 50 , Graphics.TOP |Graphics.LEFT);
g.drawString(" Use bomb: # ", 0, 65 , Graphics.TOP |Graphics.LEFT);
g.drawString(" Can kill all enemy.", 0, 75 , Graphics.TOP |Graphics.LEFT);
g.setColor(255,0,0);
g.drawString(" Don't kell civilian!", 0, 105 , Graphics.TOP |Graphics.LEFT);
}
else{
//设置
switch(tsx){
case 0:
//bozi logo
gtimer2(5000);
g.setColor(0, 0,0);
g.fillRect(0,0,128,128);
g.drawImage(loinImage("/tu1.png",121,92,-2,-126),0,20,Graphics.LEFT|Graphics.TOP);
ftu=null;
gmgd=true;
tsx=1;
break;
case 1:
tm2.cancel();
g.setColor(0, 0,0);
g.fillRect(0,0,128,128);
g.drawImage(loinImage("/tu1.png",127,125,0,0),-1,0,Graphics.LEFT|Graphics.TOP);
g.setColor(0, 0,220);
ftu=null;
g.setFont ( Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
switch(xz){
case 0:
rr=140;gg=140;rr1=255;gg1=255;rr2=140;gg2=140;rr3=140;gg3=140;
break;
case 1:
rr1=140;gg1=140;rr=255;gg=255;rr2=140;gg2=140;rr3=140;gg3=140;
break;
case 2:
rr1=140;gg1=140;rr=140;gg=140;rr2=255;gg2=255;rr3=140;gg3=140;
break;
case 3:
rr1=140;gg1=140;rr=140;gg=140;rr3=255;gg3=255;rr2=140;gg2=140;
break;
}
g.setColor(rr1, gg1, 0);
g.drawString("Soldier", getWidth()/2, 61 , Graphics.TOP | Graphics.HCENTER);
g.setColor(rr, gg, 0);
g.drawString("Partizan", getWidth()/2, 74 , Graphics.TOP | Graphics.HCENTER);
g.setColor(rr2, gg2, 0);
g.drawString("Help", getWidth()/2, 87 , Graphics.TOP | Graphics.HCENTER);
g.setColor(rr3, gg3, 0);
g.drawString("Exit", getWidth()/2, 100 , Graphics.TOP | Graphics.HCENTER);
gm=false;
//tsx=1;
break;
//zhu String.valueOf(jf)
case 3:
g.setColor(0,0,0);
g.fillRect(0,0,128,128);
if(xz==1){a=-24;}
else{a=0;}
g.drawImage(loinImage("/tu2.png",24,19,a,0),4,4,Graphics.LEFT|Graphics.TOP);
ftu=null;
g.drawImage(loinImage("/tu0.png",128,128,0,0),0,0,Graphics.LEFT|Graphics.TOP);
g.drawImage(loinImage("/cj0.png",122,109,0,0),3,16,Graphics.LEFT|Graphics.TOP);
ftu=null;
g.setColor(255, 255,0);
g.setFont ( Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
g.drawString("X"+String.valueOf(lei), 73, 2 , Graphics.TOP | Graphics.LEFT);
g.drawString("L"+String.valueOf(guan), 29, 2 , Graphics.TOP | Graphics.LEFT);
g.drawString(String.valueOf(jf), 95, 2 , Graphics.TOP | Graphics.LEFT);//98
g.setColor(255,0,0);
g.fillRect(18,123,92,1);
g.setColor(255,150,0);
g.fillRect(18,124,92,1);
gtimer(100);
tsx=5;
suanshu();
//dtm=
break;
//kaiqiang*/
case 4:
if ((dz==0)&(X1!=0)&(z>1)){
xu=xu-4;
s.play(1);
if (xu<=0){
gm=true;
tm.cancel();
gtimer2(1);
}
if (qiang1==null){qiang1=loinImage("/tu2.png",7,8,-72,0);}
g.drawImage(qiang1,X1+8,Y1+11,Graphics.LEFT|Graphics.TOP);
g.setColor(0,0,0);
g.fillRect(18+xu,123,4,2);}
break;
//huatu
case 5:
//清原来图
dz=0;
g.setColor(0,0,0);
if(X1!=0){g.fillRect(X1,Y1,HT,19);}
switch(z){
//renzhi
case 0:
if (rz1==null){rz1=loinImage("/tu2.png",24,19,-48,0);rz2=loinImage("/tu2.png",19,19,-48,0);}
if(x==52){g.drawImage(rz1,x,y,Graphics.LEFT|Graphics.TOP);HT=24;}
else{g.drawImage(rz2,x,y,Graphics.LEFT|Graphics.TOP);HT=19;}
break;
//yiyaoxiang
case 1:
if (yyx1==null){yyx1=loinImage("/tu2.png",19,19,-105,0);}
g.drawImage(yyx1,x,y,Graphics.LEFT|Graphics.TOP);HT=19;
break;
//diren
default:
if(xz==1){ht2=0;}else{ht2=-24;}
if(dr1==null){dr1=loinImage("/tu2.png",24,19,ht2,0);dr2=loinImage("/tu2.png",19,19,ht2,0);}
if(x==52){g.drawImage(dr1,x,y,Graphics.LEFT|Graphics.TOP);HT=24;}
else{g.drawImage(dr2,x,y,Graphics.LEFT|Graphics.TOP);HT=19;}
}
ftu=null;
X1=x;Y1=y;
break;
//zidan/xue
case 6:
if((dz==0)&(j==X1)&(k==Y1)){
dz=1;
if(xue1==null){xue1=loinImage("/tu2.png",19,19,-85,0);}
ds=4;
switch(z){
case 0:
s1.play(1);xu=xu-4;g.setColor(0,0,0);g.fillRect(18+xu,123,4,2);
if (xu<=0){gm=true;
tm.cancel();
gtimer2(1);
}
g.drawImage(xue1,j,k,Graphics.LEFT|Graphics.TOP);
break;
case 1:
s3.play(1);xu=xu+8;
if (xu>92){xu=92;}g.setColor(255,0,0);g.fillRect(18,123,xu,2);
break;
default:
s2.play(1);
jf++;
g.drawImage(xue1,j,k,Graphics.LEFT|Graphics.TOP);
}
tsx=2;
}
else{a4=j+8;a5=k+8;s.play(1);
if(qiang2==null){qiang2=loinImage("/tu2.png",4,5,-80,0);}
g.drawImage(qiang2,a4,a5,Graphics.LEFT|Graphics.TOP);
}
if(jf>=9999){jf=9999;}
if(jf<=0){jf=0;}
if((dz==1)&(z>1)){
if((jf%40==0)&(jf!=0)){
if(lei<3){lei++;}
guan=guan+1;
g.setColor(109,103,168);
g.fillRect(29,2,27,11);
g.setColor(0,0,0);
g.fillRect(70,2,18,10);
g.setFont ( Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
g.setColor(255,255,0);
g.drawString("X"+String.valueOf(lei), 73, 2 , Graphics.TOP | Graphics.LEFT);
g.drawString("L"+String.valueOf(guan), 29, 2 , Graphics.TOP | Graphics.LEFT);
if(guan%4==1){g.drawImage(loinImage("/cj1.png",122,109,0,0),3,16,Graphics.LEFT|Graphics.TOP);}
if(guan%4==2){g.drawImage(loinImage("/cj2.png",122,109,0,0),3,16,Graphics.LEFT|Graphics.TOP);}
if(guan%4==3){g.drawImage(loinImage("/cj3.png",122,109,0,0),3,16,Graphics.LEFT|Graphics.TOP);}
if(guan%4==0){g.drawImage(loinImage("/cj0.png",122,109,0,0),3,16,Graphics.LEFT|Graphics.TOP);}
ftu=null;
g.setColor(255,0,0);
g.fillRect(18,123,92,1);
g.setColor(255,150,0);
g.fillRect(18,124,92,1);
g.setColor(0,0,0);
g.fillRect(18+xu,123,92-xu,2);
}
if(sd>13){if(jf%10==0){sd--;}}
if((sd>11)&(sd<=13)){if(jf%15==0){sd--;}}
if((sd>7)&(sd<=11)){if(jf%30==0){sd--;}}
if((sd>4)&(sd<=7)){if(jf%40==0){sd--;}}
g.setColor(0,0,0);
g.fillRect(92,3,31,10);
g.setFont ( Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
g.setColor(255, 255,0);
g.drawString(String.valueOf(jf), 95, 2 , Graphics.TOP | Graphics.LEFT);//98
}
break;
case 2:
g.setColor(0,0,0);
if(X1!=0){g.fillRect(X1,Y1,HT,19);}
//suanshu();
break;
case 7:
g.setColor(0,0,0);
for(i=0;i<9;i++){
if((X[i]!=X1)|(Y[i]!=Y1)){
g.fillRect(X[i],Y[i],15,15);}}
tsx=5;
break;
//lei
case 8:
//dz=1;
try{
DeviceControl.startVibra(100, 200);}
catch(IllegalStateException e){}
if(mm==2){g.setColor(255,100,50);s.play(1);}
else{g.setColor(0,0,0);s2.play(1);}
for(i=0;i<9;i++){
if((i==1)|(i==4)|(i==7)){kd=24;}
else{kd=19;}
g.fillRect(X[i],Y[i],kd,19);}
break;
//lei雷
case 9:
g.setFont ( Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
g.setColor(0,0,0);
g.drawString("X"+String.valueOf(lei+1), 73, 2 , Graphics.TOP | Graphics.LEFT);
g.setColor(255,255,0);
g.drawString("X"+String.valueOf(lei), 73, 2 , Graphics.TOP | Graphics.LEFT);
g.setColor(0,0,0);
g.fillRect(92,3,31,10);
g.setFont ( Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
g.setColor(255, 255,0);
g.drawString(String.valueOf(jf), 95, 2 , Graphics.TOP | Graphics.LEFT);//98
break;
case 10:
tm.cancel();
tm2.cancel();
gm=false;
gtimer2(6000);
gmgd=true;
yn=true;
tsx=100;
sd=18;
xu=92;
xz=0;
lei=3;
ds=10;
rz1=null;
rz2=null;
dr1=null;
dr2=null;
dz=0;
//g.setColor(120,0,0);
//g.fillRect(0,0,128,128);
g.setFont ( Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE));
g.setColor(0,255,100);
g.drawString("GAME OVER", getWidth()/2, 20 , Graphics.TOP | Graphics.HCENTER);
g.setColor(255,0,0);
g.setFont ( Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
g.drawString("killed:"+String.valueOf(jf), getWidth()/2, 65 , Graphics.TOP |Graphics.HCENTER);
g.drawString("Level:"+String.valueOf(guan), getWidth()/2, 50 , Graphics.TOP |Graphics.HCENTER);
//g.drawString("gold plate:"+String.valueOf(jp/(guan+1)), 4, 70 , Graphics.TOP | Graphics.LEFT);
g.setFont ( Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
g.setColor(200,200,220);
g.drawString("Art: Lady Li.zx", getWidth()/2, 85 , Graphics.TOP | Graphics.HCENTER);
g.drawString("programme:Mr.Zhang.gx", getWidth()/2, 95 , Graphics.TOP | Graphics.HCENTER);
g.setColor(255,255,255);
g.drawString("Bozi Sichuan China", getWidth()/2, 110 , Graphics.TOP | Graphics.HCENTER);
guan=1;
jf=0;
break;
case 13:
xu=xu-4;
s.play(1);
if (xu<=0){
gm=true;
tm.cancel();
gtimer2(1);
}
g.setColor(0,0,0);
g.fillRect(18+xu,123,4,2);
g.setFont ( Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
g.setColor(0,0,0);
g.drawString("X"+String.valueOf(lei+1), 73, 2 , Graphics.TOP | Graphics.LEFT);
g.setColor(255,255,0);
g.drawString("X"+String.valueOf(lei), 73, 2 , Graphics.TOP | Graphics.LEFT);
break;
default:
}
}}
//键盘
protected void keyPressed(int keyCode)
{
if(tsx!=100){
if(tsx==0){tsx=1;}
if(tsx==1){
keys=getKeyName(keyCode);
switch(getGameAction(keyCode))
{
case FullCanvas.UP:if(xz>0){xz--;}
break;
case FullCanvas.DOWN:if(xz<3){xz++;}
break;
}
if(keyCode==KEY_SOFTKEY1)
{ if(helps){helps=false;repaint();}
else{if(xz==3){destroyApp(false);
notifyDestroyed();}
else{if(xz==2){helps=true;}
else{
gmgd=false;
tsx=3;}}}
}
//repaint();
}
//游戏键盘
else{
if(keyCode==KEY_SOFTKEY2){
tm.cancel();
gm=false;
gmgd=true;
yn=true;
tsx=1;
sd=18;
xu=92;
xz=0;
lei=3;
guan=1;
jf=0;
ds=10;
rz1=null;
rz2=null;
dr1=null;
dr2=null;
dz=0;
}
else{
switch(keyCode){
case KEY_NUM1:
j=19;k=32;kkk=0;
tsx=6;
break;
case KEY_NUM2:
j=52;k=32;kkk=1;
tsx=6;
break;
case KEY_NUM3:
j=90;k=32;kkk=2;
tsx=6;
break;
case KEY_NUM4:
j=19;k=64;kkk=3;
tsx=6;
break;
case KEY_NUM5:
j=52;k=64;kkk=4;
tsx=6;
break;
case KEY_NUM6:
j=90;k=64;kkk=5;
tsx=6;
break;
case KEY_NUM7:
j=19;k=96;kkk=6;
tsx=6;
break;
case KEY_NUM8:
j=52;k=96;kkk=7;
tsx=6;
break;
case KEY_NUM9:
j=90;k=96;kkk=8;
tsx=6;
break;
case KEY_POUND:
if(lei>0){
lei--;
if(z==0){tsx=13;}
if(z>1){jf++;tsx=9;}
ds=1;
mm=3;
}
break;
}}
}
repaint();}}
}
//启动
public Image loinImage(String fls,int k,int h,int K,int H)
{Image tu;
try{
tu = Image.createImage(fls);
}
catch(Exception e){tu=null;}
ftu=DirectUtils.createImage(k, h, 0x00000000);//logo
Graphics g = ftu.getGraphics();
g.drawImage(tu, K , H, Graphics.TOP | Graphics.LEFT);
tu=null;
return ftu;
}
//定时任务
public class ttt extends TimerTask
{
public void run(){
ds--;
if(tsx==100){tsx=1;tm.cancel();}
else{
if(gm){tm.cancel();tsx=10;}
else{
if(kq++>=3){kq=0;tsx=7;}
if(ds<=0){suanshu();}
if(mm>0){mm--;tsx=8;}
if(ds==2){tsx=4;}
}
}
fca.repaint();
}
}
public void gtimer(int yanchi){
tm=new Timer();
TimerTask tk = new ttt();
tm.schedule(tk,10,yanchi);
}
public class ttt2 extends TimerTask
{
public void run(){
if(tsx==1){fca.repaint();}
if(tsx==100){tm2.cancel();tsx=1;fca.repaint();}
else if(gm){tm2.cancel();tsx=10;fca.repaint();}
}
}
public void gtimer2(int yanchi){
tm2=new Timer();
TimerTask tk = new ttt2();
tm2.schedule(tk,yanchi);
}
//确定人物和位置
public void suanshu(){
int lw=10;
Random rand = new Random();
//确定人物
z=Math.abs(rand.nextInt()%25);
//确定位置
do{lw=Math.abs(rand.nextInt()%9);}
while(w==lw);
switch(lw){
case 0:x=19;y=32;
break;
case 1:x=52;y=32;
break;
case 2:x=90;y=32;
break;
case 3:x=19;y=64;
break;
case 4:x=52;y=64;
break;
case 5:x=90;y=64;
break;
case 6:x=19;y=96;
break;
case 7:x=52;y=96;
break;
case 8:x=90;y=96;
break;
}
w=lw;
ds=sd;
tsx=5;
fca.repaint();
}
}
评论