actionscript 3 - AS3 Check if movieclips inside array are all the same color -


i've created simple puzzle game , have uploaded kongregate, want upload highscores (the least amount of moves = better) using api. make sure no 1 can cheat system (submitting score before puzzle finished) need make sure none of pieces in puzzle black. pieces of puzzle movieclips , inside array called buttons.

i've got this:

    public function sumbitscore(e:mouseevent)     {         (var v:int = 0; v < buttons.length; v++)         {             if (buttons[v].transform.colortransform.color != 0x000000)             {                 _root.kongregatescores.submit(1000);             }         }     } 

but think submit score checks movieclip not black , it'll ignore rest.

i think way go keep track of whether or not 'empty button' found in for-loop. after loop submit score if no empty tiles found or let player know puzzle has completed before submitting.

i've added comments in code below:

// (i changed function name 'sumbitscore' 'submitscore') public function submitscore(e:mouseevent) {     // use boolean variable store whether or not empty button found.     var foundemptybutton : boolean = false;     (var v:int = 0; v < buttons.length; v++)     {         // check whether current button black         if (buttons[v].transform.colortransform.color == 0x000000)         {             // if button empty, 'foundemptybutton' variable updated true.             foundemptybutton = true;             // break out of for-loop don't need check if there other buttons still empty.             break;         }     }     if(foundemptybutton == false)     {         // send score kongregate api         _root.kongregatescores.submit(1000);     }     else     {         // i'd suggest let player know should first complete puzzle     } } 

alternatively let player know how many buttons still has finish:

public function submitscore(e:mouseevent) {     // use int variable keep track of how many empty buttons found     var emptybuttons : uint = 0;     (var v:int = 0; v < buttons.length; v++)     {         // check whether current button black         if (buttons[v].transform.colortransform.color == 0x000000)         {             // if button empty increment emptybuttons variable             emptybuttons++;             // , don't break out of loop here you'd want keep counting         }     }     if(emptybuttons == 0)     {         // send score kongregate api         _root.kongregatescores.submit(1000);     }     else     {         // let player know there still 'emptybuttons' buttons finish before or can submit highscore     } } 

hope it's clear.

good luck!


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -