일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- CSS
- dictation
- Unreal
- Euler
- cout
- Polymorphism
- bool
- std
- 파이선
- if
- cow
- html5
- endl
- html
- Project
- unreal engine4
- Bull
- 알고리즘
- Java
- Notting hill
- for
- C++
- 연결리스트
- UE4
- font weight
- 파이썬
- 코딩도장
- 영알남
- codecademy
- python
- Today
- Total
BullCowGame - FBullCowGame.cpp 본문
#pragma once
#include "FBullCowGame.h"
#include <map>
#define TMap std::map
using int32 = int;
FBullCowGame::FBullCowGame() { Reset(); }
int32 FBullCowGame::GetCurrentTry() const { return MyCurrentTry; }
int32 FBullCowGame::GetHiddenWordLength() const{return MyHiddenWord.length();}
bool FBullCowGame::IsGameWon() const{return bGameIsWon;}
int32 FBullCowGame::GetMaxTries() const
{
TMap<int32, int32> WordLengthToMaxTries{ {3,5},{4,7},{5,10},{6,13} };
return WordLengthToMaxTries[MyHiddenWord.length()];
}
void FBullCowGame::Reset()
{
const FString HIDDEN_WORD = "planet";
MyHiddenWord = HIDDEN_WORD;
MyCurrentTry = 1;
bGameIsWon = false;
return;
}
EWordStatus FBullCowGame::CheckGuessValidity(FString Guess) const
{
if (!IsIsogram(Guess)) { return EWordStatus::Not_Isogram; }// if the guess isn't an isogram, return error
else if (!IsLowercase(Guess)) {return EWordStatus::Not_Lowercase; }// if the guess isn't all lowercase return error
else if (Guess.length()!=GetHiddenWordLength()) {return EWordStatus::Wrong_Length;}//if the guess length is wrong return error
else { return EWordStatus::OK;}//otehrwise return ok
}
// receives a VALID guess, incriments turn, and returns count
FBullCowCount FBullCowGame::SubmitValidGuess(FString Guess)
{
MyCurrentTry++;
FBullCowCount BullCowCount;
int32 WordLength = MyHiddenWord.length();
for (int32 MHWChar = 0; MHWChar < WordLength; MHWChar++)
{
// compare letters against the guess
for (int32 Gchar = 0; Gchar < WordLength; Gchar++)
{
// if they match then
if (Guess[Gchar] == MyHiddenWord[MHWChar])
{
if (MHWChar == Gchar)
{
BullCowCount.Bulls++;
}
else {
BullCowCount.Cows++;
}
}
}
}
if (BullCowCount.Bulls == WordLength) {
bGameIsWon = true;
}
else { bGameIsWon = false; }
return BullCowCount;
}
bool FBullCowGame::IsIsogram(FString Word) const
{
if (Word.length() <= 1) { return true; }
TMap<char, bool> LetterSeen;
for (auto Letter : Word) {
Letter=tolower(Letter);
if (LetterSeen[Letter]) {
return false;
}
else {
LetterSeen[Letter] = true;
}
}
return true;
}
bool FBullCowGame::IsLowercase(FString Word) const
{
for (auto Letter : Word)
{
if (!islower(Letter)) // if not a lowercase letter
{
return false;
}
}
return true;
}
'Programming > 기타 언어들' 카테고리의 다른 글
<단축키> 그룹 지정 / 해제 (0) | 2017.07.21 |
---|---|
BullCowGame - main.cpp (0) | 2017.07.18 |
BullCowGame - FBullCowGame.h (0) | 2017.07.18 |
콜리전 반응과 충돌 이벤트 조건 (0) | 2017.07.18 |
ATriggerVolume VS에 안뜨는경우 (0) | 2017.07.17 |