DesignPattern/21.StatePattern/2.Code/Level.cpp

155 lines
2.9 KiB
C++
Raw Normal View History

2019-11-09 02:41:43 +00:00
#include "Level.h"
/*********** Level *************/
Level::Level(){
}
void Level::playCard(){
this->play();
this->doubleScore();
this->changeCards();
this->peekCards();
}
void Level::play(){
2021-10-28 15:15:51 +00:00
printf("\t使用基本技能,");
2019-11-09 02:41:43 +00:00
}
void Level::setGameAccount(GameAccount* iGameAccount){
this->gameAccount = iGameAccount;
}
GameAccount* Level::getGameAccount(){
return gameAccount;
}
/*********** Primary *************/
Primary::Primary(){
}
Primary::Primary(GameAccount* iGameAccount){
this->setGameAccount(iGameAccount);
}
Primary::Primary(Level* level){
getGameAccount()->setLevel(level);
}
void Primary::doubleScore(){
return;
}
void Primary::changeCards(){
return;
}
void Primary::peekCards(){
return;
}
void Primary::upgradeLevel(){
if (this->getGameAccount()->getScore() > 150){
this->getGameAccount()->setLevel(new Secondary(this));
2021-10-28 15:15:51 +00:00
printf("\t升级! 级别SECONDARY\n\n");
2019-11-09 02:41:43 +00:00
}
else{
printf("\n");
}
}
/*********** Secondary *************/
Secondary::Secondary(){
}
Secondary::Secondary(Level* level){
this->setGameAccount(level->getGameAccount());
}
void Secondary::doubleScore(){
2021-10-28 15:15:51 +00:00
printf("使用胜利双倍积分技能");
2019-11-09 02:41:43 +00:00
}
void Secondary::changeCards(){
return;
}
void Secondary::peekCards(){
return;
}
void Secondary::upgradeLevel(){
if (this->getGameAccount()->getScore() < 150){
this->getGameAccount()->setLevel(new Primary(this));
2021-10-28 15:15:51 +00:00
printf("\t降级! 级别PRIMARY\n\n");
2019-11-09 02:41:43 +00:00
}
else if (this->getGameAccount()->getScore() > 200){
this->getGameAccount()->setLevel(new Professional(this));
2021-10-28 15:15:51 +00:00
printf("\t升级! 级别PROFESSIONAL\n\n");
2019-11-09 02:41:43 +00:00
}
}
/*********** Professional *************/
Professional::Professional(){
}
Professional::Professional(Level* level){
this->setGameAccount(level->getGameAccount());
}
void Professional::doubleScore(){
2021-10-28 15:15:51 +00:00
printf("使用胜利双倍积分技能,");
2019-11-09 02:41:43 +00:00
}
void Professional::changeCards(){
2021-10-28 15:15:51 +00:00
printf("使用换牌技能");
2019-11-09 02:41:43 +00:00
}
void Professional::peekCards(){
return;
}
void Professional::upgradeLevel(){
if (this->getGameAccount()->getScore() < 200){
this->getGameAccount()->setLevel(new Secondary(this));
2021-10-28 15:15:51 +00:00
printf("\t降级! 级别SECONDARY\n\n");
2019-11-09 02:41:43 +00:00
}
else if (this->getGameAccount()->getScore() > 250){
this->getGameAccount()->setLevel(new Final(this));
2021-10-28 15:15:51 +00:00
printf("\t升级! 级别FINAL\n\n");
2019-11-09 02:41:43 +00:00
}
}
/*********** Final *************/
Final::Final(){
}
Final::Final(Level* level){
this->setGameAccount(level->getGameAccount());
}
void Final::doubleScore(){
2021-10-28 15:15:51 +00:00
printf("使用胜利双倍积分技能,");
2019-11-09 02:41:43 +00:00
}
void Final::changeCards(){
2021-10-28 15:15:51 +00:00
printf("使用换牌技能,");
2019-11-09 02:41:43 +00:00
}
void Final::peekCards(){
2021-10-28 15:15:51 +00:00
printf("使用偷看卡牌技能");
2019-11-09 02:41:43 +00:00
}
void Final::upgradeLevel(){
if (this->getGameAccount()->getScore() < 250){
this->getGameAccount()->setLevel(new Professional(this));
2021-10-28 15:15:51 +00:00
printf("\t降级! 级别PROFESSIONAL\n\n");
2019-11-09 02:41:43 +00:00
}
else{
2021-10-28 15:15:51 +00:00
printf("\t%s 已经是最高级\n\n", this->getGameAccount()->getName().c_str());
2019-11-09 02:41:43 +00:00
}
}