网址:http://www.lufylegend.com/

 <!DOCTYPE html>
<html>
<head>
<title>A Little Game!</title>
<meta charset="utf-8" />
<style>
html,body{
height:100%;
width: 100%;
margin: 0;
padding: 0;
} body{
background-color: black;
}
#playground{
background-color: white;
position: absolute;
width: 800px;
height: 400px;
left: 50%;
top: 50%;
margin-left: -400px;
margin-top: -200px;
}
</style>
</head>
<body>
<div id="playground"></div>
<script type="text/javascript" src="js/lufylegend-1.10.1.js.js"></script>
<script>
var playerData = {
win : 0,
lose : 0,
dogfall : 0,
jiandan : 0,
shitou : 0,
bu : 0
}; var computerData = {
win : 0,
lose : 0,
dogfall : 0,
jiandan : 0,
shitou : 0,
bu : 0
}; var playground;
var backlayer;
var graphic;
var loadManager ;
var loadingProgress;
var bitmapData;
var title; var clicklayer;
var jiandanBtn;
var shitouBtn;
var buBtn; var playerBitmap;
var computerBitmap; var playStatus;
var computerStatus;
var winText1;
var loseText1;
var dogFallText1;
var jiandanText1;
var shitouText1;
var buText1;
var winText2;
var loseText2;
var dogFallText2;
var jiandanText2;
var shitouText2;
var buText2; var imgList = Array();
var imgData = [
{ name : "title",path : "./images/title.png"},
{ name : "bu",path : "./images/bu.png"},
{ name : "jiandao",path : "./images/jiandao.png"},
{ name : "shitou",path : "./images/shitou.png"}
]; playground = document.getElementById("playground"); init(50,"playground",800,400,main); function main()
{
backlayer = new LSprite();
addChild(backlayer); loadingProgress = new LoadingSample3();
backlayer.addChild(loadingProgress); LLoadManage.load(imgData,function(p){
loadingProgress.setProgress(p);
},gameInit);
} function gameInit(result)
{
backlayer.removeChild(loadingProgress);
loadingProgress = null; // 存储图片的数据
imgList.push(new LBitmapData(result["title"]));
imgList.push(new LBitmapData(result["jiandao"]));
imgList.push(new LBitmapData(result["shitou"]));
imgList.push(new LBitmapData(result["bu"])); // 标题
title = new LBitmap(imgList[0]);
title.x = playground.clientWidth/2 - title.getWidth()/2;
backlayer.addChild(title); // 三八线
backlayer.graphics.drawLine(1,"#06061F",[playground.clientWidth/2,title.getHeight(),playground.clientWidth/2,playground.clientHeight-title.getHeight()]); // 显示玩家的名称
var computerText = new LTextField();
computerText.text = "电脑";
computerText.color = "#250012";
computerText.size = 17;
computerText.font = "Calibri Light";
computerText.x = playground.clientWidth/4 - computerText.getWidth()/2;
computerText.y = playground.clientHeight-title.getHeight();
backlayer.addChild(computerText); var playerText = new LTextField();
playerText.text = "玩家";
playerText.color = "#250012";
playerText.size = 17;
playerText.font = "Calibri Light";
playerText.x = (playground.clientWidth/4)*3 - playerText.getWidth()/2;
playerText.y = playground.clientHeight - title.getHeight();
backlayer.addChild(playerText); // 放置剪刀、石头、布的图片
var jiandaoUp = new LBitmap(imgList[1]);
jiandaoUp.scaleX = 0.5;
jiandaoUp.scaleY = 0.5;
var jiandaoOver = new LBitmap(imgList[1]);
jiandaoOver.scaleX = 0.5;
jiandaoOver.scaleY = 0.5;
jiandanBtn = new LButton(jiandaoUp,jiandaoOver);
jiandanBtn.name = "jiandao";
jiandanBtn.x = 0;
jiandanBtn.y = 0; var shitouUp = new LBitmap(imgList[2]);
shitouUp.scaleX = 0.5;
shitouUp.scaleY = 0.5;
var shitouOver = new LBitmap(imgList[2]);
shitouOver.scaleX = 0.5;
shitouOver.scaleY = 0.5;
shitouBtn = new LButton(shitouUp,shitouOver);
shitouBtn.name = "shitou";
shitouBtn.x = jiandanBtn.getWidth() + 10;
shitouBtn.y = 0; var buUp= new LBitmap(imgList[3]);
buUp.scaleX = 0.5;
buUp.scaleY = 0.5;
var buOver = new LBitmap(imgList[3]);
buOver.scaleX = 0.5;
buOver.scaleY = 0.5;
buBtn = new LButton(buUp,buOver);
buBtn.name = "bu";
buBtn.x = shitouBtn.getWidth() + jiandanBtn.getWidth() + 20;
buBtn.y = 0; clicklayer = new LSprite();
clicklayer.width = jiandaoUp.getWidth() * 3 + 30;
clicklayer.height = title.getHeight();
clicklayer.x = playground.clientWidth/2 - clicklayer.width/2;
clicklayer.y = playground.clientHeight - title.getHeight(); clicklayer.addChild(jiandanBtn);
clicklayer.addChild(shitouBtn);
clicklayer.addChild(buBtn);
backlayer.addChild(clicklayer); // 显示统计数据
computerStatus = new LSprite();
computerStatus.graphics.drawRect(1,'#250012',[0,title.getHeight()+10,150,200],true,"#ffffff");
backlayer.addChild(computerStatus); playStatus = new LSprite();
playStatus.graphics.drawRect(1,"250012",[playground.clientWidth-150,title.getHeight()+10,150,200],true,"#ffffff");
backlayer.addChild(playStatus); initTextStatus(); // 监听事件
jiandanBtn.addEventListener(LMouseEvent.MOUSE_UP,onBtnClick);
shitouBtn.addEventListener(LMouseEvent.MOUSE_UP,onBtnClick);
buBtn.addEventListener(LMouseEvent.MOUSE_UP,onBtnClick);
} function onBtnClick(e,btn)
{
var player,computer; switch(btn.name)
{
case "jiandao":
player = 1;
playerData.jiandan += 1;
break;
case "shitou":
player = 2;
playerData.shitou += 1;
break;
case "bu":
player = 3;
playerData.bu += 1;
break;
}
// 电脑随机出拳
computer = Math.ceil(Math.random()*3);
switch(computer)
{
case 1:
computerData.jiandan += 1;
break;
case 2:
computerData.shitou += 1;
break;
case 3:
computerData.bu += 1;
break;
} // 显示出拳结果
computerBitmap = new LBitmap(imgList[computer]);
computerBitmap.x = playground.clientWidth/2 - computerBitmap.getWidth() - 10;
computerBitmap.y = playground.clientHeight/2 - computerBitmap.getHeight()/2;
backlayer.addChild(computerBitmap); playerBitmap = new LBitmap(imgList[player]);
playerBitmap.x = playground.clientWidth/2 + 10;
playerBitmap.y = playground.clientHeight/2 - playerBitmap.getHeight()/2;
backlayer.addChild(playerBitmap); // 平局
if(player == computer)
{
playerData.dogfall += 1;
computerData.dogfall += 1;
}
else if(player-1 == computer || player+2 == computer) // 胜场
{
playerData.win += 1;
computerData.lose += 1;
}
else
{
playerData.lose += 1;
computerData.win += 1;
} winText2.text = "Win : " + playerData.win;
loseText2.text = "Lose : " + playerData.lose;
dogFallText2.text = "DogFall : " + playerData.dogfall;
jiandanText2.text = "JianDao : " + playerData.jiandan;
shitouText2.text = "ShiTou : " + playerData.shitou;
buText2.text = "Bu : " + playerData.bu; winText1.text = "Win : " + computerData.win;
loseText1.text = "Lose : " + computerData.lose;
dogFallText1.text = "DogFall : " + computerData.dogfall;
jiandanText1.text = "JianDao : " + computerData.jiandan;
shitouText1.text = "ShiTou : " + computerData.shitou;
buText1.text = "Bu : " + computerData.bu;
} function initTextStatus()
{
winText1 = new LTextField();
winText1.x = 10;
winText1.y = title.getHeight() + 15;
winText1.text = "Win : " + computerData.win;
computerStatus.addChild(winText1); loseText1 = new LTextField();
loseText1.x = 10;
loseText1.y = title.getHeight() + 35;
loseText1.text = "Lose : " + computerData.lose;
computerStatus.addChild(loseText1); dogFallText1 = new LTextField();
dogFallText1.x = 10;
dogFallText1.y = title.getHeight() + 55;
dogFallText1.text = "DogFall : " + computerData.dogfall;
computerStatus.addChild(dogFallText1); jiandanText1 = new LTextField();
jiandanText1.x = 10;
jiandanText1.y = title.getHeight() + 75;
jiandanText1.text = "JianDao : " + computerData.jiandan;
computerStatus.addChild(jiandanText1); shitouText1 = new LTextField();
shitouText1.x = 10;
shitouText1.y = title.getHeight() + 95;
shitouText1.text = "ShiTou : " + computerData.shitou;
computerStatus.addChild(shitouText1); buText1 = new LTextField();
buText1.x = 10;
buText1.y = title.getHeight() + 115;
buText1.text = "Bu : " + computerData.bu;
computerStatus.addChild(buText1); winText2 = new LTextField();
winText2.x = playground.clientWidth - 140;
winText2.y = title.getHeight() + 15;
winText2.text = "Win : " + playerData.win;
playStatus.addChild(winText2); loseText2 = new LTextField();
loseText2.x = playground.clientWidth - 140;
loseText2.y = title.getHeight() + 35;
loseText2.text = "Lose : " + playerData.lose;
playStatus.addChild(loseText2); dogFallText2 = new LTextField();
dogFallText2.x = playground.clientWidth - 140;
dogFallText2.y = title.getHeight() + 55;
dogFallText2.text = "DogFall : " + playerData.dogfall;
playStatus.addChild(dogFallText2); jiandanText2 = new LTextField();
jiandanText2.x = playground.clientWidth - 140;
jiandanText2.y = title.getHeight() + 75;
jiandanText2.text = "JianDao : " + playerData.jiandan;
playStatus.addChild(jiandanText2); shitouText2 = new LTextField();
shitouText2.x = playground.clientWidth - 140;
shitouText2.y = title.getHeight() + 95;
shitouText2.text = "ShiTou : " + playerData.shitou;
playStatus.addChild(shitouText2); buText2 = new LTextField();
buText2.x = playground.clientWidth - 140;
buText2.y = title.getHeight() + 115;
buText2.text = "Bu : " + playerData.bu;
playStatus.addChild(buText2);
}
</script>
</body>
</html>

HTML5  lufylegend引擎学习(一) -- 剪刀石头布小游戏-LMLPHP

05-06 03:18