flash on 2013-9-12
Copyright marcsali ( http://wonderfl.net/user/marcsali )
MIT License ( http://www.opensource.org/licenses/mit-license.php )
Downloaded from: http://wonderfl.net/c/sdaz
import caurina.transitions.Tweener;
[SWF(width=600, height=380, backgroundColor="#AA0000", frameRate=30)]
♥0 |
Line 131 |
Modified 2013-09-13 03:18:34 |
MIT License
archived:2017-03-20 09:04:30
ActionScript3 source code
/**
* Copyright marcsali ( http://wonderfl.net/user/marcsali )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/hiKA
*/
/**
* Copyright marcsali ( http://wonderfl.net/user/marcsali )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/sdaz
*/
// forked from flashrod's 15 puzzle
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.MouseEvent;
// import caurina.transitions.Tweener;
import gs.TweenLite;
import flash.text.TextField;
import flash.text.TextFormat;
//[SWF(width=600, height=380, backgroundColor="#AA0000", frameRate=30)]
public class Main extends Sprite {
private var W:int = 300; //465
private var H:int = 300; //465
private var U:int = int(W/4);
private var V:int = int(H/4);
private var board:Array = [];
public var count:int=0;
public function Main():void {
for (var k:int = 1; k < 17; ++k) {
var p:Piece = new Piece(k, U, V);
addChild(p);
board.push(p);
}
var i:int, j:int = 3;
for (k = 0; k < 20; ++k) {
i = int(Math.random()*3);
shift(i, j);
j = int(Math.random()*3);
shift(i, j);
}
stage.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
shift(e.stageX/U, e.stageY/V);
repaint();
});
repaint();
Fifteen();
// Info2();
}
private function shift(x:int, y:int):void {
if (x>=0 && x<4 && y>=0 && y<4) {
for (var i:int = 0; i < 4; ++i) {
var p:Piece = board[y*4+i];
if (p.value == 16) {
for (; i>x; --i)
board[y*4+i] = board[y*4+i-1];
for (; i<x; ++i)
board[y*4+i] = board[y*4+i+1];
board[y*4+x] = p;
return;
}
}
for (var j:int = 0; j<4; ++j) {
p = board[j*4+x];
if (p.value == 16) {
for (; j>y; --j)
board[j*4+x] = board[(j-1)*4+x];
for (; j<y; ++j)
board[j*4+x] = board[(j+1)*4+x];
board[y*4+x] = p;
return;
}
}
}
}
private function repaint():void {
for (var j:int = 0; j < 4; ++j) {
for (var i:int = 0; i < 4; ++i) {
var p:Piece = board[j*4+i];
var cntrX:int = 150;
var cntrY:int =50;
// p.x = i*U;
// p.y = j*V;
// Tweener.addTween(p, {x:i*U, y:j*V, time:1.0, transition:"easeOutQuad"});
TweenLite.to(p, 1 ,{x:i*U+cntrX, y:j*V+cntrY});
TweenLite.to(p, 2, {x:i*U, y:j*V});
}
}
//Fifteen();
Info2();
}
public function Fifteen():void {
var unFormat:TextFormat = new TextFormat();
var unTexte:TextField = new TextField();
unFormat.font = "Arial";
unFormat.size = 14;
unFormat.align = "center";
unFormat.color = 0xCCBBCC;
unTexte.defaultTextFormat = unFormat;
unTexte.x = 10;
unTexte.y = 300;
unTexte.selectable = false;
unTexte.multiline = true;
unTexte.background = false;
unTexte.border = false;
unTexte.type = "dynamic";
unTexte.text = "Nbr.Coups:";
addChild(unTexte);
// unTexte.x = 450;
// unTexte.y = 400;
// unTexte.text="SkyDro";
}
public function Info2():void {
var unFormat2:TextFormat = new TextFormat();
unFormat2.font = "Arial";
unFormat2.size = 14;
unFormat2.align = "center";
unFormat2.color = 0x333333;
var unTexte2:TextField = new TextField();
unTexte2.x = 100;
unTexte2.y = 300;
unTexte2.width = 15;
unTexte2.height = 20;
unTexte2.defaultTextFormat = unFormat2;
unTexte2.selectable = false;
unTexte2.multiline = true;
unTexte2.background = true;
unTexte2.border = false;
unTexte2.type = "dynamic";
unTexte2.text = String(count++);
addChild(unTexte2);
}
}
}
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
class Piece extends Sprite {
public var value:int;
public function Piece(value:int, w:int, h:int) {
this.value = value;
var fmt:TextFormat = new TextFormat();
fmt.font = "Courrier";
fmt.size = Math.min(w, h) * .8;
fmt.color= 0xBBBBBB;
var t:TextField = new TextField();
t.defaultTextFormat = fmt;
t.text = value < 16 ? String(value) : "[*]";
t.selectable = false;
addChild(t);
}
}