.cpp file
// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"
#include"HiddenWordList.h"
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay();
SetupGame(); //Setiing up the game
//PrintLine(TEXT("Hidden word is : %s"), *HiddenWord); //Debug Line
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
//ClearScreen();//Clears the terminal
if (bGameOver){
ClearScreen();
SetupGame();//Setting up the game
}
else{ //Checking Player guess
ProcessGuess(Input);
}
}
void UBullCowCartridge::SetupGame(){
//Welcoming the game
PrintLine(TEXT("Oyuna hosgeldin!"));
PrintLine(TEXT("%i adet sihirli kelime bulunmaktadir."), HWords.Num());//.Num() dizinin içerisinde kaç adet element olduğunu gösteriyor.
GetValidWords(HWords); //This code that I update just before Errors
//Set the HiddenWord
HiddenWord = TEXT("Hakan");
//Lives that player has at the start
Lives = HiddenWord.Len();
bGameOver = false;
PrintLine(TEXT("Canin: %i"), Lives);
PrintLine(TEXT("\nDevam etmek için %i karakter uzulugundaki\nsihirli ismi gir..."), HiddenWord.Len());
}
void UBullCowCartridge::EndGame(){
bGameOver = true;
PrintLine(TEXT("\nTekrar oynamak için enter'a bas..."));
}
void UBullCowCartridge::ProcessGuess(FString Guess){
if (Guess == HiddenWord){
PrintLine(TEXT("Kazandin"));
EndGame();
return;
}
// if (Guess.Len() != HiddenWord.Len() && Lives > 1){
// PrintLine(TEXT("Canini yerim!"));
// PrintLine(TEXT("Canin: %i"), --Lives);
// PrintLine(TEXT("Sihirli kelime %i karakter uzunlugunda"), HiddenWord.Len());
// return;
if(Guess.Len() != HiddenWord.Len()){
//PrintLine(TEXT("Canin: %i"), Lives);
PrintLine(TEXT("Sihirli kelime %i karakter uzunlugunda."), HiddenWord.Len());
}
if(!Isogram(Guess)){
PrintLine("Ayni karakterler arka arkaya\ntekrarlanamaz!");
return;
}
//Remove Lives
PrintLine(TEXT("\nCanini Yedim!"));
--Lives;
if(Lives <= 0){
ClearScreen();
PrintLine(TEXT("Canin bitti."));
PrintLine(TEXT("Bilemedigin sihirli kelime: %s"), *HiddenWord);
EndGame();
return;
}
PrintLine(TEXT("Canin: %i"), Lives);
}
bool UBullCowCartridge::Isogram(FString Word) const{
for(int32 Index = 0; Index < Word.Len(); Index++){
for(int32 Comparison = Index + 1; Comparison < Word.Len(); Comparison++){
if(Word[Index] == Word[Comparison]){
return false;
}
}
}
return true;
}
//This code that I update just before Errors
TArray<FStiring> UBullCowCartridge::GetValidWords(TArray<FStiring> WordList) const{
TArray<FString> RightLengthWords;
for(int32 i = 0; i < WordList.Num(); i++){
int32 CheckLen = WordList[i].Len();
if(CheckLen >=4 && CheckLen <= 8){
if(!Isogram(WordList)){
RightLengthWords.Emplace(WordList[i]);
}
}
}
return *RightLengthWords;
}
And the header file
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Console/Cartridge.h"
#include "BullCowCartridge.generated.h"
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class BULLCOWGAME_API UBullCowCartridge : public UCartridge
{
GENERATED_BODY()
public:
virtual void BeginPlay() override;
virtual void OnInput(const FString& Input) override;
void SetupGame();
void EndGame();
void ProcessGuess(FString Guess);
bool Isogram(FString Word) const;
TArray<FStiring> GetValidWords(TArray<FString>) const; //This code that I update just before Errors
// Your declarations go below!
private:
FString HiddenWord;
int32 Lives;
bool bGameOver;
};
Lastly this is the log
I exactly copy the code, by writing, from github link from lesson except the varrible names. I also check the issue several time by commenting out updated codes there is no an error.
I have any clue about the error log. I also tried to solve that by examine trough the codes.
Need a hand to solve my problem. Thanks.