Posted By

nicoptere on 05/17/11


Tagged

fun practice bad obsfuscate


Versions (?)

mastermind


 / Published in: ActionScript 3
 

a horrible master mind with as few code as possible, can be even worse

  1. package
  2. {
  3. import flash.display.Bitmap;
  4. import flash.display.BitmapData;
  5. import flash.display.Sprite;
  6. import flash.events.MouseEvent;
  7. import flash.geom.Matrix;
  8. import flash.geom.Point;
  9. import flash.geom.Rectangle;
  10. public class MMind extends Sprite
  11. {
  12. private var bd:BitmapData;
  13. private var validation:BitmapData;
  14. private var offset:Point = new Point( 0, 16 );
  15. private var colors:Array = [0xFF0000, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF, 0xFF00FF, 0];
  16. private var solution:Array = [];
  17. public function MMind()
  18. {
  19. addChild( new Bitmap( bd = new BitmapData( 9, 20, false, 0x808080 ) ) ).transform.matrix = new Matrix(25,0,0,25 );
  20. bd.fillRect( new Rectangle( 2, 2, 5, 15), 0xFFFFFF );
  21. addChild( new Bitmap( validation = new BitmapData( 7, 18, false, 0x808080 ) ) ).transform.matrix = new Matrix(5,0,0,5, bd.width * 25 + 10, 50 );
  22. validation.fillRect( new Rectangle( 1, 2, 5, 15), 0xDDDDDD );
  23. var i:int = colors.length;
  24. while ( i-- )
  25. {
  26. bd.setPixel( 1 + i, 18, colors[ i ] );
  27. if ( i < 5 )solution[i]=colors[int( Math.random()*colors.length)];
  28. }
  29. stage.addEventListener( MouseEvent.MOUSE_DOWN, function mHandler(e:MouseEvent):void
  30. {
  31. bd.setPixel( 2 + offset.x++ % 5, offset.y, bd.getPixel( int( mouseX / 25), int( mouseY / 25 ) ) );
  32. if ( offset.x % 5 == 0 )
  33. {
  34. for ( var i:int = 0; i < 5; i++)
  35. {
  36. var col:int = 0;
  37. if ( bd.getPixel( 2 + i, offset.y ) == solution[ i ] ) col = 0x00FF00
  38. else for ( var j:int = 0; j < solution.length; j++) if ( solution[j] == bd.getPixel( 2 + i, offset.y ) ) col = 0xFF0000;
  39. validation.setPixel(1 + i, offset.y, col);
  40. }
  41. offset.y--;
  42. }
  43. } );
  44. }
  45. }
  46. }

Report this snippet  

You need to login to post a comment.