/**
* Copyright dannnn ( http://wonderfl.net/user/dannnn )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gCBq
*/
// forked from YoupSolo's forked from: forked from: forked from: forked from: forked from: flash on 2014-8-21
// forked from dannnn's forked from: forked from: forked from: forked from: flash on 2014-8-21
// forked from YoupSolo's forked from: forked from: forked from: flash on 2014-8-21
// forked from dannnn's forked from: forked from: flash on 2014-8-21
// forked from YoupSolo's forked from: flash on 2014-8-21
// guessing you want to keep track of the current move ?
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
[SWF(width = "465", hight = "465", frameRate = "30")]
public class FlashTest3 extends Sprite
{
[Embed(systemFont = "sansserif", fontName = "myFont", mimeType = "application/x-font")]
private static const myFont:Class;
private var kifu:Kifu;
public function FlashTest3()
{
// you don't need to create a display object (Sprite) for a background and lines
this.graphics.beginFill(Board.COLOR);
this.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
this.graphics.endFill();
// same here draw directly on the stage
this.graphics.lineStyle(1);
var numbers:TextField
for ( var i: int = 0; i <= Board.TILE_NUM; i++)
{
numbers = new TextField();
numbers.selectable = false;
numbers.x = Board.MARGINX + 15 + (i * Board.TILE_SIZE);
numbers.text = ( (Board.TILE_NUM - i) != 0) ? (Board.TILE_NUM - i).toString() : "";
addChild(numbers);
this.graphics.moveTo(Board.MARGINX+Board.TILE_SIZE*i, Board.MARGINY);
this.graphics.lineTo(Board.MARGINX+Board.TILE_SIZE*i, Board.MARGINY);
this.graphics.lineTo(Board.MARGINX+Board.TILE_SIZE*i, Board.MARGINY + Board.TILE_NUM * Board.TILE_SIZE);
}
for ( var j: int = 0; j <= Board.TILE_NUM; j++)
{
numbers = new TextField();
numbers.selectable = false;
numbers.x = 5 + Board.TILE_NUM2 * Board.TILE_SIZE;
numbers.y = -5 + (j * Board.TILE_SIZE);
numbers.text = ( j == 0) ? "" : j.toString();
addChild(numbers);
this.graphics.moveTo(Board.MARGINX, Board.MARGINY+Board.TILE_SIZE*j);
this.graphics.lineTo(Board.MARGINX, Board.MARGINY+Board.TILE_SIZE*j);
this.graphics.lineTo(Board.MARGINX + Board.TILE_NUM * Board.TILE_SIZE, Board.MARGINY + Board.TILE_SIZE * j);
}
//////////////////////////////////
// creating the board
// reseting the counter
Board.KOMA_NAMES_IDX = 0;
fillLine(2, 2);
addChild( new Koma2(1, 7) );
addChild( new Koma2(1, 1) ); // create a Koma at 1,1 for player 2
fillLine(0, 2);
// reseting the counter
Board.KOMA_NAMES_IDX = 0;
fillLine(6, 1);
addChild( new Koma1(7, 1) );
addChild( new Koma1(7, 7) );
fillLine(8, 1);
// creating the Kifu Object and adding it to the display list
kifu = new Kifu();
addChild(kifu);
// you can create one listener to handle the whole DnD mechanic
this.addEventListener(MouseEvent.MOUSE_DOWN, onDrag);
this.addEventListener(MouseEvent.MOUSE_UP, onDrop);
}
// fill the @line with pawns for the @player
private function fillLine(lineNumber:int, player:int):void
{
for (var index:int = 0; index < Board.TILE_NUM; index++)
{
// with addchild add directly the pawn to the display list
if (player == 1) {
addChild( new Koma1(lineNumber, index) );
}else {
addChild( new Koma2(lineNumber, index) );
}
}
}
// on drag behavior
public function onDrag(e:MouseEvent):void
{
// if we click on a Koma, I put this one on the top of the display list ( the pawn is now over the others )
if (e.target is Koma) {
var targetKoma:Koma = e.target as Koma;
targetKoma.filters = [Board.DROP_SHADOW]; // added a drop shadow
addChild( targetKoma );
// dragging
targetKoma.startDrag();
kifu.lastMoveLine = targetKoma.line;
kifu.lastMoveColumn = targetKoma.column;
//kifu.text = kifu.lastMoveColumn+" "+kifu.lastMoveLine+" "+targetKoma.name;
}
}
public function onDrop(e:MouseEvent):void
{
stopDrag();
// the koma is centered in the curent Tile
if (e.target is Koma)
{
// now, Koma1 and Koma2 inherits from Koma
var targetKoma:Koma = e.target as Koma;
targetKoma.filters = [];
//var newX:int = Board.MARGINX + Board.KOMA_OFFSET_X + (int((e.stageX - e.localX) / Board.TILE_SIZE)) * Board.TILE_SIZE;
var newX:int = Board.KOMA_OFFSET_X + Board.KOMA_OFFSET_X + (int((e.stageX - e.localX) / Board.TILE_SIZE)) * Board.TILE_SIZE;
var newY:int = Board.MARGINY + Board.KOMA_OFFSET_Y + (int((e.stageY - e.localY) / Board.TILE_SIZE)) * Board.TILE_SIZE;
// new coordinates
targetKoma.x = newX;
targetKoma.y = newY;
trace(targetKoma.x);
if (e.target is Koma1)
{
if ( kifu.lastMoveColumn <= 0) {
kifu.lastMoveColumn = 0;
kifu.lastMoveLine = 0;
}
if ( kifu.lastMoveColumn >= 10) {
kifu.lastMoveColumn = 0;
kifu.lastMoveLine = 0;
}
kifu.text2 ="+" + kifu.lastMoveColumn + "" + kifu.lastMoveLine + "" + targetKoma.column + "" + targetKoma.line + "" + targetKoma.name;
}
if (e.target is Koma2)
{
kifu.text2 ="-" + kifu.lastMoveColumn + "" + kifu.lastMoveLine + "" + targetKoma.column + "" + targetKoma.line + "" + targetKoma.name;
}
kifu.text = targetKoma.name+" " + kifu.lastMoveColumn + " " + kifu.lastMoveLine+" > " + targetKoma.column + " " + targetKoma.line;
if (targetKoma.x < Board.MARGINX || targetKoma.x > Board.TILE_SIZE * 10) {
var targetKoma2:Koma = e.target as MochiGoma1;
if (e.target is Koma1) {
targetKoma.rotation = 20;
targetKoma.x = Board.TILE_SIZE;
}
if (e.target is Koma2) {
targetKoma.rotation = 20;
targetKoma.x = 400;
}
if (e.target is MochiGoma1) {
targetKoma.x = -13 + Board.KOMA_OFFSET_X + Board.KOMA_OFFSET_X + (int((e.stageX - e.localX) / Board.TILE_SIZE)) * Board.TILE_SIZE;
targetKoma.y = Board.MARGINY + Board.KOMA_OFFSET_Y + (int((e.stageY - e.localY) / Board.TILE_SIZE)) * Board.TILE_SIZE;;
}
if (e.target is MochiGoma2) {
targetKoma.x = Board.KOMA_OFFSET_X + Board.KOMA_OFFSET_X + (int((e.stageX - e.localX) / Board.TILE_SIZE)) * Board.TILE_SIZE;
targetKoma.y = Board.MARGINY + Board.KOMA_OFFSET_Y + (int((e.stageY - e.localY) / Board.TILE_SIZE)) * Board.TILE_SIZE;
}
}
}
}
}
}
import flash.filters.DropShadowFilter;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import com.bit101.components.*;
class Kifu extends Sprite
{
private var _tf:TextField;
public var lastMoveLine:int;
public var lastMoveColumn:int;
private var a:Slider = new Slider();
private var c:com.bit101.components.List = new com.bit101.components.List(null, 150, 350);
public function Kifu()
{
_tf = new TextField()
//_tf.embedFonts = true;
_tf.selectable = false;
_tf.x = 30;
_tf.y = 350;
_tf.defaultTextFormat = new TextFormat('myFont', 12, 0x0);
_tf.autoSize = TextFieldAutoSize.LEFT;
addChild( _tf );
// --
this.text2 = "N+player1";
this.text2 = "N-player2";
this.text2 = "P1-KY-KE-GI-KI-OU-KI-GI-KE-KY";
this.text2 = "P2 * -HI * * * * * -KA * ";
this.text2 = "P3-FU-FU-FU-FU-FU-FU-FU-FU-FU";
this.text2 = "P4 * * * * * * * * * ";
this.text2 = "P5 * * * * * * * * * ";
this.text2 = "P6 * * * * * * * * * ";
this.text2 = "P7+FU+FU+FU+FU+FU+FU+FU+FU+FU";
this.text2 = "P8 * +KA * * * * * +HI * ";
this.text2 = "P9+KY+KE+GI+KI+OU+KI+GI+KE+KY";
this.text = "waiting...";
}
//
public function set text(str:String):void
{
_tf.text = str;
}
public function set text2(str:String):void
{
var index:int = 0;
_tf.text = str;
c.width = 200;
c.height = 100;
c.addItem(str);
c.buttonMode = true;
addChild(c);
}
}
import flash.filters.DropShadowFilter;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
class Koma extends Sprite
{
public var owner:int;
public const showName:Boolean = true;
private var _column:int;
private var _line:int;
protected var tf:TextField;
public function Koma(lineNumber:int, index:int)
{
mouseChildren = false;
mouseEnabled = true;
x = Board.MARGINX + Board.KOMA_OFFSET_X + index * Board.TILE_SIZE;
y = Board.MARGINY + Board.KOMA_OFFSET_Y + lineNumber * Board.TILE_SIZE;
//name = lineNumer+ "_" + index;
name = Board.KOMA_NAMES[Board.KOMA_NAMES_IDX++];
tf = new TextField();
tf.embedFonts = true;
tf.x = 5; // centering the text
tf.y = 7; // centering the text
tf.defaultTextFormat = new TextFormat('myFont', 10, 0x0);
tf.autoSize = TextFieldAutoSize.LEFT;
tf.text = name;
addChild( tf );
tf.visible = showName;
draw();
}
public function get line():int
{
return 1 + int( y / Board.TILE_SIZE );
}
public function get column():int
{
return 10 - int( x / Board.TILE_SIZE );
}
public function draw():void
{
// to override
}
}
class Koma1 extends Koma
{
public function Koma1(lineNumber:int, index:int)
{
owner = 1;
super(lineNumber, index);
}
override public function draw():void
{
graphics.beginFill(Board.KOMA_COLOR);
graphics.lineStyle(1);
graphics.moveTo(13, 0);
graphics.lineTo(13, 0);
graphics.lineTo(22, 5);
graphics.lineTo(26, 26);
graphics.lineTo(0, 26);
graphics.lineTo(5, 5);
graphics.endFill();
}
}
class Koma2 extends Koma
{
public function Koma2(lineNumber:int, index:int)
{
owner = 2;
super(lineNumber, index);
tf.rotation = 180;
tf.x = 22;
tf.y = 22;
}
override public function draw():void
{
graphics.beginFill(Board.KOMA_COLOR);
graphics.lineStyle(1);
graphics.moveTo(13, 26);
graphics.lineTo(13, 26);
graphics.lineTo(5, 22);
graphics.lineTo(0, 0);
graphics.lineTo(26, 0);
graphics.lineTo(22, 22);
graphics.endFill();
}
}
class MochiGoma1 extends Koma
{
public function MochiGoma1(lineNumber:int, index:int)
{
owner = 2;
super(lineNumber, index);
}
}
class MochiGoma2 extends Koma
{
public function MochiGoma2(lineNumber:int, index:int)
{
owner = 1;
super(lineNumber, index);
}
}
// a config object
class Board
{
//public static const MARGIN:int = 40;
public static const MARGINX:int = 40;
public static const MARGINY:int = 20;
public static const TILE_SIZE:int = 35;
public static const TILE_NUM:int = 9;
public static const TILE_NUM2:int = 10;
public static const KOMA_OFFSET_X:int = 5;
public static const KOMA_OFFSET_Y:int = 5;
public static const COLOR:int = 0xC2922F;
public static const KOMA_COLOR:int = 0xE2A22F;
public static const KOMA_COLOR_BLACK:int = 0x000000;
public static const KOMA_COLOR_WHITE:int = 0xFFFFFF;
public static const DROP_SHADOW:DropShadowFilter = new DropShadowFilter(5,45,0x0,.5);
public static const KOMA_NAMES:Array = ["FU","FU","FU","FU","FU","FU","FU","FU","FU","KA","HI","KY","KE","GI","KI","OU","KI","GI","KE","KY"];
public static const KOMA_NAMES2:Array = ["TO","NY","NK","NG","UM","RY"]
public static var KOMA_NAMES_IDX:int = 0;
public function Board() {}
}