javascript写游戏脚本(原生JS实现飞机大战小游戏)
类别:编程学习 浏览量:1625
时间:2022-01-21 00:11:29 javascript写游戏脚本
原生JS实现飞机大战小游戏本文实例为大家分享了JS实现飞机大战小游戏的具体代码,供大家参考,具体内容如下
<html> <head> <title> 飞机大战 </title> <style type="text/css"> *{margin:0;padding:0;font-family:"Microsoft yahei"} body{overflow:hidden;;} </style> </head> <body> <script> window.onload = function(){ Game.exe(); }; var Game = { //启动程序 exe :function(){ document.body.style.background = '#fff'; var oli = document.createElement('li'); oli.id = 'GameBox'; oli.style.cssText = 'width:600px;height:500px;border:10px solid #999;margin:50px auto;font-family:"Microsoft yahei";text-align:center;position:relative;overflow:hidden;background:#fff'; document.body.appendChild(oli); this.init(); }, score : 0 , ifEnd : false, //初始化 init: function(){ var This = this; var oli = document.getElementById('GameBox'); oli.innerHTML = ''; Game.score = 0; Game.ifEnd = false; var oH = document.createElement('h1'); oH.innerHTML = '飞机大战 v1.0'; oH.style.cssText = 'color:#555555;font-size:30px;padding-top:50px;'; oli.appendChild( oH ); for (var i=0;i<4 ;i++ ) { var oP = document.createElement('p'); oP.index = i; oP.style.cssText = 'font-size:18px;color:white;width:180px;height:50px;margin:40px auto;text-align:center;background:#999;line-height:40px;font-family:"Microsoft yahei";font-weight:bold;cursor:pointer;' var html = ''; oP.onmouseenter = function(){ this.style.background = '#ff9933'; this.style.color = '##ff6600' }; oP.onmouseleave = function(){ this.style.background = '#999'; this.style.color = 'white' }; oP.onclick = function( e ){ e = e || window.event; This.start( this.index , oli , e ); }; switch( i ){ case 0: html = '简单难度'; break; case 1: html = '中等难度'; break; case 2: html = '困难难度'; break; case 3: html = '小天才附体'; break; } oP.innerHTML = html; oli.appendChild(oP); }; }, //游戏开始 start : function( index , oGameBox , e ){ oGameBox.innerHTML = ''; var oS = document.createElement('span'); oS.innerHTML = this.score; oS.style.cssText = 'position:absolute;left:20px;top:20px;font-size:14px;color:black;'; oGameBox.appendChild( oS ); this.plane( oGameBox , e ,index ); this.enemy( oGameBox ,oS ,index ); }, //关于飞机 plane : function( oGameBox , e ,index ){ var x = e.pageX; y = e.pageY; var oPlane = new Image(); oPlane.src = 'images/plane.jpg" alt="javascript写游戏脚本(原生JS实现飞机大战小游戏)" border="0" />
效果图
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持开心学习网。
您可能感兴趣
- 前端表单验证(AmazeUI的JS表单验证框架实战示例分享)
- js中substring的用法、与substr的区别
- nodejs 内部模块代码(详解Node.js如何处理ES6模块)
- ExtJs 中Viewport 的使用
- JS实现金额大小写转换
- js中arguments的用法
- json和xml比较与区别
- Extjs msgTarget 提示位置
- MVC JsonResult的用法
- js获取微信版本号
- vue购物车怎么实现(Vue.js框架实现购物车功能)
- JS中对象的属性
- sqlserver字段说明(详解SQL Server 中 JSON_MODIFY 的使用)
- JS动态操作select的option
- js页面跳转的几种代码
- asp.net后台输出js脚本
- 心理学 四个金蟾,哪个最招财 测你今生的运势有多棒(心理学四个金蟾)
- 吉善缘《聚宝金蟾》金蟾招财摆件 三足全铜蟾蜍客厅店铺开业礼品(吉善缘聚宝金蟾金蟾招财摆件)
- 招财化煞神兽,金蟾变了(招财化煞神兽金蟾变了)
- 26岁杨紫的白素贞遇上24岁鞠婧祎,哪个最美(26岁杨紫的白素贞遇上24岁鞠婧祎)
- 鞠婧祎和杨紫两种风格的女生,你心里谁比较美(鞠婧祎和杨紫两种风格的女生)
- 三千年第一美女鞠婧祎出演白素贞pk杨紫,颜值胜赵雅芝王祖贤(三千年第一美女鞠婧祎出演白素贞pk杨紫)
热门推荐
- nginx 使用手册(nginx服务器的下载安装与使用详解)
- python微信红包代码(php生成微信红包数组的方法)
- mysql数据库下载安装步骤(MySQL数据库压缩版本安装与配置详细教程)
- 国产云主机哪个好(便宜好用的国内云主机怎么挑选?)
- apache服务配置详解(apache配置开启网站服务步骤)
- nodejs json文件读写(nodejs将JSON字符串转化为JSON对象报错的解决)
- dedecms标签怎么用(dedecms三级栏目调用方法)
- 怎么用python获取目录(python 获得任意路径下的文件及其根目录的方法)
- submit与button的区别
- javascript写计算器教程(基于JavaScript实现简易计算器)