2019-11-09 02:41:43 +00:00
|
|
|
|
#include "GameAccount.h"
|
|
|
|
|
#include "Level.h"
|
2023-08-26 08:44:30 +00:00
|
|
|
|
// #include <Windows.h>
|
2019-11-09 02:41:43 +00:00
|
|
|
|
#include <time.h>
|
|
|
|
|
#define random(x) (rand()%x)
|
|
|
|
|
|
|
|
|
|
GameAccount::GameAccount(){
|
2021-10-28 15:15:51 +00:00
|
|
|
|
level = nullptr;
|
|
|
|
|
printf("创立游戏角色,积分:100,级别:PRIMARY\n");
|
2019-11-09 02:41:43 +00:00
|
|
|
|
score = 100;
|
|
|
|
|
name = "none";
|
|
|
|
|
setLevel(new Primary(this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GameAccount::GameAccount(string iName){
|
2021-10-28 15:15:51 +00:00
|
|
|
|
level = nullptr;
|
|
|
|
|
printf("创立游戏角色,积分:100,级别:PRIMARY\n");
|
2019-11-09 02:41:43 +00:00
|
|
|
|
score = 100;
|
|
|
|
|
name = iName;
|
|
|
|
|
setLevel(new Primary(this));
|
|
|
|
|
}
|
2022-10-16 10:09:39 +00:00
|
|
|
|
GameAccount::~GameAccount(){
|
|
|
|
|
if(level){
|
|
|
|
|
delete level;
|
|
|
|
|
level = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-09 02:41:43 +00:00
|
|
|
|
void GameAccount::setLevel(Level* iLevel){
|
2021-10-28 15:15:51 +00:00
|
|
|
|
if(level != nullptr){
|
|
|
|
|
delete level;
|
|
|
|
|
level = nullptr;
|
|
|
|
|
}
|
2019-11-09 02:41:43 +00:00
|
|
|
|
this->level = iLevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string GameAccount::getName(){
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameAccount::playCard(){
|
|
|
|
|
this->level->playCard();
|
|
|
|
|
|
2023-08-26 08:44:30 +00:00
|
|
|
|
// Sleep(100);
|
2019-11-09 02:41:43 +00:00
|
|
|
|
srand((int)time(0));
|
|
|
|
|
int res = random(2);
|
|
|
|
|
if (res % 2 == 0){
|
|
|
|
|
this->win();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
this->lose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->level->upgradeLevel();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-16 10:09:39 +00:00
|
|
|
|
|
2019-11-09 02:41:43 +00:00
|
|
|
|
void GameAccount::win(){
|
|
|
|
|
if (this->getScore() < 200){
|
|
|
|
|
setScore(getScore() + 50);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
setScore(getScore() + 100);
|
|
|
|
|
}
|
2021-10-28 15:15:51 +00:00
|
|
|
|
printf("\n\t胜利,最新积分为 %d\n", score);
|
2019-11-09 02:41:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameAccount::lose(){
|
|
|
|
|
setScore(getScore() + 30);
|
2021-10-28 15:15:51 +00:00
|
|
|
|
printf("\n\t输牌,最新积分为 %d\n", score);
|
2019-11-09 02:41:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GameAccount::getScore(){
|
|
|
|
|
return this->score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameAccount::setScore(int iScore){
|
|
|
|
|
this->score = iScore;
|
|
|
|
|
}
|