-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ben Tristem
committed
Jan 12, 2016
1 parent
0f6b87a
commit ae0a805
Showing
4 changed files
with
23 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
ae0a805
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition will be if (Guess[j] == MyHiddenWord[i]) in place of if (Guess[i] == MyHiddenWord[i])
ae0a805
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have trouble with Visual Studio, after this lecture. It always says me errors Those are the files what aren't allright
this is the main.cpp
/* This is a console executable, that makes use of the BullCow class
This acts as the view in a MVC pattern, and it's responsible for all
for all user interaction. For game logic see FBullCowGame
*/
#include
#include
#include "FBullCowGame.h"
using FText = std::string;
using int32 = int;
void Printintro();
void PlayGame();
FText GetGuess();
bool AskToPlayAgain();
FBullCowGame BCGame; // instantiate a new game
// the entry point32 for our application
int32 main()
{
Printintro();
PlayGame();
// TODO summarise game
AskToPlayAgain();
bool bPlayAgain = false;
do {
Printintro();
PlayGame();
bPlayAgain = AskToPlayAgain();
}
while (bPlayAgain);
}
void PlayGame()
{
BCGame.Reset();
int32 MaxTries = BCGame.GetMaxTries();
}
void Printintro()
{
// introduce the game
constexpr int32 WORD_LENGHT = 5;
std::cout << "Welcome to Bulls and Cows, a fun word game.\n";
std::cout << "Can you guess the " << WORD_LENGHT;
std::cout << " letter isogram I am thinking of?\n";
std::cout << std::endl;
return;
}
FText GetGuess()
{
int32 GetCurrentTry = BCGame.GetCurrentTry();
// get a guess from the player
std::cout << "Try " << GetCurrentTry << ". Enter your guess: ";
FText Guess = "";
std::getline(std::cin, Guess);
return Guess;
}
bool AskToPlayAgain()
{
std::cout << "Do you want to play again?(y/n) ";
FText Response = "";
std::getline(std::cin, Response);
}
This is the FBullCowGame.h
class FBullCowGame {
public:
FBullCowGame(); // constructor
int32 GetMaxTries() const;
int32 GetCurrentTry() const;
bool IsGameWon() const;
bool CheckGuessValidity(FStirng); // TODO make a more rich return value.
void Reset(); // TODO make a more rich return value.
// Counts bulls and cows, and increases try # assuming vaild guesses
FBullCowCount FBullCowCount::SubmitGuess(FStirng);
// ^^ Please try and ignore this and focus on the interface above ^^
private:
// see constructor for initialisation
int32 MyCurrentTry;
int32 MyMaxTries;
FStirng MyHiddenWord;
};
This is the FBullCowGame.cpp
#include "FBullCowGame.h"
using FStirng = std::string;
using int32 = int;
FBullCowGame::FBullCowGame() { Reset(); }
int32 FBullCowGame::GetMaxTries() const { return MyMaxTries; }
int32 FBullCowGame::GetCurrentTry() const { return MyCurrentTry; }
void FBullCowGame::Reset()
{
constexpr int32 MAX_TRIES = 8;
MyMaxTries = MAX_TRIES;
}
// recives a VALID guess, incriments turn, and return count
FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
{
// increment the turn number
MyCurrentTry++;
// setup a return variable
FBullCowCount BullCowCount;
// loop trough all letters in the guess
int32 HiddenWordLength = MyHiddenWord.length();
for (int32 MWHChar = 0; MWHChar < HiddenWordLength; MWHChar++) {
// compare letters againts the hidden word
for (int32 GChar = 0; GChar < HiddenWordLength; GChar++) {
// if they match then
if (Guess[MWHChar] == MyHiddenWord[MWHChar]) {
if (MWHChar == GChar) { // if they're in the same place
BullCowCount.Bulls++; // incriment bulls
}
else {
BullCowCount.Cows++; // must be a cow
}
}
}
}
return BullCowCount;
}
bool FBullCowGame::IsGameWon () const
{
return false;
}
bool FBullCowGame::CheckGuessValidity(FStirng)
{
return false;
}
Please if you can help me, write it in comments. Thanks!
ae0a805
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same problem, idk what I need to do, heeelp me