II already said it in the second reply.
And as I said in the first message I was already testing the possible solution to modify:
UnrealHeaderTool.target
I was in section 3 of the UnReal course in C ++.
(Now, i’m in section 4)
And the code was the BullCowCartridge.cpp and .h
And it does not have more than some differences with what Michael tries to explain in the Secction 3 of the course …
But I have no problem.
Here it is.
“BullCowCartridge.h”
// 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"
#define _static static
#define cstatic
struct FBullCowCount
{
int32 Bulls;
int32 Cows;
FBullCowCount()
{
Bulls = 0;
Cows = 0;
}
};
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(const FString & Guess);
TArray<FString> & LoadWordsFromFile(const FString & sFichero, TArray<FString> & ListaDestino) const;
TArray<FString> & GetValidWords(const TArray<FString> & ListaOrigen, TArray<FString> & ListaDestino) const;
void MostrarLista(const TArray<FString> & Lista) const;
void GetBullsCows(const FString& Guess, FBullCowCount& Count) const;
// Puede ser static, y le quitamos el const
// bool IsIsogram(const FString & Word) const;
static bool IsIsogram(const FString & Word);
// Your declarations go below!
private:
FString HiddenWord;
int32 Lives;
bool bGameOver;
TArray<FString> Words;
};
And the “BullCowCartridge.cpp”
// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"
#include "HiddenWordList.h"
#include "Misc/FileHelper.h"
#include "Misc/Paths.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
{
ProcessGuess(Input);
}
}
void UBullCowCartridge::SetupGame()
{
PrintLine(TEXT("Bienvenido a BullCowGame!"));
TArray<FString> TempWords;
TempWords = LoadWordsFromFile(TEXT("Datos/HiddenWordList.txt"), TempWords);
Words = GetValidWords(TempWords, Words);
int RamdomIndex = FMath::RandRange(0, Words.Num()-1);
HiddenWord = Words[RamdomIndex];
PrintLine(TEXT("Palabra Oculta: %s"), *HiddenWord);
Lives=HiddenWord.Len();
bGameOver=false;
PrintLine(TEXT("Adivina la palabra de %i letras"), HiddenWord.Len());
PrintLine(TEXT("Tienes %i vidas"), Lives);
PrintLine(TEXT("Escribe tu apuesta y"));
PrintLine(TEXT("pulsa Enter para continuar"));
}
void UBullCowCartridge::EndGame()
{
bGameOver=true;
PrintLine(TEXT("Pulsa Enter para jugar. (otra vez)"));
}
void UBullCowCartridge::ProcessGuess(const FString & Guess)
{
if (Guess==HiddenWord)
{
PrintLine(TEXT("Has ganado!"));
EndGame();
return;
}
if (Guess.Len() != HiddenWord.Len())
{
PrintLine(TEXT("La palabra oculta tiene %i letras"), HiddenWord.Len());
PrintLine(TEXT("Lo siento. Intenta adivinarla de nuevo."));
PrintLine(TEXT("Te quedan %i vidas."), Lives);
return;
}
if (!UBullCowCartridge::IsIsogram(Guess))
{
PrintLine(TEXT("Hay letras repetidas. Intentalo de nuevo"));
return;
}
PrintLine(TEXT("Has perdido una vida"));
--Lives;
if (Lives<=0)
{
ClearScreen();
PrintLine(TEXT("No te quedan Vidas"));
PrintLine(TEXT("La palabra oculta es: %s"), *HiddenWord);
EndGame();
return;
}
FBullCowCount Counts;
GetBullsCows(Guess, Counts);
PrintLine(TEXT(" - Hay %i Cows, y hay %i Bulls"), Counts.Cows, Counts.Bulls);
PrintLine(TEXT("Adivina otra vez. Te quedan %i vidas"), Lives);
}
void UBullCowCartridge::GetBullsCows(const FString& Guess, FBullCowCount& Counts) const
{
for(int32 GuessIndex=0; GuessIndex<Guess.Len(); GuessIndex++)
{
if (Guess[GuessIndex] == HiddenWord[GuessIndex])
{
Counts.Bulls++;
continue;
}
for(int32 HiddenIndex=0; HiddenIndex<HiddenWord.Len(); HiddenIndex++)
{
if (HiddenWord[HiddenIndex] == Guess[GuessIndex])
{
Counts.Cows ++;
// No estan repetidas, porque son isogramas
// lo mejor es salir.
break;
}
}
}
}
cstatic bool UBullCowCartridge::IsIsogram(const FString & Word)
{
for (int32 Index=0; Index<Word.Len(); Index++)
{
for (int32 SubIndex=Index+1; SubIndex<Word.Len(); SubIndex++)
{
if (Word[Index] == Word[SubIndex])
{
return false;
}
}
}
return true;
}
TArray<FString> & UBullCowCartridge::LoadWordsFromFile(const FString & sFichero, TArray<FString> & ListaDestino) const
{
ListaDestino.Reset();
// El Operador / mete este '/' para concatenar los caminos de un fichero.
const FString WordListPath = FPaths::ProjectContentDir() / sFichero;
PrintLine(TEXT("Content: %s"), *sFichero);
FFileHelper::LoadFileToStringArray(ListaDestino, *WordListPath);
// MostrarLista(ListaDestino);
return ListaDestino;
}
TArray<FString> & UBullCowCartridge::GetValidWords(const TArray<FString> & ListaOrigen, TArray<FString> & ListaDestino) const
{
ListaDestino.Reset();
for (FString palabra : ListaOrigen)
{
if (UBullCowCartridge::IsIsogram(palabra) && palabra.Len()>=4 && palabra.Len()<=8)
{
ListaDestino.Emplace(palabra);
}
}
// MostrarLista(ListaDestino);
return ListaDestino;
}
void UBullCowCartridge::MostrarLista(const TArray<FString> & Lista) const
{
// compruebo contenido:
for(int32 i=0; i<Lista.Num(); i++)
{
PrintLine(TEXT("+ %i %s"), i, *Lista[i]);
}
}
This last version from the first compilation is obviously different from the first compilations, but the compilation average is between 100 and 500 seconds.
(It does not make sense that we talk about the example of a person, who increases the compilation in 20 seconds, when I speak to you about 200 seconds)
But I am already telling you, that is for all the codes that I am compiling.
I have resigned myself, and I continue as I can with the course.
I wish it was a problem with my code but it is not.
You already said it, I don’t have the right equipment.
Although I still insist that
> the UE compilation is killing flies with cannon shots
Otherwise, forgive me if I seem very vehement, and thanks for the effort.
.