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

📄 gobanghallcanvas.java

📁 游戏说明
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	
	
	
	//判断并显示用户昵称
	private void displayuserinfo(int tableid,int tableseq){
		if(userinfosprite!=null)
			userinfosprite.setVisible(false);
		if(otherinfosprite!=null)
			otherinfosprite.setVisible(false);
		if(tableid!=0){
			int i = 2*tableid-1+tableseq;
			if(!player[i].userid.equals("")){
				Image userinfoimage = null;
				userinfoimage = Image.createImage(OTHER_INFO_WIDTH,OTHER_INFO_HEIGHT);
				Graphics gra = userinfoimage.getGraphics();
				gra.setFont(infofont);
				String tempstr = player[i].nickname ;
				gra.drawString(tempstr,0,0,Graphics.TOP|Graphics.LEFT);
				tempstr = "[" + player[i].userid+ "]   ";
				gra.drawString(tempstr,0,infofont.getHeight(),Graphics.TOP|Graphics.LEFT);
				userinfoimage = setImageAlph(userinfoimage,false,0xffffffff);
				if(userinfosprite==null){
					userinfosprite = new Sprite(userinfoimage);
					lm.insert(userinfosprite,1);
				}if(tableid%3==1||(tableid%3==2&&tableseq==0)){
					userinfosprite.setPosition(handsprite.getX(),handsprite.getY());
				}else{
					userinfosprite.setPosition(handsprite.getX()-OTHER_INFO_WIDTH,handsprite.getY());
				}
				
				userinfosprite.setImage(userinfoimage,userinfoimage.getWidth(),userinfoimage.getHeight());
				userinfosprite.setVisible(true);
				
			}
			
		}
		
	}
	
	
	//显示其他用户的详细资料
	private void displaydetailinfo(int tableid,int tableseq){
		if(otherinfosprite!=null)
			otherinfosprite.setVisible(false);
		if(userinfosprite!=null)
			userinfosprite.setVisible(false);
		if(tableid!=0){
			if(!otherinfonode.getUserId().equals("")){
				Image userinfoimage = Image.createImage(OTHER_DETAIL_WIDTH,OTHER_DETAIL_HEIGHT);
				Graphics gra = userinfoimage.getGraphics();
				gra.setFont(infofont);
				String SexArry[] = {"男","女"};
				int sex = otherinfonode.getSex();
				String tempstr = otherinfonode.getNickName() + "[" + otherinfonode.getUserId()
								+ "]   ";
				gra.drawString(tempstr,0,0,Graphics.TOP|Graphics.LEFT);
				tempstr = "普通权限  "+ SexArry[sex-1];
				gra.drawString(tempstr,0,infofont.getHeight(),Graphics.TOP|Graphics.LEFT);
				
				tempstr = "级别 "+otherinfonode.gamelevel+"  积分 "+String.valueOf(otherinfonode.integer);
				gra.drawString(tempstr,0,2*infofont.getHeight(),Graphics.TOP|Graphics.LEFT);
				tempstr = "赢 "+String.valueOf(otherinfonode.wincount)+" 输 "
						+ String.valueOf(otherinfonode.failcount);
				gra.drawString(tempstr,0,3*infofont.getHeight(),Graphics.TOP|Graphics.LEFT);
				tempstr = "和 "	+ String.valueOf(otherinfonode.equalcount)+" 胜率 "+otherinfonode.winrate ;
				gra.drawString(tempstr,0,4*infofont.getHeight(),Graphics.TOP|Graphics.LEFT);
				userinfoimage = setImageAlph(userinfoimage,false,0xffffffff);
				if(otherinfosprite==null){
					otherinfosprite = new Sprite(userinfoimage);
					lm.insert(otherinfosprite,2);
				}else{
					otherinfosprite.setImage(userinfoimage,userinfoimage.getWidth(),userinfoimage.getHeight());
				}
				otherinfosprite.setVisible(true);
				
				otherinfosprite.setVisible(true);
				otherinfosprite.setPosition(OTHERINFO_X,OTHERINFO_Y+moveheight);
			/*	
				int xcor=handsprite.getX();
				int ycor=handsprite.getY();
				
				if((tableid%3 == 2 && tableseq == 1)|| (tableid%3 ==0)){  //用户在屏幕偏右
					xcor = handsprite.getX()-OTHER_DETAIL_WIDTH;
				}
				if(handsprite.getY()-yViewWindow > mainHeight-OTHER_DETAIL_HEIGHT){   //用户在屏幕的下方
					ycor= handsprite.getY()-OTHER_DETAIL_HEIGHT;
				}
				
				otherinfosprite.setPosition(xcor,ycor);*/
			}
			
		}
		
	}
	
	
	
//	显示玩家的详细资料
	private void displayMYINFO(int tableid,int tableseq){
		if(otherinfosprite!=null)
			otherinfosprite.setVisible(false);
		if(userinfosprite!=null)
			userinfosprite.setVisible(false);
		myinfoflag = true;
		if(tableid!=0){
			if(!commstructnode.getUserId().equals("")){
				Image userinfoimage = Image.createImage(MY_INFO_WIDTH,MY_INFO_HEIGHT);
				Graphics gra = userinfoimage.getGraphics();
				gra.setFont(infofont);
				String SexArry[] = {"男","女"};
				int sex = commstructnode.getSex();
				String tempstr = commstructnode.getNickName() + "[" + commstructnode.getUserId()
								+ "]   ";
				gra.drawString(tempstr,0,0,Graphics.TOP|Graphics.LEFT);
				tempstr = null;
				tempstr = "普通权限  "+ SexArry[sex-1];
				gra.drawString(tempstr,0,infofont.getHeight(),Graphics.TOP|Graphics.LEFT);
				tempstr = null;
				tempstr = "级别 "+commstructnode.gamelevel+"  积分 "+String.valueOf(commstructnode.integer);
				gra.drawString(tempstr,0,2*infofont.getHeight(),Graphics.TOP|Graphics.LEFT);
				tempstr = null;
				tempstr = "赢 "+String.valueOf(commstructnode.wincount)+" 输 "
						+ String.valueOf(commstructnode.failcount);
				gra.drawString(tempstr,0,3*infofont.getHeight(),Graphics.TOP|Graphics.LEFT);
				tempstr = null;
				tempstr = "和 "	+ String.valueOf(commstructnode.equalcount)+" 胜率 "+commstructnode.winrate ;
				gra.drawString(tempstr,0,4*infofont.getHeight(),Graphics.TOP|Graphics.LEFT);
				gra.drawString("修改资料",50,MY_INFO_HEIGHT-infofont.getHeight(),Graphics.TOP|Graphics.LEFT);
				tempstr = null;
				userinfoimage = setImageAlph(userinfoimage,false,0xffffffff);
				if(myinfosprite==null){
					myinfosprite = new Sprite(userinfoimage);
					lm.insert(myinfosprite,3);
				}else{
					myinfosprite.setImage(userinfoimage,userinfoimage.getWidth(),userinfoimage.getHeight());
					lm.insert(myinfosprite,3);
				}
				myinfosprite.setVisible(true);
				myinfosprite.setPosition(MYINFO_X,MYINFO_Y+moveheight);
				handsprite.setVisible(true);
				handsprite.setPosition(MYINFO_X+60,MYINFO_Y+moveheight+MY_INFO_HEIGHT-infofont.getHeight());
			}
			
		}
		if(menucontrol.getvisibleflag()){
			menucontrol.toHide();
			handsprite.setVisible(true);
		}
		gobangcontrol.rt.gc();
		
	}
	
	public void handleEvent(int eventID, MainGameEvent e) {
		// TODO 自动生成方法存根
		maingameevent = e;
		switch(eventID){
			case GobangEvent.HALLINFORECEIVE:   //接收大厅信息
				sendflag = false;
				resendflag = 0;
				drawhallinfo();
				paintCanvas();
				break;
				
			case GobangEvent.OTHERSITRESPOND:  //其他用户坐下
				modifyhallinfo();
				paintCanvas();
				break;
			case GobangEvent.OTHERUPRESPOND:
				modifyhallinfo();
				paintCanvas();
				break;
			case GobangEvent.MODIFYFAIL:  //用户资料修改失败
			case UniGameEvent.MODIFYSUCCESSFUL:  //资料修改成功
				myinfosprite.setVisible(false);
				myinfoflag = false;
				handsprite.reflesh();
				paintCanvas();
				display.setCurrent(this);
				break;
			case GobangEvent.EXITROOMRESPOND:  //用户退出房间请求响应
				sendflag = false;
				resendflag = 0;
				clearCanvas();
				gobangcontrol.handleEvent(GobangEvent.EXITROOMRESPOND,maingameevent);
				break;
			case GobangEvent.SITRESPOND:  //用户坐下成功响应
				sendflag = false;
				resendflag = 0;
				inroomflag = true;
				commstructnode = maingameevent.getCommNode();
				commstructnode.setTableId(String.valueOf(handsprite.getTableid()));
				commstructnode.setTableSeq(handsprite.getTableseq());
				maingameevent.setCommNode(commstructnode);
				SitCanvasDeal();
				gobangcontrol.handleEvent(GobangEvent.SITRESPOND,maingameevent);
				break;
			case GobangEvent.SITFAILRESPOND:  //坐下失败
				sendflag = false;
				resendflag = 0;
				inroomflag = true;
				commstructnode = maingameevent.getCommNode();
				commstructnode.setTableId("0");
				maingameevent.setCommNode(commstructnode);
				handsprite.setRelase();
				paintCanvas();
				break;
			case GobangEvent.USERREADY:  //用户准备好响应
				otherstatusmodfy(0);
				break;
			case GobangEvent.OTHEREXIT:   //其他用户退出游戏,或站起
				modifyhallinfo();
				paintCanvas();
				break;
			case GobangEvent.OTHERREADY:
				otherstatusmodfy(0);
				paintCanvas();
				break;
			case GobangEvent.OTHERSTART:
				otherstatusmodfy(1);
				paintCanvas();
				break;
			case GobangEvent.OTHERGAMEOVER:
				otherstatusmodfy(2);
				paintCanvas();
				break;
				
			case GobangEvent.OTHERINFORECIVE:  //获取其他用户详细信息
				sendflag = false;
				resendflag = 0;
				otherinfonode = gobangdeal.getOtherUserInfo();
				displaydetailinfo(handsprite.getTableid(),handsprite.getTableseq());
				otherinfonode.init();
				handsprite.setRelase();
				paintCanvas();
				break;
			
			default:
				break;
		}

	}//

	//用户坐下,清空各种图层
	private void SitCanvasDeal(){
		if(gobangtimer!=null){
			gobangtimer.ToExit();
			gobangtimer = null;
		}
		if(lm != null){
			for(int i=0;i<lm.getSize();i++){
				lm.remove(lm.getLayerAt(i));
			}
		}
		myinfosprite = null;
		for(int i=0;i<SITCOUNT+1;i++){
			playersprite[i] = null;
		}
		lm = null;
	 	g = null;
	 	helpsprite = null;
	 	menucontrol.setNull();
	 	myinfosprite = null;
		otherinfosprite = null;
		userinfosprite = null;
		boyimage1 = null;
		boyimage2 = null;
		girlimage1 = null;
		girlimage2 = null;      //玩家图片
		gobangcontrol.rt.gc();
			
	}
	
		
	
	//清空大厅数据
	public void clearCanvas(){
		if(gobangtimer!=null){
			gobangtimer.ToExit();
			gobangtimer = null;
		}
		if(lm != null){
			for(int i=0;i<lm.getSize();i++){
				lm.remove(lm.getLayerAt(i));
			}
		}
		lm = null;
	 	g = null;
		for(int i=0;i<SITCOUNT+1;i++){
			playersprite[i] = null;
		}
		
	 	helpsprite = null;
	 	if(menucontrol!=null)
	 		menucontrol.setNull();
	 	menucontrol = null;
	 	handsprite = null;
	 	myinfosprite = null;
		otherinfosprite = null;
		userinfosprite = null;
		boyimage1 = null;
		boyimage2 = null;
		girlimage1 = null;
		girlimage2 = null;      //玩家图片
		inroomflag = false;
		gobangcontrol.rt.gc();
	}

	//每秒操作
	public void addSec() {
		// TODO 自动生成方法存根
		currcount++;
		if(currcount>=30){ //每30秒发送一个在线检测包
			if(maingameevent!=null)
				gobangdeal.setCheckFlag(maingameevent.getCommNode().getUserId());
				currcount=0;
		}
		if(resendflag>=10&&sendflag){//如果发起一次数据请求后20秒内没接受到响应信息,则重发
			sendflag = true;
			gobangdeal.ReSend();
			resendflag = 0;
		}
		if(sendflag){//数据请求已经发出
			resendflag++;
		}else{
			resendflag=0;
		}
		
		//System.out.println("*********************gobanghallcanvas");
	}
	
//	将图片背景变透明(alphflag: true 全透明 false 半透明  )
	private Image setImageAlph(Image orignImage,boolean alphflag,int backcolor){
		Image tempimage = null;
		int tempwidth= 0;
		int tempheight = 0;
		tempwidth = orignImage.getWidth();
		tempheight = orignImage.getHeight();
		int temprect[]= new int[tempwidth*tempheight];
		orignImage.getRGB(temprect,0,tempwidth,0,0,tempwidth,tempheight);
		orignImage = null;
		gobangcontrol.rt.gc();
		
		for(int i = 0;i<tempwidth*tempheight;i++){
			if(temprect[i]==backcolor)   //将白底的图片变透明
				if(alphflag)
					temprect[i]=temprect[i]&0x00ffffff;
				else
					temprect[i]=temprect[i]&0xaaffffff;
		}
		tempimage = Image.createRGBImage(temprect,tempwidth,tempheight,true);
		temprect = null;
		gobangcontrol.rt.gc();
		
		return tempimage;
	}
	
	
	
	
	
	//清空对象
	public void setNull(){
		if(gobangtimer!=null){
			gobangtimer.ToExit();
			gobangtimer = null;
		}
		if(lm != null){
			for(int i=0;i<lm.getSize();i++){
				lm.remove(lm.getLayerAt(i));
			}
		}
		for(int i=0;i<SITCOUNT+1;i++){
			playersprite[i] = null;
		}
		lm = null;
		gaminglayer = null;
	  	helpsprite = null;
	  	if(menucontrol!=null){
	  		menucontrol.setNull();
		 	menucontrol = null;
	  	}
	 	handsprite = null;
		myinfosprite = null;
		otherinfosprite = null;
		userinfosprite = null;
		instance = null;
		player = null;   //存放所有坐下的用户信息
		playersprite = null;
		gobangdeal = null;
	 	display = null;
		g = null;
		boyimage1 = null;
		boyimage2 = null;
		girlimage1 = null;
		girlimage2 = null;      //玩家图片
		gobangcontrol.rt.gc();
		gobangcontrol = null;
		
	}

}

⌨️ 快捷键说明

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