论坛首页 入门讨论版 Java

重写了一个贪吃蛇小游戏

浏览 261 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
最后更新时间:2007-11-28
昨天看了几年前写贪吃蛇程序,代码实在不敢恭维,怎么样容易就怎么写了,
各个类的职责完全不清.当时,作为第一个写的比较大的程序,可以说是以后我大规模程
序设计的一个开端吧,这么有意义的一个程序,不能就这么任他烂下去了.况且这个小游戏难度比较小,对刚从课堂的程序设计到实际开发的来说是一个很好的例子.花了一个晚上重写了一个,注释今天上午也加上了.希望对想开始写比较大的程序的同学们有所帮助.
注:最近感冒了,没有怎么测试,自己玩了一把,看到正常,没怎么找bug...
   
最后更新时间:2007-11-28
自己刚发现Snake类的一个bug:
private boolean checkRunOutOfBound() {
		SnakeNode head = snake.get(0);
		return head.getCol() <= -1 || head.getCol() >= ConstantUtils.DEFAULT_COLS 
		       || head.getRow() >= ConstantUtils.DEFAULT_ROWS || head.getRow() <= -1;
//There is a bug in the follow code,when run out of bound and at the same time you change the direction
		/*switch (direction) {
		case ConstantUtils.WEST:
			return head.getCol() <= -1;
		case ConstantUtils.EAST:
			return head.getCol() >= ConstantUtils.DEFAULT_COLS;
		case ConstantUtils.SOUTH:
			return head.getRow() >= ConstantUtils.DEFAULT_ROWS;
		case ConstantUtils.NORTH:
			return head.getRow() <= -1;
		default:
			return false;
		}*/
	}

注释的代码为原来的代码.现在原文件以更新.
   
0 请登录后投票
论坛首页 入门讨论版 Java

跳转论坛:
JavaEye推荐