📄 gobangcanvas.java
字号:
numimage = Image.createImage("/png/number.png");
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
timelayer = new TiledLayer(4,1,numimage,TIME_TILE_WIDTH,TIME_TILE_HEIGHT);
timelayer.setPosition(USER_TIME_X,USER_TIME_Y);
lm.insert(timelayer,1);
}
timelayer.fillCells(0,0,3,1,9);
//制作用户名片精灵
Image userinfoimage = Image.createImage(INFO_IMAGE_WIDTH,INFO_IMAGE_HEIGHT);
Graphics gra = userinfoimage.getGraphics();
gra.setFont(chatfont);
String SexArry[] = {"男","女"};
int sex = commstructnode.getSex();
String tempstr = commstructnode.getNickName() + "[" + commstructnode.getUserId()
+ "] ";
gra.drawString(tempstr,0,0,Graphics.TOP|Graphics.LEFT);
tempstr = "普通权限 "+ SexArry[sex-1];
gra.drawString(tempstr,0,chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
tempstr = "级别 "+commstructnode.gamelevel+" 积分 "+String.valueOf(commstructnode.integer);
gra.drawString(tempstr,0,2*chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
tempstr = "赢 "+String.valueOf(commstructnode.wincount)+" 输 "
+ String.valueOf(commstructnode.failcount);
gra.drawString(tempstr,0,3*chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
tempstr = "和 " + String.valueOf(commstructnode.equalcount)+" 胜率 "+commstructnode.winrate ;
gra.drawString(tempstr,0,4*chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
if(userinfosprite == null){
userinfosprite = new Sprite(userinfoimage);
lm.insert(userinfosprite,0);
}else{
userinfosprite.setImage(userinfoimage,userinfoimage.getWidth(),userinfoimage.getHeight());
}
userinfoimage = null;
userinfosprite.setVisible(false);
userinfosprite.setPosition(USER_INFO_X,USER_INFO_Y);
}
private void displayoppinfo(){
oppuserinfo = gobangdeal.getOtherUserInfo();
if(!oppuserinfo.getUserId().equals("")){
Image oppheadimage = null;
try {
if(oppuserinfo.getPicture().equals("00"))
oppheadimage = Image.createImage("/png/boyhead.png");
else
oppheadimage = Image.createImage("/png/girlhead.png");
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
oppheadsprite = new Sprite(oppheadimage);
oppheadsprite.setPosition(OPP_ORIGIN_X,OPP_ORIGIN_Y);
lm.insert(oppheadsprite,1);
//插入对家时间
if(opptimelayer == null){
opptimelayer = new TiledLayer(4,1,numimage,TIME_TILE_WIDTH,TIME_TILE_HEIGHT);
opptimelayer.setPosition(OPP_TIME_X,OPP_TIME_Y);
lm.insert(opptimelayer,1);
}
opptimelayer.fillCells(0,0,3,1,9);
opptimelayer.setVisible(true);
//判断并显示对家的游戏状态
if(oppuserinfo.getStatus().equals(USERREADYSTR)){
if(usercolor == BLACK_COLOR){
whitesprite.setPosition(OPP_COLOR_X,OPP_COLOR_Y);
whitesprite.setVisible(true);
}else{
blacksprite.setPosition(OPP_COLOR_X,OPP_COLOR_Y);
blacksprite.setVisible(true);
}
}
// 制作对家信息精灵
if(oppinfosprite != null){
lm.remove(oppinfosprite);
oppinfosprite = null;
}
Image oppinfoimage = Image.createImage(INFO_IMAGE_WIDTH,INFO_IMAGE_HEIGHT);
Graphics gra = oppinfoimage.getGraphics();
gra.setFont(chatfont);
String SexArry[] = {"男","女"};
int sex = oppuserinfo.getSex();
String tempstr = oppuserinfo.getNickName() + "[" + oppuserinfo.getUserId()
+ "] ";
gra.drawString(tempstr,0,0,Graphics.TOP|Graphics.LEFT);
tempstr = "普通权限 "+ SexArry[sex-1];
gra.drawString(tempstr,0,chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
tempstr = "级别 "+oppuserinfo.gamelevel+" 积分 "+String.valueOf(oppuserinfo.integer);
gra.drawString(tempstr,0,2*chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
tempstr = "赢 "+String.valueOf(oppuserinfo.wincount)+" 输 "
+ String.valueOf(oppuserinfo.failcount);
gra.drawString(tempstr,0,3*chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
tempstr = "和 " + String.valueOf(oppuserinfo.equalcount)+" 胜率 "+oppuserinfo.winrate ;
gra.drawString(tempstr,0,4*chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
oppinfosprite = new Sprite (oppinfoimage);
oppinfosprite.setVisible(false);
lm.insert(oppinfosprite,0);
oppinfosprite.setPosition(OPP_INFO_X,OPP_INFO_Y);
}else{
oppinfosprite = null;
}
}
private void resetoppinfo(){// 制作对家信息精灵
oppuserinfo = gobangdeal.getOtherUserInfo();
if(!oppuserinfo.getUserId().equals("")){
Image oppheadimage = null;
try {
if(oppuserinfo.getPicture().equals("00"))
oppheadimage = Image.createImage("/png/boyhead.png");
else
oppheadimage = Image.createImage("/png/girlhead.png");
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
oppheadsprite.setImage(oppheadimage,oppheadimage.getWidth(),oppheadimage.getHeight());
if(oppuserinfo.getStatus().equals(USERREADYSTR)){
if(usercolor == BLACK_COLOR){
whitesprite.setPosition(USER_COLOR_X,USER_COLOR_Y);
whitesprite.setVisible(true);
}else{
blacksprite.setPosition(USER_COLOR_X,USER_COLOR_Y);
blacksprite.setVisible(true);
}
}
Image oppinfoimage = Image.createImage(INFO_IMAGE_WIDTH,INFO_IMAGE_HEIGHT);
Graphics gra = oppinfoimage.getGraphics();
gra.setFont(chatfont);
String SexArry[] = {"男","女"};
int sex = oppuserinfo.getSex();
String tempstr = oppuserinfo.getNickName() + "[" + oppuserinfo.getUserId()
+ "] ";
gra.drawString(tempstr,0,0,Graphics.TOP|Graphics.LEFT);
tempstr = "普通权限 "+ SexArry[sex-1];
gra.drawString(tempstr,0,chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
tempstr = "级别 "+oppuserinfo.gamelevel+" 积分 "+String.valueOf(oppuserinfo.integer);
gra.drawString(tempstr,0,2*chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
tempstr = "赢 "+String.valueOf(oppuserinfo.wincount)+" 输 "
+ String.valueOf(oppuserinfo.failcount);
gra.drawString(tempstr,0,3*chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
tempstr = "和 " + String.valueOf(oppuserinfo.equalcount)+" 胜率 "+oppuserinfo.winrate ;
gra.drawString(tempstr,0,4*chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
oppinfosprite.setImage(oppinfoimage,oppinfoimage.getWidth(),oppinfoimage.getHeight());
oppinfosprite.setVisible(false);
}
}
private void resetuserinfo(){
// 制作用户名片精灵
Image userinfoimage = Image.createImage(INFO_IMAGE_WIDTH,INFO_IMAGE_HEIGHT);
Graphics gra = userinfoimage.getGraphics();
gra.setFont(chatfont);
String SexArry[] = {"男","女"};
int sex = commstructnode.getSex();
String tempstr = commstructnode.getNickName() + "[" + commstructnode.getUserId()
+ "] ";
gra.drawString(tempstr,0,0,Graphics.TOP|Graphics.LEFT);
tempstr = "普通权限 "+ SexArry[sex-1];
gra.drawString(tempstr,0,chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
tempstr = "级别 "+commstructnode.gamelevel+" 积分 "+String.valueOf(commstructnode.integer);
gra.drawString(tempstr,0,2*chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
tempstr = "赢 "+String.valueOf(commstructnode.wincount)+" 输 "
+ String.valueOf(commstructnode.failcount);
gra.drawString(tempstr,0,3*chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
tempstr = "和 " + String.valueOf(commstructnode.equalcount)+" 胜率 "+commstructnode.winrate ;
gra.drawString(tempstr,0,4*chatfont.getHeight(),Graphics.TOP|Graphics.LEFT);
userinfosprite.setImage(userinfoimage,userinfoimage.getWidth(),userinfoimage.getHeight());
userinfosprite.setVisible(false);
}
public void rectinit(){
chatrect = new MouseRect(); //聊天框区域
chatrect.firX = CHAT_ORIGIN_X;
chatrect.firY = CHAT_ORIGIN_Y;
chatrect.endX = CHAT_ORIGIN_X + CHATCONTROL_WIDTH;
chatrect.endY = CHAT_ORIGIN_Y + CHATCONTROL_HEIGHT;
chatrect.orignX = 165; //此区域内指针的初试位置
chatrect.orignY = 5;
chatrect.height = 15;//20; //此区域内指针每次上下移动的高度
chatrect.rectflag = CHAT_RECT_FLAG; //区域标志
chatrect.ynum = 1; //此区域内指针可停放位置的个数-1;
chatrect.rightrect = true; //各个方向是否有相另的区域
chatrect.uprect = true;
chatrect.downrect = true;
operaterect = new MouseRect(); //操作菜单区域
operaterect.firX = OPERATE_X;
operaterect.firY = OPERATE_Y;
operaterect.endX = OPERATE_X+OPERATE_WIDTH;
operaterect.endY = OPERATE_Y+OPERATE_HEIGHT;
operaterect.orignX = 10;
operaterect.orignY = 170;//190;
operaterect.width = OPERATE_TILE_WIDTH;
operaterect.xnum = OPERATE_WIDTH_TILES-1;
operaterect.rectflag = OPERATE_RECT_FLAG;
operaterect.rightrect = true;
operaterect.downrect = true;
operaterect.uprect = true;
inforect = new MouseRect(); //用户信息区域
inforect.firX = OPP_ORIGIN_X - 10;
inforect.firY = OPP_ORIGIN_Y;
inforect.endX = OPP_ORIGIN_X + 30;
inforect.endY = USER_ORIGIN_Y + 10;
inforect.orignX = 155;//170;
inforect.orignY = 40;
inforect.ynum = 1;
inforect.height = 125;//150;
inforect.rectflag = INFO_RECT_FLAG;
inforect.leftrect = true;
inforect.uprect = true;
inforect.rightrect=true;
qipanrect = new MouseRect(); //棋盘信息区
qipanrect.firX = QIPAN_X;
qipanrect.firY = QIPAN_Y;
qipanrect.endX = QIPAN_X + QIPAN_WIDTH;
qipanrect.endY = QIPAN_Y + QIPAN_HEIGHT;
qipanrect.orignX = 7;
qipanrect.orignY = 7;
qipanrect.rectflag = QIPAN_RECT_FLAG;
qipanrect.rightrect = true;
qipanrect.downrect = true;
qipanrect.uprect = true;
}
/**
* 画布重画事件,替代Canvas中的paint()事件, 根据不同的游戏状态(gameState)画出游戏画面
* 本方法由thread每次重新启动, 最后执行flushGraphics()重画缓冲区
*/
public synchronized void paintCanvas(){
lm.paint(g,ORIGIN_X,ORIGIN_Y);
this.flushGraphics();
}
//同意询问框的按键响应
//对确认框的按键操作
private void AgreenDeal(int keyCode){
int action = getGameAction(keyCode);
switch(action)
{
case Canvas.LEFT : //向左
agreencontrol.setDirection(true);
mousesprite.setPosition(agreencontrol.getFocusX()+10,agreencontrol.getFocusY()+10);
break;
case Canvas.RIGHT: //向右
agreencontrol.setDirection(false);
mousesprite.setPosition(agreencontrol.getFocusX()+10,agreencontrol.getFocusY()+10);
break;
case Canvas.FIRE: //选择键
if(agreencontrol.getValue()){//同意类键
if(agreetype == REGRET){ //同意悔棋
regetflag = false;
stepnum++;
sendflag = true;
gobangdeal.AgreeOppRegret(commstructnode,stepnum,"0");
mousesprite.setDisplay();
}else if(agreetype == QUESTTIE){ //同意求和
regetflag = false;
stepnum++;
sendflag = true;
gobangdeal.AgreeOppTie(commstructnode,stepnum,"0");
mousesprite.setDisplay();
}
}else{
if(agreetype == REGRET){
stepnum++;
sendflag = true;
gobangdeal.AgreeOppRegret(commstructnode,stepnum,"1");
mousesprite.setDisplay();
}else if(agreetype == QUESTTIE){ //不同意求和
stepnum++;
sendflag = true;
gobangdeal.AgreeOppTie(commstructnode,stepnum,"1");
mousesprite.setDisplay();
}
}
agreencontrol.setHide();
break;
default:
break;
}
}
protected synchronized void keyPressed(int keyCode){
if(initflag){
initother();
initflag = false;
}
if(mousesprite ==null){
return;
}
gameendlayer.setCell(0,0,0);
if(agreencontrol.getVisibleFlag()){ //确定框跳出
AgreenDeal(keyCode);
}else if(promptcontrol.getVisibleFlag()){ //确认框跳出
if(getGameAction(keyCode) == Canvas.FIRE){
promptcontrol.setHide();
gamestate = USERFALL;
mousesprite.setCurrRect(qipanrect);
mousesprite.setVisible(false);
}
}else if(helpflag){
helpsprite.setVisible(false);
helpflag = false;
if(mousesprite.getRectFlag()!=QIPAN_RECT_FLAG)
mousesprite.setVisible(true);
}else{
hideUserinfo();
if(keyCode == 35){ //#返回房间
if(backflag){
sendflag = true;
gobangdeal.setUpRequest(maingameevent.getCommNode());
backflag = false;
}
}//else if(keyCode == 21||keyCode == -6){ //左恻软件 显示操作菜单
else if(keyCode == 21||keyCode == -21){ //左恻软件 显示操作菜单
if(menucontrol.getvisibleflag()){
menucontrol.toHide();
mousesprite.setDisplay();
}
else{
mousesprite.setVisible(false);
menucontrol.toShow();
}
}else {
if(keyCode == 42){
mousesprite.RectConvert();
if(!qipanselectflag||gamestate == OPPFALL){ //棋盘区域不能被选种
if(mousesprite.getRectFlag()==QIPAN_RECT_FLAG)
mousesprite.RectConvert(); //移动中心到棋盘区域的下一个区域
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -