Zurück   Flashforum > Flash > ActionScript > Softwarearchitektur und Entwurfsmuster

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 20-03-2005, 14:34   #1 (permalink)
rekursiv definiert
 
Benutzerbild von minimal-ist
 
Registriert seit: Feb 2002
Ort: trier
Beiträge: 1.137
simon says in 140 zeilen

habe aus langeweile mal wieder etwas an meinem senso / simon says spiel gebastelt und als 'abfallprodukt' ist eine geskriptet variante entstanden.
den folgenden code einfach in den ersten frame und fettisch.

da ich nicht viel mit flash arbeite habe ich etwas den ueberblick verloren was nun as1 und was as2 syntax ist ... wenn also jemand langeweile hat kann er den source ja mal ins reine schreiben

also: ansehen
und code:
ActionScript:
  1. stop();
  2. /*******************************************************************************/
  3. /****************************MAIN GAME FUNCTIONS*********************************/
  4. _global.nxtColor;   
  5. _global.ptsCount;
  6. _global.speed = 2;
  7. _global.setAllVisible = new Boolean(false);
  8. _global.butt_enabler = new Boolean(true);
  9. _global.gameInProgress = new Boolean();
  10. _global.com_array = new Array();                //saves computers choice
  11. _global.usr_array = new Array();                //saves players choice
  12. /*************************/
  13. function initGame() {
  14.     gameInProgress = true;
  15.     ptsCount = -1;
  16.     nxtColor = -1;
  17.     com_array = new Array();
  18.     usr_array = new Array();
  19.     setAllVisible = false;
  20.     /*****start game*****/
  21.     mainGame();
  22. }
  23. /*******************************************************************************/
  24. function mainGame() {
  25.     butt_enabler = false;               //disable buttons
  26.     /*computer choice:*/
  27.     var newColor = random(9);
  28.     var i = 0;
  29.     if (com_array.length>0) {
  30.         setAllVisible = false;
  31.     }
  32.     // avoid colour double choice
  33.     while (newColor == lastColor) {
  34.         newColor = random(8);
  35.     }
  36.     com_array.push(newColor);
  37.     function showComputerChoice() {
  38.         if (i<com_array.length) {
  39.             i++;
  40.             nxtColor = com_array[i-1];
  41.         } else {
  42.             clearInterval(count);
  43.             setAllVisible = true;
  44.             i = 0;
  45.             usr_array.splice(0);
  46.             lastColor = nxtColor;
  47.             //preventing colour 'afterburning'
  48.             delete nxtColor;
  49.             butt_enabler = true;            //enable buttons again
  50.         }
  51.     }
  52.     var count = setInterval(showComputerChoice, 700-(speed*100));
  53. }
  54. /*******************************************************************************/
  55. MovieClip.prototype.butt_action = function() {
  56.     if (butt_enabler) {
  57.         nextUsrChoice = this._name;
  58.         usr_array.push(nextUsrChoice);
  59.         ptsCount = ptsCount+usr_array.length;
  60.         if (usr_array[usr_array.length-1] != com_array[usr_array.length-1]) {
  61.             butt_enabler = false;
  62.             gameInProgress = false;
  63.             setAllVisible = false;
  64.             return;
  65.         }
  66.         if (usr_array.length == com_array.length) {
  67.             mainGame();
  68.         }
  69.     }
  70. };
  71. /*******************************************************************************/
  72. MovieClip.prototype.butt_behave = function() {
  73.     if (this._alpha<=100) {
  74.         if (nxtColor == this._name || setAllVisible == true) {
  75.             this._alpha += 25;
  76.         }
  77.     }
  78.     if (this._alpha>=0) {
  79.         if (setAllVisible != true) {
  80.             if (nxtColor != this._name) {
  81.                 this._alpha -= 25;
  82.             }
  83.         }
  84.     }
  85. };
  86. /*******************************************************************************/
  87. /****************************CREATE PLAYGROUND***********************************/
  88. _global.numbers = new Boolean(true);
  89. _global.design = new Array("0xCC3300", "0x336666", "0x000099", "0xFFCC00", "0x996699", "0xFF9900", "0x993300", "0x3399FF", "0xFF6699");
  90. function generatePlayground(design:Array, num:Boolean) {
  91.     //trace("generatePlayground called!");
  92.     _root.createEmptyMovieClip("playground", 10);
  93.     var x = 0;
  94.     var y = 0;
  95.     for (var i = 1; i<10; i++) {
  96.         var buttonName = i-1;
  97.         playground.createEmptyMovieClip(buttonName, i);
  98.         playground[""+buttonName]._name = buttonName;
  99.         playground[""+buttonName]._x = x;
  100.         x += 70;
  101.         playground[""+buttonName]._y = y;
  102.         if (i%3 == 0) {
  103.             y += 70;
  104.             x = 0;
  105.         }
  106.         drawRect(playground[""+buttonName], 50, design[i-1]);
  107.         playground[""+buttonName].onEnterFrame = butt_behave;
  108.         playground[""+buttonName].onRelease = butt_action;
  109.     }
  110. }
  111. function drawRect(mc:MovieClip, size:Number, color) {
  112.     mc.beginFill(color);
  113.     mc.lineTo(size, 0);
  114.     mc.lineTo(size, size);
  115.     mc.lineTo(0, size);
  116.     mc.lineTo(0, 0);
  117.     mc.endFill();
  118. }
  119. generatePlayground(design, true);
  120. /*******************************************************************************/
  121. /****************************CREATE STARTBUTTON*********************************/
  122. _global.txtFormat = new TextFormat();
  123. txtFormat.color = 0xff0000;
  124. txtFormat.font = "verdana";
  125. txtFormat.size = 10;
  126. /*******************************************************************************/
  127. function createStartButton() {
  128.     _root.createEmptyMovieClip("startButton", 11);
  129.     startButton._x = 200;
  130.     startButton._y = 0;
  131.     startButton.createTextField("label_txt",12,2,3,20,20);
  132.     startButton.label_txt.setNewTextFormat(txtFormat);
  133.     startButton.label_txt.text = "GO";
  134.     drawRect(startButton, 25, "0xCC3300");
  135.     startButton.onRelease = initGame;
  136. }
  137. createStartButton();
__________________

optimismus ist nur ein mangel an information!

minimal-ist.de: my little piece of the world wide web
iTouch ...train your brain!

Geändert von minimal-ist (20-03-2005 um 14:44 Uhr)
minimal-ist ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 15:43 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele