前几天粗略地学了HTML5,然后就用它写了一个《经典坦克大战》游戏。

  现在想分享一下我写的代码,写得不好请大家多多指教。

  给大家推荐一个网站,这个网站是为大学生而做,为方便学习编程的同学而做的。(淘课学院)http://www.taokeschool.com/

  

《经典坦克大战》游戏截图

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8" />
<title>HTML5经典坦克大战</title>
<script src="jquery-1.10.2.min.js"></script>
<style type="text/css">
body {
margin: 0px 0px;
padding: 0px 0px;
}
.con {
margin-left: auto;
margin-right: auto;
width: 650px;
}
</style>
</head>
<body onkeydown="getCommand()">
<div class="con">
<h1>HTML5——经典坦克大战</h1> <canvas id="tankmap" width="600" height="500" style="background-color:#000;"></canvas>
<div style="margin-top:20px;font-weight:bolder;font-size:20px;color:red;">
W、S、A、D分别控制:上、下、左、右;J是发子弹。暂时不支持Firefox浏览器。
</div>
</div> <script type="text/javascript">
var gameover = false;
var verygood = false;
var canH = document.getElementById("tankmap");
var cxt = canH.getContext("2d"); var bomb3 = new Image();
bomb3.src = "images/bomb_3.gif";
var bomb2 = new Image();
bomb2.src = "images/bomb_2.gif";
var bomb1 = new Image();
bomb1.src = "images/bomb_1.gif"; var born1 = new Image();
born1.src = "images/born1.gif";
var born2 = new Image();
born2.src = "images/born2.gif";
var born3 = new Image();
born3.src = "images/born3.gif";
var born4 = new Image();
born4.src = "images/born4.gif"; var buBoImg = new Image();
buBoImg.src = "images/blast1.gif"; var base1 = new Image();
base1.src = "images/symbol.gif";
var base2 = new Image();
base2.src = "images/destory.gif"; </script>
<script src="Draw.js"></script>
<script src="opera_js.js"></script>
</body>
</html> HTML页

HTML页

 ///玩家坦克颜色(机身颜色,盖子颜色)
var heroColor1 = new Array("#ba9658", "#fef26e");
var heroColor2 = new Array("#00a2b5", "#00fefe"); ///敌人坦克颜色(机身颜色,盖子颜色)
var enemyColor1 = new Array("#006f43", "#43b387");
var enemyColor2 = new Array("#f00", "#e34444");
var enemyColor3 = new Array("#fa02e6", "#d45bca");
var enemyColor4 = new Array("#0600fd", "#3531c4"); ///敌人子弹数组
var enemyBullets = new Array(null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null);
///敌人子弹爆炸数组
var enemyBulletBombs = new Array(null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null);
///定义玩家子弹数组
var hero1bullet = null;
var hero1bulletBomb = null; ////出身效果
function Born(x, y) {
this.x = x;
this.y = y;
this.time = 0;
this.born = true; this.drawBorn = function drawBorn() {
if (this.time <= 1) {
cxt.drawImage(born1, this.x, this.y, 50, 50);
}
if (this.time > 1 && this.time <= 3) {
cxt.drawImage(born2, this.x, this.y, 50, 50);
}
if (this.time >= 4 && this.time <= 5) {
cxt.drawImage(born3, this.x, this.y, 50, 50);
}
if (this.time >= 6 && this.time <= 7) {
cxt.drawImage(born4, this.x, this.y, 50, 50);
}
if (this.time >= 8 && this.time <= 9) {
cxt.drawImage(born2, this.x, this.y, 50, 50);
}
if (this.time >= 10 && this.time <= 11) {
cxt.drawImage(born3, this.x, this.y, 50, 50);
}
if (this.time >= 12 && this.time <= 13) {
cxt.drawImage(born4, this.x, this.y, 50, 50);
} this.time++;
if (this.time >= 13) {
this.born = false;
this.time = 0;
}
}
} ////坦克类
function Tank(x, y, speed, direct, tankcolor, islive)
{
this.x = x;
this.y = y;
this.speed = speed;
this.direct = direct;
this.tankcolor = tankcolor;
this.islive = islive; this.moveUp = function ()
{
this.y = this.y - this.speed;
if (this.y <= 0)
{
this.y = 0;
}
this.direct = 0;
}
this.moveDown = function ()
{
this.y = this.y + this.speed;
if (this.y >= 450)
{
this.y = 450;
}
this.direct = 2;
}
this.moveLeft = function ()
{
this.x = this.x - this.speed;
if (this.x <= 0)
{
this.x = 0;
}
this.direct = 3;
}
this.moveRight = function ()
{
this.x = this.x + this.speed;
if (this.x >= 550)
{
this.x = 550;
}
this.direct = 1;
}
} ///玩家坦克类,继承于坦克类(Tank)
function Hero(x, y, speed, direct, tankcolor, islive)
{
this.tank = Tank;
this.tank(x, y, speed, direct, tankcolor, islive); this.attackEnemy = function ()
{
if (hero1bullet != null)
{
return;
}
switch (this.direct)
{
case 0:
hero1bullet = new Bullet(this.x + 24, this.y, 4, 0);
break;
case 1:
hero1bullet = new Bullet(this.x + 50, this.y + 24, 4, 1);
break;
case 2:
hero1bullet = new Bullet(this.x + 24, this.y + 50, 4, 2);
break;
case 3:
hero1bullet = new Bullet(this.x, this.y + 24, 4, 3);
break;
}
hero1bullet.time = window.setInterval("hero1bullet.run('h')", 20);
}
}
///敌人坦克类,继承坦克类(Tank)
function Enemy(x, y, speed, direct, tankcolor, islive)
{
this.tank = Tank;
this.tank(x, y, speed, direct, tankcolor, islive);
///敌人移动
this.run = function ()
{
if (this.islive == 0)
{
return;
}
this.changeDir();
switch (this.direct)
{
case 0:
if (this.y <= 0)
{
this.beyondChange();
}
if (!this.enemyTankCollision(this)) {
this.moveUp();
}
break;
case 1:
if (this.x >= 550)
{
this.beyondChange();
}
if (!this.enemyTankCollision(this))
{
this.moveRight();
}
break;
case 2:
if (this.y >= 450)
{
this.beyondChange();
}
if (!this.enemyTankCollision(this)) {
this.moveDown();
}
break;
case 3:
if (this.x <= 0)
{
this.beyondChange();
}
if (!this.enemyTankCollision(this)) {
this.moveLeft();
}
break;
}
}
this.changeDir = function ()
{
var dri_num = Math.round(Math.random() * 99);
if (dri_num < 4) {
this.direct = Math.round(Math.random() * 3);
}
}
this.beyondChange = function () {
this.direct = Math.round(Math.random() * 3);
} ///敌人攻击
this.attackEnemy = function (en)
{
if (enemyBullets[en] != null)
{
return;
}
if ((Math.round(Math.random() * 99)) < 4)
{
switch (this.direct) {
case 0:
enemyBullets[en] = new Bullet(this.x + 24, this.y, 4, 0);
break;
case 1:
enemyBullets[en] = new Bullet(this.x + 50, this.y + 24, 4, 1);
break;
case 2:
enemyBullets[en] = new Bullet(this.x + 24, this.y + 50, 4, 2);
break;
case 3:
enemyBullets[en] = new Bullet(this.x, this.y + 24, 4, 3);
break;
} enemyBullets[en].time = window.setInterval("enemyBullets[" + en + "].run(" + en + ")", 20);
}
}
///敌人坦克碰撞
this.enemyTankCollision = function (enemy1)
{ var enemy2 = null;
{
for (var en2 = 0; en2 < enemys.length; en2++)
{
enemy2 = enemys[en2];
if (enemy2 != null && enemy2.islive != 0)
{
switch (enemy1.direct) {
case 0:
if ((hero1 != null && hero1.islive != 0) && (enemy1.x > hero1.x - 50) && (enemy1.x < hero1.x + 50) &&
((enemy1.y == hero1.y + 47) || (enemy1.y == hero1.y + 50) || (enemy1.y == hero1.y + 49) || (enemy1.y == hero1.y + 48))) {
return true;
}
if ((enemy1.x > enemy2.x - 50) && (enemy1.x < enemy2.x + 50) &&
((enemy1.y == enemy2.y + 47) || (enemy1.y == enemy2.y + 50) || (enemy1.y == enemy2.y + 49) || (enemy1.y == enemy2.y + 48))) {
return true;
} break;
case 1:
if ((hero1 != null && hero1.islive != 0) && (enemy1.y > hero1.y - 50) && (enemy1.y < hero1.y + 50) &&
((enemy1.x + 47 == hero1.x) || (enemy1.x + 50 == hero1.x) || (enemy1.x + 49 == hero1.x) || (enemy1.x + 48 == hero1.x))) {
return true;
}
if ((enemy1.y > enemy2.y - 50) && (enemy1.y < enemy2.y + 50) &&
((enemy1.x + 47 == enemy2.x) || (enemy1.x + 50 == enemy2.x) || (enemy1.x + 49 == enemy2.x) || (enemy1.x + 48 == enemy2.x))) {
return true;
}
break;
case 2:
if ((hero1 != null && hero1.islive != 0) && (enemy1.x > hero1.x - 50) && (enemy1.x < hero1.x + 50) &&
((enemy1.y == hero1.y - 47) || (enemy1.y == hero1.y - 50) || (enemy1.y == hero1.y - 49) || (enemy1.y == hero1.y - 48))) {
return true;
}
if ((enemy1.x > enemy2.x - 50) && (enemy1.x < enemy2.x + 50) &&
((enemy1.y == enemy2.y - 47) || (enemy1.y == enemy2.y - 50) || (enemy1.y == enemy2.y - 49) || (enemy1.y == enemy2.y - 48))) {
return true;
}
break;
case 3:
if ((hero1 != null && hero1.islive != 0) && (enemy1.y > hero1.y - 50) && (enemy1.y < hero1.y + 50) &&
((enemy1.x - 47 == hero1.x) || (enemy1.x - 50 == hero1.x) || (enemy1.x - 49 == hero1.x) || (enemy1.x - 48 == hero1.x))) {
return true;
}
if ((enemy1.y > enemy2.y - 50) && (enemy1.y < enemy2.y + 50) &&
((enemy1.x - 47 == enemy2.x) || (enemy1.x - 50 == enemy2.x) || (enemy1.x - 49 == enemy2.x) || (enemy1.x - 48 == enemy2.x))) {
return true;
}
break;
}
}
}
} ///敌人坦克与阻碍物之间碰撞
var hamper = null;
for (var ha = 0; ha < hampers.length; ha++)
{
hamper = hampers[ha];
if (hamper != null)
{
switch (hampers[ha].style) {
case 1:
switch (enemy1.direct) {
case 0:
if ((enemy1.x >= hamper.x - 50) && (enemy1.x <= hamper.x + 17) &&
((enemy1.y == hamper.y + 7) || (enemy1.y == hamper.y + 8) || (enemy1.y == hamper.y + 9) || (enemy1.y == hamper.y + 10))) {
return true;
}
break;
case 1:
if ((enemy1.y > hamper.y - 50) && (enemy1.y < hamper.y + 10) &&
((enemy1.x + 50 == hamper.x) || (enemy1.x + 49 == hamper.x) || (enemy1.x + 48 == hamper.x) || (enemy1.x + 47 == hamper.x))) {
return true;
}
break;
case 2:
if ((enemy1.x > hamper.x - 50) && (enemy1.x < hamper.x + 17) &&
((enemy1.y + 50 == hamper.y) || (enemy1.y + 49 == hamper.y) || (enemy1.y + 48 == hamper.y) || (enemy1.y + 47 == hamper.y))) {
return true;
}
break;
case 3:
if ((enemy1.y > hamper.y - 50) && (enemy1.y < hamper.y + 10) &&
((enemy1.x == hamper.x + 17) || (enemy1.x == hamper.x + 16) || (enemy1.x == hamper.x + 15) || (enemy1.x == hamper.x + 14))) {
return true;
}
break;
}
break;
case 2:
switch (enemy1.direct) {
case 0:
if ((enemy1.x >= hamper.x - 50) && (enemy1.x <= hamper.x + 17) &&
((enemy1.y == hamper.y + 14) || (enemy1.y == hamper.y + 15) || (enemy1.y == hamper.y + 16) || (enemy1.y == hamper.y + 17))) {
return true;
}
break;
case 1:
if ((enemy1.y > hamper.y - 50) && (enemy1.y < hamper.y + 10) &&
((enemy1.x + 50 == hamper.x) || (enemy1.x + 49 == hamper.x) || (enemy1.x + 48 == hamper.x) || (enemy1.x + 47 == hamper.x))) {
return true;
}
break;
case 2:
if ((enemy1.x > hamper.x - 50) && (enemy1.x < hamper.x + 17) &&
((enemy1.y + 50 == hamper.y) || (enemy1.y + 49 == hamper.y) || (enemy1.y + 48 == hamper.y) || (enemy1.y + 47 == hamper.y))) {
return true;
}
break;
case 3:
if ((enemy1.y > hamper.y - 50) && (enemy1.y < hamper.y + 10) &&
((enemy1.x == hamper.x + 17) || (enemy1.x == hamper.x + 16) || (enemy1.x == hamper.x + 15) || (enemy1.x == hamper.x + 14))) {
return true;
}
break;
}
break;
case 3:
break;
case 4:
break;
}
}
} } } ///子弹类
function Bullet(x, y, speed, direct)
{
this.x = x;
this.y = y;
this.speed = speed;
this.direct = direct;
this.time = null;
this.islive = true;
this.run = function run(whotank)
{
//$("#tx").html(heroBullets[0].x);
//$("#ty").html(heroBullets[0].y); if ((this.x >= 600 || this.x <= 0 || this.y >= 500 || this.y <= 0) && this.islive) {
window.clearInterval(this.time);
this.islive = false;
if (whotank == "h") {
hero1bullet = null;
switch (this.direct) {
case 0:
hero1bulletBomb = new bulletBomb(this.x - 68, this.y - 50);
break;
case 1:
hero1bulletBomb = new bulletBomb(this.x - 68, this.y - 54);
break;
case 2:
hero1bulletBomb = new bulletBomb(this.x - 68, this.y - 54);
break;
case 3:
hero1bulletBomb = new bulletBomb(this.x - 68, this.y - 52);
break;
}
//alert("00");
}
else {
enemyBullets[whotank] = null;
switch (this.direct)
{
case 0:
enemyBulletBombs[whotank] = new bulletBomb(this.x - 68, this.y - 50);
break;
case 1:
enemyBulletBombs[whotank] = new bulletBomb(this.x - 68, this.y - 54);
break;
case 2:
enemyBulletBombs[whotank] = new bulletBomb(this.x - 68, this.y - 54);
break;
case 3:
enemyBulletBombs[whotank] = new bulletBomb(this.x - 68, this.y - 52);
break;
} } }
else {
switch (this.direct) {
case 0:
this.y = this.y - this.speed;
break;
case 1:
this.x = this.x + this.speed;
break;
case 2:
this.y = this.y + this.speed;
break;
case 3:
this.x = this.x - this.speed;
break;
}
} }
} ////画坦克函数
function DrawTank(tank)
{
switch (tank.direct)
{
case 0:
case 2:
///画玩家坦克,坦克尺寸为50*50
cxt.beginPath();
cxt.fillStyle = tank.tankcolor[0];
cxt.fillRect(tank.x, tank.y, 11, 50); //画玩家坦克轮子
cxt.fillRect(tank.x + 12, tank.y + 10, 26, 30); //中间部分
cxt.fillRect(tank.x + 39, tank.y, 11, 50); //画玩家坦克轮子
///画坦克盖子
cxt.fillStyle = tank.tankcolor[1];
cxt.arc(tank.x + 25, tank.y + 25, 10, 360, 0, true);
cxt.fill();
cxt.closePath();
////画炮口(炮口2px)
cxt.beginPath(); //开始一条新的路径,或重置当前的路径。
cxt.strokeStyle = tank.tankcolor[1]; //线条的颜色
cxt.lineWidth = 2; //线条的宽度(炮口2px)
cxt.moveTo(tank.x + 25, tank.y + 25); //炮口开始位置
if (tank.direct == 0) {
cxt.lineTo(tank.x + 25, tank.y + 0); //炮口结束位置
}
else if (tank.direct == 2) {
cxt.lineTo(tank.x + 25, tank.y + 50); //炮口结束位置
} cxt.closePath(); //创建从当前点到开始点的路径。
cxt.stroke(); //画线
break;
case 1:
case 3:
///画玩家坦克,坦克尺寸为50*50
cxt.beginPath();
cxt.fillStyle = tank.tankcolor[0];
cxt.fillRect(tank.x, tank.y, 50, 11); //画玩家坦克轮子
cxt.fillRect(tank.x + 10, tank.y + 12, 30, 26); //中间部分
cxt.fillRect(tank.x, tank.y + 39, 50, 11); //画玩家坦克轮子
///画坦克盖子
cxt.fillStyle = tank.tankcolor[1];
cxt.arc(tank.x + 25, tank.y + 25, 10, 360, 0, true);
cxt.fill();
cxt.closePath();
////画炮口(炮口2px)
cxt.beginPath(); //开始一条新的路径,或重置当前的路径。
cxt.strokeStyle = tank.tankcolor[1]; //线条的颜色
cxt.lineWidth = 2; //线条的宽度(炮口2px)
cxt.moveTo(tank.x + 25, tank.y + 25); //炮口开始位置
if (tank.direct == 1) {
cxt.lineTo(tank.x + 50, tank.y + 25); //炮口结束位置
}
else if (tank.direct == 3) {
cxt.lineTo(tank.x, tank.y + 25); //炮口结束位置
}
cxt.closePath(); //创建从当前点到开始点的路径。
cxt.stroke(); //画线
break;
}
}
///画出阻碍物(地图)、(style有4个值,1表示砖头、2表示钢铁、3表示草地、4表示河流)
function Hamper(x, y, style)
{
this.x = x;
this.y = y;
this.style = style;
//this.islive = true;
this.Draw = function ()
{
switch (this.style)
{
case 1:
cxt.fillStyle = "#bc5018";
cxt.fillRect(this.x, this.y, 17, 10);
break;
case 2:
cxt.fillStyle = "#ffffff";
cxt.fillRect(this.x, this.y, 17, 17);
break;
case 3:
break;
case 4:
break;
}
}
} ///画出子弹
function DrawBullet()
{
var enemyBullet = null;
cxt.fillStyle = "#ba9658";
for (var en = 0; en < enemyBullets.length; en++) {
enemyBullet = enemyBullets[en];
if (enemyBullet != null && enemyBullet.islive) {
switch (enemyBullet.direct) {
case 0:
case 2:
cxt.fillRect(enemyBullet.x, enemyBullet.y, 2, 3);
break;
case 1:
case 3:
cxt.fillRect(enemyBullet.x, enemyBullet.y, 3, 2);
break;
}
}
}
if (hero1bullet != null && hero1bullet.islive) {
switch (hero1bullet.direct) {
case 0:
case 2:
cxt.fillRect(hero1bullet.x, hero1bullet.y, 2, 3);
break;
case 1:
case 3:
cxt.fillRect(hero1bullet.x, hero1bullet.y, 3, 2);
break;
}
} } ////画出基地
function DrawSymbol()
{
cxt.beginPath();
if (gameover) {
cxt.drawImage(base2, 280, 450, 50, 50);
}
else {
cxt.drawImage(base1, 280, 450, 50, 50);
}
cxt.closePath();
} ////判断子弹是否打中坦克
function hitTank()
{
////敌人子弹是否打中玩家坦克
for (var eb = 0; eb < enemyBullets.length; eb++)
{
if (hero1 != null && hero1.islive != 0 && enemyBullets[eb] != null) {
switch (enemyBullets[eb].direct) {
case 0:
if ((enemyBullets[eb].x + 2 >= hero1.x) && (enemyBullets[eb].x + 2 <= hero1.x + 50) && (enemyBullets[eb].y + 3 <= hero1.y + 50) && (enemyBullets[eb].y + 3 >= hero1.y)) {
enemyBullets[eb].islive = false;
window.clearInterval(enemyBullets[eb].time);
enemyBullets[eb] = null;
hero1.islive--;
}
break;
case 1:
if ((enemyBullets[eb].x + 3 >= hero1.x) && (enemyBullets[eb].x + 3 <= hero1.x + 50) && (enemyBullets[eb].y + 2 >= hero1.y) && (enemyBullets[eb].y + 2 <= hero1.y + 50)) {
enemyBullets[eb].islive = false;
window.clearInterval(enemyBullets[eb].time);
enemyBullets[eb] = null;
hero1.islive--;
}
break;
case 2:
if ((enemyBullets[eb].x + 2 >= hero1.x) && (enemyBullets[eb].x + 2 <= hero1.x + 50) && (enemyBullets[eb].y + 3 <= hero1.y + 50) && (enemyBullets[eb].y + 3 >= hero1.y)) {
enemyBullets[eb].islive = false;
window.clearInterval(enemyBullets[eb].time);
enemyBullets[eb] = null;
hero1.islive--;
}
break;
case 3:
if ((enemyBullets[eb].x <= hero1.x + 50) && (enemyBullets[eb].x >= hero1.x) && (enemyBullets[eb].y + 2 >= hero1.y) && (enemyBullets[eb].y + 2 <= hero1.y + 50)) {
enemyBullets[eb].islive = false;
window.clearInterval(enemyBullets[eb].time);
enemyBullets[eb] = null;
hero1.islive--;
}
break;
}
if (hero1.islive == 0) {
var tankbomb = new TankBomb(hero1.x, hero1.y);
tankbombs.push(tankbomb);
hero1 = null;
if (hero1 == null) {
gameover = true;
}
}
}
}
////敌人子弹是否打中阻碍物
var enemybullet = null;
var hamper = null;
for (var eb = 0; eb < enemyBullets.length; eb++)
{
enemybullet = enemyBullets[eb];
if (enemybullet != null)
{
for (var ha = 0; ha < hampers.length; ha++) {
hamper = hampers[ha];
if (hamper != null && enemybullet != null) {
switch (enemybullet.direct) {
case 0:
switch (hamper.style) {
case 1:
if ((enemybullet.x >= hamper.x - 1) && (enemybullet.x <= hamper.x + 17) &&
(enemybullet.y <= hamper.y + 10) && (enemybullet.y >= hamper.y)) {
enemyBullets[eb].islive = false;
window.clearInterval(enemyBullets[eb].time);
enemyBulletBombs[eb] = new bulletBomb(enemybullet.x - 68, enemybullet.y - 50);
enemyBullets[eb] = null;
hampers[ha] = null;
}
break;
case 2:
if ((enemybullet.x >= hamper.x - 1) && (enemybullet.x <= hamper.x + 17) &&
(enemybullet.y <= hamper.y + 20) && (enemybullet.y >= hamper.y)) {
enemyBullets[eb].islive = false;
window.clearInterval(enemyBullets[eb].time);
enemyBulletBombs[eb] = new bulletBomb(enemybullet.x - 68, enemybullet.y - 50);
enemyBullets[eb] = null;
}
break; } break;
case 1:
switch (hamper.style) {
case 1:
if ((enemybullet.x >= hamper.x) && (enemybullet.x <= hamper.x + 17) &&
(enemybullet.y <= hamper.y + 10) && (enemybullet.y >= hamper.y - 1)) {
enemyBullets[eb].islive = false;
window.clearInterval(enemyBullets[eb].time);
enemyBulletBombs[eb] = new bulletBomb(enemybullet.x - 68, enemybullet.y - 50);
enemyBullets[eb] = null;
hampers[ha] = null;
}
break;
case 2:
if ((enemybullet.x >= hamper.x) && (enemybullet.x <= hamper.x + 17) &&
(enemybullet.y <= hamper.y + 17) && (enemybullet.y >= hamper.y - 1)) {
enemyBullets[eb].islive = false;
window.clearInterval(enemyBullets[eb].time);
enemyBulletBombs[eb] = new bulletBomb(enemybullet.x - 68, enemybullet.y - 50);
enemyBullets[eb] = null;
}
break; }
break;
case 2:
switch (hamper.style) {
case 1:
if ((enemybullet.x >= hamper.x - 1) && (enemybullet.x <= hamper.x + 17) &&
(enemybullet.y + 2 <= hamper.y + 10) && (enemybullet.y + 2 >= hamper.y)) {
enemyBullets[eb].islive = false;
window.clearInterval(enemyBullets[eb].time);
enemyBulletBombs[eb] = new bulletBomb(enemybullet.x - 68, enemybullet.y - 50);
enemyBullets[eb] = null;
hampers[ha] = null;
}
break;
case 2:
if ((enemybullet.x >= hamper.x - 1) && (enemybullet.x <= hamper.x + 17) &&
(enemybullet.y + 2 <= hamper.y + 17) && (enemybullet.y + 2 >= hamper.y)) {
enemyBullets[eb].islive = false;
window.clearInterval(enemyBullets[eb].time);
enemyBulletBombs[eb] = new bulletBomb(enemybullet.x - 68, enemybullet.y - 50);
enemyBullets[eb] = null;
}
break;
}
break;
case 3:
switch (hamper.style) {
case 1:
if ((enemybullet.x >= hamper.x) && (enemybullet.x <= hamper.x + 17) &&
(enemybullet.y + 1 <= hamper.y + 10) && (enemybullet.y + 1 >= hamper.y)) {
enemyBullets[eb].islive = false;
window.clearInterval(enemyBullets[eb].time);
enemyBulletBombs[eb] = new bulletBomb(enemybullet.x - 68, enemybullet.y - 50);
enemyBullets[eb] = null;
hampers[ha] = null;
}
break;
case 2:
if ((enemybullet.x >= hamper.x) && (enemybullet.x <= hamper.x + 17) &&
(enemybullet.y + 1 <= hamper.y + 20) && (enemybullet.y + 1 >= hamper.y)) {
enemyBullets[eb].islive = false;
window.clearInterval(enemyBullets[eb].time);
enemyBulletBombs[eb] = new bulletBomb(enemybullet.x - 68, enemybullet.y - 50);
enemyBullets[eb] = null;
}
break; }
break;
}
}
} }
}
////玩家子弹是否打中敌人坦克
////是否打中阻碍物
if (hero1bullet != null)
{
for (var en = 0; en < enemys.length; en++) {
if (enemys[en] != null && enemys[en].islive != 0 && hero1bullet != null) {
switch (hero1bullet.direct) {
case 0:
if ((hero1bullet.x + 2 >= enemys[en].x) && (hero1bullet.x + 2 <= enemys[en].x + 50) && (hero1bullet.y + 3 <= enemys[en].y + 50) && (hero1bullet.y + 3 >= enemys[en].y)) {
hero1bullet.islive = false;
window.clearInterval(hero1bullet.time);
hero1bullet = null;
enemys[en].islive--;
}
break;
case 1:
if ((hero1bullet.x + 3 >= enemys[en].x) && (hero1bullet.x + 3 <= enemys[en].x + 50) && (hero1bullet.y + 2 >= enemys[en].y) && (hero1bullet.y + 2 <= enemys[en].y + 50)) {
hero1bullet.islive = false;
window.clearInterval(hero1bullet.time);
hero1bullet = null;
enemys[en].islive--;
}
break;
case 2:
if ((hero1bullet.x + 2 >= enemys[en].x) && (hero1bullet.x + 2 <= enemys[en].x + 50) && (hero1bullet.y + 3 <= enemys[en].y + 50) && (hero1bullet.y + 3 >= enemys[en].y)) {
hero1bullet.islive = false;
window.clearInterval(hero1bullet.time);
hero1bullet = null;
enemys[en].islive--;
}
break;
case 3:
if ((hero1bullet.x <= enemys[en].x + 50) && (hero1bullet.x >= enemys[en].x) && (hero1bullet.y + 2 >= enemys[en].y) && (hero1bullet.y + 2 <= enemys[en].y + 50)) {
hero1bullet.islive = false;
window.clearInterval(hero1bullet.time);
hero1bullet = null;
enemys[en].islive--;
}
break;
}
if (enemys[en].islive == 0) {
var tankbomb = new TankBomb(enemys[en].x, enemys[en].y);
tankbombs.push(tankbomb);
enemys[en] = null;
}
}
}
var hamper = null;
for (var ha = 0; ha < hampers.length; ha++)
{
hamper = hampers[ha];
if (hamper != null && hero1bullet!=null)
{
switch (hero1bullet.direct) {
case 0:
switch (hamper.style)
{
case 1:
if ((hero1bullet.x >= hamper.x - 1) && (hero1bullet.x <= hamper.x + 17) &&
(hero1bullet.y <= hamper.y + 10) && (hero1bullet.y >= hamper.y)) {
hero1bullet.islive = false;
window.clearInterval(hero1bullet.time);
hero1bulletBomb = new bulletBomb(hero1bullet.x - 68, hero1bullet.y - 50);
hero1bullet = null;
hampers[ha] = null;
}
break;
case 2:
if ((hero1bullet.x >= hamper.x - 1) && (hero1bullet.x <= hamper.x + 17) &&
(hero1bullet.y <= hamper.y + 20) && (hero1bullet.y >= hamper.y)) {
hero1bullet.islive = false;
window.clearInterval(hero1bullet.time);
hero1bulletBomb = new bulletBomb(hero1bullet.x - 68, hero1bullet.y - 50);
hero1bullet = null;
}
break; } break;
case 1:
switch (hamper.style) {
case 1:
if ((hero1bullet.x >= hamper.x) && (hero1bullet.x <= hamper.x + 17) &&
(hero1bullet.y <= hamper.y + 10) && (hero1bullet.y >= hamper.y-1)) {
hero1bullet.islive = false;
window.clearInterval(hero1bullet.time);
hero1bulletBomb = new bulletBomb(hero1bullet.x - 68, hero1bullet.y - 50);
hero1bullet = null;
hampers[ha] = null;
}
break;
case 2:
if ((hero1bullet.x >= hamper.x) && (hero1bullet.x <= hamper.x + 17) &&
(hero1bullet.y <= hamper.y + 17) && (hero1bullet.y >= hamper.y-1)) {
hero1bullet.islive = false;
window.clearInterval(hero1bullet.time);
hero1bulletBomb = new bulletBomb(hero1bullet.x - 68, hero1bullet.y - 50);
hero1bullet = null;
}
break; }
break;
case 2:
switch (hamper.style) {
case 1:
if ((hero1bullet.x >= hamper.x - 1) && (hero1bullet.x <= hamper.x + 17) &&
(hero1bullet.y + 2 <= hamper.y + 10) && (hero1bullet.y + 2 >= hamper.y)) {
hero1bullet.islive = false;
window.clearInterval(hero1bullet.time);
hero1bulletBomb = new bulletBomb(hero1bullet.x - 68, hero1bullet.y - 50);
hero1bullet = null;
hampers[ha] = null;
}
break;
case 2:
if ((hero1bullet.x >= hamper.x - 1) && (hero1bullet.x <= hamper.x + 17) &&
(hero1bullet.y+2 <= hamper.y + 17) && (hero1bullet.y+2 >= hamper.y)) {
hero1bullet.islive = false;
window.clearInterval(hero1bullet.time);
hero1bulletBomb = new bulletBomb(hero1bullet.x - 68, hero1bullet.y - 50);
hero1bullet = null;
}
break;
}
break;
case 3:
switch (hamper.style) {
case 1:
if ((hero1bullet.x >= hamper.x) && (hero1bullet.x <= hamper.x + 17) &&
(hero1bullet.y+1 <= hamper.y + 10) && (hero1bullet.y+1 >= hamper.y)) {
hero1bullet.islive = false;
window.clearInterval(hero1bullet.time);
hero1bulletBomb = new bulletBomb(hero1bullet.x - 68, hero1bullet.y - 50);
hero1bullet = null;
hampers[ha] = null;
}
break;
case 2:
if ((hero1bullet.x >= hamper.x) && (hero1bullet.x <= hamper.x + 17) &&
(hero1bullet.y+1 <= hamper.y + 20) && (hero1bullet.y+1 >= hamper.y)) {
hero1bullet.islive = false;
window.clearInterval(hero1bullet.time);
hero1bulletBomb = new bulletBomb(hero1bullet.x - 68, hero1bullet.y - 50);
hero1bullet = null;
}
break; }
break;
}
}
} }
} ///坦克爆炸类
function TankBomb(x, y) {
this.x = x;
this.y = y;
this.time = 0;
this.imgsrc = "";
this.isLive = true; this.drawBomb = function drawBomb() {
if (this.time <= 2) {
cxt.drawImage(bomb3, this.x, this.y, 50, 50);
}
if (this.time > 2 && this.time <= 5) {
cxt.drawImage(bomb2, this.x, this.y, 50, 50);
}
if (this.time >= 6 && this.time <= 9) {
cxt.drawImage(bomb1, this.x, this.y, 50, 50);
}
if (this.time >= 10 && this.time <= 12)
{
cxt.drawImage(bomb2, this.x, this.y, 50, 50);
}
if (this.time >= 13 && this.time <= 15)
{
cxt.drawImage(bomb3, this.x, this.y, 50, 50);
}
this.time++;
if (this.time >= 15) {
this.isLive = false;
this.time = 0;
}
};
}
///子弹爆炸类
function bulletBomb(x, y)
{
this.x = x;
this.y = y; this.drawBomb = function ()
{
cxt.drawImage(buBoImg, this.x, this.y); }
}
///判断基地是否被打中
function hitBase() {
if (gameover) {
return;
}
var enemybullet = null;
for (var en = 0; en < enemyBullets.length; en++) {
enemybullet = enemyBullets[en];
if (enemybullet != null) {
switch (enemybullet.direct) {
case 0:
break;
case 1:
if ((enemybullet.x >= 280) && (enemybullet.x <= 330) &&
(enemybullet.y + 1 >= 450) && (enemybullet.y <= 500)) {
gameover = true;
enemyBullets[en] = null;
}
break;
case 2:
if ((enemybullet.x + 1 >= 280) && (enemybullet.x <= 330) &&
(enemybullet.y + 2 >= 450) && (enemybullet.y + 2 <= 500)) {
gameover = true;
enemyBullets[en] = null;
}
break;
case 3:
if ((enemybullet.x >= 280) && (enemybullet.x <= 330) &&
(enemybullet.y + 1 >= 450) && (enemybullet.y <= 500)) {
gameover = true;
enemyBullets[en] = null;
}
break;
}
}
}
if (hero1bullet != null) {
switch (hero1bullet.direct) {
case 0:
break;
case 1:
if ((hero1bullet.x >= 280) && (hero1bullet.x <= 330) &&
(hero1bullet.y + 1 >= 450) && (hero1bullet.y <= 500)) {
gameover = true;
window.clearInterval(hero1bullet.time);
hero1bullet = null;
}
break;
case 2:
if ((hero1bullet.x + 1 >= 280) && (hero1bullet.x <= 330) &&
(hero1bullet.y + 2 >= 450) && (hero1bullet.y + 2 <= 500)) {
gameover = true;
window.clearInterval(hero1bullet.time);
hero1bullet = null;
}
break;
case 3:
if ((hero1bullet.x >= 280) && (hero1bullet.x <= 330) &&
(hero1bullet.y + 1 >= 450) && (hero1bullet.y <= 500)) {
gameover = true;
window.clearInterval(hero1bullet.time);
hero1bullet = null;
}
break;
}
}
} ///画出GAMEOVER
var gameY = 500;
function GameOver()
{
if (gameY > 193) {
gameY = gameY - 4;
}
if (verygood)
{
cxt.beginPath();
cxt.fillStyle = "#CCCCCC";
cxt.fillRect(190, gameY, 215, 115)
cxt.closePath();
cxt.beginPath();
cxt.fillStyle = "#ff0000";
cxt.font = "35px Engravers MT";
cxt.fillText("V E R Y", 212, gameY + 57);
cxt.fillText("G O O D", 212, gameY + 90);
cxt.closePath();
return;
}
if (gameover)
{
cxt.beginPath();
cxt.fillStyle = "#CCCCCC";
cxt.fillRect(190, gameY, 215, 115)
cxt.closePath();
cxt.beginPath();
cxt.fillStyle = "#ff0000";
cxt.font = "35px Engravers MT";
cxt.fillText("G A M E", 212, gameY + 57);
cxt.fillText("O V E R", 212, gameY + 90);
cxt.closePath();
} }

Draw.js

 ////阻碍物 Hamper类参数:x,y,style
var hampers = new Array();
///画出保存基地的墙(一个20块砖头)
var basehamX = 260;
var basehamY = 490;
for (var ham = 0; ham < 20; ham++) {
if (ham < 7) {
hampers[ham] = new Hamper(basehamX, basehamY - ham * 11, 1);
}
if (ham >= 7 && ham < 10) {
hampers[ham] = new Hamper(basehamX + (ham - 6) * 18, basehamY - 5 * 11, 1);
}
if (ham >= 10 && ham < 13) {
hampers[ham] = new Hamper(basehamX + (ham - 9) * 18, basehamY - 6 * 11, 1);
}
if (ham >= 13) {
hampers[ham] = new Hamper(basehamX + 4 * 18, basehamY - (ham - 13) * 11, 1)
}
}
$.getScript("script/js/map1.js"); ///定义玩家1坦克
var hero1born = new Born(180, 450);
var hero1 = null; //敌人坦克出生数组
var enemyborns = new Array(); enemyborns[0] = new Born(0, 0);
enemyborns[1] = new Born(275, 0);
enemyborns[2] = new Born(550, 0); ///定义敌人数组
var enemys = new Array(); ///判断屏幕是否有5个敌人坦克,如果少于5个,则生产一个
var enemy_loca = 1;
function enemyBorn() {
var enemynum = 0;
for (var en = 0; en < enemys.length; en++) {
if (enemys[en] != null) {
enemynum++;
}
}
if (enemynum < 5 && enemys.length < 20) {
var enemyborn = null;
switch (enemy_loca) {
case 1:
enemyborn = new Born(0, 0);
enemy_loca = 2;
break;
case 2:
enemyborn = new Born(275, 0);
enemy_loca = 3;
break;
case 3:
enemyborn = new Born(550, 0);
enemy_loca = 1;
break;
default:
enemyborn = new Born(0, 0);
break;
} enemyborns.push(enemyborn);
}
if (enemynum <= 0 && enemys.length >= 20) {
verygood = true;
} }
window.setInterval("enemyBorn()", 3000); ////爆炸
var tankbombs = new Array(); ///敌人坦克移动
function moveEnemyTank() {
for (var e = 0; e < enemys.length; e++) {
if (enemys[e] != null && enemys[e].islive != 0) {
enemys[e].run();
enemys[e].attackEnemy(e);
}
}
}
window.setInterval("moveEnemyTank()", 100); function flashTankMap() {
cxt.clearRect(0, 0, 600, 500);
///画出阻碍物
for (var ha = 0; ha < hampers.length; ha++) {
if (hampers[ha] != null) {
hampers[ha].Draw();
}
}
/// //画出玩家坦克
if (hero1born != null) {
if (hero1born.born) {
hero1born.drawBorn();
}
else {
hero1 = new Hero(hero1born.x, hero1born.y, 2, 0, heroColor1, 4);
hero1born = null;
}
}
if (hero1 != null && hero1.islive != 0) {
DrawTank(hero1);
}
///画出子弹
DrawBullet();
///判断子弹是否打中坦克
///画出敌人坦克
for (var bo = 0; bo < enemyborns.length; bo++) {
if (enemyborns[bo] != null) {
if (enemyborns[bo].born) {
enemyborns[bo].drawBorn();
}
else {
var enemy = null;
switch (Math.round(Math.random() * 3)) {
case 0:
enemy = new Enemy(enemyborns[bo].x, enemyborns[bo].y, 3, 2, enemyColor1, 1);
break;
case 1:
enemy = new Enemy(enemyborns[bo].x, enemyborns[bo].y, 3, 2, enemyColor2, 1);
break;
case 2:
enemy = new Enemy(enemyborns[bo].x, enemyborns[bo].y, 3, 2, enemyColor3, 1);
break;
case 3:
enemy = new Enemy(enemyborns[bo].x, enemyborns[bo].y, 3, 2, enemyColor4, 1);
break;
}
if (enemy != null) {
enemys.push(enemy);
}
enemyborns[bo] = null;
}
}
}
for (var e = 0; e < enemys.length; e++) {
if (enemys[e] != null && enemys[e].islive != 0) {
DrawTank(enemys[e]);
}
}
///画出爆炸效果
for (var bo = 0; bo < tankbombs.length; bo++) {
if (tankbombs[bo].isLive) {
tankbombs[bo].drawBomb();
}
}
////子弹爆炸
for (var bubo = 0; bubo < enemyBulletBombs.length; bubo++) {
if (enemyBulletBombs[bubo] != null) {
enemyBulletBombs[bubo].drawBomb();
}
enemyBulletBombs[bubo] = null;
}
if (hero1bulletBomb != null) {
hero1bulletBomb.drawBomb();
hero1bulletBomb = null;
}
///画出基地
DrawSymbol();
///调用判断基地是否被打中的函数
hitBase();
///
GameOver();
}
flashTankMap(); ///判断按键
var lastcode = 87;
function getCommand() {
if (hero1 == null || hero1.islive == 0 || gameover) {
return;
}
var keycode = event.keyCode;
switch (keycode) {
case 87:///上
if (lastcode == 87) {
if (!heroTankCollision()) {
hero1.moveUp();
}
}
else {
lastcode = 87;
hero1.direct = 0;
}
break;
case 68:///右
if (lastcode == 68) {
if (!heroTankCollision()) {
hero1.moveRight();
}
}
else {
lastcode = 68;
hero1.direct = 1;
}
break;
case 83:////下
if (lastcode == 83) {
if (!heroTankCollision()) {
hero1.moveDown();
}
}
else {
lastcode = 83;
hero1.direct = 2;
}
break;
case 65:///左
if (lastcode == 65) {
if (!heroTankCollision()) {
hero1.moveLeft();
}
}
else {
lastcode = 65;
hero1.direct = 3;
}
break;
case 74:////开炮
//hero1.tankbullet = "1";
hero1.attackEnemy();
break;
case 66:
break;
default:
break;
}
flashTankMap();
}
window.setInterval("flashTankMap()", 100);
window.setInterval("hitTank()", 20);
//玩家坦克与敌人坦克、阻碍物之间的碰撞
function heroTankCollision() {
//玩家坦克与敌人坦克之间的碰撞
var enemy = null;
for (var en = 0; en < enemys.length; en++) {
enemy = enemys[en];
if (enemy != null && enemy.islive != 0) {
switch (hero1.direct) {
case 0:
if ((hero1.x > enemy.x - 50) && (hero1.x < enemy.x + 50) &&
((hero1.y == enemy.y + 47) || (hero1.y == enemy.y + 48) || (hero1.y == enemy.y + 49) || (hero1.y == enemy.y + 50))) {
return true;
}
//else {
// return false;
//}
break;
case 1:
if ((hero1.y > enemy.y - 50) && (hero1.y < enemy.y + 50) &&
((hero1.x + 47 == enemy.x) || (hero1.x + 50 == enemy.x) || (hero1.x + 49 == enemy.x) || (hero1.x + 48 == enemy.x))) {
return true;
} break;
case 2:
if ((hero1.x > enemy.x - 50) && (hero1.x < enemy.x + 50) &&
((hero1.y + 47 == enemy.y) || (hero1.y + 50 == enemy.y) || (hero1.y + 49 == enemy.y) || (hero1.y + 48 == enemy.y))) {
return true;
} break;
case 3:
if ((hero1.y > enemy.y - 50) && (hero1.y < enemy.y + 50) &&
((hero1.x == enemy.x + 47) || (hero1.x == enemy.x + 50) || (hero1.x == enemy.x + 49) || (hero1.x == enemy.x + 48))) {
return true;
} break;
}
}
}
//玩家坦克与阻碍物之间的碰撞
var hamper = null;
for (var ha = 0; ha < hampers.length; ha++) {
hamper = hampers[ha];
if (hamper != null) {
switch (hampers[ha].style) {
case 1:
switch (hero1.direct) {
case 0:
if ((hero1.x > hamper.x - 50) && (hero1.x < hamper.x + 17) &&
((hero1.y == hamper.y + 7) || (hero1.y == hamper.y + 8) || (hero1.y == hamper.y + 9) || (hero1.y == hamper.y + 10))) {
return true;
}
break;
case 1:
if ((hero1.y > hamper.y - 50) && (hero1.y < hamper.y + 10) &&
((hero1.x + 50 == hamper.x) || (hero1.x + 49 == hamper.x) || (hero1.x + 48 == hamper.x) || (hero1.x + 47 == hamper.x))) {
return true;
}
break;
case 2:
if ((hero1.x > hamper.x - 50) && (hero1.x < hamper.x + 17) &&
((hero1.y + 50 == hamper.y) || (hero1.y + 49 == hamper.y) || (hero1.y + 48 == hamper.y) || (hero1.y + 47 == hamper.y))) {
return true;
}
break;
case 3:
if ((hero1.y > hamper.y - 50) && (hero1.y < hamper.y + 10) &&
((hero1.x == hamper.x + 17) || (hero1.x == hamper.x + 16) || (hero1.x == hamper.x + 15) || (hero1.x == hamper.x + 14))) {
return true;
}
break;
}
break;
case 2:
switch (hero1.direct) {
case 0:
if ((hero1.x >= hamper.x - 50) && (hero1.x <= hamper.x + 17) &&
((hero1.y == hamper.y + 14) || (hero1.y == hamper.y + 15) || (hero1.y == hamper.y + 16) || (hero1.y == hamper.y + 17))) {
return true;
}
break;
case 1:
if ((hero1.y > hamper.y - 50) && (hero1.y < hamper.y + 10) &&
((hero1.x + 50 == hamper.x) || (hero1.x + 49 == hamper.x) || (hero1.x + 48 == hamper.x) || (hero1.x + 47 == hamper.x))) {
return true;
}
break;
case 2:
if ((hero1.x > hamper.x - 50) && (hero1.x < hamper.x + 17) &&
((hero1.y + 50 == hamper.y) || (hero1.y + 49 == hamper.y) || (hero1.y + 48 == hamper.y) || (hero1.y + 47 == hamper.y))) {
return true;
}
break;
case 3:
if ((hero1.y > hamper.y - 50) && (hero1.y < hamper.y + 10) &&
((hero1.x == hamper.x + 17) || (hero1.x == hamper.x + 16) || (hero1.x == hamper.x + 15) || (hero1.x == hamper.x + 14))) {
return true;
}
break;
}
break;
case 3:
break;
case 4:
break;
}
}
} }

opera_js.js

  还有地图……
  需要代码的可以联系我,我的邮箱是:YJZhen@live.com

  如需更多教程,请到 淘课学院 http://www.taokeschool.com/ 下载。

(欢迎关注“角速度”微信:jiaosud)

《HTML5经典坦克大战》游戏(代码)的更多相关文章

  1. HTML5之坦克大战游戏开发

    1.在使用arc方法进行画圆时,在IE9+,FF,Safari,Chrome等已经支持HTML5标准的浏览器中进行渲染时,采用逆时针方向画时,也就是说 arc(x, y, radius, startA ...

  2. 小强的HTML5移动开发之路(7)——坦克大战游戏1

    来自:http://blog.csdn.net/dawanganban/article/details/17693145 上一篇中我们介绍了关于Canvas的基础知识,用Canvas绘制各种图形和图片 ...

  3. 基于HTML5坦克大战游戏简化版

    之前我们有分享过不少经典的HTML5游戏,有些还是很有意思的,比如HTML5版切水果游戏和HTML5中国象棋游戏.今天要分享的是一款简化版的HTML5坦克大战游戏,方向键控制坦克的行进方向,空格键发射 ...

  4. 小强的HTML5移动开发之路(8)——坦克大战游戏2

    来自:http://blog.csdn.net/cai_xingyun/article/details/48629015 在上一篇文章中我们已经画出了自己的坦克,并且可以控制自己的坦克移动,我们继续接 ...

  5. cocos2d-x游戏开发系列教程-坦克大战游戏启动界面的编写

    用前面介绍的方法,创建一个cocos2d-x项目,可以看到新项目内容如下图:

  6. 最简容器动手小实践——FC坦克大战游戏容器化

    FC 经典力作相信大家一点也不陌生.童年时期最频繁的操作莫过于跳关,在 果断跳到最后一关之后,一般都是以惨败告终,所以还是一关一关的过原始积累才能笑到最后.这款游戏的经典就在于双人配合,守家吃装备.也 ...

  7. 3D坦克大战游戏源码

    3D坦克大战游戏源码,该游戏是基于xcode 4.3,ios sdk 5.1开发.在xcode4.3.3上完美无报错.兼容ios4.3-ios6.0 ,一款ios平台上难得的3D坦克大战游戏源码,有2 ...

  8. 3D坦克大战游戏iOS源码

    3D坦克大战游戏源码,该游戏是基于xcode 4.3,ios sdk 5.1开发.在xcode4.3.3上完美无报错.兼容ios4.3-ios6.0 ,一款ios平台上难得的3D坦克大战游戏源码,有2 ...

  9. [置顶] 小强的HTML5移动开发之路(9)——坦克大战游戏3

    上一篇我们创建了敌人的坦克和自己的坦克,接下来就应该让坦克发子弹了,我们下面来看一下如何让我们的坦克发出子弹. 前面我们用面向对象的思想对Tank进行了封装,又利用对象冒充实现了我们的坦克和敌人的坦克 ...

随机推荐

  1. 卓越网的kindle paperwhite

    卓越网的kindle paperwhite, 899元的价钱,好吸引啊,我是不是也应该买一个呢,从卓越网中看见kindle paperwhite的1代开始,一直想买,等到现在的2代也出了,也继续在考虑 ...

  2. shell脚本实例一,移动文件夹中大于2000B的文件到另一个文件夹

    shell脚本能帮我们简化linux下的一些工作,现在有个需求,把TMPA文件夹下大于2000B的文件都移动到TMPB下 #! /bin/bash function movefiles() { ` d ...

  3. Ubuntu12.04 下安装QQ

    1:点此下载DEB安装包http://www.longene.org/download/WineQQ2012-20120712-Longene.deb 2:打开终端输入到目录中运行命令安装. sudo ...

  4. Printing Architecture

    Printing Architecture http://www.codeproject.com/Articles/8916/Printing-Architecture     This articl ...

  5. 8.2.1.7 Use of Index Extensions 使用索引扩展

    8.2.1.7 Use of Index Extensions 使用索引扩展 InnoDB 自动扩展每个secondary index 通过添加primary key columns to it,考虑 ...

  6. Android中Chronometer 计时器和震动服务控件

    Chronometer 计时器控件 首先在布局文件中添加chronometer控件:然后在mainActivity中获取到该控件 4 然后通过Button时间监听器中开启计时操作 5 chronome ...

  7. LINQPad 调试

    var ss=from o in Orders from od in OrderDetails.Where(od=>od.OrderId == od.OrderId) from c in Cou ...

  8. codeforces284 div1 B:概率dp

    蛋疼的期末..好久没有A题了,,惭愧啊 昨晚打起精神准备做cf 结果竟然忘记注册了..拿学长号看了看题,今早起来补了一道dp 题目大意: 有n首歌,你需要边听边猜 对于第 i 首歌 每听一分钟你猜出它 ...

  9. JAVA并发七(多线程环境中安全使用集合API)

    在集合API中,最初设计的Vector和Hashtable是多线程安全的.例如:对于Vector来说,用来添加和删除元素的方法是同步的.如果只有一个线程与Vector的实例交互,那么,要求获取和释放对 ...

  10. NuGet学习笔记(2)——使用图形化界面打包自己的类库

    上文NuGet学习笔记(1) 初识NuGet及快速安装使用说到NuGet相对于我们最重要的功能是能够搭建自己的NuGet服务器,实现公司内部类库的轻松共享更新.在安装好NuGet扩展后,我们已经能够通 ...