学习用C++开发你的第一个游戏(英文)
// FBullCowGame.cpp
#include "FBullCowGame.h"
using int32 = int;
void FBullCowGame::Reset()
{
constexpr int32 MAX_TRIES = 8;
MyCurrentTry = 1;
MyMaxTries = MAX_TRIES;
const FString HIIDEN_WORD = "ant";
MyHiddenWord = HIIDEN_WORD;
return;
}
// receives a VALID guess, incriments turn, and returns count
FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
{
// incriment the turn number
MyCurrentTry++;
// setup a return variable
FBullCowCount BullCowCount;
// loop through all letters in the guess
int32 HiddenWordLength = MyHiddenWord.length();
for (int32 MHWChar = 0; MHWChar < HiddenWordLength; MHWChar++)
{
// compare letter aginst the hidden word
for (int32 GChar = 0; GChar < HiddenWordLength; GChar++)
{
// if they match then
if(Guess[GChar] == MyHiddenWord[MHWChar])
{
//if they're in the same place
if (MHWChar == GChar)
{
BullCowCount.Bulls++;// incriment bulls
}
else
{
BullCowCount.Cows++; // must be a cow
}
}
}
}
return BullCowCount;
}
FBullCowGame::FBullCowGame()
{
Reset();
}
int32 FBullCowGame::GetMaxTries() const
{
return MyMaxTries;
}
int32 FBullCowGame::GetCurrentTry() const
{
return MyCurrentTry;
}
bool FBullCowGame::IsGameWon() const
{
return false;
}
bool FBullCowGame::CheckGuessValidity(std::string)
{
return false;
}