/ Published in: ActionScript 3
a horrible master mind with as few code as possible, can be even worse
Expand |
Embed | Plain Text
package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.Matrix; import flash.geom.Point; import flash.geom.Rectangle; public class MMind extends Sprite { private var bd:BitmapData; private var validation:BitmapData; private var offset:Point = new Point( 0, 16 ); private var colors:Array = [0xFF0000, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF, 0xFF00FF, 0]; private var solution:Array = []; public function MMind() { addChild( new Bitmap( bd = new BitmapData( 9, 20, false, 0x808080 ) ) ).transform.matrix = new Matrix(25,0,0,25 ); bd.fillRect( new Rectangle( 2, 2, 5, 15), 0xFFFFFF ); addChild( new Bitmap( validation = new BitmapData( 7, 18, false, 0x808080 ) ) ).transform.matrix = new Matrix(5,0,0,5, bd.width * 25 + 10, 50 ); validation.fillRect( new Rectangle( 1, 2, 5, 15), 0xDDDDDD ); var i:int = colors.length; while ( i-- ) { bd.setPixel( 1 + i, 18, colors[ i ] ); if ( i < 5 )solution[i]=colors[int( Math.random()*colors.length)]; } stage.addEventListener( MouseEvent.MOUSE_DOWN, function mHandler(e:MouseEvent):void { bd.setPixel( 2 + offset.x++ % 5, offset.y, bd.getPixel( int( mouseX / 25), int( mouseY / 25 ) ) ); if ( offset.x % 5 == 0 ) { for ( var i:int = 0; i < 5; i++) { var col:int = 0; if ( bd.getPixel( 2 + i, offset.y ) == solution[ i ] ) col = 0x00FF00 else for ( var j:int = 0; j < solution.length; j++) if ( solution[j] == bd.getPixel( 2 + i, offset.y ) ) col = 0xFF0000; validation.setPixel(1 + i, offset.y, col); } offset.y--; } } ); } } }
You need to login to post a comment.
