html5坦克大战完整版

tanke.js文件:

 //定义敌人和我们自己的坦克的颜色
 var enemyColor = new Array('#00FEFE','#00A2B5');
 var heroColor = new Array('#FEF26E','#BA9658');
 //封装一个公用的坦克类
 function Tank(x,y,direct){
  this.x = x;
  this.y = y;
  this.speed = 3;
  this.direct = direct;
  this.moveUp = function(){
   hero.y -= hero.speed;
   hero.direct = 0;
  }
  this.moveRight = function(){
   hero.x += hero.speed;
   hero.direct = 1;
  }
  this.moveBottom = function(){
   hero.y += hero.speed;
   hero.direct = 2;
  }
  this.moveLeft = function(){
   hero.x -= hero.speed;
   hero.direct = 3;
  }
 }
 
 //英雄坦克类
 function Hero(x,y,direct,color){
  //将坦克类的构造方法赋给hero
  this.hero = Tank;
  //调用,拥有坦克类的所有的属性和方法
  this.hero(x,y,direct);
  this.color = color;
  this.direct = direct;
  this.isLive = true;
  this.shotEnemy = function(){
   switch(this.direct){
    case 0:
     heroBullet = new Bullet(this.x+9,this.y,this.direct);
    break;
    case 1:
     heroBullet = new Bullet(this.x+30,this.y+9,this.direct);
    break;
    case 2:
     heroBullet = new Bullet(this.x+9,this.y+30,this.direct);
    break;
    case 3:
     heroBullet = new Bullet(this.x,this.y+9,this.direct);
    break;
   }
   heroBullets.push(heroBullet);
   heroBullets[heroBullets.length-1].timer = window.setInterval("heroBullets["+(heroBullets.length-1)+"].run()",50);
  }
 }
 //敌人的坦克
 function EnemyTank(x,y,direct,color){
  //将坦克类的构造方法赋给hero
  this.enemyTank = Tank;
  //调用,拥有坦克类的所有的属性和方法
  this.enemyTank(x,y,direct);
  this.color = color;
  this.isLive = true;
  this.timer = null;
  this.speed = 1;
  this.count = 0;
  this.direct = direct;
  this.bulletIsLive = true;
  this.run = function(){
   switch(this.direct){
    case 0:
     if(this.y>0){
     this.y--;
    }
    break;
    case 1:
     if(this.x+30<500){
     this.x += this.speed;
    }
    break;
    case 2:
     if(this.y+30<300){
     this.y += this.speed;
    }
    break;
    case 3:
     if(this.x>0){
     this.x -= this.speed;
    }
    break;
   }
   
   if(this.count>=30){
    this.direct = Math.round(Math.random()*3);
    this.count=0;
   }
   this.count++;
   //在坦克走的过程中,判断一下,这个坦克的子弹是否活着
   if(this.bulletIsLive == false && this.isLive){
    //子弹已死,给他补充一颗
    switch(this.direct){
     case 0:
      enemyBullets.push(new Bullet(this.x+9,this.y,this.direct,this,'enemy'));
     break;
     case 1:
      enemyBullets.push(new Bullet(this.x+30,this.y+9,this.direct,this,'enemy'));
     break;
     case 2:
      enemyBullets.push(new Bullet(this.x+9,this.y+30,this.direct,this,'enemy'));
     break;
     case 3:
      enemyBullets.push(new Bullet(this.x,this.y+9,this.direct,this,'enemy'));
     break;
    }
    enemyBullets[enemyBullets.length-1].timer = window.setInterval("enemyBullets["+(enemyBullets.length-1)+"].run()",50);
     this.bulletIsLive = true;
   }
  }
 }
 //绘制坦克
  function drawTank(hero){
  switch(hero.direct){
   case 0:
   case 2:
   //alert(ctx);
    ctx.fillStyle = hero.color[0];
    ctx.fillRect(hero.x,hero.y,5,30);
    ctx.fillRect(hero.x+15,hero.y,5,30);
    ctx.fillRect(hero.x+6,hero.y+5,8,20);
    //需要注意,画圆的时候需要重新开启路径
    ctx.fillStyle = hero.color[1];
    ctx.beginPath();
    ctx.arc(hero.x+10,hero.y+15,3,0,Math.PI*2,true);
    ctx.closePath();
    ctx.fill();
    //画出炮筒(直线)
    ctx.strokeStyle = hero.color[1];
    ctx.lineWidth = 2;
    ctx.moveTo(hero.x+10,hero.y+15);
    if(hero.direct==0){
     ctx.lineTo(hero.x+10,hero.y);
    }else if(hero.direct==2){
     ctx.lineTo(hero.x+10,hero.y+30);
    }
    ctx.stroke();
   break;
   case 1:
   case 3:
    ctx.fillStyle = hero.color[0];
    ctx.fillRect(hero.x,hero.y,30,5);
    ctx.fillRect(hero.x,hero.y+15,30,5);
    ctx.fillRect(hero.x+5,hero.y+6,20,8);
    //需要注意,画圆的时候需要重新开启路径
    ctx.fillStyle = hero.color[1];
    ctx.beginPath();
    ctx.arc(hero.x+15,hero.y+10,3,0,Math.PI*2,true);
    ctx.closePath();
    ctx.fill();
    //画出炮筒(直线)
    ctx.strokeStyle = hero.color[1];
    ctx.lineWidth = 2;
    ctx.moveTo(hero.x+15,hero.y+10);
    if(hero.direct ==1){
     ctx.lineTo(hero.x+30,hero.y+10);
    }else if(hero.direct ==3){
     ctx.lineTo(hero.x,hero.y+10);
    }
    ctx.stroke();
   break;
  }
 }

 //定义一个子弹类
 function Bullet(x,y,direct,tank,type){
  this.x = x;
  this.y = y;
  this.speed = 3;
  this.direct = direct;
  this.timer = null;
  this.isLive = true;
  this.tank = tank;
  this.type = type;
  this.run = function(){
   switch(this.direct){
    case 0:
     this.y -= this.speed;
    break;
    case 1:
     this.x += this.speed;
    break;
    case 2:
     this.y += this.speed;
    break;
    case 3:
     this.x -= this.speed;
    break;
   }
   document.getElementById('aa').innerText = "x轴:"+this.x+"y轴:"+this.y;
   if(this.x <0 || this.x>=500 ||this.y<0 || this.y>300 ||this.isLive==false){
    this.isLive = false;
    //this.tank.bulletIsLive = false;
    if(this.type=='enemy'){
     this.tank.bulletIsLive = false;
    }
    window.clearInterval(this.timer);
   }
  }
 }
 function drawHeroBullet(bullets){
  for(var i=0;i<bullets.length;i++){
   var heroBullet = bullets[i];
   if(heroBullet.isLive){
    ctx.fillStyle = '#00FEFE';
    ctx.fillRect(heroBullet.x,heroBullet.y,2,2);
   }
  }
 }
 //画出敌人坦克的子弹
 function drawEnemyBullet(enemyBullets){
  for(var i=0;i<enemyBullets.length;i++){
   var enemyBullet = enemyBullets[i];
   if(enemyBullet.isLive){
    ctx.fillRect(enemyBullet.x,enemyBullet.y,2,2);
   }
  }
 }
 function isHitEnemyTank(heroBullets,enemyTanks){
  for(var i=0;i<heroBullets.length;i++){
   for(var j=0;j<enemyTanks.length;j++){
    //判断一下自己的子弹和敌人的坦克坐标
    if(enemyTanks[j].isLive){
     switch(enemyTanks[j].direct){
     case 0:
     case 2:
      if(heroBullets[i].x>=enemyTanks[j].x&&heroBullets[i].x<=enemyTanks[j].x+20&&heroBullets[i].y>=enemyTanks[j].y&&heroBullets[i].y<=enemyTanks[j].y+30){
       //标记敌人的坦克和我们的子弹已经死掉了
       heroBullets[i].isLive = false;
       enemyTanks[j].isLive = false;
       var bomb = new Bomb(enemyTanks[j].x,enemyTanks[j].y);
       bombs.push(bomb);

     }
     break;
     case 1:
     case 3:
      if(heroBullets[i].x>=enemyTanks[j].x&&heroBullets[i].x<=enemyTanks[j].x+30&&heroBullets[i].y>=enemyTanks[j].y&&heroBullets[i].y<=enemyTanks[j].y+20){
       //标记敌人的坦克和我们的子弹已经死掉了
       heroBullets[i].isLive = false;
       enemyTanks[j].isLive = false;
       var bomb = new Bomb(enemyTanks[j].x,enemyTanks[j].y);
       bombs.push(bomb);
     }
     break;
    }
    }
    
   }
  }
 }

 //定义炸弹类
 function Bomb(x,y){
  this.x = x;
  this.y = y;
 }

 //判断敌人的子弹是否击中自己的坦克
 function isHitHeroTank(enemyBullets,heroTank){
  for(var i=0;i<enemyBullets.length;i++){
   if(enemyBullets[i].isLive && heroTank.isLive){
    switch(heroTank.direct){
    case 0:
    case 2:
     if(enemyBullets[i].x >= heroTank.x && enemyBullets[i].x <= heroTank.x+20 && enemyBullets[i].y >= heroTank.y && enemyBullets[i].y <= heroTank.y +30){
     heroTank.isLive = false;
     enemyBullets[i].isLive = false;
    }
    break;
    case 1:
    case 3:
     if(enemyBullets[i].x >= heroTank.x && enemyBullets[i].x <= heroTank.x+30 && enemyBullets[i].y >= heroTank.y && enemyBullets[i].y <= heroTank.y +20){
     heroTank.isLive = false;
     enemyBullets[i].isLive = false;
    }
    break;
   }
   }
  }
 }

 

tanke.html文件:

 

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'/>
<script src='tankGame3.js'></script>
</head>
<body οnkeydοwn="changeDirect()">
<canvas id='tankMap' width='500px' height='300px' style='background-color:black'>
你的浏览器不支持canvas标签</canvas>
<span id='aa'></span>
</body>
<script>
 //开始画出我们的tanke
 var canvas = document.getElementById('tankMap');
 //相当于获得画笔
 var ctx = canvas.getContext('2d');
 //定义炸弹
 var bombs = new Array();
 var hero = new Hero(140,90,0,heroColor);
 var enemyTanks = new Array();
 //敌人的子弹数组
 var enemyBullets = new Array();
 for(var i=0;i<3;i++){
  var enemyTank = new EnemyTank((i+1)*50,0,2,enemyColor);
  enemyTanks[i] = enemyTank;
  //drawTank(enemyTanks[i]);
  //让敌人的坦克动起来
  var timer = window.setInterval("enemyTanks["+i+"].run()",50);
  enemyTanks[i].timer = timer;
  //让敌人发射子弹
  var enemyBullet = new Bullet(enemyTanks[i].x+9,enemyTanks[i].y+30,enemyTanks[i].direct,enemyTanks[i],'enemy');
  enemyBullets.push(enemyBullet);
  enemyBullets[i].timer = window.setInterval("enemyBullets["+i+"].run()",50);
 }
 //定义子弹数组
 var heroBullets = new Array();
 var heroBullet = null;
 
 if(hero.isLive){
   drawTank(hero);
  }

 flashMap();
 function flashMap(){
  ctx.clearRect(0,0,500,300);
  isHitHeroTank(enemyBullets,hero);
  if(hero.isLive){
   drawTank(hero);
  }
  
  isHitEnemyTank(heroBullets,enemyTanks);
  //画出自己坦克的子弹
  drawHeroBullet(heroBullets);
  //画出敌人坦克的子弹
  drawEnemyBullet(enemyBullets,enemyTanks);
  for(var i=0;i<3;i++){
   if(enemyTanks[i].isLive){
    drawTank(enemyTanks[i]);
   }
  }

  //画出炸弹
  for(var k=0;k<bombs.length;k++){
   var img = new Image();
   img.src = 'bomb_1.gif';
   var x = bombs[k].x;
   var y = bombs[k].y;
   ctx.drawImage(img,x,y,30,30);
   bombs.splice(k,1);
  }
 }

 function changeDirect(){
  var keycode = event.keyCode;
  switch(keycode){
   case 87:
   hero.moveUp();
   break;
   case 68:
   hero.moveRight();
   break;
   case 83:
   hero.moveBottom();
   break;
   case 65:
   hero.moveLeft();
   break;
   case 74:
   hero.shotEnemy();
   break;
  }
   flashMap();
 }
 window.setInterval("flashMap()",100);
</script>
</html>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
非常实用 持之以恒才是王道! 8-11 1.html介绍 html运行原理① 8-11 2.html运行原理② html文件基本结构 html元素和属性 8-11 3.符号实体 url说明 超链接 发送电邮 8-11 4.图像 表格 实际应用-菜谱 课堂练习-课程表 8-11 5.无序列表 有序列表 框架 8-12 1.浮动窗口 表单及表单控件① 8-12 2.表单及表单控件② 8-12 3.多媒体页面 标签汇总① 地图映射1 8-12 4.多媒体页面 标签汇总① 地图映射2 8-12 5.多媒体页面 标签汇总① 地图映射3 8-12 6.多标签汇总② 线包字效果 测试题 8-13 1.div+css开山篇 8-13 2.初识css 类选择器 id选择器 html选择器 8-13 3.通配符选择器 父子选择器 8-13 4.选择器使用细节 块元素?托心谠? 盒子模型 盒子模型经典应用① 8-13 5.盒子模型经典应用② 作业布置 8-15 1.div+css作业评讲① 8-15 2.div+css作业评讲② 8-15 3.div+css作业评讲③ 8-15 4.浮动 8-15 5.网站推荐 定位 8-15 6.仿sohu首页面布局 可爱屋首页面 8-16 1.动态网页技术介绍 php基本介绍 8-16 2.php快速入门 bs和cs介绍 8-16 3.web服务器介绍 apache服务器安装 8-16 4.apache服务器使用及配置① 启动和停止 端口配置 8-16 5.apache服务器使用及配置② apache目录结构 8-16 6.apache服务器使用及配置③ apache虚拟目录 8-17 1.apache服务器使用及配置④ apache虚拟主机 web访问时序图 8-17 2.apache服务器使用及配置⑤ 作业点评 提出apache和php整合的需求 8-17 3.php开发环境的搭建和使用① appserv套件安装 8-17 4.php开发环境的搭建和使用② 自定义安装 8-17 5.php开发环境的搭建和使用③ 安装并配置discuz论坛 8-19 1.解答学生问题--一个ip绑定多个域名 8-19 2.php运行过程时序图 php书写规范 8-19 3.php基本语法介绍 php数据类型介绍 8-19 4.整型细节说明 8-19 5.布尔细节 浮点数细节 字符串细节 算术运算符① 8-19 6.算术运算符② 比较运算符 逻辑运算符 8-20 1.三元运算符 类型运算符 运算符优先级 8-20 2.顺序控制 分支控制(if ifelse switch) 程序流程图 8-20 3.循环控制①(for) 8-20 4.循环控制②(while dowhile) 打印金字塔案例 8-20 5.打印金字塔案例评讲 布置练习题 8-22 1.break语句 continue语句 常量 8-22 2.函数基本概念 函数快速入门 8-22 3.函数使用函数调用初步理解 8-22 4.函数调用深入理解 函数使用注意事项① 8-22 5.函数使用注意事项② 函数作业布 8-23 1.函数再回顾 自定义函数 8-23 2.位运算① 8-23 3.位运算② 8-23 4.数组介绍 数组的创建 ?榈谋槔? 8-23 5.数组的引用 数组使用细节① 8-23 6.数组使用细节② 数组运算符 数组作业评讲① 数组小结 8-24 1.回顾 8-24 2.选择排序 插入排序 快速排序 8-24 3.选择排序 插入排序 快速排序 8-24 4.顺序查找 二分查找 8-24 5.多维数组 数组作业评讲② 8-24 6.数组作业评讲③ 8-24 7.类与对象的基本概念 8-26 1.成员属性 如何创建对象 8-26 2.对象在内存中存在形式 函数传递对象方式 8-26 3.函数传递基本数据类型和数组方式 成员方法① 8-26 4.成员方法② 8-26 5.作业评讲 8-27 mysql1 8-27 mysql2 8-28 1.mysql 8-28 2.mysql 8-28 3.mysql 8-28 4.mysql 8-28 5.mysql 8-28 6.mysql 8-30 1.mysql 8-30 2.mysql 8-30 3.mysql 8-30 4.mysql 8-30 5.mysql 8-31 1 8-31 2.外键、索引 8-31 3.事务处理 8-31 4 8-31 5 8-31 6 9-10 1.回顾 9-10 2.错误和异常处理介绍 处理错误方式①-die 9-10 3.处理错误方式②-错误处理器 错误级别 处理错误方式③-错误触发器 9-10 4.php错误日志 9-10 5.php异常处理 9-10 6.php进阶预热篇-php执行流程时序图 9-10 7.http协议深度剖析①-http请求详解 防盗链技术 9-13 0.回顾 9-13 1.http协议深度剖析②-http响应详解(302 304码运用) 9-13 2.http协议深度剖析③-http响应详解(禁用缓存设置) 9-13 3.http协议深度剖析④-http响应详解(文件下载) 9-13 4.http协议深度剖析⑤-http响应详解(作业评讲) 9-13 5.php数据库编程①-使用mysql扩展库 9-13 6.php数据库编程②-使用mysql扩展库 9-13 7.php数据库编程③-使用mysql扩展库 9-14 1.回顾 9-14 2.php数据库编程④-使用mysql扩展库(在线词典案例) 9-14 3.php数据库编程⑤-使用mysql扩展库(在线词典案例) 9-14 4.php数据库编程⑥-使用mysqli扩展库 9-14 5.php数据库编程⑦-使用mysqli扩展库 9-14 6.php数据库编程⑧-使用mysqli扩展库(布置练习) 9-14 7.php数据库编程⑨-使用mysqli扩展库增强(批量执行sql和事务控制) 9-17 1.回顾 9-17 2.php数据库编程(10)-使用mysqli扩展库增强(预处理技术) 9-17 3.php数据库编程(11)-使用mysqli扩展库增强(预处理技术) 9-17 4.预定义超全局数组①-原理分析 $_GET 9-17 5.预定义超全局数组②-$_POST $_REQUEST 9-17 6.预定义超全局数组③-$_SERVER $_ENV $GLOBALS 9-17 7.zend studio使用 项目开发五个阶段 雇员管理系统① 9-19 1.回顾 9-19 2.雇员管理系统②-model1模式简单登录 9-19 3.雇员管理系统③-model1模式数据库登录 9-19 4.雇员管理系统④-model1模式雇员分页 9-19 5.雇员管理系统⑤-分层模式管理员登录 9-20 1.回顾 9-20 2.雇员管理系统⑥-分层模式雇员分页 9-20 3.雇员管理系统⑦-分层模式整体翻页 9-20 4.雇员管理系统⑧-分层模式通用分页模块 9-20 5.雇员管理系统⑨-mvc模式介绍 9-21 1.回顾 9-21 2.mvc模式①-用mvc模式改进网站结构 9-21 3.mvc模式②-用mvc模式改进网站结构 9-21 4.cookie①-cookie原理介绍 创建cookie 获取cookie 9-21 5.cookie②-更新cookie 删除cookie cookie运用案例 9-21 6.cookie③-雇员管理系统使用cookie技术 1.显示上传登录时间2.保留登录id 9-23 1回顾 9-23 2.session①-session原理介绍 保存session 9-23 3.session②-获取session 更新session 删除session session细节和原理深入讨 9-23 4.session③-购物车 cookie禁用后如何使用session session防用户非法登录 9-23 5.session④-验证码防恶意攻击 9-23 6.session⑤-session配置 session的gc机制 自定义session处理器 9-24 0.回顾 9-24 1.回顾2 9-24 2.php文件编程①-文件操作原理 如何获取文件信息 如何读文件 9-24 3.php文件编程②-如何写文件 拷贝文件 创建和删除(文件夹、文件) 9-24 4.php文件编程③-文件的上传和下载 文件上传细节讨论 9-24 5.php文件编程④-mini文件共享网实现分析 9-24 6.PHP绘图技术 9-26 1 课程回顾 9-26 2 javascript基本介绍 9-26 3 javascript变量 标识符规范 9-26 4 javascript数据类型三大类型 9-26 5 javascript算术运算符及位运算 9-26 6 javascript三大流程控制 9-27 1 课程回顾 9-27 2 循环控制 金字塔的输出 9-27 3 循环控制 js的调试方法 9-27 4 函的数定义分类及使用 9-27 5 函数的调用 递归及深入使用 9-27 6 一维?榧笆樵谀诖嬷械拇嬖谛问? 9-27 7 常用数组的属性及使用方法 9-28 1课程回顾 9-28 2 二维数组的定义使用 数组排序 9-28 3 顺序查找 二分查找 9-28 4 javascript面向对象编程 9-28 5 javascript对象存在形式 9-28 6 javascript类与对象 9-28 7 给对象指定成员函数 自定义工厂方法 9-30 1 课程回顾 9-30 2 javascript的闭包 js变量作用域 9-30 3 仿超级玛丽兄弟游戏制作 9-30 4 构造方法 对象的常用操作 9-30 5 面向对象的封装 继承 多态 9-30 6 面向对象的封装 继承 多态2 9-5 1.php xml编程①-xml基本介绍 xml元素 xml属性 9-5 2.php xml编程②-cdata 实体字符 处理指令 dtd快速入门 编?绦Q閤ml 9-5 3.php xml编程③-内部dtd 外边dtd dtd元素 dtd修饰符 9-5 4.php xml编程④-dtd属性 引用实体 参数实体 ide开发xml 9-5 5.php xml编程⑤-复杂的dtd综合练习 9-5 6.php xml编程⑥-dom基本概念 phpdom编程(1) 9-6 1.回顾 9-6 2.php xml编程⑦-phpdom编程(2) 9-6 3.php xml编程⑧-phpdom编程(3) 综合练习-基于xml的在线词典 9-6 4.php xml编程⑨-综合练习-基于xml的在线词典 phpdom使用xpath 9-6 5.php xml编程(10)-SimpleXML 9-7 1.回顾 9-7 2.析构方法 9-7 3.static关键字(静态变量) 9-7 4.static关键字(静态方法) 面向对象编程三大特性① 9-7 5.面向对象编程三大特性② 9-7 6.面向对象编程三大特性③ 9-9 1.回顾 9-9 2.面向对象编程三大特性④ 9-9 3.面向对象编程三大特性⑤ 抽象类 9-9 4.接口 9-9 5.继承与实现比较 final const 9-9 6.面向对象编程综合练习 10-10 1 课程回顾 10-10 2 正则表达式 10-10 3 正则表达式 子表达式 引用 反向捕获 10-10 4 正则表达式 元字符 语法 10-10 5 元字符 实例应用 10-10 6 供求信息网讲解1 10-10 7 供求信息网讲解2 10-11 1 供求信息网3 10-11 2 供求信息网4 10-11 3 供求信息网5 10-11 4 供求信息网6 10-15 1 zendframe手动部署 自动部署 10-15 2 zendframe架构讲解 10-15 3 view layout布局 10-15 4 view helper视图助手 10-15 5 遗留问题解决 10-15 6 zf重新部署 10-15 7 zf controller讲解 10-16 1 model讲解 controller view调用 10-16 2 投票系统讲解1 10-16 3 投票系统讲解2 10-16 4 投票系统讲解3 10-16 5 投票系统讲解4 10-18 1 模板技术讲解 10-18 2 smarty常用功能 10-18 3 smarty常用功能 10-18 4 smarty功能讲解 10-18 5 smarty流程控制 10-18 6 10-18 7 smarty include使用 10-19 1 smarty实例 注册 10-19 2 smarty实例 注册2 10-19 3 smarty实例 注册3 10-19 4 smarty 字符串 自定义插件 缓存 10-19 5 smarty 字符串 自定义插件 缓存 10-19 6 smarty实例应?? 10-19 7 smarty实例应用2 10-19 8 smarty实例应用3 10-20 1 smarty应用 更换网站皮肤 10-20 2 smarty应用 更换网站皮肤2 10-20 3 smarty应用 更换网站皮肤3 10-20 4 smarty应用 更换网站皮肤4 10-20 5 smarty二级联动 10-20 6 smarty完成静态化 10-20 7 10-20 8 smarty分页技术 10-20 9 10-22 1 ajax介绍 无刷新验证用户名 10-22 2 ajax如何处理xml格式返回数据 10-22 3 json 10-22 4 ajax如何处理json格式返回数据 10-22 5 ajax应用 省市联动 10-22 6 ajax应用 黄金市场报价 10-23 1 简易在线聊天室1 10-23 2 简易在线聊天室2 10-23 3 简易在线聊天室3 10-23 4 简易在线聊天室4 10-23 5 简易在线聊天室5 10-23 6 简易在线聊天室6 10-25 1 jquery框架 jquery对象与dom对象区别及混合使用 10-25 2 jquery id选择器 层次选择器 10-25 3 jquery过滤选择器及练习题讲解 10-25 4 内容过滤器 可见度过滤器及练习讲解 10-26 1 课程回顾 10-26 2 属性过滤选择器 10-26 3 子元素选择器 表单对象属性选择器 10-26 4 jquery对象集合遍历的四种形式及练习题讲解 jquery的dom操作 10-27 1课程回顾 10-27 2 jquery的dom操作 内部插入 外部插入 10-27 3 jquery节点操作 10-27 4 练习题讲解 10-27 5 jquery属性操作 获取子元素和兄弟元素的方法 10-27 6 练习题讲解 10-27 7 jquery和ajax整合使用的方法 10-29 1 svn安装及常用操作 10-29 2 svn常用操作 实例讲解1 10-29 3 svn常用操作 实例讲解2 10-29 4 svn常用操作 实例讲解3 10-29 5 svn常用操作 实例讲解4 10-30 1 linux简介 10-30 2 虚拟机安装 linux安装 10-30 3 常用命令 远程控制软件使用 10-30 4 vi编辑器使用 linux目录讲解 10-4 1 课程回顾 10-4 2 js面向对象多态 10-4 3 js内部对象和系统函数 10-4 5 js内部类 string array 10-4 6 js对象数组 常用系统函数 10-4 7 js事件 事件驱动机制 10-4 8 10-5 1 课程回顾 10-5 2 js dom编程 10-5 3 dom编程实例 乌龟抓鸡 10-5 4 dom编程实例 乌龟抓鸡2 10-5 5 dom层次关系 dom对象 10-5 6 dom实例讲解 小人行走 10-7 1 课程回顾 10-7 2 dom对象详解 10-7 3 dom对象详解2 10-7 4 document对象 10-7 5 乌龟抓鸡游戏加强版 10-7 6 常用dom对象node节点属性讲解 10-7 7 坦克大战初步讲解 10-8 1 课程回顾 乌龟抓鸡游戏bug修复 10-8 2 style对象 10-8 3 style对象实例讲解 10-8 4 form forms对象 img对象 link对象 table对象 10-8 5 table实例讲解 10-8 6 正则表达式 11-1 1 常用命令讲解 用户管理 运行级别 11-1 2 常用开发命令讲解2 11-1 3 常用开发命令讲解3 11-1 4 文件所在组 所有组 其它组讲解 11-2 lamp安装(php和apache的整合)2011-11-2-3 11-2 lamp安装之-mysql的安装和配置(2011-11-2-2) 11-2 rpm命令+samba安装(2011-11-2-5) 11-2 在linux下安装phpmyadmin软(2011-11-2-4) 11-5-1(上次课回顾) 11-5-2(页面静态化介绍) 11-5-3新闻管理系统(页面真静态) 11-5-4(真静态) 11-5-5(伪静态) 11-6 1(memcache原理介绍) 11-6 2-1(memcache的telnet操作,安装和基本使用) 11-6 2-2(memcach3的php的操作) 11-6 4(mysql数据库优化1) 11-6 5(mysql数据库优化 11-6 6(mysql数据库优化 11-8 商务网站项目1_1 11-8 商务网站项目1_2 11-8 商务网站项目1_3 11-9 商务网站项目2_1 11-9 商务网站项目2_2 11-9 商务网站项目2_3 11-9 商务网站项目2_4-单例模式 11-9 商务网站项目2_5 11-10 商务网站项目3_1 11-10 商务网站项目3_2 11-10 商务网站项目3_3 11-12 商务网站项目4_1 11-12 商务网站项目4_2 11-12 商务网站项目4_3-订单提交 11-13 商务网站项目4_4(没声音) 11-13 商务网站项目4_5 11-13 商务网站项目4_6 11-15 商务网站项目5_ec二次开发 11-17 yii_store项目1 11-19 yii框架_store项目 11-19 yii框架_store项目 11-19 yii框架_store项目 11-19 yii框架_store项目 11-19 yii框架_store项目 11-20-yii框架_store项目 11-20-yii_store项目 11-20-yii_store项目 11-20-yii_store项目 11-20-yii_store项目 11-22 yii_store项目 11-22 yii_store项目 11-23 yii_store项目 11-23 yii_store项目 11-24 yii_store项目 11-24 yii_store项目 11-24 yii_store项目 11-25 yii_store项目
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。
抱歉,我不能在这里提供完整的游戏代码。但是,以下是游戏的主要类和方法,可以帮助你开始编写自己的 Java 坦克大战游戏: 1. Tank 类 - 代表游戏中的坦克 ```java public class Tank { private int x, y; //坦克的位置 private int speed; //坦克的速度 private int direction; //坦克的方向 public Tank(int x, int y, int speed, int direction) { this.x = x; this.y = y; this.speed = speed; this.direction = direction; } //坦克的移动方法 public void move() { //根据方向改变坦克的位置 switch (direction) { case 0: //上 y -= speed; break; case 1: //右 x += speed; break; case 2: //下 y += speed; break; case 3: //左 x -= speed; break; } } //坦克的开火方法 public void fire() { //创建子弹对象,并设置子弹的初始位置、方向和速度 Bullet bullet = new Bullet(x, y, direction, speed * 2); } } ``` 2. Bullet 类 - 代表游戏中的子弹 ```java public class Bullet { private int x, y; //子弹的位置 private int speed; //子弹的速度 private int direction; //子弹的方向 public Bullet(int x, int y, int direction, int speed) { this.x = x; this.y = y; this.direction = direction; this.speed = speed; } //子弹的移动方法 public void move() { //根据方向改变子弹的位置 switch (direction) { case 0: //上 y -= speed; break; case 1: //右 x += speed; break; case 2: //下 y += speed; break; case 3: //左 x -= speed; break; } } } ``` 3. GamePanel 类 - 游戏主面板,包含游戏的主逻辑和绘制 ```java public class GamePanel extends JPanel implements Runnable { private Tank playerTank; //玩家坦克 private ArrayList<Tank> enemyTanks; //敌方坦克 private ArrayList<Bullet> bullets; //子弹 public GamePanel() { //初始化玩家坦克、敌方坦克和子弹列表 playerTank = new Tank(100, 100, 2, 0); enemyTanks = new ArrayList<>(); bullets = new ArrayList<>(); //创建敌方坦克,并设置初始位置、方向和速度 for (int i = 0; i < 3; i++) { Tank enemyTank = new Tank(300 + i * 100, 200, 1, 2); enemyTanks.add(enemyTank); } } //游戏主逻辑 public void gameLoop() { //移动玩家坦克 playerTank.move(); //移动敌方坦克 for (Tank enemyTank : enemyTanks) { enemyTank.move(); } //移动子弹 for (Bullet bullet : bullets) { bullet.move(); } //检测子弹是否击中敌方坦克 for (Bullet bullet : bullets) { for (Tank enemyTank : enemyTanks) { if (bullet.getX() >= enemyTank.getX() && bullet.getX() <= enemyTank.getX() + 50 && bullet.getY() >= enemyTank.getY() && bullet.getY() <= enemyTank.getY() + 50) { //移除子弹和敌方坦克 bullets.remove(bullet); enemyTanks.remove(enemyTank); break; } } } //重绘面板 repaint(); } //绘制面板 protected void paintComponent(Graphics g) { super.paintComponent(g); //绘制玩家坦克 g.drawImage(playerTank.getImage(), playerTank.getX(), playerTank.getY(), null); //绘制敌方坦克 for (Tank enemyTank : enemyTanks) { g.drawImage(enemyTank.getImage(), enemyTank.getX(), enemyTank.getY(), null); } //绘制子弹 for (Bullet bullet : bullets) { g.drawImage(bullet.getImage(), bullet.getX(), bullet.getY(), null); } } //启动游戏主循环 public void run() { while (true) { gameLoop(); try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } } } ``` 以上是游戏的主要类和方法,你可以根据需求进行修改和扩展,实现自己的 Java 坦克大战游戏。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值