设为首页
收藏本站
最近更新

文章搜索
本类热门

首页 >> 网络编程 >> JSP >> JSP实例 >> 新闻正文 [字体: ] [打印文档]
J2ME再现华容道

文章作者:
责任编辑:admin 录入时间:2005-10-25 16:18:41 来源:
频道声明:本频道的文章除部分特别声明禁止转载的专稿外,可以自由转载.但请务必注明出出处和原始作者 文章版权归本频道与文章作者所有.对于被频道转载文章的个人和网站,我们表示深深的谢意.

百特科技[http://www.PCbyte.cn]专业的空间、主机提供商,域名注册绝对优惠!
>this.SelectArea[1] = this.loc[1];//设置光标的竖直位置
//设置光标的宽度
if (this.loc[0] + 1 < Images.WIDTH) {
  this.SelectArea[2] = this.MyMap.Grid[this.loc[1]][this.loc[0] + 1] != (byte) '1' ?
  1 : 2;
}else {
  this.SelectArea[2] = 1;
}
//设置光标的高度
if (this.loc[1] + 1 < Images.HEIGHT) {
  this.SelectArea[3] = this.MyMap.Grid[this.loc[1] + 1][this.loc[0]] != (byte) '2' ?
      1 : 2;
}else {
  this.SelectArea[3] = 1;
}
  }

  private boolean setMoveRange() {
//设置要移动到的区域,能够移动返回true,否则返回false
for (int i = 0; i < this.SelectArea[2]; i++) {
  for (int j = 0; j < this.SelectArea[3]; j++) {
    if (this.loc[1] + j >= Images.HEIGHT ||
  this.loc[0] + i >= Images.WIDTH ||
  (!isInRange(this.loc[0] + i, this.loc[1] + j) &&
  this.MyMap.Grid[this.loc[1] + j][this.loc[0] + i] !=
  Images.BLANK)) {
    return false;
}
  }
}
this.MoveArea[0] = this.loc[0];
this.MoveArea[1] = this.loc[1];
this.MoveArea[2] = this.SelectArea[2];
this.MoveArea[3] = this.SelectArea[3];
return true;
  }

  private boolean isInRange(int x, int y) {
//判断给定的(x,y)点是否在选定区域之内,x是水平坐标,y是竖直坐标
if (x >= this.SelectArea[0] &&
  x < this.SelectArea[0] + this.SelectArea[2] &&
  y >= this.SelectArea[1] &&
  y < this.SelectArea[1] + this.SelectArea[3]) {
return true;
}else {
return false;
}
  }

  private boolean isInRange2(int x, int y) {
//判断给定的(x,y)点是否在要移动到的区域之内,x是水平坐标,y是竖直坐标
if (x >= this.MoveArea[0] &&
  x < this.MoveArea[0] + this.MoveArea[2] &&
  y >= this.MoveArea[1] &&
      y < this.MoveArea[1] + this.MoveArea[3]) {
return true;
}else {
return false;
}
  }

  protected void keyPressed(int keyCode) {
//处理按下键盘的事件,这是Canvas的实例方法
switch (getGameAction(keyCode)) {//将按键的值转化成方向常量
    case Canvas.UP://向上
if (!this.selected) {//还没有选定要移动的区域
    if (this.loc[1] - 1 >= 0) {//向上还有移动空间
this.loc[1]--;//向上移动一下
setRange();//设置光标移动的区域,该函数能将光标移动到地图主位置
repaint();//重新绘图
  }
}else {//已经选定了要移动的区域
  if (this.loc[1] - 1 >= 0) {//向上还有移动空间
this.loc[1]--;//向上移动一下
if (setMoveRange()) {//能够移动,该函数能够设置要移动到的区域
  repaint();//重新绘图
}else {//不能移动
  this.loc[1]++;//退回来
}
  }
}
break;
  case Canvas.DOWN://向下
if (!this.selected) {//还没有选定要移动的区域
  if (this.loc[1] + 1 < Images.HEIGHT) {//向下还有移动空间
if (this.MyMap.Grid[this.loc[1] + 1][this.loc[0]] ==
  Images.DUP){//该图片有两个格高
this.loc[1]++;//向下移动一下
if (this.loc[1] + 1 < Images.HEIGHT) {//向下还有
                    <A href="file://移">file://移</A>动空间
  this.loc[1]++;//向下移动一下
  setRange();//设置光标移动的区域,
    <A href="file://该">file://该</A>函数能将光标移动到地图主位置
  repaint();//重新绘图
}else {//向下没有移动空间
  this.loc[1]--;//退回来
}
}else {//该图片只有一个格高
this.loc[1]++;//向下移动一下
setRange();//设置光标移动的区域,
      <A href="file://该">file://该</A>函数能将光标移动到地图主位置
repaint();//重新绘图
}
  }else {
      }
}else {//已经选定了要移动的区域
  if (this.loc[1] + 1 < Images.HEIGHT) {//向下还有移动空间
this.loc[1]++;//向下移动一下
if (setMoveRange()) {//能够移动,该函数能够设置要移动到的区域
  repaint();//重新绘图
}else {//不能移动
  this.loc[1]--;//退回来
}
  }
}
break;
  case Canvas.LEFT://向左
if (!this.selected) {//还没有选定要移动的区域
        if (this.loc[0] - 1 >= 0) {//向左还有移动空间
this.lo

此新闻共有8页 上一页 1 2 3 4 5 6 7 8 下一页

推荐好友 | 频道收藏 | 打印文档 | 报告错误  
相关连接
·J2ME再现华容道
同一专题
·无相关专题
发表评论 版权声明:除部分特别声明不要转载,或者授权我站独家播发的文章外,大家可以自由转载我站点的原创文章,但原作者和来自我站的链接必须保留(非我站原创的,按照原来自一节,自行链接)。文章版权归我站和作者共有
转载
要求转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印,亦不能抹去我站点水印。
共有评论查看评论
姓名: