昨天看了几年前写贪吃蛇程序,代码实在不敢恭维,怎么样容易就怎么写了,
各个类的职责完全不清.当时,作为第一个写的比较大的程序,可以说是以后我大规模程
序设计的一个开端吧,这么有意义的一个程序,不能就这么任他烂下去了.况且这个小游戏难度比较小,对刚从课堂的程序设计到实际开发的来说是一个很好的例子.花了一个晚上重写了一个,注释今天上午也加上了.希望对想开始写比较大的程序的同学们有所帮助.
注:最近感冒了,没有怎么测试,自己玩了一把,看到正常,没怎么找bug...
评论
fuliang 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;
		}*/
	}

注释的代码为原来的代码.现在原文件以更新.
发表评论

提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则

您还没有登录,请登录后发表评论

fuliang
搜索本博客
我的相册
D6f3070c-8515-32e2-8add-644207eff61a-thumb
spy
共 7 张
存档
最新评论