Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

Flash shooting game question

Hi,
I am making this shoot game that shooting number does not match with the shooting objects or sometimes the number shows NaN.

For this game, first, there are two layers, Scores and balls. In the scores layers, there is script for the generate problem and control the red cross. In the balls layer, it has script for the balls's random number and control them to move from right to left and left to right.

So, How these two part script part work ? First, score layer script generate problem then send the "answer" ( script line 3 to 16 ) to the balls' layer script then ball's script will generate a same answer number on one of these 18 balls.

Then the red cross should move when the mouse arrow movie within the shooting area ( left = -398 right = -11 top = -253 bottom = 56 ). Then the red corss will follow the mouse arrow within these area. And when click on mouse, the white ball will shoot out and hit the orange ball... then if it is right answer, orange ball will be gone and scroe layers script will generate a new problem then whole game will continue......

Any suggestions ? thanks  download demo @ http://www.brianlinstudio.com/question/shooting_game.zip
0
Brian Lin
Asked:
Brian Lin
  • 8
  • 6
  • 3
  • +1
2 Solutions
 
Duncan54XCommented:
Hello mingchih,
I don't quite understand what the game is about, I read most of the code and I assume you need to find the answer in the ducks. Now the problem is that when I look in the code, I see you
- create an answer array
- look into it to see if the answer is there
 - then if not, you create it again, that just doens't make sense to me. Am I missing something?

Why do you want to create an answer array if you delete it entirely just to create it again? What's the function of it?

From my humble point of view, if you have two number arrays and select numbers from them to propose the problem then you don't need to re-create the values.

ie:
myArray_A, myArray_B

get random values for myArray_A and B
copy myArray_B to duckArray
pick a random number from myArray_A
pick a random number from myArray_B
check if substracting A-B is greater than 0 (if you don't want negative values)
put the resulting number and myArray_A into the textboxes
and perform the "shoot" check when user click.

that is what i'd do.

Let me know and good luck!

Cërf.
0
 
Duncan54XCommented:
sorry, my friends account...
0
 
CerfCommented:
This is my account...

Cërf.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Brian LinDesignerAuthor Commented:
yeah, this game is just about find answer on ducks ( balls ) and shoot the answer.....
0
 
CerfCommented:
So, what do you think of my idea?
Do you want to implement it?
I'm open to help you with any doubts you might have.

That's what we are hewre for, huh?

Cërf.
0
 
BillystyxCommented:
This is what I would do, get rid of all your other number gereating code and add this:

generate();
function generate(){
      whichNum=random(this._parent.ducks_mc.duckNumbers.length);
      answer=this._parent.ducks_mc.duckNumbers[whichNum];
      eq1=random(70);
      eq2=eq1-answer;
      if(eq2<0){
            eq2=Math.abs(eq2);
            trace(eq1+"+ "+eq2+"="+answer);
            sign="+";
      }else{
            trace(eq1+"- "+eq2+"="+answer);
            sign="-";
      }
b=eq2;
a=eq1;
c=answer;
}

Billystyx
0
 
Brian LinDesignerAuthor Commented:
Can I ask.... can I just make question to always show minus sign ?
0
 
BillystyxCommented:
generate();
function generate(){
      whichNum=random(this._parent.ducks_mc.duckNumbers.length);
      answer=this._parent.ducks_mc.duckNumbers[whichNum];
      eq1=random(70);
      eq2=eq1-answer;
      if(eq2<0){
            //eq2=Math.abs(eq2);
            //trace(eq1+"+ "+eq2+"="+answer);
            //sign="+";
            generate();
      }else{
            trace(eq1+"- "+eq2+"="+answer);
            sign="-";
      }
b=eq2;
a=eq1;
c=answer;
}

just remove those lines I have comented out and replace them with a call to the function again.

Billystyx
0
 
CerfCommented:
Really nice code Billystyx!

Have a good one,

Cërf.
0
 
BillystyxCommented:
thanks:)
Billystyx
0
 
Brian LinDesignerAuthor Commented:
thanks:) Billystyx

Brian
0
 
BillystyxCommented:
no worries!
0
 
Brian LinDesignerAuthor Commented:
hi, Billystyx
I would like to ask, if I want to have two level of game.... first level "question" number range from 0 to 20 ( ex. 1-1 ~ 20-20 ) and second level "question" number range from 20 to 60 ( 20 -20 ~ 60 - 60 ). If I pass the 1st level and should go to the second level.... How can I do that ? thanks
0
 
BillystyxCommented:
You would need to set varaibles startpt and endpt on the _root for example, depending on level.
Then just access them in the function (where I have commented below), instead of using numbers, use those variables

generate();
function generate(){
      whichNum=random(this._parent.ducks_mc.duckNumbers.length);
      answer=this._parent.ducks_mc.duckNumbers[whichNum];
      Rand=[];
      for(i=20;i<41;i++){//these variables you would set depending on level
//like startpt=20;endpt=41, and then inside the for loop there
//you would do for(i=_root.startpt;i<_root.endpt;i++){
            Rand.push(i);
      }
      eq1=random(Rand.length);
      eq1=Rand[eq1];
      eq2=eq1-answer;
      if(eq2<0){
            //eq2=Math.abs(eq2);
            //trace(eq1+"+ "+eq2+"="+answer);
            //sign="+";
            generate();
      }else{
            trace(eq1+"- "+eq2+"="+answer);
            sign="-";
      }
b=eq2;
a=eq1;
c=answer;
}

Billystyx
0
 
Brian LinDesignerAuthor Commented:
so, I put for(i=_root.startpt;i<_root.endpt;i++){  within the ducks ( balls ) area ?
0
 
Brian LinDesignerAuthor Commented:
thanks for your last post....I would like to ask if I did right or not.....

I change from............
//give balls random number
for ( var i = 0; i < 18; i ++ ) {
    var n = random( 50 )
    this[ "duck_" + i ].num_txt.text = n;
    this[ "duck_" + i ].num = n;
    duckNumbers[i] = n;
}

to script like this ?
//give balls random number
for(i=_root.startpt;i<_root.endpt;i++){
    var n = random( 50 )
    this[ "duck_" + i ].num_txt.text = n;
    this[ "duck_" + i ].num = n;
    duckNumbers[i] = n;
}

After I change it, I got the trace shows "19- NaN=undefined"....

Did I change the wrong place ?

thanks

Brian
0
 
Brian LinDesignerAuthor Commented:
Also, Can I make ball's number generate different random numbers after got hit each time ?
0
 
BillystyxCommented:
hello, just posted a response to your new question (as above), but when I sent it was deleted...
anyway, like this:

_root.startpt=20;
_root.endpt=61;
var invisible;
generate();
function generate(){
      whichNum=random(this._parent.ducks_mc.duckNumbers.length);
      answer=this._parent.ducks_mc.duckNumbers[whichNum];
      Rand=[];
      for(i=_root.startpt;i<_root.endpt;i++){
            Rand.push(i);
      }
      eq1=random(Rand.length);
      eq1=Rand[eq1];
      eq2=eq1-answer;
      if(eq2<0){
            
            generate();
      }else{
            trace(eq1+"- "+eq2+"="+answer);
            sign="-";
      }
b=eq2;
a=eq1;
c=answer;
}
Hope that helps:)
0
 
Brian LinDesignerAuthor Commented:
hi,
thanks...I can see why it is not working..... Can I also ask, sometimes answer does not show up on the balls ( maybe 1 in 9 times ). How to fix that problem ? I think is it possible to generate new numbers when ball reach the end on each rows. and have answer among the new generate radom numbers.... also, about that new questions....I try to move the generate random number scripting from ball to shooting.....it is a big mass....maybe you can take a look @ http://www.brianlinstudio.com/question/numberQ4.fla.zip 

thanks

Biran


Below is the question I delete -------
I have this games that question numbers show NaN and undefined. Also, It does not show random number on balls. I think it is the problem with "function generate()" under "scorekeeper" movie clip. I need different random numbers on balls after shoot each time. Also, there should be a new generate number for question. Answer needs to match one of number on orange ball..... Demo can download @ http://www.brianlinstudio.com/question/numberQ4.fla.zip thanks for any suggestions :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 8
  • 6
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now