1/***************************************************************************
2* KBlocks, a falling blocks game for KDE *
3* Copyright (C) 2010 Zhongjie Cai <squall.leonhart.cai@gmail.com> *
4* *
5* This program is free software; you can redistribute it and/or modify *
6* it under the terms of the GNU General Public License as published by *
7* the Free Software Foundation; either version 2 of the License, or *
8* (at your option) any later version. *
9***************************************************************************/
10#include "KBlocksScore.h"
11
12KBlocksScore::KBlocksScore()
13{
14 mPoint = 0;
15 mLines = 0;
16 mLevel = 0;
17
18 mType = 0;
19 mLFactor = 0;
20 mSFactor = 0;
21}
22
23KBlocksScore::~KBlocksScore()
24{
25}
26
27int KBlocksScore::getScorePoint()
28{
29 return mPoint;
30}
31
32int KBlocksScore::getLineCount()
33{
34 return mLines;
35}
36
37int KBlocksScore::getGameLevel()
38{
39 return mLevel;
40}
41
42void KBlocksScore::setLevelUpFactor(int type, int factor)
43{
44 mType = type;
45 mLFactor = factor;
46}
47
48void KBlocksScore::setScoreUpFactor(int factor)
49{
50 mSFactor = factor;
51}
52
53bool KBlocksScore::addScore(int lines)
54{
55 mLines += lines;
56
57 switch(lines)
58 {
59 case 1:
60 mPoint += mSFactor;
61 break;
62 case 2:
63 mPoint += mSFactor * 3;
64 break;
65 case 3:
66 mPoint += mSFactor * 6;
67 break;
68 case 4:
69 mPoint += mSFactor * 10;
70 break;
71 default:
72 break;
73 }
74
75 int levelUpScore = 0;
76 switch(mType)
77 {
78 case KBlocksScore_Level_x_Factor:
79 levelUpScore = mLevel * mLFactor;
80 break;
81 case KBlocksScore_Level_x_Level_x_Factor:
82 levelUpScore = mLevel * mLevel * mLFactor;
83 break;
84 default:
85 levelUpScore = mLevel * mLFactor;
86 break;
87 }
88
89 if (mPoint >= levelUpScore)
90 {
91 mLevel++;
92 return true;
93 }
94
95 return false;
96}
97
98void KBlocksScore::clearScore()
99{
100 mPoint = 0;
101 mLines = 0;
102 mLevel = 0;
103}
104
105