1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>HTML5-lufyLegend测试</title> 8 <script type="text/javascript" src="js/lufylegend-1.5.1.min.js"></script> 9 <script type="text/javascript" src="js/Box2dWeb-2.1.a.3.min.js"></script> 10 <script type="text/javascript" src="js/jquery-1.10.2.js"></script> 11 <script type="text/javascript"> 12 $(function(){ 13 var backLayer = ""; 14 var resultLayer = ""; 15 var clickLayer = ""; 16 var loadingLayer = ""; 17 var enmeyBitmap = ""; 18 var selfBitmap = ""; 19 var imageList = {}; 20 var showList = []; 21 22 var selfTextAll=""; 23 var selfTextWin=""; 24 var selfTextLoss=""; 25 var selfTextEq=""; 26 var win = 0; 27 var lost = 0; 28 var eq = 0; 29 var imageData = new Array( 30 { name:"title",path:"image/title.png"}, 31 { name:"shitou",path:"image/shitou.png"}, 32 { name:"jiandao",path:"image/jiandao.png"}, 33 { name:"bu",path:"image/bu.png"} 34 ); 35 init(50,"mylegend",1500,500,main); 36 function main(){ 37 backLayer = new LSprite(); 38 addChild(backLayer); 39 loadingLayer = new LoadingSample3(); 40 backLayer.addChild(loadingLayer); 41 LLoadManage.load(imageData, 42 function(data){ 43 loadingLayer.setProgress(data); 44 },function(result){ 45 imageList = result; 46 backLayer.removeChild(loadingLayer); 47 loadingLayer = null; 48 //游戏界面初始化 49 gameInit(); 50 }); 51 } 52 function gameInit(){ 53 showList.push(new LBitmapData(imageList["shitou"])); 54 showList.push(new LBitmapData(imageList["jiandao"])); 55 showList.push(new LBitmapData(imageList["bu"])); 56 var titleBitmap = new LBitmap(new LBitmapData(imageList["title"])); 57 titleBitmap.x = 100; 58 titleBitmap.y = 10; 59 backLayer.addChild(titleBitmap); 60 //名称设定 61 var selfText = new LTextField(); 62 selfText.text="玩家"; 63 selfText.color="white"; 64 selfText.weight = "bold"; 65 selfText.x = 215; 66 selfText.y = 90; 67 backLayer.addChild(selfText); 68 //玩家方出拳图片 69 selfBitmap = new LBitmap(showList[0]); 70 selfBitmap.x = 170; 71 selfBitmap.y = 110; 72 backLayer.addChild(selfBitmap); 73 //我放出拳图片 74 enmeyBitmap = new LBitmap(showList[1]); 75 enmeyBitmap.x = 350; 76 enmeyBitmap.y = 110; 77 backLayer.addChild(enmeyBitmap); 78 //名称设定 79 var selfText = new LTextField(); 80 selfText.text="电脑"; 81 selfText.color="white"; 82 selfText.x = 400; 83 selfText.weight = "bold"; 84 selfText.y = 90; 85 backLayer.addChild(selfText); 86 backLayer.graphics.drawRect(1,"black",[0,0,600,700],true,"black"); 87 backLayer.x = 300; 88 backLayer.y = 100; 89 //结果显示初始化 90 initialResult(); 91 //操作层初始化 92 initialClick(); 93 } 94 function initialResult(){ 95 resultLayer = new LSprite(); 96 resultLayer.graphics.drawRect(1,"black",[0,0,150,100],true,"white"); 97 resultLayer.x = 10; 98 resultLayer.y = 117; 99 backLayer.addChild(resultLayer); 100 selfTextAll = new LTextField(); 101 selfTextAll.text = "猜拳次数:0"; 102 selfTextAll.x = 10; 103 selfTextAll.y = 10; 104 resultLayer.addChild(selfTextAll); 105 106 selfTextWin = new LTextField(); 107 selfTextWin.text = "胜利次数:0"; 108 selfTextWin.x = 10; 109 selfTextWin.y = 30; 110 resultLayer.addChild(selfTextWin); 111 112 selfTextLoss = new LTextField(); 113 selfTextLoss.text = "失败次数:0"; 114 selfTextLoss.x = 10; 115 selfTextLoss.y = 50; 116 resultLayer.addChild(selfTextLoss); 117 118 selfTextEq = new LTextField(); 119 selfTextEq.text = "平局次数:0"; 120 selfTextEq.x = 10; 121 selfTextEq.y = 70; 122 resultLayer.addChild(selfTextEq); 123 } 124 125 function initialClick(){ 126 clickLayer = new LSprite(); 127 clickLayer.graphics.drawRect(1,"black",[0,0,250,100],true,"white"); 128 clickLayer.x = 200; 129 clickLayer.y = 280; 130 backLayer.addChild(clickLayer); 131 var text1 =new LTextField(); 132 text1.text="请出拳"; 133 text1.x = 10; 134 text1.y = 10; 135 clickLayer.addChild(text1); 136 var btn_Shitou = getButton("shitou"); 137 var btn_Jiandao = getButton("jiandao"); 138 var btn_Bu = getButton("bu"); 139 btn_Shitou.x = 10; 140 btn_Shitou.y = 30; 141 btn_Jiandao.x = 90; 142 btn_Jiandao.y = 30; 143 btn_Bu.x = 170; 144 btn_Bu.y = 30; 145 btn_Shitou.addEventListener(LMouseEvent.MOUSE_UP,onclick); 146 btn_Jiandao.addEventListener(LMouseEvent.MOUSE_UP,onclick); 147 btn_Bu.addEventListener(LMouseEvent.MOUSE_UP,onclick); 148 clickLayer.addChild(btn_Shitou); 149 clickLayer.addChild(btn_Jiandao); 150 clickLayer.addChild(btn_Bu); 151 } 152 153 function onclick(event,display){ 154 var self,enmey; 155 if(display.name == "shitou"){ 156 self = 0; 157 }else if(display.name == "jiandao"){ 158 self = 1; 159 }else { 160 self = 2; 161 } 162 enmey = Math.floor(Math.random()*3); 163 selfBitmap.bitmapData = showList[self]; 164 enmeyBitmap.bitmapData = showList[enmey]; 165 var checkList = [[0,1,-1],[-1,0,1],[1,-1,0]]; 166 var result = checkList[self][enmey]; 167 if(result == -1){ 168 lost +=1; 169 } else if(result == 1){ 170 win+=1; 171 }else{ 172 eq+=1; 173 } 174 selfTextAll.text = "猜拳次数:"+(lost+eq+win); 175 selfTextWin.text = "胜利次数:"+win; 176 selfTextLoss.text = "失败次数:"+lost; 177 selfTextEq.text = "平局次数:"+eq; 178 } 179 180 function getButton(flag){ 181 var btn_UP = new LBitmap(new LBitmapData(imageList[flag])); 182 btn_UP.scaleX= 0.5; 183 btn_UP.scaleY= 0.5; 184 var btn_Over = new LBitmap(new LBitmapData(imageList[flag])); 185 btn_Over.scaleX= 0.5; 186 btn_Over.scaleY= 0.5; 187 btn_Over.x = 1; 188 btn_Over.y = 1; 189 var btn = new LButton(btn_UP, btn_Over); 190 btn.name = flag; 191 return btn; 192 } 193 194 }); 195 </script> 196 </head> 197 <body> 198 <div id="mylegend">loading...</div> 199 </body> 200 </html>