WEB泡泡堂2.0(图形界面+电脑对玩)(javascript)
Hxyman Popo Ver 1.0
"+str+"");
}
this.InitBulb = function(n){
for (var i=0; i●");
}
}
this.ReDrawBox = function(x, y, str){
document.getElementById("box"+x+"_"+y).innerHTML = str;
}
this.InitMap = function(){
for (var i=0; i■");
break;
case " ":
this.DrawBox(i, j, "box"+i+"_"+j, " ");
break;
case "k":
this.DrawBox(i, j, "box"+i+"_"+j, "■");
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 0 && str.indexOf(this.Map[x][y]) != -1)
{
for (var i=0; i◎"
break;
case "p":
this.Map[x][y] = "p";
GetEquip = "☆"
break;
default:
this.Map[x][y] = " ";
}
break;
case "#":
this.stop[dir] = 1;
return 0;
break;
default:
this.Map[x][y] = " ";
}
this.ReDrawBox(x, y, "¤");
for (var i=0; i 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 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 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()}
//-->
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
谢谢大家支持,玩法如Rimifon版主所说:
玩家1的方向键:asdw,炸弹为空格
玩家2的方向键位键盘方向键,炸弹为回车
可以炸出绿色泡泡和红色加威力的五角星。
图形都是字符,所以不太好看。
[2006-9-10]
这两天我把它改成图形界面了。呵呵,差不多可以乱真了。不过加了声音后好慢。我的声音是用几个bgsound来处理,当几个一起播放时会卡。不知道怎么才能处理好声音。暂时发个截图。等问题都解决了再整个发上来:)