[HAXE] - Initialisation des variables
Bonjour,
voila un bout d'un programme pour tester un peu le langage... il se compile mais bug sans "raison apparente".
Il s'agit d'un bout de code d'un jeu de morpion ( je sais pas très original ;) mais c'est du test :D)
l'erreur est la ligne en rouge.
en effet le programme ne s'execute plus au delà de cette ligne (une fois le commentaire retiré)
quelqu'un aurait il une idée de pourquoi ??
2ème question : quelqu'un saurait il comment fonctionne les pointeurs en HAXE (syntaxe, ...)
Voila le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| import flash.Lib;
import flash.events.MouseEvent;
import flash.display.MovieClip;
class Morpion {
private var _root : MovieClip;
private var _mainbg : MovieClip;
// Main loop
public static function main():Void {
new Morpion(flash.Lib.current);
}
public function new(parent:MovieClip):Void {
this._root = parent;
this._mainbg = new MovieClip();
var bx:Int = 35;var by:Int = 35;
var ca:Array<Array<Cell>>;
// mainbg
this._mainbg.graphics.beginFill(255, 1);
this._mainbg.graphics.drawRect(bx, by, 152, 152);
this._mainbg.graphics.endFill();
this._root.addChild(this._mainbg);
for (i in 0...3){
for (j in 0...3) {
var nx:Int = bx+50*i;
var ny:Int = by+50*j;
var nc:Cell = new Cell(nx,ny,this._mainbg) ;
//ca[i][j] = nc ;
}
}
}
}
class Cell {
private var _mpcase : MovieClip;
private var _redCross : MovieClip;
private var _blueCross : MovieClip;
public var id : String ;
public var curpos_x :Float ;
public var curpos_y :Float ;
public var cellSize:Int ;
public var crossSize:Int ;
public function new(sx:Int,sy:Int,parent:MovieClip):Void {
this.cellSize = 49 ;
this.crossSize = 15 ;
this._mpcase = new MovieClip();
this._mpcase.graphics.beginFill(0xFFFFFF, 1);
this._mpcase.graphics.drawRect(sx, sy, this.cellSize, this.cellSize);
this._mpcase.graphics.endFill();
this.curpos_x = sx+this.cellSize/2-this.crossSize/2 ;
this.curpos_y = sy+this.cellSize/2-this.crossSize/2 ;
this._mpcase.addEventListener(MouseEvent.CLICK, checkCell);
parent.addChild(this._mpcase);
}
public function checkCell(curEvt:MouseEvent){
this._redCross = new MovieClip();
// redCross
this._redCross.graphics.beginFill(0xFF0000, 1);
this._redCross.graphics.moveTo(this.curpos_x,this.curpos_y);
this._redCross.graphics.lineTo(this.curpos_x,this.curpos_y);
this._redCross.graphics.lineTo(this.curpos_x+this.crossSize,this.curpos_y+this.crossSize);
this._redCross.graphics.lineTo(this.curpos_x,this.curpos_y+this.crossSize);
this._redCross.graphics.lineTo(this.curpos_x+this.crossSize,this.curpos_y);
this._redCross.graphics.endFill();
this._mpcase.addChild(this._redCross);
}
} |
merci d'avance.
:D