首页 > 文库大全 > 精品范文库 > 11号文库

坦克大战大报告

坦克大战大报告



第一篇:坦克大战大报告

大作业题目:坦克大战程序

一、需求分析

功能需求

坦克大战其中包括对主战坦克的编写、坦克的初始位置的编写、坦克的移动方向的编写、坦克的速度的编写、坦克的子弹速度的编写、敌军的子弹速度的编写、设置游戏难度的编写、子弹的编写、敌军坦克的编写、构造函数的编写,初始化敌军坦克的位置和状态的编写、键盘控制坦克的移动的编写、发弹的编写、判断是否被击中的编写、判断是否击中敌军的编写等。通过上下左右键进行对坦克的移动,通过F键发射子弹,其它坦克可以随机移动。构造主窗口中所需要的类,并将坦克加到窗口中,实现坦克的四个方向的移动并创建炮弹类,并让屏幕中的坦克能发射炮弹,让坦克可以朝对方信息统计功能,在游戏界面左上角,显示当前屏幕子弹数。.(1)、我方坦克,形状为一辆坦克图片,和坦克的移动方向保持一致。根据键盘的方向键,坦克的移动方向分为上、下、左、右。当按住F键的时候,能够发送炮弹,多次按键,多次发送。坦克有血量,满血为100,每次被击中,都会掉血10,直到0后,坦克死亡。(2)、敌军坦克,形状为一个黄色圆,移动为随机移动,血量为当被一发炮弹击中的时候,立即死亡消失。(3)、补血包,当我方坦克碰撞到补血包时,可补血,敌方坦克碰撞到时,穿过补血包,不会补血。补血包随机出现。.(4)、碰撞:当子弹碰撞坦克时,子弹消失。当敌军坦克碰撞到我方坦克时,相互穿过。当子弹碰撞到墙壁时,子弹消失,不可穿透墙壁。当坦克碰撞到坦克时,可穿越。当坦克碰撞到四周的游戏界面时,不可走出游戏界面。

运行需要

(1)数据精确性

在进行存取款金额时,需求数据记录定位精确,要求输入数精确金额。(2)时间特性

系统要求用户进行相应操作后系统的响应时间应尽量短,不能超过一定的时间范围本设 计暂规定为1-2s。(3)适应性

要求平台具有很好的更新能力,平台应该能够对并发事件,对于“不可靠”数据具有较强的识别处理能力。(4)可维护性

为满足系统在以后运行过程中出现问题能够修正以及系统需要升级等要求,系统应该具有可维护、可扩充、可更新的性能。(6)兼容性适合

Windows2003及以上版本的操作系统。(7)安全性

系统运行应该满足具有一定能够避免黑客、病毒等恶意攻击的安全防范措施。但相对如此简单的平台,应考虑到这些东西。

二、类的设计

1、类的设计:

坦克大战游戏主要涉及到的对象有地图、坦克、炮弹、血包。因此,整个系统的功能可以由以下几个类完成:

TankMap类: 此类主要功能是利用java中AWT包来实现坦克游戏的主窗口,以及对其他类的调用和实例化;游戏地图的初始化,重绘地图上的其他元素。

Blood类:此类主要是定义玩家坦克的生命值,有可以控制玩家坦克的加血等操作的方法。

Tank类:此类主要定义的是游戏中的坦克,可以实例化出玩家坦克,在此类中有坦克的移动,开火等方法。

EnemyTank类:此类主要定义的是游戏中的敌方坦克,可以实例化出敌方坦克,在此类中有敌方坦克的移动,开火等方法。

Shell类:此类主要定义的是游戏中的炮弹类,其中有炮弹的大小以及移动等因素。Explor类:此类定义的是坦克被攻击后的爆炸,其中有坦克击毁后爆炸的图形变化。

2、方法的设计: TankMap类的方法:

init():初始化地图以及地图上的元素

paint():绘制地图以及地图上的元素

update():重绘地图以及地图上的元素

Main():程序入口,创建TankMap对象 Tank类的方法:

Move():按照指定的方向,实现坦克的移动

checkDirection():判断用户点击的方向键,更新坦克运动方向

Fire():当用户单击F键时,发射炮弹

getRec():获取坦克当前所处位置的矩形

isLive():判断坦克的生命值是否为0

setLife(int life):设定坦克生命值

Draw():在指定的地图上绘制坦克

Tank():构造方法,初始化坦克,指定坦克所在地图 Shell类的方法:

Move():按照发射该炮弹的坦克的方向移动

getRec():获取炮弹当前所处位置的矩形

Draw():在指定地图上绘制炮弹

hitTank():打击指定坦克

Shell():构造方法,初始化炮弹 Blood类的方法:

getRec():获取血包当前所处位置的矩形

Draw():在指定地图上绘制血包

Blood():构造方法,初始化血包

三、编码实现及说明

TankMap类:

public class TankMap extends Frame {

public static final int MAPWIDTH=800;public static final int MAPHEIGHT=600;Random r=new Random();public int time=0;int s=1;//城墙数 Tank t=null;public static java.util.Listshells= new ArrayList();static static

java.util.List java.util.List

walls=new enemys=new public

public java.util.ArrayList();ArrayList();public static java.util.List bloods=new ArrayList();public static

java.util.List

explors=new java.util.ArrayList();

} public void paint(Graphics g){

Color c=g.getColor();g.setColor(Color.PINK);g.fillRect(0,0,MAPWIDTH,MAPHEIGHT);g.setColor(Color.RED);g.drawString(“当前炮弹数目:”+shells.size(),20,40);g.drawString(“生命值:”,20,60);g.fillRect(65,55,t.getLife(),5);g.setColor(c);t.draw(g);public int enemyCount=10;

public static void main(String[] args){

} public void drawImage(){ } public void init(){

this.setSize(MAPWIDTH,MAPHEIGHT);this.setTitle(“TankWar”);

this.setVisible(true);

this.addKeyListener(new DirectionHandler());

this.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent arg0){ } System.exit(0);TankMap tv=new TankMap();tv.init();});for(int i=0;i

}

if(r.nextInt(10)==9 && bloods.size()==0)

for(int i=0;i

} for(int i=0;i

} for(int i=0;i

} for(int i=0;i

} for(int i=0;i

} Shell s=shells.get(i);if(s.isLive && s.isgood){

} s.draw(g);s.hitTanks(enemys);s.hitTank(t);}else if(s.isLive&&!s.isgood){ Wall w=walls.get(i);w.wallb(t);w.draw(g);

Blood b=bloods.get(i);b.bloodb(t);b.draw(g);Explor e=explors.get(i);e.draw(g);EnemyTank et=enemys.get(i);et.draw(g);bloods.add(new Blood());bloods.remove(0);if(r.nextInt(30)==7 && bloods.size()==1)public void update(Graphics g){ } class PaintThread implements Runnable{

public void run(){

while(true){ repaint();time++;paint(g);

}

}

}

} try{

} Thread.sleep(100);e.printStackTrace();}catch(InterruptedException e){ class DirectionHandler extends KeyAdapter{

} public void keyPressed(KeyEvent arg0){ } t.checkDirection(arg0);

Tank类:

public class Tank {

public static final int WIDTH=50,HEIGHT=50,xspeed=10,yspeed=10;public int x=400,y=300;public Direction direction = Direction.STOP;TankMap tm;boolean isLive = true;boolean isgood = true;int life = 100;public int zhuanxiang=1;public boolean isLive(){ } public void setLive(boolean isLive){ } public int getLife(){ } public void setLife(int life){ } public Tank(){} public Tank(TankMap t){ } public void draw(Graphics g){ if(zhuanxiang==1){ tm=t;this.life = life;return life;this.isLive=isLive;return isLive;

}

} ImageIcon icon=new ImageIcon(“tank_shang.gif”);Image tankImage=icon.getImage();g.drawImage(tankImage,x,y,null);else if(zhuanxiang==-2){

} else if(zhuanxiang==2){

} else {

}

/*Color c = g.getColor();g.setColor(Color.RED);g.fillOval(x,y,WIDTH,HEIGHT);g.setColor(c);*/ move(direction);ImageIcon icon=new ImageIcon(“tank_xia.gif”);Image tankImage=icon.getImage();g.drawImage(tankImage,x,y,null);ImageIcon icon=new ImageIcon(“tank_zuo.gif”);Image tankImage=icon.getImage();g.drawImage(tankImage,x,y,null);ImageIcon icon=new ImageIcon(“tank_you.gif”);Image tankImage=icon.getImage();g.drawImage(tankImage,x,y,null);public void move(Direction d){

if(d==Direction.STOP){ }else if(d==Direction.UP){

zhuanxiang=1;y-= yspeed;if(y<=20)y=20;}else if(d==Direction.RIGHT){ zhuanxiang=-2;x+=xspeed;if(x>=800-WIDTH)x=800-WIDTH;}else if(d==Direction.DOWN){ zhuanxiang=-1;y+=yspeed;

}

}

} if(y>=600-HEIGHT)y=600-HEIGHT;}else if(d==Direction.LEFT){ zhuanxiang=2;x-=xspeed;if(x<=0)x=0;public void checkDirection(KeyEvent k){

} public void fire(){ tm.shells.add(new if(k.getKeyCode()==KeyEvent.VK_UP){

} if(k.getKeyCode()==KeyEvent.VK_F){ } fire();direction=Direction.UP;direction=Direction.RIGHT;direction=Direction.DOWN;direction=Direction.LEFT;}else if(k.getKeyCode()==KeyEvent.VK_RIGHT){ }else if(k.getKeyCode()==KeyEvent.VK_DOWN){ }else if(k.getKeyCode()==KeyEvent.VK_LEFT){ Shell(this.x+WIDTH/2,this.y+HEIGHT/2,this.direction,tm,Color.RED,} public Rectangle getRec(){ } return new Rectangle(this.x,this.y,this.WIDTH,this.HEIGHT);true));EnemyTank类:

public class EnemyTank extends Tank {

public static final int WIDTH=20,HEIGHT=20,xspeed=3,yspeed=3;public int x=400,y=300;public Direction direction = Direction.DOWN;public boolean islive = true;Color color = Color.YELLOW;TankMap tm;Random r=new Random();int randomCount = r.nextInt(10)+5;

public EnemyTank(){} public EnemyTank(int wx,int wy,Color c){

} @Override public void draw(Graphics g){

} public void move(){

if(randomCount==0){

} randomCount--;if(r.nextInt(40)>36){ } if(direction==Direction.UP){

ImageIcon icon=new ImageIcon(“tank_shang.gif”);Image enemytankImage=icon.getImage();y-=yspeed;if(y<=HEIGHT)y=HEIGHT;fire();Direction dirs[]=Direction.values();direction = dirs[r.nextInt(dirs.length-1)];randomCount = r.nextInt(10)+5;Color c = g.getColor();g.setColor(color);g.fillOval(x, y, WIDTH, HEIGHT);g.setColor(c);move();x=wx;y=wy;color=c;}else if(direction==Direction.RIGHT){ ImageIcon icon=new ImageIcon(“tank_you.gif”);Image enemytankImage=icon.getImage();x+=xspeed;if(x>=800-WIDTH)x=800-WIDTH;}else if(direction==Direction.DOWN){ ImageIcon icon=new ImageIcon(“tank_xia.gif”);Image enemytankImage=icon.getImage();y+=yspeed;if(y>=600-HEIGHT)y=600-HEIGHT;}else if(direction==Direction.LEFT){ ImageIcon icon=new ImageIcon(“tank_zuo.gif”);

}

}

} Image enemytankImage=icon.getImage();x-=xspeed;if(x<=0)x=0;@Override public void fire(){ tm.shells.add(new

Shell(this.x+WIDTH/2,this.y+HEIGHT/2,this.direction,tm,Color.BLUE} public Rectangle getRec(){ } return new Rectangle(this.x,this.y,this.WIDTH,this.HEIGHT);,false));Blood类:

public class Blood {

public final int WIDTH=30,HEIGHT=30;public int

x=

new

Random().nextInt(770),y=

new Random().nextInt(570);TankMap tm;{

} public boolean bloodb(Tank t){

if(t.isLive&&this.getRec().intersects(t.getRec())){

if(t.getLife()<=60){

} else { System.out.println(“blood up”);t.setLife(100);System.out.println(“恭喜你,补血啦啦啦!”);t.setLife(t.getLife()+40);tm.bloods.remove(this);

ImageIcon icon=new ImageIcon(“blood.JPG”);Image tankImage=icon.getImage();g.drawImage(tankImage,x,y,null);public void draw(Graphics g)

}

}

} } tm.bloods.remove(this);return false;public Rectangle getRec(){ } return new Rectangle(this.x,this.y,this.WIDTH,this.HEIGHT);Shell类:

public class Shell {

public final int WIDTH=5,HEIGHT=5,xspeed=8,yspeed=8;public int x,y;Direction dir = Direction.STOP;public boolean islive=true;TankMap tm=null;Color color=Color.RED;boolean isgood=true;boolean isLive=true;//构造方法

public Shell(){} public Shell(int xd,int yd,Direction d,TankMap t){

} public Shell(int xd,int yd,Direction d,TankMap t,Color c,boolean g){

} public void draw(Graphics g){

if(islive){

Color c = g.getColor();g.setColor(color);g.fillOval(x,y,WIDTH,HEIGHT);g.setColor(c);move(dir);x=xd;y=yd;dir=d;tm=t;color=c;isgood=g;x=xd;y=yd;dir=d;tm=t;}else{

} } tm.shells.remove(this);public void move(Direction d){

} public Rectangle getRec(){ } public boolean hitTank(Tank t){ if(this.isLive&&t.isLive&&this.getRec().intersects(t.getRec())){/return new Rectangle(this.x,this.y,this.WIDTH,this.HEIGHT);if(d==Direction.UP){

} y-=yspeed;if(y<=0)islive=false;}else if(d==Direction.RIGHT){ x+=xspeed;if(x>=800)islive=false;}else if(d==Direction.DOWN){ y+=yspeed;if(y>=600)islive=false;}else if(d==Direction.LEFT){ x-=xspeed;if(x<0)islive=false;/用户坦克生命值减20

t.setLife(t.getLife()-20);

} public boolean hitTanks(List enemyTanks){

} return false;if(t.getLife()<=0){

} this.islive=false;Explor e=new Explor(x-3,y-3,this.tm);tm.explors.add(e);return true;t.setLive(false);t.direction=Direction.STOP;JOptionPane.showMessageDialog(tm, “Game Over!”);System.exit(0);

}

} EnemyTank e;for(int i=0;i

} return false;e = enemyTanks.get(i);if(this.getRec().intersects(e.getRec())){

} System.out.println(“hittanks”);e.setLive(false);tm.enemys.remove(e);this.islive=false;Explor ex=new Explor(x-3,y-3,this.tm);tm.explors.add(ex);return true;过程收获

这已经是本学期第二个小程序了,有了第一份的基础,做第二次的时候明显熟练的很多,效率比之前也提高了很多,求助老师与同学也少了许多,基本可以独自完成坦克大战这一小游戏

可能是收以前学习的知识影响吧,在刚刚学习的时候总摆脱不了思维定势的阴影,总是找不到感觉,老师讲的都会,可到自己写的时候却完全无从下手,“难道我真的一无是处,什么都做不了?”,我已经近乎崩溃了,或许是我的性格原因吧,很快我就说服自己,走出了阴霾,我想起曾听一位说过的话:我的天资愚钝,也许别人花一天就能做完的事我肯能要话十天,但我知道,我花一天去做一件事永远没有花十天时间做的好,那样也就永远赶不上别人。所以我不停的看老师的代码,不停的问助教老师,就这样不厌其烦的,有了长足的进步。

java体系知识点很多,很多东西是要记忆的,可能会学了后面忘了前面,所以,一定要有“一百万次理论”的实践,那样没有什么事是做不好的。这又将是我人生的一笔弥足珍贵的财富,我相信这绝不是一笔意外的财富。在java学习过程中出现的不足,在学习中由于为了追求学得快,导致敲的代码很少,所以很多的知识都不牢固,很容易忘记,每当提到有关的问题是只知道但很难解决;需要通过很多时间去查资料。这样让我导致出现了不自信和有了不乐意敲代码想法。所以我们学编程的要想满足别人的要求,必须先满足自己,多敲代码,让自己有实力有信心。

学生签名:

日期:2014年4月15日

第二篇:坦克大战,及源代码

采用双向循环链表作太极形式旋转的图案,图案的变化采用刷新屏幕的方法做到。首先,建立一个二维字符数组,保存图形数据,然后通过更改该二维字符数组和清屏,再显示,做到图像的变化。用它提示坦克大战游戏的操作方法。

再显示问题解决后,通过无回显读取函数getch();和输入流检查函数kbhit();读取输入的方向键或回车键进入下一页面。

用同样的方法,读取方向键和回车键,更改内部图案方法,使用户选择关: 第一关:仅有4个坦克同时作战,总数为30个!第二关:仅有5个坦克同时作战,总数为40个!第三关:

有6个坦克同时作战,总数为50个!第四关:

有7个坦克同时作战,总数为60个!第五关:

有8个坦克同时作战,总数为70个!选择关卡后,进入下一页面:

进行相关提示。最后进入游戏界面。

也可以通过按左方向键返回上一级重新选择!!第一关到第三关:都是宽80,高42的。最后两关:都是宽160,高42的。

右击标题栏选择属性,进入设置。

接着就是进入最重要的坦克大战游戏了:这时采用的就不是刷新屏幕能解决的问题了。

由于界面太大,不能刷新屏幕,仅能用光标移动函数来更改图像。光标移动函数为gotoxy(int ,int);读者自己查看定义。采用同样输入流读取方法。

接着是游戏规则,操作者用W.w.A.a.S.s.D.d移动坦克,空格是停下。用方向键改变炮筒的方向,回车键是开火。但当自己的炮弹还在运行时,不得开火!!

用链表保存每一辆坦克(包括主坦克)的数据。电脑控制的坦克,被控制者的坦克炮弹击中,就会发生爆炸,并死亡。当界面上的所有坦克小于特定值时,如果内部还有未出现的坦克,就会在上方的随机位置,产生新坦克。如果操作者的坦克被击中,它的HP(我称为生命值)就会减一点。刚开始游戏时的HP=5;

但升级进入下一关时保留上一局的最后分数和HP。不会重置。

但游戏中有补血包,可以补充生命值(HP)补血包每90秒出现一次,出现的时间长为60秒。如果在这期间操作者的坦克运动到它的位置,补血包将给操作者的坦克补血。补血包不会给其它坦克补血,仅会给操作者的坦克补血。补血包会闪烁,提示它的出现。

界面还提供了每局的游戏时间。和剩敌数,及一些操作命令。当游戏结束或胜利要进入下一关时,界面还会运行5秒钟。

B.b.的暂停是用getch();读取做到的。退出是直接将循环条件重置为0;

重载视图会在视图为80×42的视图中显示边界,或消失边界。操作者可以自己调整。

为了更好的游戏,让操作者的坦克跑得比其它坦克块。

当电脑控制的坦克在正前方发现操作者的坦克就准备并等待着开火。开火完就跑。游戏的目的是反映的挑战。

当游戏结束或退出时会回到关卡的选择界面,在那里选择退出,就会有留恋的告别对话,此时仍然可以返回上一级,继续游戏。

通过设置颜色改变字体和背景颜色,使界面更好看:

以下是总结: 在这个有点大的游戏中最大的难题,不是显示问题,也不是同时控制多个对象的问题。

最难的有两个:

一、坦克的智能化处理。

二、修复同时控制最多有23个对象时共用数据时产生的bug。如,当坦克被击中,就应该扫描是谁被击中,否则不可能知道是谁。可是扫描到链表的最后一个节点时,直接往下就将指针重置为NULL了,可是返回主函数我还在求那个指针所指向的链表节点的数据。直接接bug,并且把所有的函数分开测或,重新检查,再100年也检查不出问题的所在。这就是最大的痛苦,前一次尝试,就是吃了这个苦头,前一天晚上检差到第二天的晚上都检查不出来。心理陷入极度的痛苦,最终放弃。这就是最大的教训之一!!

又比如:前一次尝试中,采用同一种方法控制所有内部的坦克,结果所有的坦克,聚成一团,怎么也拆不开。用统一的“引力”和“排斥力”都不管用。写了一个又一个方案都只能宣告失败。自信受到了极大的打击,十分痛苦。

经过演示版本(操作者的坦克阵亡后,不自动退出)的测试:

在长达13小时多的运行中没有任何bug的出现。

这是一张代表图: 图案不同于其它的是操作者控制的坦克。有一辆坦克将炮筒指向了它。它却先跑了一段。圆球都是敌方坦克的炮弹。它身陷危险之中。因为这些坦克是猛兽而并不像表面那么温和。它的右上方有一个补血包正在闪烁。下方有很多重要的提示信息。

#include #include #include #include #include using std::cin;using std::cout;const int S_X=80;

const int S_Y=40;

int welcome(void);void start_restart_end(int cammand);void message(int cammand);3 void new_tank(void);void auto_aim(void);void find_control_tank(void);void through_all_aim(void);int tank_move(void);void fire(void);void shell_move(void);void shell_explode(void);void delete_tank(void);void tank_die(void);void renew_tank(void);int HP_plus(int cammand);void gotoxy(int x, int y);void write_1(int x,int y,char type);void write_3(int x,int y,char type);void write_3_no(int x,int y,char type);

char S_S[S_Y][S_X];int the_right;char tank_xx[3][7]= {“■■■”,“ █

”,“■■■”},tank_yy[3][7]= {“■

■”,“■█■”,“■

■”};char tank_0_xx[3][7]={“███”,“ █

”,“███”},tank_0_yy[3][7]={“█

█”,“███”,“█

█”};char clear_3[3][7]={“

”,“

”,“

”};char HP_showing[3][7]={“┏

┓”,“ ╋

”,“┗

┛”};char explode_showing_0[3][7]={“╳╋╳”,“╋╳╋”,“╳╋╳”},explode_showing_1[3][7]={“╋╳╋”,“╳╋╳”,“╋╳╋”};char fire_xx[3]=“━”,fire_yy[3]=“┃”;char shell[3]=“●”;char clear_1[3]=“ ”;char well[3]=“▐”;int control_tank_HP;int auto_tank_sum,auto_tank_now;int grade=0,score;

struct tank{int tank_direction_and_life;int change_direction_temporary;int tank_x;int tank_y;int shell_direction;int shell_explode;int shell_x;int shell_y;int aim_x;int aim_y;int fire_direction;int found_enemy_and_wasting_fire;tank *next;}*head=NULL,*here;void main(){while(welcome()){int control_upgrade=1;score=0;control_tank_HP=5;do{int control_gaming=1,control_out=200;start_restart_end(1);message(1);int time_to_message=(int)time(0);int time_to_plus_HP=(int)time(0),have_HP_plus=0,time_pause_save;int control_tank_wasting_go=0,control_tank_going=0;int auto_tank_wasting_go=0,auto_tank_going=1;here=head->next;do{Sleep(25);int direction_key=0,cammand_to_control_tank=0;while(kbhit()){switch(getch()){case(224):direction_key=1;break;case(72):if(direction_key)cammand_to_control_tank=11;break;case(77):if(direction_key)cammand_to_control_tank=12;break;case(75):if(direction_key)cammand_to_control_tank=14;break;case(80):if(direction_key)cammand_to_control_tank=13;break;case(13):cammand_to_control_tank=5;break;4 case(119):case(87):cammand_to_control_tank=1;break;case(97): case(65):cammand_to_control_tank=4;break;case(115):case(83):cammand_to_control_tank=3;break;case(100):case(68):cammand_to_control_tank=2;break;case(32):cammand_to_control_tank=6;break;case(114):case(82):message(2);break;case(112):control_upgrade=0;control_gaming=0;break;case(66):case(98):message(3);time_pause_save=(int)time(0);getch();time_to_plus_HP+=(((int)time(0))-time_pause_save);message(4);break;}} if(control_tank_HP){tank *temp_here=here;here=head;if(control_tank_wasting_go==0){if(control_tank_going){tank_move();control_tank_wasting_go=4;}}else{--control_tank_wasting_go;} switch(cammand_to_control_tank){ case(11):case(12):case(13):case(14):{ here->fire_direction=cammand_to_control_tank%10;new_tank();}break;case(1):case(2):case(3):case(4):{ here->tank_direction_and_life=cammand_to_control_tank;new_tank();control_tank_going=1;}break;case(5):{fire();}break;case(6):{control_tank_going=0;}break;} here=temp_here;} if(auto_tank_going){if(here->tank_direction_and_life){ if(here->found_enemy_and_wasting_fire){if(--here->found_enemy_and_wasting_fire==0)fire();} else{through_all_aim();auto_aim();if(((int)(100*rand()/RAND_MAX))<5)fire();if(control_tank_HP)find_control_tank();} }if(here->next){here=here->next;}else{auto_tank_going=0;here=head->next;}} if(auto_tank_wasting_go==0){auto_tank_going=1;auto_tank_wasting_go=8;}else

--auto_tank_wasting_go;if(here==head->next){if(((int)time(0))-time_to_plus_HP>=90){HP_plus(1);have_HP_plus=1;time_to_plus_HP+=90;} if(have_HP_plus){have_HP_plus=HP_plus(0);}} {tank *temp_here=here;here=head;while(here){if(here->shell_direction){shell_move();if(control_tank_HP==0&&control_upgrade){here=head;delete_tank();control_upgrade=0;break;}} if(here->shell_explode)shell_explode();here=here->next;}here=temp_here;} if(control_tank_HP==0||(auto_tank_sum+auto_tank_now)==0){if(--control_out==0)control_gaming=0;} if(here==head->next)if(time_to_message!=(int)time(0)){message(0);tank_die();time_to_message=(int)time(0);} }while(control_gaming);if(control_upgrade){if(grade==5)control_upgrade=0;else grade++;} }while(control_upgrade);}start_restart_end(0);} void gotoxy(int x, int y){ int xx=0x0b;HANDLE hOutput;COORD loc;loc.X=x;loc.Y=y;hOutput = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(hOutput, loc);return;} void write_1(int x,int y,char type){ gotoxy(x*2,y);switch(type){ 5 case('x'):cout<

出”};char S_OK_0[]=“当窗口大小和屏幕缓冲区大小为宽160,高42时”,S_OK_1[]=“也可用通过重载视图显示右界而不用设置”,S_OK_2[]=“可设置窗口属性->布局->(窗口大小和屏幕缓冲区大小)为宽80,高42。”,S_OK_3[]=“当视图错误后,通过设置窗口属性,再重载视图可以纠正视图”,S_OK_4[]=“请设置窗口属性->布局->(窗口大小和屏幕缓冲区大小)为宽160,高42。”,S_OK_5[]=“再见,欢迎来玩”,S_OK_6[]=“(→键)完成”;const int welcome_showing_Y=15;char

welcome_showing[welcome_showing_Y][S_X];{register

int i=-1,sum_char=welcome_showing_Y*S_X-1;while(++iX=temporary;here->Y=around_Y_0;here->next=new SA;here=here->next;}while(++temporaryX=around_X_1;here->Y=temporary;here->next=new SA;here=here->next;}while(++temporaryX=temporary;here->Y=around_Y_1;here->next=new SA;here=here->next;}while(--temporary>around_X_0);temporary=around_Y_1;do{here->X=around_X_0;here->Y=temporary;here->next=new SA;here=here->next;}while(--temporary>around_Y_0+1);here->X=around_X_0;here->Y=temporary;here->next=head;here=head;do{here->next->ahead=here;here=here->next;}while(here!=head);} int control=1,judge;if(grade)page_now=2;else grade=1;do{here=head;int i=-1,j,k;while(++i<8){j=0;k=here->X*2;while(S_1[i][j])welcome_showing[here->Y][k++]=S_1[i][j++];here=here->ahead;}head=head->next;here=half;i=-1;while(++i<8){j=0;k=here->X*2;while(S_2[i][j])welcome_showing[here->Y][k++]=S_2[i][j++];here=here->ahead;}half=half->next;{judge=0;while(kbhit()){switch(getch()){ case(224):judge=1;break;case(72):if(judge)judge=72;break;case(75):if(judge)judge=75;break;case(77):if(judge)judge=77;break;case(80):if(judge)judge=80;break;case(13):judge=13;break;}} {if(page_showing==0){ 6 {register int i=-1,sum_char=welcome_showing_Y*S_X-1;while(++i

i=0;j=30;while(S_C_2[i])welcome_showing[grade*2][j++]=S_C_2[i++];}break;case(3):{switch(grade){ case(1):case(2):case(3):{i=0;j=20;while(S_OK_0[i])welcome_showing[6][j++]=S_OK_0[i++];i=0;j=20;while(S_OK_1[i])welcome_showing[9][j++]=S_OK_1[i++];i=0;j=8;while(S_OK_2[i])welcome_showing[3][j++]=S_OK_2[i++];}break;

case(4):case(5):{i=0;j=14;while(S_OK_3[i])welcome_showing[8][j++]=S_OK_3[i++];i=0;j=9;while(S_OK_4[i])welcome_showing[4][j++]=S_OK_4[i++];}break;case(6):{i=0;j=33;while(S_OK_5[i])welcome_showing[6][j++]=S_OK_5[i++];}break;

}i=0;j=10;while(S_C_1[i])welcome_showing[12][j++]=S_C_1[i++];i=0;j=60;while(S_OK_6[i])welcome_showing[12][j++]=S_OK_6[i++];}break;}page_showing=1;} switch(judge){ case(72):if(page_now==2){{i=0;j=30;while(S_C_2[i++])welcome_showing[grade*2][j++]=' ';if(grade>1)grade--;else grade=6;} {i=0;j=30;while(S_C_2[i])welcome_showing[grade*2][j++]=S_C_2[i++];}}break;case(80):if(page_now==2){{i=0;j=30;while(S_C_2[i++])welcome_showing[grade*2][j++]=' ';{if(grade<6)grade++;else grade=1;}} {i=0;j=30;while(S_C_2[i])welcome_showing[grade*2][j++]=S_C_2[i++];}}break;case(75):{if(page_now>1){page_now--;page_showing=0;}}break;case(77):case(13):{switch(page_now){case(1):case(2):page_now++;page_showing=0;break;case(3):if(grade==6)grade=0;control=0;break;}}break;}}}system(“CLS”);printf(“nnnnn%s”,welcome_showing);Sleep(50);}while(control);{head->ahead->next=NULL;do{here=head;head=head->next;delete here;}while(head->next);delete head;} return grade;} void start_restart_end(int cammand){ {while(head){here=head;head=here->next;delete here;}} if(cammand){ {register int i=-1,sum_char=S_Y*S_X;while(++i

srand((int)time(0));auto_tank_now=grade+3;auto_tank_sum=grade*10+20;head=new tank;here=head;head->tank_direction_and_life=1;head->change_direction_temporary=0;head->tank_x=the_right/2;head->tank_y=S_Y-2;head->fire_direction=1;head->shell_direction=0;head->shell_explode=0;int i=-1;while(++inext=new tank;here=here->next;here->tank_direction_and_life=0;here->change_direction_temporary=0;here->shell_direction=0;7 here->shell_explode=0;here->found_enemy_and_wasting_fire=0;}here->next=NULL;}} void message(int cammand){static int used,time_first,time_pause=0;static char M_S_r[]=“游戏中...”,M_S_p[]=“暂停中...”,*now_M_S=M_S_r;switch(cammand){case(1):{used=0;time_first=(int)time(0);} case(2):{system(“CLS”);tank *temp_here=here;here=head;while(here){if(here->tank_direction_and_life)new_tank();here=here->next;} here=temp_here;gotoxy(0,S_Y);int i=-1;while(++i

tank_direction;if(here->change_direction_temporary==0)tank_direction=here->tank_direction_and_life;else tank_direction=here->change_direction_temporary;if(here==head){if(tank_direction%2)type='B';else type='A';}else{if(tank_direction%2)type='Y';else type='X';} write_3(here->tank_x,here->tank_y,type);int differ_x=0,differ_y=0;switch(here->fire_direction){case(1):differ_y=-1;break;case(2):differ_x=1;break;case(3):differ_y=1;break;case(4):differ_x=-1;break;} if(here->fire_direction%2)type='y';else type='x';write_1(here->tank_x+differ_x,here->tank_y+differ_y,type);} void delete_tank(void){ write_3(here->tank_x,here->tank_y,' ');here->tank_direction_and_life=0;here->change_direction_temporary=0;} int tank_move(void){ write_3(here->tank_x,here->tank_y,' ');int can_it=1,i,j;int tank_direction=here->change_direction_temporary;switch(tank_direction){ case(1):j=(--here->tank_y)-1;if(j>=0)

{i=-2;while(++i<2)if(S_S[j][here->tank_x+i]!=' ')can_it=0;}else can_it=0;break;case(2):i=(++here->tank_x)+1;if(itank_y+j][i]!=' ')can_it=0;}else can_it=0;break;case(3):j=(++here->tank_y)+1;if(j

{i=-2;while(++i<2)if(S_S[j][here->tank_x+i]!=' ')can_it=0;}else can_it=0;break;case(4):i=(--here->tank_x)-1;if(i>=0)

{j=-2;while(++j<2)if(S_S[here->tank_y+j][i]!=' ')can_it=0;}else can_it=0;break;} if(can_it==0){switch(tank_direction){case(1):here->tank_y++;break;case(2):here->tank_x--;break;case(3):here->tank_y--;break;case(4):here->tank_x++;break;}} new_tank();return can_it;} void fire(void){if(here->shell_explode||here->shell_direction)return;here->shell_x=here->tank_x;here->shell_y=here->tank_y;switch(here->fire_direction){case(1):here->shell_y--;break;case(2):here->shell_x++;break;case(3):here->shell_y++;break;case(4):here->shell_x--;break;} here->shell_direction=here->fire_direction;}

tank_direction;if(here->change_direction_temporary==0)tank_direction=here->tank_direction_and_life;else 8 void shell_move(void){ if(S_S[here->shell_y][here->shell_x]!='0'&&S_S[here->shell_y][here->shell_x]!='1')write_1(here->shell_x,here->shell_y,' ');switch(here->shell_direction){case(1):here->shell_y--;break;case(2):here->shell_x++;break;case(3):here->shell_y++;break;case(4):here->shell_x--;break;} if(here->shell_x>=0&&here->shell_xshell_y>=0&&here->shell_yshell_y][here->shell_x]==' '){ if(here==head)write_1(here->shell_x,here->shell_y,'S');else write_1(here->shell_x,here->shell_y,'s');}else{switch(S_S[here->shell_y][here->shell_x]){ case('0'):{control_tank_HP--;here->shell_direction=0;here->shell_explode=8;}break;case('1'):{if(here==head){int differ_x=0,differ_y=0;here=head->next;while(here){if(here->tank_direction_and_life){ differ_x=head->shell_x-here->tank_x;differ_y=head->shell_y-here->tank_y;if(differ_y<=1&&differ_y>=-1&&differ_x<=1&&differ_x>=-1){ delete_tank();head->shell_direction=0;head->shell_explode=8;head->shell_x=here->tank_x;head->shell_y=here->tank_y;score++;if(auto_tank_sum==0)auto_tank_now--;break;}}here=here->next;}here=head;}}break;case('s'):{if(here==head){here=head->next;while(here){if(here->shell_direction)if(here->shell_x==head->shell_x&&here->shell_y==head->shell_y){ write_1(here->shell_x,here->shell_y,' ');here->shell_direction=0;here->shell_explode=8;head->shell_direction=0;break;}here=here->next;}here=head;}}break;case('S'):{here->shell_direction=0;here->shell_explode=8;write_1(head->shell_x,head->shell_y,' ');head->shell_direction=0;}break;}}}else{here->shell_direction=0;}} void renew_tank(void){ int i_x=4,i_c=-1,i,j,can_it;while(++i_ctank_x=i_x;here->tank_y=1;here->fire_direction=3;here->change_direction_temporary=0;here->tank_direction_and_life=3;here->aim_x=(int)(1+(the_right-3)*rand()/RAND_MAX);here->aim_y=(int)(1+(S_Y-3)*rand()/RAND_MAX);here->found_enemy_and_wasting_fire=0;new_tank();auto_tank_sum--;} void through_all_aim(void){ int differ_x=0,differ_y=0;differ_x=here->aim_x-here->tank_x;differ_y=here->aim_y-here->tank_y;if(differ_x<=1&&differ_x>=-1&&differ_y<=1&&differ_y>=-1){ here->aim_x=(int)(1+(the_right-3)*rand()/RAND_MAX);here->aim_y=(int)(1+(S_Y-3)*rand()/RAND_MAX);}} void auto_aim(void){ int can_it=0;if(here->change_direction_temporary==0){int differ_x=here->tank_x-here->aim_x,differ_y=here->tank_y-here->aim_y;int x_differ=differ_x>0?differ_x:(differ_x*-1),y_differ=differ_y>0?differ_y:(differ_y*-1);if(x_differ!=0&&y_differ!=0){

if(x_differ>y_differ){if(differ_y>0)here->tank_direction_and_life=1;else here->tank_direction_and_life=3;}

else{if(differ_x>0)here->tank_direction_and_life=4;else here->tank_direction_and_life=2;}}

else {if(x_differ){if(differ_x>0)here->tank_direction_and_life=4;else here->tank_direction_and_life=2;} else{if(differ_y>0)here->tank_direction_and_life=1;else here->tank_direction_and_life=3;}} {here->fire_direction=here->tank_direction_and_life;can_it=tank_move();if(can_it==0){if(here->tank_direction_and_life==4)here->change_direction_temporary=1;else here->change_direction_temporary=here->tank_direction_and_life+1;here->fire_direction=here->change_direction_temporary;can_it=tank_move();}}} else{int temp_the_temp_direction=here->change_direction_temporary;9 here->change_direction_temporary=0;here->fire_direction=here->tank_direction_and_life;can_it=tank_move();if(can_it==0){here->change_direction_temporary=temp_the_temp_direction;here->fire_direction=here->change_direction_temporary;can_it=tank_move();}} if(can_it==0){here->aim_x=(int)(1+(the_right-3)*rand()/RAND_MAX);here->aim_y=(int)(1+(S_Y-3)*rand()/RAND_MAX);here->change_direction_temporary=0;}} void tank_die(void){if(auto_tank_sum==0)return;tank *temp_here=here;here=head->next;while(here){if(here->tank_direction_and_life==0&&here->shell_direction==0&&here->shell_explode==0){ renew_tank();break;}here=here->next;}here=temp_here;} void shell_explode(void){ if(here->shell_explode==0||here->shell_direction)return;if(here->shell_explode%2){write_3_no(here->shell_x,here->shell_y,'x');} else write_3_no(here->shell_x,here->shell_y,'X');if(--here->shell_explode==0){write_3_no(here->shell_x,here->shell_y,' ');if(control_tank_HP){tank *temp_here=here;here=head;new_tank();here=temp_here;}}} void find_control_tank(void){ if(here->tank_x==head->tank_x||here->tank_y==head->tank_y){ int judge_direction;if(judge_direction=(here->tank_x-head->tank_x)){ if(judge_direction>0){here->fire_direction=4;}else{here->fire_direction=2;}}else{if(here->tank_y-head->tank_y>0){ here->fire_direction=1;}else{here->fire_direction=3;} }here->found_enemy_and_wasting_fire=2;new_tank();}} int HP_plus(int cammand){ static int times,time_change,HP_plus_x,HP_plus_y;int differ_x,differ_y;if(cammand){int can_it;do{can_it=1;HP_plus_x=(int)(1+(the_right-3)*rand()/RAND_MAX);HP_plus_y=(int)(1+(S_Y-3)*rand()/RAND_MAX);differ_x=head->tank_x-HP_plus_x;differ_y=head->tank_y-HP_plus_y;if(differ_x>=-1&&differ_x<=1&&differ_y>=-1&&differ_y<=1)can_it=0;}while(can_it==0);times=30;return 1;} differ_x=head->tank_x-HP_plus_x;differ_y=head->tank_y-HP_plus_y;if(differ_x>=-1&&differ_x<=1&&differ_y>=-1&&differ_y<=1){ control_tank_HP++;write_3_no(HP_plus_x,HP_plus_y,' ');return 0;} if(((int)time(0))%2){write_3_no(HP_plus_x,HP_plus_y,'+');time_change=1;} else{write_3_no(HP_plus_x,HP_plus_y,' ');if(time_change){time_change=0;if(--times==0)return 0;}} return 1;} 10

第三篇:1情境描写—坦克大战

坦克大战

一.教学目标:学习新的形状——六边形,并运用六边形进行绘画。二.教学准备:8开素描纸、油性笔、油画棒。三.教学重点:

重点:运用六边形进行绘画。

难点:颜色的搭配与填涂。

四.教学过程:

(一)导言:直接揭开主题并板书。

(二)新课教授:

1、老师先在黑板上画出六边形,并向学生讲解六边形是将长方形的四个角裁掉而得来的。

2、示范:

①用油性笔的左边画上一个扁扁的六边形。在这个六边形上面画一个小一点的六边

形,坦克的样子就出来了。接着再给坦克加上一个盖子,还有炮筒。最后再在大的六边形 里面画出一些图形,作为轮子,将坦克的履带部分画完整。用同样的方法再在右边画出另 一辆坦克。

②上色。用油画棒将坦克和背景都涂上颜色。颜色要涂均匀些。

(三)作业布置:完成一幅以坦克为主题的图画。

五、小结:作品展示,相互欣赏,教师引导评价。

第四篇:计算机实习报告(坦克大战C++开发)

实习报告

校:学院:专业班级:学号:姓名:

中南大学

信息科学与工程信息安全0801 0909080910 李亨

实习单位:湖南省软件评测中心

实习内容:C++游戏开发

实习时间:2011.9.21-2011.9.9

实习心得体会:

一转眼为期3个星期的实习生活过去了,现在又开始了紧张的学校生活。回想自己的实习经历,感觉自己真的收获不少。明年这个时候,我们就已经离开校园,去社会上去打拼了。最大的心愿就是好好把握校园里的生活,尽量多的学习知识本领,为以后的工作做足够的储备。而学校为我们组织安排的实习,恰恰满足了我们的需求,为我们提供了很好的锻炼机会,使我们能充分有效的利用时间去时间锻炼。真心感谢学校!!

实习的过程虽然有些辛苦,学校跟实习单位的距离还算是蛮远的,每天花在公交车上的时间大概有2个小时,而且每天都要一直呆在机房里面编程序和听课。但是,令人欣慰的是,我们从短短3个星期的实习中,发现了很多自身的问题和不足,特别是专业知识上的匮乏,以及遇到编程问题时候的解决思路与方法。只有通过不断的实践才能知道自己水平的高低。有付出才会有收获!实习单位的老师给人的印象非常好,他们总是不厌其烦的为我们答疑,细心的向我们传授各种专业知识,耐心的给我们做专业的指导。更为重要的是,他们还为告诉我们一些从业经验和做人的道理。

记得有位老师“咬文嚼字”的为我们分析了“赢”字的含义,上面的“亡”代表死亡,告诫我们要有死亡来临的危机感;“口”代表口才,一个人必须要有一定的口才,这样才能立于不败之地;“月”代表时间,一寸光阴一寸金,寸金难买寸光阴,这让我们懂得时间的宝贵性,不要蹉跎岁月,浪费宝贵的青春;“贝”代表金钱,金钱不是万能的,但没有金钱是万万不能的,人必须驾驭于金钱之上,学会理财,懂得挣钱和花钱;“凡”表示着一颗平凡的心,高调做事,低调做人,时刻保持的谦卑平凡的态度,此所谓“满招损,谦受益”也。

实习期间,我们的主要内容就是C++的游戏开发,以前从未做过游戏开发,对游戏的引擎知识从未有过了解,老师认真细致的向我们讲解了引擎的知识,从简到难,逐步带领我们进入游戏开发的领域。由于时间有限,我们只能做那种简单的单机游戏,互联网的游戏由于涉及到网络模块,需要花费更多的时间跟精力,所以我们主要的研究方向就是2D单机游戏。游戏开发都是分组完成,每个小组都是4到6个人,我们这组是6个成员。我们选择的项目是《坦克大战》。《坦克大战》(Battle City)是一款经典的老游戏了。是1985年日本南梦宫Namco游戏公司任天堂FC平台上,推出的一款多方位平面射击游戏。游戏以坦克战斗及保卫基地为主题,属于策略型联机类。同时也是FC平台上少有的内建关卡编辑器的几个游戏之一,玩家可自己创建独特的关卡,并通过获取一些道具使坦克和基地得到强化。

 开发组长管理编程、代码审查、单元测试、集成测试、缺陷管理

与改错等活动。

 开发人员依据计划编写代码,并对自己的代码进行必要的审查和

测试。

 开发人员依据计划审查、测试同伴的代码。

我们分工明细之后,开始了各自模块的工作。我要完成的任务是地图的设计和障碍物的设计。其中涉及到图片的加载,类的一些继承知识,总体来说算是简单。完成自己的内容之后,我还协助组长完成总体框架的设计。

将游戏画面底部作为一条数轴,划分为22个部分。玩家输入射击仰角N,根据仰角N的不同,出现不同的爆炸效果(包括击中对方获胜)。程序给出一个随机数M,作为敌对坦克的设计仰角,根据仰角M,出现不同的爆炸效果(包括击中玩家致使玩家失败)。

功能函数设计:

1.不同的效果画面,包括背景颜色的输出。

2.请玩家输入设计仰角。

3.爆炸效果的判断以及调用相应的子函数。

4.判断胜负,并输出相对应的效果画面。

5.游戏未分胜负时进行循环。

函数调用流程

1.调用开头画面子函数

2.调用主要背景画面函数

3.根据玩家射击仰角调用对应的爆炸画面子函数

4.根据随机给出的射击仰角调用对应的敌对的爆炸画面的子函数

这次实习让我受益匪浅。

刚开始做这个坦克设计游戏程序的时候,不知道从何入手,后来经过仔细考虑后,画了程序设计分析图,把游戏的功能、流程和要求等罗列出来,程序才渐渐明晰起来,导致经常漏了一些必要的步骤没有编写出来。重新安排好位置,使分配合理之后,整个程序需的结构一目了然。使得编写也变得很轻松。在最后的调试中,由于镶嵌了一些小功能的程序语句,使得编写出现了错误,个别功能没有实现,但是由于程序结构的清晰,错误很快就找了出来,并给予更改。所以我认为一个清晰明了的程序结构很重要。这也为我以后自己做程序项目打下了基础,而其积累了不少程序设计的经验。以后还要继续加强专业知识的积累!!

第五篇:拓展项目——坦克大战

坦克大战

明阳天下拓展

项目简介

团队的所有成员在规定的时间和规则的约束下,进行角色分配后,蒙上双眼依次进入模拟战场,在躲避地雷的同时用炮弹尽可能的击中对手,最终战场剩余人数最多的小组获胜。

项目规则

1、每队队员同时蒙眼进入雷区,听由场外队员指挥捡炮弹,中途如有触碰地雷,该队员视为中弹身亡,由下一名队员顶替;

2、场内队员蒙眼听从场外队员的指挥,捡起炮弹,击中对方队员身体任意部位,即可淘汰对方队员继续存活;

3、场外队员只能在限定的区域内活动,不可触发到其他组的区域;

4、最后场外留有人数最多组获胜。

项目目标

有效沟通,战略与决策,在特殊的情况下如何和其他学员进行有效沟通; 团队的力量如何发挥才能体现最大的力量; 怎样才能是更合理的指挥方式; 默契程度和信任度的考验。

北京明阳天下拓展培训机构是国内体验培训领域的“黄埔军校”。在体验式培训、户外教育理论、专项主题研究、软件实操开发等软件设施方面已走在行业前列;而硬件拓展设备、拓展器材、拓展设施设计建造和大型独资实操基地等硬件设施方面同样领先全国。强大的课程研发队伍,与国际接轨的先进培训理念,完善的硬件设备,优越的服务意识,明阳天下拓展始终秉承“专业致胜,效果为王”的理念,为成千上万的客户打造专业化、高标准的拓展培训方案。

    版权声明:此文自动收集于网络,若有来源错误或者侵犯您的合法权益,您可通过邮箱与我们取得联系,我们将及时进行处理。

    本文地址:https://www.feisuxs.com/wenku/jingpin/11/1958886.html

相关内容

热门阅读

最新更新

随机推荐