Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 1.0/2.0 (http://www.flasher.ru/forum/forumdisplay.php?f=93)
-   -   Пятнашки (http://www.flasher.ru/forum/showthread.php?t=96670)

VladBD 04.06.2007 17:26

Пятнашки
 
начал по мере чтения книг, писать пятнахи...
в исходнике пометил !!! - там не выводит значения, как надо написать
загрузка файла неудалась в любом формате, так что вот код
Код:

_root.createEmptyMovieClip("f15th", 0);
//init f15th
f15th.init = function (i,j) {
  //создаем массив random
  var arr = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
  //создаем cell's
  for (x=0;x<=3;x++) {
    for (y=1;y<=4;y++) {
          this.createTextField("cell"+x*4+y,this.getNextHighestDepth(),0,0,i,i);
            var tf=this["cell"+x*4+y];
      tf.text="";
      tf._x=(y-1)*i+y*j;
          tf._y=(x*i+(x+1)*j)+13;
          tf.selectable=false;
      var tf_fmt:TextFormat = new TextFormat();
          tf_fmt.font = "Times New Roman"
          tf_fmt.size = 36;
          tf_fmt.color = 0x000000;
          tf_fmt.align = "center";
      tf.setTextFormat(tf_fmt);
        }
  }
}

//создаем сетку       
f15th.drawgrid = function (i,j) {
  this.lineStyle(j, 0x000000, 100);
  for (var n=0; n<=4; n++) {
    this.moveTo(0,n*i+j*n);
    this.lineTo(i*4+j*4,n*i+j*n);
        this.moveTo(n*i+j*n,0);
    this.lineTo(n*i+j*n, i*4+j*4);
  }
  //!!!
  for (var n=1; n<=16; n++) {
    this["cell"+n].text=n;
  } 
}

f15th.init(75,2);
f15th.drawgrid(75,2);


iNils 04.06.2007 17:33

Готовые 15-ки
Код:

this.lineStyle (0, 0, 0);
this.beginFill (0x666666);
this.moveTo (10, 10);
this.lineTo (140, 10);
this.lineTo (140, 140);
this.lineTo (10, 140);
this.lineTo (10, 10);
this.endFill ();
/*******************************************************************/
f = new TextFormat ("Verdana", 13, 0xFF6600, true);
f.align = "center";
/*******************************************************************/
init = function () {
        a = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]];
        v = [[0,-1],[0,1],[-1,0],[1,0]]
        x = 3;
        y = 3;
        for (p = 1; p < 200;){
                r = random (4);
                i = x + v[r][0];
                j = y + v[r][1];
                if (a[i][j] and a[i][j]!= o) {
                        o = a[i][j];
                        a[i][j] = a[x][y];
                        a[x][y] = o;
                        x = i;
                        y = j;
                        p++;
                }
        }
        v = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]];
        p = [[],[],[],[]];
        for (i = 0; i < 4; i++) {
                for (j = 0; j < 4; j++) {
                        p[i][j] = a[i][j];
                        if (a[i][j] != 0) {
                                createEmptyMovieClip ("m" + p[i][j], p[i][j]);
                                this["m" + p[i][j]].lineStyle (0, 0, 0);
                                this["m" + p[i][j]].beginFill (0x333333);
                                this["m" + p[i][j]].lineTo (30, 0);
                                this["m" + p[i][j]].lineTo (30, 30);
                                this["m" + p[i][j]].lineTo (0, 30);
                                this["m" + p[i][j]].lineTo (0, 0);
                                this["m" + p[i][j]].endFill ();
                                this["m" + p[i][j]].createTextField ("t", 0, 0, 3, 30, 30);
                                this["m" + p[i][j]].t.setNewTextFormat (f);
                                this["m" + p[i][j]].t.text = p[i][j];
                                this["m" + p[i][j]].i = i;
                                this["m" + p[i][j]].j = j;
                                this["m" + p[i][j]]._y = i * 32 + 12;
                                this["m" + p[i][j]]._x = j * 32 + 12;
                                this["m" + p[i][j]].onRelease = function () {
                                        if (p[this.i][this.j - 1] == 0) {
                                                this._x -= 32;
                                                o = p[this.i][this.j - 1];
                                                p[this.i][this.j - 1] = p[this.i][this.j];
                                                p[this.i][this.j] = o;
                                                this.j--;
                                        } else if (p[this.i][this.j + 1] == 0) {
                                                this._x += 32;
                                                o = p[this.i][this.j + 1];
                                                p[this.i][this.j + 1] = p[this.i][this.j];
                                                p[this.i][this.j] = o;
                                                this.j++;
                                        } else if (p[this.i - 1][this.j] == 0) {
                                                this._y -= 32;
                                                o = p[this.i - 1][this.j];
                                                p[this.i - 1][this.j] = p[this.i][this.j];
                                                p[this.i][this.j] = o;
                                                this.i--;
                                        } else if (p[this.i + 1][this.j] == 0) {
                                                this._y += 32;
                                                o = p[this.i + 1][this.j];
                                                p[this.i + 1][this.j] = p[this.i][this.j];
                                                p[this.i][this.j] = o;
                                                this.i++;
                                        }
                                        if (p.toString () == v.toString ()) {
                                                for (i = 0; i < 16; i++) {
                                                        _root["m" + i].removeMovieClip ();
                                                }
                                                _root.createTextField ("t", 100, 0, 60, 150, 25);
                                                _root.t.setNewTextFormat (f);
                                                _root.t.selectable = false;
                                                _root.t.text = "WIN";
                                                _root.onMouseUp = function () {
                                                        delete _root.onMouseUp;
                                                        _root.init ();
                                                };
                                        }
                                }
                        }
                }
        }
};
init ();


VladBD 04.06.2007 17:44

Спасибо. Буду разбираться. Тема закрыта


Часовой пояс GMT +4, время: 09:56.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.