Multimedia Blog

Research, Design & Reflection


Dart Scoring Application So Far...

TO SCORE FOR EACH PLAYER YOU MUST SELECT THE PLAYER FIRST




I had some problems, so I'll list them below with the solution I used. I'm pretty sure I have wrote a few bits of bad code and my script is like 1000 lines long when I'm guessing it could be done with a lot less code but it works and I learnt it all from a really bad book.

1)I named my functions for the subtraction of the scores 'minus40', 'minus10' etc. before I realised that there are some values on the board that get used more than once and I had duplicated function names.

2)I wanted it to score for 2 players and be able to toggle between each player whenever I liked. So I used the following code to say that if one was on the 2nd frame of the movie the other must move to the first.

//Player Selection

player1.addEventListener(MouseEvent.CLICK, selectPlayer1)
player2.addEventListener(MouseEvent.CLICK, selectPlayer2)

function selectPlayer1(e:MouseEvent){
player1.gotoAndStop(2);
player2.gotoAndStop(1);
}

function selectPlayer2(e:MouseEvent){
player2.gotoAndStop(2);
player1.gotoAndStop(1);
}


I controlled the scorer within each function so that depending on which frame the player movie clips and the text boxes (that were also movie clips) were on effected which variables to apply the score changes to. Here's an example for a double (the only sections that you can win the game on). This enables the scorer to recognise if the player busts, wins or whether the game should go on as normal.

function twenty40(e:MouseEvent){
if (player1.currentFrame==2){
score=score-40; score_output.text=score;}
else if (player2.currentFrame==2){
score2=score2-40; score_output2.text=score2;}
if (score2=="0" && player2.currentFrame==2) {text_output2.gotoAndStop(2);}
if (score=="0" && player1.currentFrame==2) {text_output.gotoAndStop(2);}
if (score2<0 && player2.currentFrame==2) {text_output2.gotoAndStop(3);}
if (score<0 && player1.currentFrame==2) {text_output.gotoAndStop(3);}
}


Since I coded this I have come across the 'switch' statement that uses 'cases' to declare conditions but to be honest it would be a lot of effort to change it all now.

IMPROVEMENTS

I would like to make a preloader and allow the user to input their names before they begin. Obviously I want to improve the look of it as well but my focus is on the actionscript for now. I'll probably be updating this soon with the improved version.

Labels:

0 Responses to “Dart Scoring Application So Far...”

Post a Comment



© 2006 Multimedia Blog