天天减肥网,内容丰富有趣,生活中的好帮手!
天天减肥网 > 此吃鸡非彼吃鸡

此吃鸡非彼吃鸡

时间:2023-02-04 23:23:21

相关推荐

此吃鸡非彼吃鸡

来啦,来啦,你们的小白白来了,他带着超级简单的吃鸡

此吃鸡非彼吃鸡,你们以为是这个吃鸡吗?,oh,不不不,虽然在疫情期间,我已经很久没有吃过鸡腿,但是,我们说的吃鸡不是这个,而是这个,没错就是这个,很火爆的游戏,它别称吃鸡,它全名有刺激战场,荒野求生,和平精英等等。

来,我们看看简单的类有哪些

玩家 Player

姓名 String name

血量 int blood

枪械 Gun gun

持枪 void holdGun(Gun gun)

开枪 void shootEnemy(Player enemy)

如果没枪械则提示

装弹夹 void loadClip(Clip clip)

受伤 void damage(int hurt)

如果为0则提示

显示信息 void showPlayer()

枪械 Gun

弹夹 Clip clip

装弹夹 void loadClip(Clip clip)

开枪 void shootEnemy(Player enemy)

如果没有弹夹则提示

如果没有子弹则提示

显示信息 void showGun()

弹夹 Clip

容量 int capacity

余量 int surplus

弹仓 Bullet[] magazine

装子弹 void pushBullet(Bullet bullet)

如果已满则提示

卸子弹 Bullet popBullet()

如果已空则提示 并返回null

显示信息 void showClip()

子弹 Bullet

伤害值 hurt

击中 void hitEnemy(Player enemy)

来来来,咋们分析一波,首先,咋们得先有四个类,来逐个分析这四个类,为了简单一点,咋们就从下往上进行分析吧

首先是子弹类,Bullet

咋们需要定义的是,每一颗子弹对敌人的伤害,咋们总不能是对自己吧,难不成咋们打敌人,还没有打到敌人呢,自己就死了,伤敌一千自损八百也不是这样的啊!

//子弹类class Bullet{private int hurt=10;public Bullet(){}public Bullet(int hurt){this.hurt=hurt;}public void hitEnemy(Player enemy){enemy.damage(hurt);}}

子弹的家是哪里?是弹夹啊,所以,咋们接下来看的是弹夹类Clip

弹夹是干什么?弹夹是子弹的家,所以,我们需要规定弹夹的容量

规定了弹夹的容量之后,我们需要当我们打出一发子弹之后,少一个子弹,当弹夹没有子弹之后,我们需要对其进行补充,但是,我们补充子弹的个数,不能超过弹夹的容量

//弹夹类class Clip{private Bullet[] magazine;private int capacity=30;private int surplus;public Clip(){this(30);}public Clip(int capacity){this.magazine=new Bullet[capacity];this.surplus=0;showClip();}public void pushBullet(Bullet bullet){if(surplus==capacity){System.out.println(">>>弹夹已满,请勿重复装弹!");return;}magazine[surplus]=bullet;surplus++;showClip();}public Bullet popBullet(){if(surplus==0){System.out.println(">>>弹夹已空,无法弹出子弹!");return null;}Bullet bullet=magazine[surplus-1];magazine[surplus-1]=null;surplus--;showClip();return bullet;}public void showClip(){System.out.printf(">>>弹夹状态:%d/%d\n",surplus,capacity);}}

既然,弹夹已经装满,我们就要让他有用武之地,所以,我们需要将弹夹装入手枪中

所以,我们要说的类是Gun枪类

一个枪,我们需要知道,他里面有没有弹夹,没有弹夹,你就是在对着空气打,多尴尬啊

//枪类class Gun{private Clip clip;public Gun(){this(null);}public Gun(Clip clip){this.clip=clip;showGun();}public void loadClip(Clip clip){this.clip=clip;showGun();}public void shootEnemy(Player enemy){if(clip==null){System.out.println(">>>枪械没有弹夹,放了一个空枪!");return;}Bullet bullet=clip.popBullet();if(bullet==null){System.out.println(">>>枪械的弹夹已空,放了一个空枪!");return;}bullet.hitEnemy(enemy);}public void showGun(){if(clip!=null){System.out.println(">>>枪械信息:有弹夹");}else{System.out.println(">>>枪械信息:无弹夹");}}}

有枪之后,我们就应该拿起我们的枪,用它来攻击我们的敌人

所以,我们要说的类就是Player玩家类

这个玩家除了你自己,肯定得有敌人对吧,不然,你整局一个人,对着空气,不寂寞,不诡异吗?万一你一掉头,出现一个……

这个敌人,他有他固定的血量,当你拿枪杀掉敌人之后,你还要继续残忍的鞭打尸体吗?好过分,还有就是,你每一次打完一枪之后,剩余的血量是多少,你得知道,你也得知道,你手中有没有枪

//玩家类class Player{private String name;private int blood=100;private Gun gun;public Player(){}public Player(String name){this(name,100);}public Player(String name,int blood){this.name=name;this.blood=blood;showPlayer();}public void holdGun(Gun gun){this.gun=gun;showPlayer();}public void shootEnemy(Player enemy){System.out.printf("%s向%s开了一枪\n",this.name,enemy.name);if(gun==null){System.out.println(">>>"+name+"没有枪,无法进行射击!");return;}gun.shootEnemy(enemy);}public void loadClip(Clip clip){if(gun==null){System.out.println(">>>"+name+"没有枪,无法装弹夹!");return;}gun.loadClip(clip);}public void damage(int hurt){if(blood==0){System.out.println(">>>"+name+"已死亡,请勿鞭尸!");return;}

最后,咋们来一个测试类吧

class ChiJi{public static void main(String[] args){Player p1=new Player("老张",100);Player p2=new Player("老王",100);Gun gun=new Gun();p1.holdGun(gun);Clip clip=new Clip();for(int i=1;i<=30;i++){clip.pushBullet(new Bullet(12));}p1.loadClip(clip);for(int i=1;i<=40;i++){p1.shootEnemy(p2);}}}

嘿嘿嘿,一整个关于老王和老张的战争就到此结束了

如果觉得《此吃鸡非彼吃鸡》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。