用lufy引擎写的小游戏

//注意引用的lufy游戏引擎
 
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<script src="js/jquery-2.1.0.js"></script>
		<script src="js/lufylegend-1.10.1.js"></script>
		<style>
			*{margin: 0;padding: 0;}
		</style>
	</head>
	<body>
	<div id="mylegend">loading...</div>
	<script>
//	$(function() {
//		$("body").on("touchmove", function(e) {
//			e.preventDefault();
//	});		
	//初始化游戏
	//var gameWidth = $(window).width();
	var gameWidth = 640;
	//var gameHeight = $(window).height();
	var gameHeight = window.innerHeight * gameWidth / window.innerWidth;
	console.log(gameHeight)
	//-----------------------判断横屏------------------------------------------------
	var initFlag = true;
	var landscape = false;
	//判断横屏
	function orien() {
		//alert(window.orientation);
		if (window.orientation == 90 || window.orientation == -90) {
			//log("这是横屏");
			if(initFlag) {
				initFlag = false;
				landscape = true;
			}
			$("#landscape").show();

		} else {
			if(initFlag) {
				initFlag = false;
			}
			if(landscape) {
				//window.location.reload();
				window.location.reload(true);
			} else {
				$("#landscape").hide();	
			}
		}
	};	
	
	//屏幕自适应
	var backLayer,resultLayer,clickLayer,loadingLayer,numtextLayer,selfImg,computerImg;
	var imglist = {};
	var imgData = new Array(
		{name:"title",path:"images/title.png"},
		{name:"shitou",path:"images/shitou.png"},
		{name:"jiandao",path:"images/jiandao.png"},
		{name:"bu",path:"images/bu.png"}		
	);
	var Win = 0;
	var Draw = 0;
	var Loss = 0;
	//main
	LGlobal.stageScale = LStageScaleMode.EXACT_FIT;
	LSystem.screen(LStage.FULL_SCREEN);
	LInit(50,"mylegend",gameWidth,gameHeight,main);	
	function main(){
		backLayer = new LSprite();
		addChild(backLayer);
		loadingLayer = new LoadingSample3();
		backLayer.addChild(loadingLayer);
		LLoadManage.load(
	        imgData,
	        function(progress){
	            loadingLayer.setProgress(progress);
        },
        gameInit
    );
	}
	function gameInit(result){
		//图片
		imglist = result;
		//remove 加载动画
		backLayer.removeChild(loadingLayer);
		//bg
		backLayer.graphics.drawRect(10,"#008800",[0,0,LGlobal.width,LGlobal.height],true,"#000000");
		initResultLayer();
		initClickLayer();
		littleLayer();
	}
	//little text
	function littleLayer(){
		var littleText = new LBitmap(new LBitmapData(imglist["title"]));
		backLayer.addChild(littleText);
		littleText.x = LGlobal.width/2 - littleText.getWidth()/2;
		littleText.y = 20;
		//玩家出拳
		//img
		selfImg = new LBitmap(new LBitmapData(imglist["shitou"]));
		backLayer.addChild(selfImg);
		selfImg.x = LGlobal.width/4 - selfImg.getWidth()/2;
		selfImg.y = LGlobal.height/2 - selfImg.getHeight()/2;
		//text
		selfText = new LTextField();
		backLayer.addChild(selfText);
		selfText.text = "本身";	
		selfText.color = "#ffffff"
		selfText.size = 30;		
		selfText.x = LGlobal.width/4 - selfText.getWidth()/2;
		selfText.y = LGlobal.height/2 - selfImg.getHeight();
		//电脑出拳
		//img
		computerImg = new LBitmap(new LBitmapData(imglist["shitou"]));
		backLayer.addChild(computerImg);
		computerImg.x = LGlobal.width/4*3 - selfImg.getWidth()/2;
		computerImg.y = LGlobal.height/2 - selfImg.getHeight()/2;
		//text
		computerText = new LTextField();
		backLayer.addChild(computerText);
		computerText.text = "电脑";	
		computerText.color = "#ffffff"
		computerText.size = 30;		
		computerText.x = LGlobal.width/4*3 - selfText.getWidth()/2;
		computerText.y = LGlobal.height/2 - selfImg.getHeight();		
		
		
	}
	//
	function initResultLayer(){
		resultLayer = new LSprite();
		backLayer.addChild(resultLayer);
		resultLayer.graphics.drawRect(4,"#ff8800",[0,0,LGlobal.width,100],true,"#ffffff");
		resultLayer.x = 0;
		resultLayer.y = 100;
		numText();
	}
	function initClickLayer(){
		clickLayer = new LSprite();
		backLayer.addChild(clickLayer);
		clickLayer.graphics.drawRect(4,"#ff8800",[0,0,LGlobal.width,LGlobal.height/4],true,"#ffffff");
		clickLayer.x = 0;
		clickLayer.y = LGlobal.height - (LGlobal.height/4);
		clickImg();
	}
//	分数记录层
	function numText(){
		var textHeihgt = 10;
		var textHeihgt2 = 10 + 40;
		var textColor = "#ca4341";
		var textSize = 40;
		var textWidth = LGlobal.width/4 - 150;
		var textWidth2 = LGlobal.width/2 + 10;
		console.log(textWidth)
		numtextLayer = new LSprite();
		resultLayer.addChild(numtextLayer);
		//all
		selfTextAll = new LTextField();
		numtextLayer.addChild(selfTextAll);
		selfTextAll.x = textWidth;
		selfTextAll.y = textHeihgt;
		selfTextAll.text = "猜拳次数:0";
		selfTextAll.size = textSize;
		selfTextAll.color = textColor;
		//win
		selfTextWin = new LTextField();
		numtextLayer.addChild(selfTextWin);
		selfTextWin.x = textWidth2;
		selfTextWin.y = textHeihgt;
		selfTextWin.text = "胜利次数:0";
		selfTextWin.size = textSize;
		selfTextWin.color = textColor;
		//loss
		selfTextLoss = new LTextField();
		numtextLayer.addChild(selfTextLoss);
		selfTextLoss.x = textWidth;
		selfTextLoss.y = textHeihgt2;
		selfTextLoss.text = "失败次数:0";
		selfTextLoss.size = textSize;
		selfTextLoss.color = textColor;
		//
		selfTextDraw = new LTextField();
		numtextLayer.addChild(selfTextDraw);
		selfTextDraw.x = textWidth2;
		selfTextDraw.y = textHeihgt2;
		selfTextDraw.text = "平局次数:0";
		selfTextDraw.size = textSize;
		selfTextDraw.color = textColor;
	}
	//点击层
	function clickImg(){
		//文字
		clickText = new LTextField();
		clickLayer.addChild(clickText);
		clickText.x = 10;
		clickText.y = 10;
		clickText.text = "请出拳:";
		clickText.size = 40;
		clickText.color = "#ff464e";
		//石头
		var shitouButton = getButton("shitou");
		//console.log(shitouButton.name)
		shitouButton.x = clickLayer.getWidth()/2*0.25 + shitouButton.getWidth()/2;
		shitouButton.y = clickLayer.getHeight()/2 - shitouButton.getHeight()/2;
		clickLayer.addChild(shitouButton);
		//剪刀
		var jiandaoButton = getButton("jiandao");
		jiandaoButton.x = clickLayer.getWidth()/2 - shitouButton.getWidth()/2;
		jiandaoButton.y = clickLayer.getHeight()/2 - shitouButton.getHeight()/2;
		clickLayer.addChild(jiandaoButton);		
		//布
		var buButton = getButton("bu");
		buButton.x = clickLayer.getWidth()/1.5 + shitouButton.getWidth()/2;
		buButton.y = clickLayer.getHeight()/2 - shitouButton.getHeight()/2;
		clickLayer.addChild(buButton);	
		//点击事件
		shitouButton.addEventListener(LMouseEvent.MOUSE_UP,onclick);
		jiandaoButton.addEventListener(LMouseEvent.MOUSE_UP,onclick);
		buButton.addEventListener(LMouseEvent.MOUSE_UP,onclick);		
	}
	
	function onclick(event,display){
		var showList = new Array;
		var selfValue;
		var enemyValue = Math.floor(Math.random()*3);
		var checkList = [
		[0,1,-1],
		[-1,0,1],
		[1,-1,0]
		];	
		showList.push(new LBitmapData(imglist["shitou"]));
		showList.push(new LBitmapData(imglist["jiandao"]));
		showList.push(new LBitmapData(imglist["bu"]));
		//点击出
		switch(display.name){
			case 'shitou':
				selfValue = 0;
				break;
			case 'jiandao':
				selfValue = 1;
				break;
			case 'bu':
				selfValue = 2;
				break;	
		}
		//显示
		selfImg.bitmapData = showList[selfValue];
		computerImg.bitmapData = showList[enemyValue];
		var result = checkList[selfValue][enemyValue];
		console.log(result);
		//判断结果
		switch(result){
			case 0 :
				Draw +=1;
				break;
			case 1 : 
				Win +=1;
				break;
			case -1 :
				Loss +=1;
				break;
		}
		//修改text
		selfTextWin.text = "胜利次数:" + Win;
		selfTextDraw.text = "平局次数:" + Draw;
		selfTextLoss.text = "失败次数:" + Loss;	
		selfTextAll.text = "猜拳次数:" + (Win + Draw + Loss);
	}
	
	
	
	
	
	
	
	
	
	
	
	//but方法
	function getButton(value){
		var btnUp = new LBitmap(new LBitmapData(imglist[value]));
		btnUp.scaleX = 0.5;
		btnUp.scaleY = 0.5;
		var btnOver = new LBitmap(new LBitmapData(imglist[value]));
		btnOver.scaleX = 0.5;
		btnOver.scaleY = 0.5;
		btnOver.x = 2;
		btnOver.y = 2;
		var btn = new LButton(btnUp,btnOver);
		btn.name = value;
		return btn;
	}	

	
	
	//console.log(getButton(""))
	</script>
	</body>
</html>