Java课程设计:吃豆子游戏源代码
glwzu原创
2010年5月22日,是吃豆子(Pac-Man)游戏发布30周年,为了纪念这个日子,Google在首页推出了其有史以来第一次真正的互动性和可玩的Logo,整个游戏界面围绕Google字样构成,配色配音全部尊重原著。这个在Google首页推出的游戏,虽然平均每人只花了36秒的时间在这小游戏上,但是仅在美国范围内就造成近500万小时的时间浪费,造成120,483,800 美元的成本浪费。这笔支出已经足够支付谷歌公司所有19835名成员6周的薪水。
看着这笔巨款,不由心动,故这几天捧着一本《java课程设计案例精编》,传说的清华大学出版社出版,累死累活看了几天,整理好代码,运行成功。
见图:

简单介绍下游戏程序由以下文件组成:
1)Wall.java :根据墙的位置,绘制图形;
2)Gold.java :根据豆子的位置,绘制图形,包括体积大/小类型
3)Player.java:初始化吃豆子的位置、张合角度及前进角度。
4)Fruit.java:初始化水果位置、出现时间、以及移动方向。
5)Enmey.java:根据不同位置,初始化敌人。
6)Ticker.java:控制游戏的起始。
7)Packman.java:初始化图形界面的布局。声音的播放,确定游戏规则。
8)Pac-man.html:引用Applet的HTML文件。
游戏规则:
点击画面,按空格键开始;方向键控制,直到吃完所有豆子;
吃到大豆子可吃掉敌人,敌人此时无法攻击(即自己无敌状态);吃水果将体力恢复100%。
下载运行:
代码下好后,在自己电脑中装好java环境,点击查看如何安装;
将吃豆子包放在合适的目录下,如C:\eatbean;
运行cmd,进入C:\eatbean;
命令1: javac Packman.java;
命令2:appletviewer Pac-Man.html
很遗憾的一点,就是游戏会闪屏。
闪屏的问题纠结好久没有解决,虽然用了传说中的双缓冲技术:
public void update(Graphics g) {
Graphics offScreenGraphics;
if (offScreenImage == null) {
//返回创建一幅用于双缓冲的、可在屏幕外绘制的图像。
//如果组件是不可显示的,则返回值可能为 null。
offScreenImage = createImage(545, 482);
}
offScreenGraphics = offScreenImage.getGraphics();
offScreenGraphics.setColor(Color.white);
offScreenGraphics.fillRect(0, 0, 545, 482);
paint(offScreenGraphics);
g.drawImage(offScreenImage, 0, 0, this);
}
问题仍存在,现在向各位大侠讨教。怎么解决这个闪屏问题呢?
闪闪增加难度,很好的设计~
[回复]
@hesiway
闪的我眼晕哦
[回复]
同上,头晕了 :roll:
[回复]
世界一直很奇妙.. 要是贪吃蛇和吃豆子结合肯定很好看..
[回复]
@HACKCRAFT
创意啊!
[回复]
This really is my very first time i visit here. I discovered so numerous fascinating stuff in your weblog particularly its discussion. From the plenty of comments on your content articles, I guess I am not the only one having all the enjoyment right here! keep up the great work.
[回复]
Some guys create their blogs knowing nothing about linkbuilding. Thence, their websites have got bad ranking. These people just do not understand that forum profiles services can solve this kind of issue!
[回复]
It is no matter what is a topic of your paper just because experienced custom companies propose to buy essay papers of good enough academic standards.
[回复]
If you are willing to buy a house, you would have to get the home loans. Moreover, my mother all the time uses a consolidation loan, which occurs to be the most firm.
[回复]
Perfectly written essays aren’t a problem at present time just because high school students are able to get online essay writers. Previous years guys could not have such opportunities.
[回复]
Get great advantages purchasing created by specialists essays at the formatting service. Strive to get more advantages ordering term papers in internet!
[回复]