加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
PlayerTank.cs 2.45 KB
一键复制 编辑 原始数据 按行查看 历史
olex-ui 提交于 2021-04-07 16:14 . Initial commit
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TankGameV._10版本;
using TankGameV._10版本.Properties;
namespace mytankgame
{
class PlayerTank : TankFather
{
private static Image[] imgs = {
Resources.p1tankU,
Resources.p1tankD,
Resources.p1tankL,
Resources.p1tankR
};
public PlayerTank(int x, int y, int speed, int life, Direction dir)
: base(x, y, imgs, speed, life, dir)
{
Born();
}
public int ZDLevel
{
get;
set;
}
public override void Born()
{
SingleObject.GetSingle().AddGameObject(new TankBorn(this.X, this.Y));
}
public void KeyDown(KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.W:
this.Dir = Direction.Up;
base.Move();
break;
case Keys.S:
this.Dir = Direction.Down;
base.Move();
break;
case Keys.A:
this.Dir = Direction.Left;
base.Move();
break;
case Keys.D:
this.Dir = Direction.Right;
base.Move();
break;
case Keys.K:
Fire();
break;
}
}
public override void Fire()
{
switch (ZDLevel)
{
case 0: SingleObject.GetSingle().AddGameObject(new PlayerZD(this, 10, 10, 1));
break;
case 1: SingleObject.GetSingle().AddGameObject(new PlayerZD(this, 20, 10, 1));
break;
case 2: SingleObject.GetSingle().AddGameObject(new PlayerZD(this, 30, 10, 1));
break;
}
}
public override void IsOver()
{
SoundPlayer sp = new SoundPlayer(Resources.hit);
sp.Play();
SingleObject.GetSingle().RemoveGameObject(this);
SingleObject.GetSingle().AddGameObject(new Boom(this.X - 25, this.Y - 25));
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化