代码驿站移动版
频道导航
HTML/Xhtml
CSS
JavaScript
HTML5
PHP教程
ASP.NET
正则表达式
AJAX
ThinkPHP
Yii
MySQL
MariaDB
Oracle
MongoDB
Redis
DedeCMS
PHPCMS
帝国CMS
WordPress
Discuz
其它CMS
Zend Studio
Sublime
Notepad
Dreamweaver
Windows
Linux
Nginx
Apache
IIS
CentOS
Ubuntu
Debian
网站优化
工具资源
PHP源码
ASP.NET源码
其它源码
图标素材
按钮素材
字体素材
DedeCMS模板
帝国CMS模板
PHPCMS模板
WordPress模板
Discuz!模板
单页模板
开发软件下载
服务器软件下载
广告投放
联系我们
版权申明
软件编程
网页前端
移动开发
数据库
服务器
脚本语言
PHP代码
JAVA代码
Python代码
Android代码
当前位置:
主页
>
网页前端
>
JavaScript代码
>
WEB泡泡堂2.0(图形界面+电脑对玩)(javascript)
时间:2022-05-08 10:04:46 | 栏目:
JavaScript代码
| 点击:次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Hxyman Popo Ver 1.0</title> <meta name="Generator" content="EditPlus"> <meta name="Author" content="Hxyman"> <style> <!-- body { font-size: 8pt; font-family: Arial } --> </style> </head> <body> <span id=Canvas></span> <SCRIPT LANGUAGE="JavaScript"> <!-- //WEB泡泡堂(javascript) //2006-9-5 //Hxyman QQ:86815260 EMail:Hxyman at yahoo.com.cn function Player(x, y) { this.x = x; this.y = y; this.popo = 1; //可放泡泡数 this.remain = 1; //剩余泡泡数 this.power = 1; //威力 this.speed = 10; //速度 this.state = 1; //正常-1 假死-2 真死-0 } function Bulb(x, y) { this.display = 0; this.player = -1; this.wait = 0; //还剩多少时间爆破 this.power = 1; //威力 this.size = 40; this.size_max = 40; this.size_min = 38; this.tendency = 0; this.x = x; this.y = y; } function Popo(ClassName) { this.GetRnd = function(Max){return Math.round(Math.random()*Max)} this.ClassName = ClassName; this.SetMap = new Array(); this.SetMap[0] = new Array( "########", "#0kkkkk#", "# k k#", "#kk k #", "#kk k #", "#kk kk1#", "########" ); this.SetMap[1] = new Array( "##########################", "#0#kkkkkkkkkkkkkkkkkkkkkk#", "# kkk kkkkkkkkkkkkkkk#", "#kk kk k#kk kkk k#", "# kk k#kkkkkkkkk #", "#kk kkk k#kk kkk k#", "# kk k#kkkkkkkkk #", "#kk kkk kkkk kkk k#", "# kk kkkkkkkkkkk #", "#kk kkk kkkk kkk k#", "# kk kkkkkkkkkkk #", "# kkk kkkkkkkkkkkkkkk#", "#kk kkk kkkk kkk k#", "# kk kkkkkkkkkkk #", "#kk kkk kkkk kkk k#", "# kk kkkkkkkkkkk #", "#kk kkk kkkk kkk k#", "# kk kkkkkkkkkkk #", "#kkkkk kkkkkkkkkkkkkkkkk1#", "##########################" ); this.SetMap[1] = new Array( "##########################", "#0#kkkkkkkkkkkkkkkkkkkkkk#", "# kkk kkkkkkkkkkkkkkk#", "#kk kk k#kk kkk k#", "# kk k#kkkkkkkkk #", "#kk kkk k#kk kkk k#", "# kk k#kkkkkkkkk #", "#kk kkk kkkk kkk k#", "# kk kkkkkkkkkkk #", "#kk kkk kkkk kkk k#", "# kk kkkkkkkkkkk #", "# kkk kkkkkkkkkkkkkkk#", "#kk kkk kkkk kkk k#", "# kk kkkkkkkkkkk #", "#kk kkk kkkk kkk k#", "# kk kkkkkkkkkkk #", "#kk kkk kkkk kkk k#", "# kk kkkkkkkkkkk #", "#kkkkk kkkkkkkkkkkkkkkkk1#", "##########################" ); this.SetMap[2] = new Array( "##########################", "#0 kkkkkkkkkk#kkkkkkkkkkk#", "# kkkkkkkkkkk#kkkkkkkkkkk#", "#kkkkkkkkkkkk#kkkkkkkkkkk#", "#kkkkkkkkkkkk#kkkkkkkkkkk#", "#kkkkkkkkkkkk#kkkkkkkkkkk#", "#kkkkkkkkkkkk#kkkkkkkkkkk#", "#kkkkkkkkkkkkkkkkkkkkkkkk#", "#kkkkkkkkkkkkkkkkkkkkkkkk#", "#kkkkkkkkkkkk#kkkkkkkkkkk#", "#kkkkkkkkkkkk#kkkkkkkkkkk#", "#kkkkkkkkkkkk#kkkkkkkkkkk#", "#kkkkkkkkkkkk#kkkkkkkkkkk#", "#kkkkkkkkkkkk#kkkkkkkkkkk#", "#kkkkkkkkkkkk#kkkkkkkkkkk#", "#kkkkkkkkkkkk#kkkkkkkkkk #", "#kkkkkkkkkkkk#kkkkkkkkk 1#", "##########################" ); //仿照上面,可以在这里加入自定义地图 this.MapIndex = this.GetRnd(this.SetMap.length-1); this.BulbMax = 50; this.BulbWait = 30; this.BulbBurst = 1000; this.PlayerRecovery = 6000; this.Itv = null; this.DeadsetTimeOut = new Array(); this.stop = new Array(0,0,0,0); this.Player = new Array(); this.Bulb = new Array(); for (var i=0; i<this.BulbMax; i++) { this.Bulb[i] = new Bulb(0, 0); } this.MapMaxX = this.SetMap[this.MapIndex][0].length; this.MapMaxY = this.SetMap[this.MapIndex].length; this.BoxWidth = this.BoxHeight = 30; //Read Map this.Map = new Array(); for (var i=0; i<this.MapMaxX; i++) { this.Map[i] = new Array(); for (var j=0; j<this.MapMaxY; j++) { this.Map[i][j] = this.SetMap[this.MapIndex][j].charAt(i) } } //道具 this.Equip = new Array("","","","","n","","","p",""); this.DrawBox = function(x, y, id, str){ Canvas.insertAdjacentHTML("beforeEnd","<span id='"+id+"' style='position:absolute;left:"+(x*this.BoxWidth)+";top:"+(y*this.BoxHeight)+";width:"+this.BoxWidth+";height:"+this.BoxHeight+";font-size:40px;'>"+str+"</span>"); } this.InitBulb = function(n){ for (var i=0; i<n; i++) { Canvas.insertAdjacentHTML("beforeEnd","<span id='bulb"+i+"' style='position:absolute;width:"+this.BoxWidth+";height:"+this.BoxHeight+";font-size:40px;display:none;color:blue;'>●</span>"); } } this.ReDrawBox = function(x, y, str){ document.getElementById("box"+x+"_"+y).innerHTML = str; } this.InitMap = function(){ for (var i=0; i<this.MapMaxX; i++) { for (var j=0; j<this.MapMaxY; j++) { switch(this.Map[i][j]) { case "#": this.DrawBox(i, j, "box"+i+"_"+j, "<span style='color: mediumseagreen'>■</span>"); break; case " ": this.DrawBox(i, j, "box"+i+"_"+j, " "); break; case "k": this.DrawBox(i, j, "box"+i+"_"+j, "<span style='color: tan'>■</span>"); break; case "0": this.DrawBox(i, j, "box"+i+"_"+j, " "); this.DrawBox(i, j, "player0", "♀"); this.Player[this.Player.length] = new Player(i, j); break; case "1": this.DrawBox(i, j, "box"+i+"_"+j, " "); this.DrawBox(i, j, "player1", "♂"); this.Player[this.Player.length] = new Player(i, j); break; } } } } this.Campaign = function(self, other){ if (self == other) return 0; if (this.Player[other].state == 2) { this.Player[other].state = 0; document.getElementById("player"+other).style.display = 'none'; this.End(); alert("Player"+self+" Win!"); } } //移动选手 this.Move = function(addx, addy, who){ if (this.Player[who].state != 1) return 0; var old = this.Map[this.Player[who].x][this.Player[who].y]; this.Player[who].x = addx+this.Player[who].x; this.Player[who].y = addy+this.Player[who].y; var str = " 01np"; if (str.indexOf(this.Map[this.Player[who].x][this.Player[who].y]) != -1) { document.getElementById("player"+who).style.left = this.Player[who].x*this.BoxWidth; document.getElementById("player"+who).style.top = this.Player[who].y*this.BoxHeight; this.Map[this.Player[who].x-addx][this.Player[who].y-addy] = old; switch(this.Map[this.Player[who].x][this.Player[who].y]) { case "n": this.Map[this.Player[who].x][this.Player[who].y] = " "; this.ReDrawBox(this.Player[who].x, this.Player[who].y, " "); this.Player[who].popo++; this.Player[who].remain++; break; case "p": this.Map[this.Player[who].x][this.Player[who].y] = " "; this.ReDrawBox(this.Player[who].x, this.Player[who].y, " "); this.Player[who].power++; break; } for (var i=0; i<this.Player.length; i++) { if (this.Player[i].x == this.Player[who].x && this.Player[i].y == this.Player[who].y) { this.Campaign(who, i); } } } else { this.Player[who].x -= addx; this.Player[who].y -= addy; } } //安放炸弹 this.Fix = function(who){ if (this.Player[who].state != 1) return 0; var x = this.Player[who].x; var y = this.Player[who].y; var str = " 01"; if (this.Player[who].remain > 0 && str.indexOf(this.Map[x][y]) != -1) { for (var i=0; i<this.BulbMax; i++) { if (0 == this.Bulb[i].display) { this.Bulb[i] = new Bulb(x, y); this.Bulb[i].player = who; this.Bulb[i].power = this.Player[who].power; this.Bulb[i].wait = this.BulbWait; this.Bulb[i].display = 1; this.Map[x][y] = "b"; this.Player[who].remain--; return 0; } } } } //假死 this.Dead = function(n){ this.Player[n].state = 2; document.getElementById("player"+n).style.color = "gray"; window.clearTimeout(this.DeadsetTimeOut[n]) this.DeadsetTimeOut[n] = setTimeout(this.ClassName+".Player["+n+"].state=1; document.getElementById('player"+n+"').style.color = '';", this.PlayerRecovery); } //爆炸的具体处理过程 this.DoBurst = function(x, y, dir){ var GetEquip = " "; switch(this.Map[x][y]) { case "k": switch(this.Equip[this.GetRnd(this.Equip.length-1)]) { case "n": this.Map[x][y] = "n"; GetEquip = "<span style='color: green'>◎</span>" break; case "p": this.Map[x][y] = "p"; GetEquip = "<span style='color: red'>☆</span>" break; default: this.Map[x][y] = " "; } break; case "#": this.stop[dir] = 1; return 0; break; default: this.Map[x][y] = " "; } this.ReDrawBox(x, y, "<span style='color: red'>¤</span>"); for (var i=0; i<this.Player.length; i++) { if (this.Player[i].x == x && this.Player[i].y == y) { this.Dead(i); } } setTimeout(this.ClassName+".ReDrawBox("+x+", "+y+", \""+GetEquip+"\");", this.BulbBurst); } //连爆 this.OtherBurst = function(x, y, n){ for (var i=0; i!=n,i<this.BulbMax; i++ ) { if (this.Bulb[i].x == x && this.Bulb[i].y == y && this.Bulb[i].display == 1) this.Bulb[i].wait = 0; } } //爆炸 this.Burst = function(n){ var x = this.Bulb[n].x; var y = this.Bulb[n].y; if (this.Player[this.Bulb[n].player].remain < this.Player[this.Bulb[n].player].popo) this.Player[this.Bulb[n].player].remain++; this.DoBurst(x, y); this.stop[0] = 0; this.stop[1] = 0; this.stop[2] = 0; this.stop[3] = 0; for (var i=1; i<=this.Bulb[n].power; i++) { //right x += i; if (!this.stop[0] && x < this.MapMaxX-1) { this.DoBurst(x, y, 0); this.OtherBurst(x, y, i); } x -= i; //up y += i; if (!this.stop[1] && y < this.MapMaxY-1) { this.DoBurst(x, y, 1); this.OtherBurst(x, y, i); } y -= i; //left x -= i; if (!this.stop[2] && x > 0) { this.DoBurst(x, y, 2); this.OtherBurst(x, y, i); } x += i; //down y -= i; if (!this.stop[3] && y > 0) { this.DoBurst(x, y, 3); this.OtherBurst(x, y, i); } y += i; } document.getElementById("bulb"+n).style.display = 'none'; this.Bulb[n].display = 0; } //不断更新炸弹状态 this.ShowBulb = function(){ for (var i=0; i<this.BulbMax; i++) { var obj = document.getElementById("bulb"+i); if (this.Bulb[i].wait-- > 0) { obj.style.left = this.Bulb[i].x*this.BoxWidth; obj.style.top = this.Bulb[i].y*this.BoxHeight; obj.style.display = ""; if (obj.tendency > 0) { this.Bulb[i].size++; if (this.Bulb[i].size > this.Bulb[i].size_max) { obj.tendency = 0; } } else { this.Bulb[i].size--; if (this.Bulb[i].size < this.Bulb[i].size_min) { obj.tendency = 1; } } obj.style.fontSize = this.Bulb[i].size+"px"; } else if (this.Bulb[i].display > 0) { this.Burst(i); } } } this.Control = function(){ switch(event.keyCode){ //player 1 case 37: //left this.Move(-1, 0, 0); break; case 38: //up this.Move(0, -1, 0); break; case 39: //right this.Move(1, 0, 0); break; case 40: //down this.Move(0, 1, 0); break; case 13: //enter this.Fix(0); break; //player 2 case 65: //left this.Move(-1, 0, 1); break; case 87: //up this.Move(0, -1, 1); break; case 68: //right this.Move(1, 0, 1); break; case 83: //down this.Move(0, 1, 1); break; case 32: //space this.Fix(1); break; } event.returnValue = false; } this.Begin = function(){ this.Itv = window.setInterval(""+this.ClassName+".ShowBulb()", 100); //主进程 } this.End = function(){ window.clearInterval(this.Itv); } } var game = new Popo("game"); game.InitMap(); game.InitBulb(game.BulbMax); game.Begin(); function document.onkeydown(){game.Control()} //--> </SCRIPT> </body> </html>
[Ctrl+A 全选 注:
引入外部Js需再刷新一下页面才能执行
]
谢谢大家支持,玩法如Rimifon版主所说:
玩家1的方向键:asdw,炸弹为空格
玩家2的方向键位键盘方向键,炸弹为回车
可以炸出绿色泡泡和红色加威力的五角星。
图形都是字符,所以不太好看。
[2006-9-10]
这两天我把它改成图形界面了。呵呵,差不多可以乱真了。不过加了声音后好慢。我的声音是用几个bgsound来处理,当几个一起播放时会卡。不知道怎么才能处理好声音。暂时发个截图。等问题都解决了再整个发上来:)
您可能感兴趣的文章:
JavaScript常见事件处理程序实例总结
Javascript的匿名函数小结
url传递的参数值中包含&时,url自动截断问题的解决方法
Javascript别踩白块儿(钢琴块儿)小游戏实现代码
兼容浏览器的js事件绑定函数(详解)
相关文章
10-19
javascript上下左右定时滚动插件
11-23
Webpack中loader打包各种文件的方法实例
11-27
Javascript实例教程(19) 使用HoTMetal(2)
10-05
javascript判断图片是否加载完成的方法推荐
11-22
在javascript中执行任意html代码的方法示例解读
JQuery
VUE
AngularJS
MSSql
MySQL
MongoDB
Redis
Linux
Tomcat
Nginx
网站首页
广告投放
联系我们
版权申明
联系站长