⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ta.java

📁 Phone poker games.用J2ME写的一个手机扑克小游戏.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import java.util.*;
public class ta extends MIDlet implements CommandListener 
{
    public MenuList list=new MenuList(this);
    public GameIlluminate illuminate=new GameIlluminate(this);
	Command exit=new Command("退出",Command.BACK,1);
	game g;
    public void NewGame()
    { 
     try{
		g=new game();
	   }
	   catch(Exception e){}
		g.addCommand(exit);
		g.setCommandListener(this);
		Display.getDisplay(this).setCurrent(g);
        if(list.play!=null)
          { if(list.play.getState()==list.play.STARTED)       
                 try { list.play.stop();   
                      } catch (MediaException ex) {
                              ex.printStackTrace();}    
            list.play=null;
           }
		g.start();        
    }
    
    public void Illuminate()
    { Display.getDisplay(this).setCurrent(illuminate);
      illuminate.start();
    }
    
    public void BACK()
    { Display.getDisplay(this).setCurrent(list);
      list.start();
    }
    
    public void exitGame()
    { this.destroyApp(false);
      this.notifyDestroyed();
    }
	public void startApp()
	{		
      Display.getDisplay(this).setCurrent(list);
      list.start();
	}
	public void pauseApp()
	{}
	public void destroyApp(boolean e)
	{}
	public void exit()
	{}
	public void commandAction(Command e,Displayable diaplayable)
	{
	if(e==exit)
	{
      Display.getDisplay(this).setCurrent(list);
      list.start();		
	}
	}
}
class game extends GameCanvas implements Runnable
{  
	Image image,aa,bm,sm,w;
	Player play;
	Sprite bg,ak,bk,ck,dk,bbm,ssm,ww;
	LayerManager lay;
	static int which=0,again;
	int cards[][]=new int[52][1];
	int is_up[]=new int[14],out_card=0,card[][]=new int[4][14],type[][]=new int[4][14],givecard=-1;
	boolean pass=false,can_draw=false,key=false,first=true,fire_down=false,running=false,running1=false,running2=false;
	int all[]=new int[4],have[][]=new int[4][6],card1[]=new int[6],type1[]=new int[6],card2[]=new int[6],type2[]=new int[6],judge=4,whos_turn=2,sum_cards;
	int one[][]=new int[4][13],two[][]=new int[4][13],thrid[][]=new int[4][13],five[][]=new int[4][60],onet[][]=new int[4][13],twot[][]=new int[4][13],thridt[][]=new int[4][13],fivet[][]=new int[4][60];
    public int fo[]=new int[13];
    public int fo4[]=new int[13];
   int mycard[]=new int [14];
   int hs[]=new int [14];
    public int fi[]=new int[13];
    public int se[]=new int[13];
    public int th[]=new int[13];
    public int fv[]=new int[60];
    public int fi1[]=new int[13];
    public int se2[]=new int[13];
    public int th3[]=new int[13];
    public int fv5[]=new int[60];
	public void contract()
	{
fi=one[whos_turn];
se=two[whos_turn];
th=thrid[whos_turn];
fv=five[whos_turn];
fi1=onet[whos_turn];
se2=twot[whos_turn];
th3=thridt[whos_turn];
fv5=fivet[whos_turn];	
mycard=card[whos_turn];
hs=type[whos_turn];	
	}
	game()
	{
	super(true);
    this.setFullScreenMode(true);
	try
	{
	image=Image.createImage("/cards.png");	
    InputStream in=this.getClass().getResourceAsStream("/Explosion.wav");
       try {
                play=Manager.createPlayer(in,"audio/x-wav");
                
            } catch (MediaException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
	}catch(IOException e){}
	try
	{
	image=Image.createImage("/bb.png");
	aa=Image.createImage("/cards.png");
	bm=Image.createImage("/bm.png");
	sm=Image.createImage("/sm.png");
	w=Image.createImage("/w.png");
	}catch(IOException e){}
    bg=new Sprite(image);
    ak=new Sprite(aa,11,17);
	bbm=new Sprite(bm);
	ssm=new Sprite(sm);
	ww=new Sprite(w);
	for(int i=0;i<52;i++)
		cards[i][0]=i;
	lay=new LayerManager();
	lay.append(bg);
	lay.setViewWindow(0,0,300,300);
	givecard();	
	}
	public void run()
	{
		Graphics g=this.getGraphics();
		while(true)
		{
		if(givecard<14)
		{
		givecard++;
		}
		else
		{
		input();
		}
		draw(g);
		try
		{
			Thread.sleep(300);
		}
		catch(InterruptedException e){}
		}
	}
	public void start()
	{
		Thread t=new Thread(this);
		t.start();
	}
	public void drawcard(Graphics g,int num,int type,int x,int y)
	{
		//g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
		g.setColor(0,0,10);
		g.drawRect(x,y,20,30);
		g.setColor(250,250,250);
		g.fillRect(x+1,y+1,19,29);
		int p=0,q=0;
		switch(type)
		{
		case 1:p=3;break;
		case 2:p=2;break;
		case 3:p=1;break;
		case 4:p=0;
		}
		q=num;
		ak.setFrameSequence(cards[p*13+q-1]);
		ak.setPosition(x+1,y);
		ak.paint(g);
		g.setColor(250,250,250);
		g.fillRect(x+11,y+1,9,29);
		g.fillRect(x+1,y+16,19,12);
	}
	public void showcard(Graphics g)
	{
		g.setColor(100,0,0);
		switch(whos_turn)
		{
		case 1:g.fillRect(50,120,45,40);	
			for(int i=0;i<sum_cards;i++)
				drawcard(g,card1[i],type1[i],52+i*5,122);
			break;
		case 2:g.fillRect(100,70,45,40);
			for(int i=0;i<sum_cards;i++)
				drawcard(g,card1[i],type1[i],102+i*5,75);
			break;
		case 3:g.fillRect(140,120,45,40);
			for(int i=0;i<sum_cards;i++)
				drawcard(g,card1[i],type1[i],142+i*5,122);
		}
	}

	public void draw(Graphics g)
	{
		if(running2&&whos_turn==1)
		{
		    bbm.setTransform(Sprite.TRANS_MIRROR);
		    bbm.setPosition(5,120);
			bbm.paint(g);
			running2=false;
		}
		else if(!running2&&whos_turn==1)
		{
            bbm.setTransform(Sprite.TRANS_NONE);
			bbm.setPosition(5,120);
			bbm.paint(g);
			running2=true;
		}
		if(running1&&whos_turn==3)
		{
		    ssm.setTransform(Sprite.TRANS_MIRROR);	
		    ssm.setPosition(200,115);
			ssm.paint(g);
			running1=false;
		}
		else if(!running1&&whos_turn==3)
		{
            ssm.setTransform(Sprite.TRANS_NONE);
			ssm.setPosition(200,115);
			ssm.paint(g);
			running1=true;
		}
		if(running&&whos_turn==2)
		{
		ww.setTransform(Sprite.TRANS_MIRROR);
		ww.setPosition(100,10);
			ww.paint(g);
			running=false;
		}
		else if(!running&&whos_turn==2)
		{	ww.setTransform(Sprite.TRANS_NONE);
			ww.setPosition(100,10);
			ww.paint(g);
		    running=true;
		}
		if(givecard>13)
		{
		   g.setColor(0,0,0);
		   g.fillRect(1,220,20,20);
		   g.fillRect(30,220,20,20);
		   g.fillRect(190,220,20,20);
		   g.fillRect(220,220,20,20);
		   g.setColor(0,220,0);
		   g.fillRect(105,125,35,40);
		   g.setColor(100,0,0);	
		   g.fillRect(110,130,20,20);
		   switch(whos_turn)
		   {
		   case 0:g.fillRect(220,220,20,20);break;
		   case 1:g.fillRect(1,220,20,20);break;
		   case 2:g.fillRect(30,220,20,20);break;
		   case 3:g.fillRect(190,220,20,20);
		   }
		   g.setColor(100,100,100);
		   if(all[1]==0)g.fillRect(1,220,20,20);
		   if(all[2]==0)g.fillRect(30,220,20,20);
		   if(all[3]==0)g.fillRect(190,220,20,20);
		   if(all[0]==0)g.fillRect(220,220,20,20);
		}
		if(all[0]==0&&whos_turn==0)
		{
			whos_turn++;
		}
        if(givecard>13&&whos_turn!=0)//如果发完牌且是机器出牌就执行
		{
        shu(one[whos_turn],two[whos_turn],thrid[whos_turn],five[whos_turn],onet[whos_turn],twot[whos_turn],thridt[whos_turn],fivet[whos_turn],card[whos_turn],type[whos_turn]);
    	g.setColor(0,250,250);
		if(judge==4)//判断是否是这一方大
		{
			if(have[whos_turn][5]!=0)
			{
				for(int i=0;i<5;i++)
				{
				card1[i]=five[whos_turn][i];
				type1[i]=fivet[whos_turn][i];
				}
				sum_cards=5;
			}
			else if(have[whos_turn][2]!=0)
			{
				for(int i=0;i<2;i++)
				{
				card1[i]=two[whos_turn][i];
				type1[i]=twot[whos_turn][i];
				}
				sum_cards=2;
			}
			else if(have[whos_turn][3]!=0)
			{
				for(int i=0;i<3;i++)
				{
				card1[i]=thrid[whos_turn][i];
				type1[i]=thridt[whos_turn][i];
				}
				sum_cards=3;
			}
			else if(have[whos_turn][1]!=0)
			{
				card1[0]=one[whos_turn][0];
				type1[0]=onet[whos_turn][0];
				sum_cards=1;
			}		
			if(all[whos_turn]!=0)
			{
			judge=1;
            sub();			
			all[whos_turn]-=sum_cards;
			showcard(g);
			}
			else
			{
		     g.setColor(100,0,0);
		     switch(whos_turn)
		     {
		     case 1:g.fillRect(50,120,45,40);	
			 break;
		     case 2:g.fillRect(100,70,45,40);
			 break;
		     case 3:g.fillRect(140,120,45,40);
		     }
			judge=4;
			}
		}
		else if(have[whos_turn][sum_cards]!=0)
		{
			int j,k;
			for(j=0;j<have[whos_turn][sum_cards];j++)
			{
			k=0;
			switch(sum_cards)
			{
			case 1:
				for(int i=j*1;i<j*1+1;i++)
				{
				card2[k]=one[whos_turn][i];
				type2[k]=onet[whos_turn][i];
				k++;
			    }
				break;
			case 2:
				for(int i=j*2;i<j*2+2;i++)
				{
				card2[k]=two[whos_turn][i];
				type2[k]=twot[whos_turn][i];
				k++;
				}
                break;
			case 3:
				for(int i=j*3;i<j*3+3;i++)
				{
				card2[k]=thrid[whos_turn][i];
				type2[k]=thridt[whos_turn][i];
				k++;
				}
                break;
			case 5:
				for(int i=j*5;i<j*5+5;i++)
				{
				card2[k]=five[whos_turn][i];
				type2[k]=fivet[whos_turn][i];
				k++;
				}
                break;
			}
			if(compare(card1,type1,card2,type2,sum_cards))//比较两牌的大小
			{
			for(int p=0;p<sum_cards;p++)
			{
				card1[p]=card2[p];
				type1[p]=type2[p];
			}
            sub();
			all[whos_turn]-=sum_cards;
		    showcard(g);
			judge=1;
			break;
			}		
			}
			if(j==have[whos_turn][sum_cards])
		   {
		     g.setColor(100,0,0);
		     switch(whos_turn)
		     {
		     case 1:g.fillRect(50,120,45,40);	
			 break;
		     case 2:g.fillRect(100,70,45,40);
			 break;
		     case 3:g.fillRect(140,120,45,40);
		     }
		     g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
		     g.setColor(200,0,0);
			 switch(whos_turn)
			 {
			 case 1: g.drawString("pass",52,122,Graphics.LEFT | Graphics.TOP);break;
			 case 2: g.drawString("pass",102,72,Graphics.LEFT | Graphics.TOP);break;
			 case 3: g.drawString("pass",142,122,Graphics.LEFT | Graphics.TOP);break;
			 }
			 judge++;		
		   }
		}
		else if(all[whos_turn]!=0)
		{		
		     g.setColor(100,0,0);
		     switch(whos_turn)
		     {
		     case 1:g.fillRect(50,120,45,40);	
			 break;
		     case 2:g.fillRect(100,70,45,40);
			 break;
		     case 3:g.fillRect(140,120,45,40);
		     }
		     g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
		     g.setColor(200,0,0);
			 switch(whos_turn)
			 {
			 case 1: g.drawString("pass",52,122,Graphics.LEFT | Graphics.TOP);break;
			 case 2: g.drawString("pass",102,72,Graphics.LEFT | Graphics.TOP);break;
			 case 3: g.drawString("pass",142,122,Graphics.LEFT | Graphics.TOP);break;
			 }
			judge++;
		}
		else
		{
		     g.setColor(100,0,0);
		     switch(whos_turn)
		     {
		     case 1:g.fillRect(50,120,45,40);	
			 break;
		     case 2:g.fillRect(100,70,45,40);
			 break;
		     case 3:g.fillRect(140,120,45,40);
		     }
		judge++;
		}
				whos_turn++;
			if(whos_turn==4)
				whos_turn=0;
		}
		for(int i=0;i<4;i++)
			if(all[i]==0)
				again++;
		if(again>2)
			showdialog(g);
		again=0;
		if(givecard<=13&&givecard>0)
		{
			//g.setColor(100,0,20);
			//g.fillRect(40,60,150,150);
			bg.setTransform(Sprite.TRANS_NONE);
			bg.setPosition(70+givecard*5,70);
			bg.paint(g);
			bg.setTransform(Sprite.TRANS_MIRROR_ROT90);
			bg.setPosition(55,100+givecard*5);
			bg.paint(g);
			bg.setPosition(140,100+givecard*5);
			bg.paint(g);
            drawcard(g,card[0][givecard],type[0][givecard],40+givecard*10,250);
		    if(givecard==13)
			{
			g.setColor(0,220,0);
			g.fillRect(40,60,155,150);
            g.setColor(100,0,0);
            g.fillRect(50,120,45,40);	
            g.fillRect(100,70,45,40);
            g.fillRect(140,120,45,40);
			g.fillRect(100,165,45,40);
			g.setColor(0,0,0);
			g.fillRect(40,60,155,10);
			g.fillRect(40,60,10,150);
			g.fillRect(185,60,10,150);
			g.fillRect(40,205,155,10);
			}
		}
		if(first)
		{		
		    g.setColor(0,100,0);		
		    g.fillRect(0,0,250,300);
       	    g.setColor(0,220,0);
		    g.fillRect(0,240,250,50);
			ssm.setPosition(200,115);
			bbm.setPosition(5,120);
			ww.setPosition(100,10);
			bbm.paint(g);
			ssm.paint(g);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -