~eda-qa/dhlib/main

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* <license>
 * This file is part of the dis-Emi-A HaXe Library. Copyright (c) edA-qa mort-ora-y
 * For full copyright and license information please refer to doc/license.txt.
 * </license> 
 */
package squix;

class Scoring
{
	var game : Game;

	public function new( game : Game )
	{
		this.game = game;
		
		game.addEventListener( GameEvent.SegmentCleared, onSegmentCleared );
		game.addEventListener( GameEvent.PuzzlePieceTaken, onPieceTaken );
		game.addEventListener( GameEvent.BonusCollected, onBonusCollected );
		game.addEventListener( GameEvent.NewLevel, onNewLevel );
		
		game.addEventListener( gamex.ObjectEvent.Removed, onObjectRemoved );
	}
	
	var bonusCollected : Int;
	function onNewLevel( ge : GameEvent )
	{
		bonusCollected = 0;
	}
	
	function onSegmentCleared( ge : GameEvent )
	{
		var base = Math.floor( ge.amountCleared * 1000 );
		game.score += base;
	}
	
	function onObjectRemoved( ge : gamex.ObjectEvent )
	{
		if( Std.is( ge.gameObject, EdgeMonster ) )
			game.score += 50;
	}
	
	function onPieceTaken( ge : GameEvent )
	{
		//TODO: know whether needed or not..., combine with any object taken
		game.score += 25;
	}
	
	public function onBonusCollected( ge : GameEvent )
	{
		game.score += 25;
		bonusCollected++;
	}
	
	public function surfaceBonus() : String
	{
		var bonus = Math.floor( game.surface.cleared * 100 ) * 10;
		game.score += bonus;
		return "Surface Bonus: " + Math.floor( game.surface.cleared * 100 ) + "%  × 10 = " + bonus;
	}
	
	public function puzzleBonus() : String
	{
		if( game.miniPuzzle == null )	
			return null;
			
		var p = game.miniPuzzle.getFilled();
		var bonus = p.num * 100;	// / p.of;
		game.score += bonus;
		return "Puzzle Bonus: " + p.num + " × 100 = " + bonus;
	}
	
	public function bonusBonus() : String
	{
		var bonus = bonusCollected * 250;
		game.score += bonus;
		return "Gift Bonus: " + bonusCollected + " × 250 = " + bonus;
	}
	
	function checkBonus( notice : Array<String>, func : Void -> String )
	{
		var b = func();
		if( b != null )
			notice.push( b );
	}
	
	public function giveEndLevelBonus() : Array<String>
	{
		var ret = new Array<String>();
		checkBonus( ret, surfaceBonus );
		checkBonus( ret, puzzleBonus );
		checkBonus( ret, bonusBonus );
		return ret;
	}
	
	public function checkBonusLife()
	{
		if( game.score >= game.nextLifeScore ) {
			game.nextLifeScore += game.global.extraLifePointDelta;
			game.numLives++;
			flashx.SoundManager.playSound( "extraLife" ); 
		}
		return true;
	}
}