일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- for
- html5
- C++
- Euler
- font weight
- UE4
- Java
- python
- Bull
- Polymorphism
- Notting hill
- bool
- cow
- codecademy
- Project
- dictation
- CSS
- 영알남
- std
- 파이썬
- cout
- unreal engine4
- 연결리스트
- html
- endl
- 파이선
- Unreal
- 알고리즘
- 코딩도장
- if
- Today
- Total
BullCowGame - main.cpp 본문
/* This is the console executable, that makes use of the BullCow class
This acts as the view in a MVC pattern, and is responsible for all
user interaction. For game logic see the FBullCowGame class.
*/
#pragma once
#include <iostream>
#include <string>
#include "FBullCowGame.h"
using FText = std::string;
using int32 = int;
void PrintIntro();
void PlayGame();
void PrintGameSummary();
FText GetValidGuess();
bool AskToPlayAgain();
FBullCowGame BCGame; // instantiate a new game
// the entry point for our application
int main()
{
bool bPlayAgain = false;
do {
PrintIntro();
PlayGame();
bPlayAgain = AskToPlayAgain();
}
while (bPlayAgain);
return 0; // exit the application
}
// introduce the game
void PrintIntro()
{
int32 WORD_LENGTH = BCGame.GetHiddenWordLength();
std::cout << "Welcome to Bulls and Cows, a fun word game.\n";
std::cout << std::endl;
std::cout << " } { ___ " << std::endl;
std::cout << " (o o) (o o) " << std::endl;
std::cout << " /-------\\ / \\ /-------\\ " << std::endl;
std::cout << " / | BULL |O O| COW | \\ " << std::endl;
std::cout << " * |-,--- | |------| * " << std::endl;
std::cout << " ^ ^ ^ ^ " << std::endl;
std::cout << "Can you guess the " << WORD_LENGTH;
std::cout << " letter isogram I'm thinking of?\n";
std::cout << std::endl;
return;
}
void PlayGame()
{
BCGame.Reset();
int32 MaxTries = BCGame.GetMaxTries();
//loop asking for guesses while the game
// is NOT won and there are sill tries remaining
while(!BCGame.IsGameWon()&&BCGame.GetCurrentTry()<=MaxTries){
FText Guess = GetValidGuess();
// submit valid guess to the game, and receive counts
FBullCowCount BullCowCount= BCGame.SubmitValidGuess(Guess);
// print number of bulls and cows
std::cout << "Bulls = " << BullCowCount.Bulls;
std::cout << ", Cows = " << BullCowCount.Cows << std::endl;
std::cout << std::endl;
}
PrintGameSummary();
return;
}
FText GetValidGuess()
{
FText Guess = "";
EWordStatus Status = EWordStatus::Invalid_Status;
do{
// get a guess from the player
int32 CurrentTry = BCGame.GetCurrentTry();
std::cout << "Try " << CurrentTry<<" of "<<BCGame.GetMaxTries() << ". Enter your guess: ";
std::getline(std::cin, Guess);
Status = BCGame.CheckGuessValidity(Guess);
switch (Status)
{
case EWordStatus::Wrong_Length:
std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter world.\n";
break;
case EWordStatus::Not_Isogram:
std::cout << "Please enter a word without repeating letters.\n";
break;
case EWordStatus::Not_Lowercase:
std::cout << "Please enter all lowercase letters.\n";
break;
default:
// assume the guess is valid
break;
}
std::cout << std::endl;
}while (Status!=EWordStatus::OK); // keep looping until we get valid input
return Guess;
}
bool AskToPlayAgain()
{
std::cout << "Do you want to play again (y/n)? ";
FText Response = "";
std::getline(std::cin, Response);
return (Response[0] == 'y') || (Response[0] == 'Y');
}
void PrintGameSummary()
{
if (BCGame.IsGameWon())
std::cout << "You won\n\n";
else
std::cout << "bad luck\n\n";
}
'Programming > 기타 언어들' 카테고리의 다른 글
<단축키> 반투명 설정 (0) | 2017.07.21 |
---|---|
<단축키> 그룹 지정 / 해제 (0) | 2017.07.21 |
BullCowGame - FBullCowGame.cpp (0) | 2017.07.18 |
BullCowGame - FBullCowGame.h (0) | 2017.07.18 |
콜리전 반응과 충돌 이벤트 조건 (0) | 2017.07.18 |