#include "MinerOwnedStates.h"
#include "State.h"
#include "Miner.h"
#include "Locations.h"
#include "ConsoleUtils.h"
#include "EntityNames.h"
#include <iostream>
using std::cout;
//define this to output to a file
#ifdef TEXTOUTPUT
#include <fstream>
extern std::ofstream os;
#define cout os
#endif
//--------------------------------------methods for EnterMineAndDigForNugget
EnterMineAndDigForNugget* EnterMineAndDigForNugget::Instance()
{
static EnterMineAndDigForNugget instance;
return &instance;
}
void EnterMineAndDigForNugget::Enter(Miner* pMiner)
{
//if the miner is not already located at the goldmine, he must
//change location to the gold mine
if (pMiner->Location() != goldmine)
{
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Walkin' to the goldmine";
pMiner->ChangeLocation(goldmine);
}
}
void EnterMineAndDigForNugget::Execute(Miner* pMiner)
{
//the miner digs for gold until he is carrying in excess of MaxNuggets.
//If he gets thirsty during his digging he packs up work for a while and
//changes state to go to the saloon for a whiskey.
pMiner->AddToGoldCarried(1);
pMiner->IncreaseFatigue();
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Pickin' up a nugget";
//if enough gold mined, go and put it in the bank
if (pMiner->PocketsFull())
{
pMiner->ChangeState(VisitBankAndDepositGold::Instance());
}
if (pMiner->Thirsty())
{
pMiner->ChangeState(QuenchThirst::Instance());
}
}
void EnterMineAndDigForNugget::Exit(Miner* pMiner)
{
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": "
<< "Ah'm leavin' the goldmine with mah pockets full o' sweet gold";
}
//----------------------------------------methods for VisitBankAndDepositGold
VisitBankAndDepositGold* VisitBankAndDepositGold::Instance()
{
static VisitBankAndDepositGold instance;
return &instance;
}
void VisitBankAndDepositGold::Enter(Miner* pMiner)
{
//on entry the miner makes sure he is located at the bank
if (pMiner->Location() != bank)
{
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Goin' to the bank. Yes siree";
pMiner->ChangeLocation(bank);
}
}
void VisitBankAndDepositGold::Execute(Miner* pMiner)
{
//deposit the gold
pMiner->AddToWealth(pMiner->GoldCarried());
pMiner->SetGoldCarried(0);
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": "
<< "Depositing gold. Total savings now: "<< pMiner->Wealth();
//wealthy enough to have a well earned rest?
if (pMiner->Wealth() >= ComfortLevel)
{
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": "
<< "WooHoo! Rich enough for now. Back home to mah li'lle lady";
pMiner->ChangeState(GoHomeAndSleepTilRested::Instance());
}
//otherwise get more gold
else
{
pMiner->ChangeState(EnterMineAndDigForNugget::Instance());
}
}
void VisitBankAndDepositGold::Exit(Miner* pMiner)
{
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Leavin' the bank";
}
//----------------------------------------methods for GoHomeAndSleepTilRested
GoHomeAndSleepTilRested* GoHomeAndSleepTilRested::Instance()
{
static GoHomeAndSleepTilRested instance;
return &instance;
}
void GoHomeAndSleepTilRested::Enter(Miner* pMiner)
{
if (pMiner->Location() != shack)
{
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Walkin' home";
pMiner->ChangeLocation(shack);
}
}
void GoHomeAndSleepTilRested::Execute(Miner* pMiner)
{
//if miner is not fatigued start to dig for nuggets again.
if (!pMiner->Fatigued())
{
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": "
<< "What a God darn fantastic nap! Time to find more gold";
pMiner->ChangeState(EnterMineAndDigForNugget::Instance());
}
else
{
//sleep
pMiner->DecreaseFatigue();
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "ZZZZ... ";
}
}
void GoHomeAndSleepTilRested::Exit(Miner* pMiner)
{
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Leaving the house";
}
//------------------------------------------------methods for QuenchThirst
QuenchThirst* QuenchThirst::Instance()
{
static QuenchThirst instance;
return &instance;
}
void QuenchThirst::Enter(Miner* pMiner)
{
if (pMiner->Location() != saloon)
{
pMiner->ChangeLocation(saloon);
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Boy, ah sure is thusty! Walking to the saloon";
}
}
void QuenchThirst::Execute(Miner* pMiner)
{
if (pMiner->Thirsty())
{
pMiner->BuyAndDrinkAWhiskey();
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "That's mighty fine sippin liquer";
pMiner->ChangeState(EnterMineAndDigForNugget::Instance());
}
else
{
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\nERROR!\nERROR!\nERROR!";
}
}
void QuenchThirst::Exit(Miner* pMiner)
{
SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Leaving the saloon, feelin' good";
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
westworld.zip (33个子文件)
WestWorld1
Miner.cpp 2KB
BaseGameEntity.h 1KB
BaseGameEntity.cpp 765B
MinerOwnedStates.h 3KB
WestWorld1.dsw 545B
Locations.h 137B
utils.h 6KB
EntityNames.h 322B
WestWorld1.dsp 5KB
main.cpp 387B
MinerOwnedStates.cpp 6KB
Miner.h 2KB
ConsoleUtils.h 876B
State.h 727B
WestWorldWithWoman
StateMachine.h 3KB
Miner.cpp 1KB
WestWorldWithWomen.dsp 5KB
BaseGameEntity.h 1KB
BaseGameEntity.cpp 765B
MinerOwnedStates.h 3KB
MinersWife.h 1KB
Locations.h 203B
utils.h 6KB
WestWorldWithWomen.dsw 561B
EntityNames.h 322B
MinersWife.cpp 194B
MinersWifeOwnedStates.h 2KB
main.cpp 652B
MinersWifeOwnedStates.cpp 2KB
MinerOwnedStates.cpp 5KB
Miner.h 3KB
ConsoleUtils.h 876B
State.h 758B
共 33 条
- 1
资源评论
Hiskoa
- 粉丝: 11
- 资源: 28
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Flume进阶-自定义拦截器jar包
- Dubins曲线算法讲解和在运动规划中的使用.pdf
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.dta
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.xlsx
- Reeds+Shepp曲线算法讲解和实现.pdf
- 毕业设计基于SpringBoot+MyBatisPlus+MySQL+Vue的外卖配送信息系统源代码+数据库
- 词向量(Word Embeddings)是自然语言处理(NLP)领域的一种重要技术.txt
- Surfer,线性函数
- MyBatis 的动态 SQL 是其核心特性之一.txt
- 时代的sdddsddsddsd
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功