Created
April 19, 2012 11:06
-
-
Save thomasjmwb/2420269 to your computer and use it in GitHub Desktop.
Score keeping class for microphone controlled game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package code { | |
import flash.events.Event; | |
import flash.net.SharedObject; | |
import flash.display.Sprite; | |
public class scoreManager extends Sprite{ | |
var gameScore:Number=0; | |
var highScore:Number; | |
var pointsPerFrame:Number=Math.floor(100/24);//points per second / frames per second | |
var newHighScore:Boolean; | |
var bossClass:gameManager; | |
var currentLevel:Number=1; | |
public function scoreManager(boss) { | |
//this class will manage the score, | |
bossClass=boss; | |
} | |
public function startScore() | |
{ | |
addEventListener(Event.ENTER_FRAME, increaseScore); | |
newHighScore=false; | |
getHighScore(); | |
} | |
private function increaseScore(e:Event) | |
{ | |
//increase score, fire while still alive | |
gameScore+=pointsPerFrame; | |
if(gameScore>highScore){highScore=gameScore;saveHighScore();newHighScore=true;} | |
//set score text | |
bossClass.scoreUI.scoretxt.text=String(gameScore); | |
} | |
private function getHighScore() | |
{ | |
//duh | |
var so:SharedObject = SharedObject.getLocal("BEEP_BOOP"); | |
if(so.data.highScore){highScore=so.data.highScore;} | |
else | |
{ | |
trace("no highscore saved"); | |
highScore=0; | |
} | |
bossClass.scoreUI.highscoretxt.text=String(highScore); | |
} | |
private function saveHighScore() | |
{ | |
//duh | |
var so:SharedObject = SharedObject.getLocal("BEEP_BOOP"); | |
//trace("overwriting "+so.data.highScore+" with "+gameScore); | |
so.data.highScore= gameScore; | |
so.flush(); // writes changes to disk | |
bossClass.scoreUI.highscoretxt.text=String(gameScore); | |
} | |
private function resetHighScore() | |
{ | |
var so:SharedObject = SharedObject.getLocal("BEEP_BOOP"); | |
so.data.highScore=null; | |
so.flush(); // writes changes to disk | |
} | |
public function gameOver():Object | |
{ | |
//this function will probably be used as so: | |
//var finalScore:Number=scoreManager.gameOver().score; | |
//var newHighScore:boolean=scoreManager.gameOver().newHighScore; | |
//showScoreScreen(finalScore); | |
var scoreObject:Object=new Object(); | |
scoreObject.score=gameScore; | |
scoreObject.highScore=newHighScore; | |
//stop increasing score | |
removeEventListener(Event.ENTER_FRAME, increaseScore); | |
return scoreObject; | |
newHighScore=false; | |
} | |
//the end is nii | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment