File indexing completed on 2024-05-05 04:02:31
0001 /*************************************************************************** 0002 * KBlocks, a falling blocks game by KDE * 0003 * SPDX-FileCopyrightText: 2010 Zhongjie Cai <squall.leonhart.cai@gmail.com> * 0004 * * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 ***************************************************************************/ 0007 #include "KBlocksScore.h" 0008 0009 KBlocksScore::KBlocksScore() 0010 { 0011 mPoint = 0; 0012 mLines = 0; 0013 mLevel = 0; 0014 0015 mType = 0; 0016 mLFactor = 0; 0017 mSFactor = 0; 0018 } 0019 0020 KBlocksScore::~KBlocksScore() 0021 { 0022 } 0023 0024 int KBlocksScore::getScorePoint() 0025 { 0026 return mPoint; 0027 } 0028 0029 int KBlocksScore::getLineCount() 0030 { 0031 return mLines; 0032 } 0033 0034 int KBlocksScore::getGameLevel() 0035 { 0036 return mLevel; 0037 } 0038 0039 void KBlocksScore::setLevelUpFactor(int type, int factor) 0040 { 0041 mType = type; 0042 mLFactor = factor; 0043 } 0044 0045 void KBlocksScore::setScoreUpFactor(int factor) 0046 { 0047 mSFactor = factor; 0048 } 0049 0050 bool KBlocksScore::addScore(int lines) 0051 { 0052 mLines += lines; 0053 0054 switch (lines) { 0055 case 1: 0056 mPoint += mSFactor; 0057 break; 0058 case 2: 0059 mPoint += mSFactor * 3; 0060 break; 0061 case 3: 0062 mPoint += mSFactor * 6; 0063 break; 0064 case 4: 0065 mPoint += mSFactor * 10; 0066 break; 0067 default: 0068 break; 0069 } 0070 0071 int levelUpScore = 0; 0072 switch (mType) { 0073 case KBlocksScore_Level_x_Factor: 0074 levelUpScore = mLevel * mLFactor; 0075 break; 0076 case KBlocksScore_Level_x_Level_x_Factor: 0077 levelUpScore = mLevel * mLevel * mLFactor; 0078 break; 0079 default: 0080 levelUpScore = mLevel * mLFactor; 0081 break; 0082 } 0083 0084 if (mPoint >= levelUpScore) { 0085 mLevel++; 0086 return true; 0087 } 0088 0089 return false; 0090 } 0091 0092 void KBlocksScore::clearScore() 0093 { 0094 mPoint = 0; 0095 mLines = 0; 0096 mLevel = 0; 0097 } 0098