flash on 2010-3-9

by shohei909
♥0 | Line 153 | Modified 2010-03-11 15:31:35 | MIT License
play

ActionScript3 source code

/**
 * Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/4IxQ
 */

<?xml version="1.0" encoding="utf-8"?>
<!--


未完


-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	paddingTop="5"
	paddingLeft="5"
	paddingRight="5"
	paddingBottom="5"
	horizontalAlign="left" verticalAlign="top"
	creationComplete="onLoad()">

	<mx:Style>
		Box{horizontalAlign:center;verticalAlign:middle;}
	</mx:Style>
	
	<mx:Script><![CDATA[
		import mx.containers.*;
		import mx.core.*;
		import flash.utils.ByteArray;

		var pass:String="3*4-a_a_a_a_b_a_a_b_b_b_b_b";
				
		var cellSize:uint = 23;
		var thickness:Number = cellSize/18;
		var w:uint=10;
		var h:uint=10;

		var grid:Canvas = new Canvas();
		var vbox:Vector.<VBox>;
		var cell:Vector.<Vector.<Box>>;

		var map:Vector.<Vector.<String>>;
		var black:Vector.<Vector.<Boolean>>;

		function onLoad():void{
			setting();
		}
		function setting():void{
			pass=question.text;
			readData();
			setCells();
			setLines();
		}
		function setCells():void{
			vbox = new Vector.<VBox>(w);
			cell=new Vector.<Vector.<Box>>(w);
			for(var x:uint=0;x<w;x++){
				vbox[x]=new VBox();
				vbox[x].setStyle("verticalGap","0");
				vbox[x].setStyle("backgroundAlpha","0.1");
				vbox[x].x=x*cellSize;
				cell[x]=new Vector.<Box>(h);
				gameBox.addChild(vbox[x]);
				for(var y:uint=0;y<h;y++){
					cell[x][y]=new Box();
					cell[x][y].width=cellSize;
					cell[x][y].height=cellSize;
					if(black[x][y]){
						cell[x][y].setStyle("backgroundColor","0x333333");
						cell[x][y].setStyle("backgroundAlpha","1");
					}else{
						cell[x][y].setStyle("backgroundColor","0xFFFFFF");
						cell[x][y].setStyle("backgroundAlpha","1");
					}

					vbox[x].addChild(cell[x][y]);
				}
			}
			gameBox.addChild(grid);
			grid.x=0;
			grid.y=0;
		}

		function readData():void{
			var subData = pass.split("_");
			if(subData.length > 1){
				var sizeData = subData[0].split("*");
				var mapData = subData[1].split("-");
				w=sizeData[0];
				h=sizeData[1];

				map=new Vector.<Vector.<String>>(w);
				black=new Vector.<Vector.<Boolean>>(w);
				for(var x:uint=0;x<w;x++){
					map[x]=new Vector.<String>(h);
					black[x]=new Vector.<Boolean>(h);
					for(var y:uint=0;y<h;y++){
						map[x][y] = mapData[x + y*w];
						black[x][y] = false;
					}
				}
			}else{
				w=0;
				h=0;
			}
		}

		function setLines():void{
			grid.graphics.clear();
			for(var x:uint=0;x<w;x++){
				for(var y:uint=0;y<h;y++){
					if(y>0){
						if(map[x][y]==map[x][y-1]){
							with(grid.graphics){
								lineStyle(thickness, 0xAAAAAA,1.0,true,"nomal",CapsStyle.NONE);
								moveTo(x*cellSize,y*cellSize);
								lineTo((x+1)*cellSize,y*cellSize);
							}
						}else{
							with(grid.graphics){
								lineStyle(thickness+1, 0x222222,1.0,true,"nomal",CapsStyle.NONE);
								moveTo(x*cellSize,y*cellSize);
								lineTo((x+1)*cellSize,y*cellSize);
							}
						}
					}

					if(x>0){
						if(x>0 && map[x-1][y]==map[x][y]){
							with(grid.graphics){
								lineStyle(thickness, 0xAAAAAA,1.0,true,"nomal",CapsStyle.NONE);
								moveTo(x*cellSize,y*cellSize);
								lineTo(x*cellSize,(y+1)*cellSize);
							}
						}else{
							with(grid.graphics){
								lineStyle(thickness+1, 0x222222,1.0,true,"nomal",CapsStyle.NONE);
								moveTo(x*cellSize,y*cellSize);
								lineTo(x*cellSize,(y+1)*cellSize);
							}
						}
					}
				}
			}
			with(grid.graphics){
				lineStyle(thickness*1.5+1, 0x222222,1.0,true,"nomal",CapsStyle.NONE);
					moveTo(0,0);
					lineTo(w*cellSize,0);
					lineTo(w*cellSize,h*cellSize);
					lineTo(0,h*cellSize);
					lineTo(0,0);
				}
		}
	]]></mx:Script>
	<mx:Label id="title" text="LITS" fontSize="30"/>
	<mx:HBox horizontalAlign="center" verticalAlign="middle" width="100%" height="100%" >
    		<mx:Box id="mainBox" width="{Application.application.width-300}" height="{Application.application.height-60}" backgroundColor="0x000000">
			<mx:Box width="{mainBox.width-20}"  height="{mainBox.height-20}"  horizontalAlign="left" verticalAlign="top"  backgroundAlpha="1" backgroundColor="0xFFFFE0" borderStyle="solid">
				<mx:Box width="100%"  height="100%"  paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
					<mx:Canvas id="gameBox" backgroundColor="0xFFFFFF" backgroundAlpha="0" />
				</mx:Box>
	    		</mx:Box>
	    	</mx:Box>
		<mx:VBox  height="{Application.application.height-60}" width="280" borderStyle="solid"  paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
			<mx:Label text="問題データ"/>
			<mx:HBox>
				<mx:TextArea id="question" width="200" height="100" />
				<mx:VBox verticalAlign="bottom">
					<mx:Button label="反映" click="setting();"/>
				</mx:VBox>
			</mx:HBox>
		</mx:VBox>
	 </mx:HBox>
</mx:Application>