package cardclient;
import javax.microedition.io.SocketConnection;
import java.io.InputStream;
import javax.microedition.io.Connector;
import java.io.OutputStream;
/**
* <p>Title: CardClient</p>
*
* <p>Description: lizhenpeng</p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: LP&P</p>
*
* @author lipeng
* @version 1.0
*/
import lipeng.*;
import javax.microedition.lcdui.*;
public class GameManager
implements Runnable
{
public GameManager()
{
inst=this;
gameState=0;
for(int i=0;i<30;i++)
{
userCard[i]=new Card();
oppoCard[i]=new Card();
userPostCard[i]=new Card();
oppoPostCard[i]=new Card();
}
}
public void run()
{
while(networkEnable)
{
try
{
in.read(recvHeadBuffer,0,4);
recvDataHead.FillData(recvHeadBuffer,0);
if(recvDataHead.size!=0)
{
recvBuffer=new byte[recvDataHead.size];
in.read(recvBuffer,0,recvDataHead.size);
//处理数据
ProcessData();
} else
{
//处理信息
ProcessData();
}
} catch(Exception e)
{
System.out.println(e);
}
}
}
public void openSocket()
{
try
{
conn=(SocketConnection)Connector.open("socket://localhost:8070");
in=conn.openInputStream();
out=conn.openOutputStream();
networkEnable=true;
sendDataHead.command=NetProtocol.LOGIN;
//16X2
sendDataHead.size=32;
byte[] buffer=userName.getBytes();
byte[] buffer2=new byte[32];
System.arraycopy(buffer,0,buffer2,0,buffer.length);
this.sendBuffer=sendDataHead.getBytes();
out.write(sendBuffer,0,sendBuffer.length);
out.write(buffer2,0,buffer2.length);
gameState=2;
} catch(Exception e)
{
System.out.print(e);
}
networkThread=new Thread(this);
networkThread.start();
}
private void hasControl()
{
this.keyAction=0;
this.iControl=true;
cursorX=0;
cursorY=MainGame.inst.h-22*3;
cardSelect=0;
currentCard=0;
isSelect=false;
}
public void ProcessData()
{
switch(recvDataHead.command)
{
case NetProtocol.HASLOGIN:
{
userList=new String[recvDataHead.size/32];
int i;
int place=0;
for(i=0;i<userList.length;i++)
{
userList[i]=new String(this.recvBuffer,place,32);
place+=32;
}
MainGame.inst.userList=new UserList();
Display.getDisplay(CardClientMIDlet.instance).setCurrent(MainGame.inst.
userList);
}
break;
case NetProtocol.STARTGAME_FIRST:
{
Display.getDisplay(CardClientMIDlet.instance).setCurrent(MainGame.inst);
int place = 0;
this.userCardNum = 54/2;
this.oppoCardNum = 54/2;
for(int i=0;i<27;i++)
{
this.userCard[i].fillData(this.recvBuffer,place);
place += 4;
}
for(int i=0;i<27;i++)
{
this.oppoCard[i].fillData(this.recvBuffer,place);
place +=4;
}
gameState = 3;
hasControl();
}
break;
case NetProtocol.STARTGAME_LAST:
{
Display.getDisplay(CardClientMIDlet.instance).setCurrent(MainGame.inst);
int place=0;
this.iControl=false;
this.userCardNum=54/2;
this.oppoCardNum=54/2;
for(int i=0;i<27;i++)
{
this.userCard[i].fillData(this.recvBuffer,place);
place+=4;
}
for(int i=0;i<27;i++)
{
this.oppoCard[i].fillData(this.recvBuffer,place);
place+=4;
}
this.gameState=3;
}
break;
case NetProtocol.OPPO_REJECT:
{
this.userPostCardNum = 0;
hasControl();
}
break;
case NetProtocol.OPPO_POSTCARD:
{
this.oppoPostCard[0].fillData(recvBuffer,0);
userPostCardNum = 0;
oppoPostCardNum=1;
hasControl();
}
break;
}
}
public void keyPressd(int keyCode,int gameKeyCode)
{
switch(gameKeyCode)
{
case Canvas.UP:
keyAction|=LPKeyMask.MASK_KEY_UP;
break;
case Canvas.DOWN:
keyAction|=LPKeyMask.MASK_KEY_DOWN;
break;
case Canvas.FIRE:
keyAction|=LPKeyMask.MASK_KEY_OK;
break;
case Canvas.LEFT:
keyAction|=LPKeyMask.MASK_KEY_LEFT;
break;
case Canvas.RIGHT:
keyAction|=LPKeyMask.MASK_KEY_RIGHT;
break;
}
}
public void keyReleased(int keyCode,int gameKeyCode)
{
switch(gameKeyCode)
{
case Canvas.FIRE:
keyAction&=~LPKeyMask.MASK_KEY_OK;
break;
case Canvas.UP:
keyAction&=~LPKeyMask.MASK_KEY_UP;
break;
case Canvas.DOWN:
keyAction&=~LPKeyMask.MASK_KEY_DOWN;
break;
case Canvas.LEFT:
keyAction&=~LPKeyMask.MASK_KEY_LEFT;
break;
case Canvas.RIGHT:
keyAction&=~LPKeyMask.MASK_KEY_RIGHT;
break;
}
}
public void menuAction()
{
if((keyAction&LPKeyMask.MASK_KEY_UP)!=0)
{
keyAction&=~LPKeyMask.MASK_KEY_UP;
if(this.menuWhichActive>0)
{
--menuWhichActive;
} else
{
menuWhichActive=2;
}
} else if((keyAction&LPKeyMask.MASK_KEY_DOWN)!=0)
{
keyAction&=~LPKeyMask.MASK_KEY_DOWN;
if(this.menuWhichActive<2)
{
++menuWhichActive;
} else
{
menuWhichActive=0;
}
} else if((keyAction&LPKeyMask.MASK_KEY_OK)!=0)
{
keyAction&=~LPKeyMask.MASK_KEY_OK;
switch(menuWhichActive)
{
case 0:
//登陆游戏
//openSocket();
gameState = 1;
Display.getDisplay(CardClientMIDlet.instance).setCurrent(MainGame.inst.input);
break;
case 1:
//帮助
break;
case 2:
//退出
break;
}
}
}
public void gameAction()
{
if(iControl)
{
int intern=MainGame.inst.w/14;
if((keyAction&LPKeyMask.MASK_KEY_OK)!=0)
{
keyAction&=~LPKeyMask.MASK_KEY_OK;
if(this.isSelect)
{
try
{
byte[] buffer=this.userCard[this.cardSelect].getBytes();
this.sendDataHead.command=NetProtocol.POST_CARD;
this.sendDataHead.size=(char)buffer.length;
this.sendBuffer=this.sendDataHead.getBytes();
this.out.write(sendBuffer,0,sendBuffer.length);
this.out.write(buffer,0,buffer.length);
this.iControl = false;
//出牌
this.userPostCard[0]= this.userCard[cardSelect];
this.userPostCardNum = 1;
//整理牌
for(int i=cardSelect;i<this.userCardNum-1;i++)
{
userCard[i] = userCard[i+1];
}
isSelect = false;
--userCardNum;
}
catch(Exception e)
{
System.out.print(e);
}
}
else
{
try
{
this.sendDataHead.command=NetProtocol.REJECT_CARD;
this.sendDataHead.size=0;
this.sendBuffer=this.sendDataHead.getBytes();
this.out.write(sendBuffer,0,sendBuffer.length);
}
catch(Exception e)
{
System.out.print(e);
}
}
} else if((keyAction&LPKeyMask.MASK_KEY_UP)!=0)
{
keyAction&=~LPKeyMask.MASK_KEY_UP;
this.isSelect = true;
this.cardSelect = currentCard;
} else if((keyAction&L
j2me 网络对站扑克游戏
需积分: 0 38 浏览量
更新于2008-12-09
1
收藏 46KB RAR 举报
j2me 网络对站扑克游戏,界面比较简陋
pengzhen295
- 粉丝: 4
- 资源: 10
最新资源
- Linux日常操作必备:常用命令详解及实战应用
- 永磁同步电机PMSM位置三环控制模型,包含所有 搭建过程,每一步搭建的过程、原理都很详尽 提供指导及学习资料
- 计算机图形学中利用POV-Ray创建复杂螺旋形图像的技术指南
- MySQL数据库课程设计:学员信息管理系统的表设计与操作详解
- 双馈风力发电机模型研究(DFIG),simulink模型 给定风速变化,电流与电压等波形效果完美
- 三电平逆变器带不平衡负载负载仿真 采用延时相消法(DSC)和双二阶广义积分器(DSOGI)的正负序分离控制 (2选1,默认dsc) 也可以做成svpwm or spwm T型 I型NPC和ANPC等拓
- 三相矩阵变器 矩阵变器MATLAB仿真,其他仿真模型也可 图中为三相矩阵 变器仿真模型及其输入输出电流波形,仿真结果还是可以的 matlab2021b
- 基于51单片机的智能路灯系统含说明文档 有程序,仿真和一万字的文档 主要实现功能:本设计以单片机为核心, DS 1302 初始化系统时间, 通过按键设置路灯工作时间段 和光照阈值, 用光敏电阻模拟周围
- 价值4000元的 兔子团聚星社区app整理修复版 带完整搭建视频教程(2.6GB)
- 给水排水管网系统课程设计:城镇给水排水工程布局及优化
- 基于滑膜控制无人车辆轨迹跟踪控制 复现滑膜控制 多车道变,MATLAB仿真 路径规划 无人船无人机 SMC控制 Sliding mode controller for trajectory trac
- 考虑抽蓄调峰作用的电网日经济调度优化建模与仿真分析
- 2024年工程经济学课程设计任务解析-财务报表与不确定性分析的应用
- 利用MATLAB GUI设计平台,用窗函数法设计FIR数字滤波器,对所给出的含有噪声的声音信号进行数字滤波处理,得到降噪的声音信号,进行时域频域分析,同时分析不同窗函数的效果 将文件解压至一个目录下
- 考虑横摆稳定性的车辆路径跟踪控制 ~ 采用分层控制器 ~ 上层控制器基于MPC计算车辆前轮转角和附加横摆力矩 ~ 下层控制器基于轮胎附着利用率最小化的目标函数分配附加力矩 ~ carsim和Siml
- Android恶意软件分类器中隐蔽性强的后门攻击研究-Jigsaw Puzzle算法及其防御方法探讨