// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay();
SetupGame();
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
if(bGameOver)
{
ClearScreen();
SetupGame();
}
else
{
/*if game is over, then do ClearScreen() and SetupGame() the game
else Checking PlayerGuess*/
// Check, if isogram
// If not, tell them and prompt to guess again
if (Input == HiddenWord)
{
PrintLine(TEXT("You are right!"));
EndGame();
}
else
{
if (HiddenWord.Len() != Input.Len())
{
PrintLine(FString::Printf(TEXT("The word must have %i characters, try again"), HiddenWord.Len()));
EndGame();
}
else
{
PrintLine(TEXT("You have lost!"));
EndGame();
//Remove the live
}
}
// check if the player has any lifes left
// if yes, he loses
// And he is aked to PlayAgain with enter or quit with escape
// If no, say try again and ask for the word
// And show left lives
}
}
void UBullCowCartridge::SetupGame()
{
HiddenWord = TEXT("unreal");
lives = HiddenWord.Len();
bGameOver = false;
PrintLine(FString::Printf(TEXT("The Hidden word is: %s."), *HiddenWord)); //Debug Line
//Welcomming the player
PrintLine(TEXT("Welcome to Bull Cows!"));
PrintLine(TEXT("Please press Tab to input something"));
PrintLine(FString::Printf(TEXT("And guess the %i letter word"), HiddenWord.Len()));
PrintLine(TEXT("Then, press enter to contine..."));
}
void UBullCowCartridge::EndGame()
{
bGameOver = true;
PrintLine(TEXT("Press enter to Play again!"));
}
Here my code so far c:
// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay();
SetupGame();
PrintLine(TEXT("La palabra secreta es: %s."), *HiddenWord); // Debug Line
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
if (bGameOver)
{
ClearScreen();
SetupGame();
}
else // Checking PlayerGuess
{
if (Input == HiddenWord) // Order doesn't matter
{
PrintLine (TEXT("Correcto"));
EndGame();
}
else
{
if (Input.Len() != HiddenWord.Len())
{
PrintLine(TEXT("La palabra tiene %i letras \nPerdiste"), HiddenWord.Len());
EndGame();
}
}
}
// Define number of lives
// Check if Isogram
// Prompt to Guess
// Check correct number of characters
// Prompt to Guess
// Remove Life
// Check If lives > 0
// If yes "Intenta de nuevo"
// Show Lives Left
// If no "Perdiste" and Show HiddenWord
// Prompt Play Again, Press Enter to play again
// Check User Input
// Finish Game or Restart
}
void UBullCowCartridge::SetupGame()
{
// Welcoming player
PrintLine (TEXT("Muuuuuy bienvenida sea usted!"));
HiddenWord = TEXT("programa");
Lives = 4;
bGameOver = false;
PrintLine (TEXT("Adivina la palabra de %i letras"), HiddenWord.Len());
PrintLine (TEXT("Escribe una palabra y \npresiona ENTER para continuar")); // Prompt PlayerGuees
}
void UBullCowCartridge::EndGame()
{
bGameOver = true;
PrintLine(TEXT("Presiona Enter para jugar de nuevo"));
}