📄 ta.java
字号:
for(int j=0;j<13;j++)
{ if(mycard[j]==i+1)
{se2[b1]=hs[j];
b1++;
}
}
}
////////////////////////////////////////////////
if(m[i]==3)
{ th[k]=i+1;
k++;
for(int j=0;j<13;j++)
{if(mycard[j]==i+1)
{ th3[k1]=hs[j];
k1++;
}
}
}
///////////////////////////////////////////////
if(m[i]==4)
{ fo[n]=i+1;
n++;
for(int j=0;j<13;j++)
{ if(mycard[j]==i+1)
{ fo4[n1]=hs[j];
n1++;
}
}
}
///////////////////////////////////////////////
}
this.comparted1(se2,b,2);
this.comparted1(th3,k,3);
this.comparted1(fo4,n,4);
///////////////////////////////////////////////////////////////////
ff=0; second=0;three=0;four=0;
for(int i=0;i<b*k;i++)
{ for(int j=0;j<2;j++)
{
fv[r2]=se[r1];
fv5[r2]=se2[ff];
r2++; ff++;
}
r1++; /////////////////////三和二的组合;
for(int j=0;j<3;j++)
{ fv[r2]=th[r4];
fv5[r2]=th3[second];
r2++;second++;
}
r3++; three++;second=four;
if(r1==b)
{ r1=0;r4++;ff=0;
}
if(three==b){second+=3;four+=3;three=0;}
}
//////////////////////////////////////////////////////////////////////////////////////////////
ff=0; second=0;three=0;four=0;r4=0;
for(int i=0;i<a*n;i++)
{ for(int j=0;j<1;j++)
{
fv[r2]=fi[r1];
fv5[r2]=fi1[ff];
r2++; ff++;
}
r1++; /////////////////////四和一的组合;
for(int j=0;j<4;j++)
{ fv[r2]=fo[r4];
fv5[r2]=fo4[second];
r2++;second++;
}
r3++; three++;second=four;
if(r1==a)
{ r1=0;r4++;ff=0;
}
if(three==a){second+=4;four+=4;three=0;}
}
////////////////////////////////////////////////////////////////////////////////////////////
r1=0;
for(int i=0;i<b;i++)
for(int j=0;j<2;j++)
{ mm[r1]=se[i]; ///恢复两张牌的张数
r1++;
}
for(int i=0;i<=r1;i++)
{ se[i]=mm[i];
}
///////////////////////////////////////////////////////////////////////////////////////////
r1=0;
for(int i=0;i<k;i++)
for(int j=0;j<3;j++)
{mm[r1]=th[i]; /////恢复三张牌的张数
r1++;
}
for(int i=0;i<=r1;i++)
{ th[i]=mm[i];
}
////////////////////////////////////////////////////////////////////////////////////////////
r1=0;
for(int i=0;i<n;i++)
for(int j=0;j<4;j++)
{ mm[r1]=fo[i];
r1++; /////恢复四张牌的张数
}
for(int i=0;i<=r1;i++)
{ fo[i]=mm[i];
}
////////////////////////////////////////////////////////////////////////////////////////////
have[whos_turn][1]=a;
have[whos_turn][2]=b;
have[whos_turn][3]=k;
have[whos_turn][5]=n*a+b*k;
}
////////////////////////////////////////////////////////////////////////////////////////////
public void comparted1(int aa[],int c,int r )
{ int p=0;
if(r==2)
{ for(int i=0;i<2*c;)
{ if(aa[i]>aa[i+1])
{ p=aa[i+1];
aa[i+1]=aa[i];
aa[i]=p;
}
i=i+2;
}
}
if(r==3)
{ for(int i=0;i<3*c;)
{ if(aa[i]>aa[i+1])
{ p=aa[i+1];
aa[i+1]=aa[i];
aa[i]=p;
}
if(aa[i+1]>aa[i+2])
{ p=aa[i+2];
aa[i+2]=aa[i+1];
aa[i+1]=p;
}
if(aa[i]>aa[i+1])
{ p=aa[i+1];
aa[i+1]=aa[i];
aa[i]=p;
}
i=i+3;
}
}
if(r==4)
{ for(int i=0;i<4*c;)
{ if(aa[i]>aa[i+1])
{ p=aa[i+1];
aa[i+1]=aa[i];
aa[i]=p;
}
if(aa[i+1]>aa[i+2])
{ p=aa[i+2];
aa[i+2]=aa[i+1];
aa[i+1]=p;
}
if(aa[i+2]>aa[i+3])
{ p=aa[i+3];
aa[i+3]=aa[i+2];
aa[i+2]=p;
}
if(aa[i]>aa[i+1])
{ p=aa[i+1];
aa[i+1]=aa[i];
aa[i]=p;
}
if(aa[i+1]>aa[i+2])
{ p=aa[i+2];
aa[i+2]=aa[i+1];
aa[i+1]=p;
}
i=i+4;
}
}
}
public void showdialog(Graphics g)
{
g.setColor(250,0,0);
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
g.fillRect(60,100,115,50);
g.setColor(250,250,250);
g.drawString("本局结束,继续吗?",65,115,Graphics.LEFT | Graphics.TOP);
if(fire_down)
{
g.setColor(0,220,0);
g.fillRect(0,0,250,300);
g.setColor(0,250,250);
g.fillRect(45,70,150,150);
givecard=1;
first=true;
givecard();
can_draw=false;
pass=false;
key=false;
fire_down=false;
}
}
}
class MenuList extends Canvas implements CommandListener,Runnable,PlayerListener
{
Image bm,sm,w;
Sprite bbm,ssm,ww;
public ta midlet;
public Player play;
public int width,height,height1,gameStates=0,b=0,m=14;
private int FONT_STATIV_TEXT;
public Font font;
public static int xx=0,yy=0;
public Command exit;
private boolean game=true;
public Image image,image1;
public MenuList(ta midlet)
{
try{
bm=Image.createImage("/bm.png");
sm=Image.createImage("/sm.png");
w=Image.createImage("/w.png");
}catch(IOException e){}
bbm=new Sprite(bm);
ssm=new Sprite(sm);
ww=new Sprite(w);
this.midlet=midlet;
exit=new Command("EXIT",Command.EXIT,1);
this.addCommand(exit);
this.setCommandListener(this);
width=this.getWidth();
height=this.getHeight();
font=Font.getFont(FONT_STATIV_TEXT);
try {
image=Image.createImage("/bb.png");
image1=Image.createImage("/c.png");
} catch (IOException ex) { ex.printStackTrace();}
}
public void start()
{
if(play==null)
{
try {
InputStream in=this.getClass().getResourceAsStream("start.mid");
play=Manager.createPlayer(in,"audio/midi");
play.start();
} catch (IOException ex) {
ex.printStackTrace();
} catch (MediaException ex) {
ex.printStackTrace();}
}
/////////////////////////////////////////////////////////////////////////////////
new Thread(this).start();
game=true;
}
protected void paint(Graphics g)
{ g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE));
height1=g.getFont().getHeight();
g.setColor(200,50,100);
g.fillRect(0,0,width,height);
g.fillRect(width/2-46,width/2+21-6,width/2-48,height1-3);
if(yy==0) g.setColor(51,102,255);
else g.setColor(255,255,255);
g.drawString("开始新游戏",width/2-10,height/2-10,g.HCENTER|g.TOP);
g.setColor(51,255,51);
g.setColor(200,50,100);
g.fillRect(width/2-46,width/2+21-6+height1,width/2-48,height1-3);
if(yy==1) g.setColor(51,102,255);
else g.setColor(255,255,255);
g.drawString("游戏说明",width/2-15,height/2+height1,g.HCENTER|g.TOP);
g.drawImage(image1,width/2-50,height/2+m-20,g.HCENTER|g.TOP);
////////////////////////////////////////////////////////////////////
if(m==14) g.setColor(0,51,255);
else g.setColor(204,255,0);
g.fillRect(0,0,10,10);
g.fillRect(this.getWidth()-10,0,10,10);
g.fillRect(0,this.getHeight()-10,10,10);
g.fillRect(this.getWidth()-10,this.getHeight()-10,10,10);
///////////////////////////////////////
g.drawLine(0,0,this.getWidth(),0);
g.drawLine(this.getWidth()-1,0,this.getWidth(),2*this.getHeight());
g.drawLine(0,0,0,this.getHeight());
g.drawLine(0,this.getHeight()-1,2*this.getWidth(),this.getHeight());
////////////////////////////////////////////////////////////////////
if(xx==0)
{
bbm.setTransform(Sprite.TRANS_MIRROR);
bbm.setPosition(5,120);
bbm.paint(g);
ssm.setTransform(Sprite.TRANS_MIRROR);
ssm.setPosition(200,115);
ssm.paint(g);
ww.setTransform(Sprite.TRANS_MIRROR);
ww.setPosition(100,10);
ww.paint(g);
g.setColor(0,0,0);
g.drawRect(width/2-20,width/2+105,image.getWidth(),image.getHeight());
g.setColor(250,0,0);
g.drawString("A",width/2-15,height/2+78,g.HCENTER|g.TOP);
}
else if(xx==1)
{
bbm.setTransform(Sprite.TRANS_NONE);
bbm.setPosition(5,120);
bbm.paint(g);
ssm.setTransform(Sprite.TRANS_NONE);
ssm.setPosition(200,115);
ssm.paint(g);
ww.setTransform(Sprite.TRANS_NONE);
ww.setPosition(100,10);
ww.paint(g);
g.drawImage(image,width/2-10,height/2+80,g.TOP|g.HCENTER);
}
}
public void run()
{
while(game)
{
try { Thread.sleep(800);
} catch (InterruptedException ex) {
ex.printStackTrace();}
if(xx==0)xx=1;
else xx=0;
this.repaint();
}
}
public void keyPressed(int keycode)
{ gameStates=this.getGameAction(keycode);
if(gameStates==Canvas.UP)
{ if(m==14) {m+=height1+10;yy=1;}
else if(m>=14+height1) {m=14;yy=0;}
this.repaint();
}
else if(gameStates==Canvas.DOWN)
{ if(m>=14+height1){m=14;yy=0;}
else {m+=height1+10;yy=1;}
this.repaint();
}
else if(gameStates==Canvas.FIRE)
if(m==14){game=false;midlet.NewGame();}
else if(m==24+height1)
{ game=false;
if(play!=null)
{ if(play.getState()==play.STARTED)
{
try { play.stop();
} catch (MediaException ex) {
ex.printStackTrace();}
}
play=null;
}
midlet.Illuminate();
}
}
//////////////////////////////////////////////////////////////////////////////////
public void playerUpdate(Player player, String string, Object object)
{ if(string==PlayerListener.END_OF_MEDIA)
{
try {
player.start();
} catch (MediaException ex) {
ex.printStackTrace();
}
}
}
////////////////////////////////////////////////////////////////////////////////////
public void commandAction(Command c, Displayable displayable)
{ if(c==exit)
{ game=false; yy=0;midlet.exitGame();
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class GameIlluminate extends Canvas implements CommandListener,Runnable
{ public ta midlet;
public int b=0 ;
public String string[]={"扑","克","游","戏","十","三","张",":","二","为","提","牌","八","为","退","牌","四","和","六","为","选","牌","五","为","出","牌","不","出","时","按","无","即","可"};
public int hh[]=new int[string.length],i=0;
public Command back;
public boolean ga=true;
private int height1,temp=20,j=0;
public Player play;
public boolean f=true;
public static int kk=0,k=0;
public GameIlluminate(ta midlet)
{
this.midlet=midlet;
back=new Command("BACK",Command.BACK,1);
this.addCommand(back);
this.setCommandListener(this);
for(int jj=0;jj<string.length;jj++)
{ hh[jj]=temp;
temp+=15;
}
}
public void start()
{ ga=true;f=true;i=0;k=0;kk=0;j=0;
/////////////////////////////////////////////////////////
try {
InputStream in=this.getClass().getResourceAsStream("Explosion.mid");
play=Manager.createPlayer(in,"audio/midi");
play.start();
} catch (IOException ex) {
ex.printStackTrace();
} catch (MediaException ex) {
ex.printStackTrace();
}
////////////////////////////////////////////////////////
new Thread(this).start();
}
public void run()
{ while(ga)
{
repaint();
try {
Thread.currentThread().sleep(100);
} catch (InterruptedException ex) {
ex.printStackTrace();}
if(i<string.length-1){i++; kk++;j++; }
if(b==0)b=1;
else b=0;
if(j*20>this.getWidth()) { k+=height1;temp=20;j=0;show();kk=0;}
}
}
public void show()
{ for(int jj=0;jj<string.length-13;jj++)
{ hh[jj]=temp;
temp+=15;
}
}
protected void paint(Graphics g)
{ if(f){
g.setColor(0,0,0);
g.fillRect(0,0,this.getWidth(),this.getHeight());
f=false;
}
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
height1=g.getFont().getHeight();
g.setColor(255,255,255);
g.drawString(string[i],hh[kk],k,g.TOP|g.LEFT);
//////////////////////////////////////////////////////////////////////////
if(b==0){
g.setColor(51,255,51);
}else g.setColor(255,255,0);
g.fillRect(0,0,10,10);
g.fillRect(this.getWidth()-10,0,10,10);
g.fillRect(0,this.getHeight()-10,10,10);
g.fillRect(this.getWidth()-10,this.getHeight()-10,10,10);
////////////////////////////////////////////////////////////////
g.drawLine(0,0,this.getWidth(),0);
g.drawLine(this.getWidth()-1,0,this.getWidth(),2*this.getHeight());
g.drawLine(0,0,0,this.getHeight());
g.drawLine(0,this.getHeight()-1,2*this.getWidth(),this.getHeight());
}
public void commandAction(Command command, Displayable displayable)
{ if(command==back)
{ ga=false;f=false;
if(play!=null)
{ if(play.getState()==play.STARTED)
try { play.stop();
} catch (MediaException ex) {
ex.printStackTrace();}
play=null;
}
midlet.BACK();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -