Reality Distortion Field

by q.kensuke forked from Reversi (オセロ)#bugあり (diff: 284)
http://www.youtube.com/watch?v=QKCSBkdEUXQ
♥0 | Line 215 | Modified 2011-02-23 21:54:20 | MIT License
play

ActionScript3 source code

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

// forked from kappaLab's Reversi (オセロ)#bugあり
package  
{
    import flash.display.Graphics;
    import flash.display.Sprite
    import flash.events.MouseEvent;
    import flash.text.TextField;
    /**
     * ...
     * @author gk
     */
    public class Reversi extends Sprite
    {
        private var model:Array;
        private var cells:Array;
        private var count:int;
        public static const UNIT:Number = 23
        public static const ENABLE:int = 1
        public static const DESABLE:int = 0
        
        private var col:int;
        private var row:int;
        private var target:int;
        private var state:int;
        private var rowModel:Array;
        private var textField:TextField
        
        public function Reversi() 
        {
            stage.scaleMode = "noScale"
            init()
        }
        
        private function init():void
        {
            model = [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 4, 0, 4, 0, 4, 0, 4, 0, 3, 0, 3, 0, 3, 0, 3, 0, 0, 0],
            [0, 0, 0, 4, 0, 4, 0, 4, 0, 2, 0, 3, 0, 3, 0, 3, 0, 3, 0, 0],
            [0, 0, 4, 0, 4, 0, 4, 0, 4, 0, 3, 0, 3, 0, 3, 0, 3, 0, 0, 0],
            [0, 0, 0, 4, 0, 4, 0, 4, 0, 2, 0, 3, 0, 3, 0, 3, 0, 3, 0, 0],
            [0, 0, 4, 0, 4, 0, 4, 0, 4, 0, 3, 0, 3, 0, 3, 0, 3, 0, 0, 0],
            [0, 0, 0, 4, 0, 4, 0, 4, 0, 2, 0, 3, 0, 3, 0, 3, 0, 3, 0, 0],
            [0, 0, 4, 0, 4, 0, 4, 0, 4, 0, 3, 0, 3, 0, 3, 0, 3, 0, 0, 0],
            [0, 0, 0, 4, 0, 4, 0, 4, 0, 2, 0, 3, 0, 3, 0, 3, 0, 3, 0, 0],
            [0, 0, 5, 0, 5, 0, 5, 0, 5, 0, 6, 0, 6, 0, 6, 0, 6, 0, 0, 0],
            [0, 0, 0, 3, 0, 3, 0, 3, 0, 1, 0, 4, 0, 4, 0, 4, 0, 4, 0, 0],
            [0, 0, 3, 0, 3, 0, 3, 0, 3, 0, 4, 0, 4, 0, 4, 0, 4, 0, 0, 0],
            [0, 0, 0, 3, 0, 3, 0, 3, 0, 1, 0, 4, 0, 4, 0, 4, 0, 4, 0, 0],
            [0, 0, 3, 0, 3, 0, 3, 0, 3, 0, 4, 0, 4, 0, 4, 0, 4, 0, 0, 0],
            [0, 0, 0, 3, 0, 3, 0, 3, 0, 1, 0, 4, 0, 4, 0, 4, 0, 4, 0, 0],
            [0, 0, 3, 0, 3, 0, 3, 0, 3, 0, 4, 0, 4, 0, 4, 0, 4, 0, 0, 0],
            [0, 0, 0, 3, 0, 3, 0, 3, 0, 1, 0, 4, 0, 4, 0, 4, 0, 4, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
            ];
            
            count = 0;
            state = (count) % 2 + 1;
            var bord:Sprite = addChild(new Sprite()) as Sprite
            var g:Graphics = bord.graphics;
            g.lineStyle(1, 0)
            
            cells = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []];
            var n:int = model.length
            for (var i:int = 0; i < n; i++) 
            {
                var m:int = model[i].length
                for (var j:int = 0; j < m; j++) 
                {
                    var cell:Cell = addChild(new Cell(j,i)) as Cell;
                    cell.x = j * UNIT;
                    cell.y = i * UNIT;
                    cell.state = model[i][j];
                    cell.buttonMode = true;
                    cell.addEventListener(MouseEvent.MOUSE_UP,onMouseup)
                    cells[i][j] = (cell)
                }
            }
            
            
        }
        
        private function onMouseup(e:MouseEvent):void 
        {
            var cell:Cell = e.target as Cell
            col = cell.col;
            row = cell.row;            
        }
 
                
    }
}
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite
import flash.filters.DisplacementMapFilterMode;
class Cell extends Sprite
{
    private var _state:uint;
    private var g:Graphics;
    private var p_lr:Shape;
    private var p_rl:Shape;
    private var p_rr:Shape;
    private var p_ll:Shape; 
    private var p_cl:Shape;
    private var p_cr:Shape;
    private var _col:int;
    private var _row:int;
    private var _tlCol:int;
    private var _tlraw:int;
    function Cell(col:int,row:int):void
    {
        _col = col;
        _row = row;
        _tlCol = (_col == 0)?0:_col;
        _tlraw = (_row == 0)?0:_row;
        
        if((row % 2) == 1 ) {
        if( (col % 2) == 1 ) { // 奇数
          g = this.graphics;
          g.lineStyle(1,0x000000)
          g.beginFill(0x000000)
          g.drawRect(0,0,Reversi.UNIT,Reversi.UNIT)
          g.endFill()
        } else {  // 偶数
          g = this.graphics;
          g.lineStyle(1,0xffffff)
          g.beginFill(0xffffff)
          g.drawRect(0,0,Reversi.UNIT,Reversi.UNIT)
          g.endFill()
        }
        }
         if((row % 2) == 0 ) {
        if( (col % 2) == 0 ) { // 奇数
          g = this.graphics;
          g.lineStyle(1,0x000000)
          g.beginFill(0x000000)
          g.drawRect(0,0,Reversi.UNIT,Reversi.UNIT)
          g.endFill()
        } else {  // 偶数
          g = this.graphics;
          g.lineStyle(1,0xffffff)
          g.beginFill(0xffffff)
          g.drawRect(0,0,Reversi.UNIT,Reversi.UNIT)
          g.endFill()
        }
        }
        
        var l:Number = 4
        var r:Number = 19
        var c:Number = 11.5
        
        p_lr = addChild(new Shape()) as Shape
        p_lr.graphics.beginFill(0xffffff)
        p_lr.graphics.drawCircle(l, r,  2.5);
        p_lr.visible = false;
        
        p_rl = addChild(new Shape()) as Shape
        p_rl.graphics.beginFill(0xffffff)
        p_rl.graphics.drawCircle(r, l,  2.5);
        p_rl.visible = false;
        
        p_rr = addChild(new Shape()) as Shape
        p_rr.graphics.beginFill(0xffffff);
        p_rr.graphics.drawCircle(r, r, 2.5);
        p_rr.visible = false;
        
        p_ll = addChild(new Shape()) as Shape
        p_ll.graphics.beginFill(0xffffff);
        p_ll.graphics.drawCircle(l, l, 2.5);
        p_ll.visible = false;
        
        p_cl = addChild(new Shape()) as Shape
        p_cl.graphics.beginFill(0xffffff);
        p_cl.graphics.drawCircle(l, c, 2.5);
        p_cl.visible = false;
        
        p_cr = addChild(new Shape()) as Shape
        p_cr.graphics.beginFill(0xffffff);
        p_cr.graphics.drawCircle(r, c, 2.5);
        p_cr.visible = false;
    }
    
    public function get state():uint { return _state; }
    
    public function set state(value:uint):void 
    {
        _state = value;
        switch(value)
        {
            case 0:
            p_lr.visible = p_rr.visible = false
            p_rl.visible = false
            break;
            case 1:
            p_lr.visible = true
            p_rr.visible = true
            mouseEnabled = false
            break;
            case 2:
            p_rl.visible = true
            p_ll.visible = true
            mouseEnabled = false
            break;
            case 3:
            p_lr.visible = true
            p_rl.visible = true
            break;
            case 4:
            p_ll.visible = true
            p_rr.visible = true
            break;
            case 5:
            p_lr.visible = true
            p_ll.visible = true
            p_cr.visible = true
            break;
            case 6:
            p_rl.visible = true
            p_rr.visible = true
            p_cl.visible = true
            break;
        }
    }
    
    public function get row():int { return _row; }
    
    public function get col():int { return _col; }
    
    public function get tlCol():int { return _tlCol; }
    
    public function get tlraw():int { return _tlraw; }
    
    public function set tlraw(value:int):void 
    {
        _tlraw = value;
    }
    
    
}
class CellModel
{
    public var col:int;
    public var raw:int;
}