diff --git a/Content/UI/UI_EndMenu.uasset b/Content/UI/UI_EndMenu.uasset index 69943b2..4d56102 100644 --- a/Content/UI/UI_EndMenu.uasset +++ b/Content/UI/UI_EndMenu.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:52576e1e1c37cb910322d8f6a1fb106722971a4ea3e989a04c25a5d650034478 -size 51033 +oid sha256:20345b4138ae06a61adfe1ac60ab6ba1e7e609f3927a1c81e4c7a613268bf08b +size 112397 diff --git a/Content/UI/UI_IngameScoreAndTurns.uasset b/Content/UI/UI_IngameScoreAndTurns.uasset index f1b95f9..a9c6a6f 100644 --- a/Content/UI/UI_IngameScoreAndTurns.uasset +++ b/Content/UI/UI_IngameScoreAndTurns.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:702e84cb60241541c38b7dc91bf7fa6cbad438e646f8313b47fc81140a6b45f9 -size 96687 +oid sha256:82403afe51dd7b3cb5844d57952d2ef08b471e469e3c92e27bf61090082573a1 +size 94660 diff --git a/Content/UI/UI_MainMenu.uasset b/Content/UI/UI_MainMenu.uasset index 0b82650..8d28484 100644 --- a/Content/UI/UI_MainMenu.uasset +++ b/Content/UI/UI_MainMenu.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9ce6c7b3c242e9622013982e799bd8ae5ecac9ea71d51a55538ab8830d395621 -size 71802 +oid sha256:ef9a737bdd16ca5b73ee560b7c896a99617af8489c3f22af44541e1bf41c8399 +size 72479 diff --git a/README.md b/README.md index 5ef4362..d19b957 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,10 @@ There is a game field consisting of hex fields containing blocks. The player nee ## Ideas for more features, expansions.. -- [ ] Score (+ UI) +- [X] ~~Score (+ UI)~~ - [ ] Varying probabilities for the different token types (the rarer, the more points it's worth) - [X] ~~Game ends after x moves~~ -- [ ] Possibility to restart the game after ending of game +- [X] ~~Possibility to restart the game after ending of game~~ - [ ] Exception Handling - [ ] Special blocks with special effects - [ ] Combos diff --git a/Source/MatchThreeLines/MTLGameState.cpp b/Source/MatchThreeLines/MTLGameState.cpp index ffae0fd..a1fce67 100644 --- a/Source/MatchThreeLines/MTLGameState.cpp +++ b/Source/MatchThreeLines/MTLGameState.cpp @@ -166,6 +166,21 @@ bool AMTLGameState::DestroyTokens(TArray SelectedTokens) return true; }; +void AMTLGameState::ResetPlayingField() +{ + for (TArray& Column : PlayingField) + { + for (AGameToken* Token : Column) + { + Token->Destroy(); + } + Column.Empty(); + } + PlayingField.Empty(); + + InitPlayingField(); +} + // protected functions void AMTLGameState::BeginPlay() { diff --git a/Source/MatchThreeLines/MTLGameState.h b/Source/MatchThreeLines/MTLGameState.h index f926cde..e85680a 100644 --- a/Source/MatchThreeLines/MTLGameState.h +++ b/Source/MatchThreeLines/MTLGameState.h @@ -73,6 +73,8 @@ class MATCHTHREELINES_API AMTLGameState : public AGameStateBase */ bool DestroyTokens(TArray SelectedTokens); + void ResetPlayingField(); + protected: virtual void BeginPlay() override; }; diff --git a/Source/MatchThreeLines/MTLPlayerController.cpp b/Source/MatchThreeLines/MTLPlayerController.cpp index 33f1a48..ca2292b 100644 --- a/Source/MatchThreeLines/MTLPlayerController.cpp +++ b/Source/MatchThreeLines/MTLPlayerController.cpp @@ -4,6 +4,7 @@ #include "MTLPlayerController.h" #include "MTLPlayerState.h" #include "GameToken.h" +#include "MTLGameState.h" // private functions void AMTLPlayerController::OnMouseClicked() @@ -88,6 +89,22 @@ void AMTLPlayerController::StartOrResumeGame() SetPause(false); } +void AMTLPlayerController::ResetGame() const +{ + AMTLGameState* GameState = GetWorld()->GetGameState(); + AMTLPlayerState* MTLPlayerState = GetPlayerState(); + + if (GameState != nullptr && MTLPlayerState != nullptr) + { + GameState->ResetPlayingField(); + MTLPlayerState->Init(); + } + else + { + GEngine->AddOnScreenDebugMessage(1, 1.f, FColor::Red, TEXT("Couldn't get GameState or PlayerState!")); + } +} + // protected functions void AMTLPlayerController::SetupInputComponent() { diff --git a/Source/MatchThreeLines/MTLPlayerController.h b/Source/MatchThreeLines/MTLPlayerController.h index 8734660..2efd614 100644 --- a/Source/MatchThreeLines/MTLPlayerController.h +++ b/Source/MatchThreeLines/MTLPlayerController.h @@ -34,10 +34,14 @@ class MATCHTHREELINES_API AMTLPlayerController : public APlayerController /** Wait for a tiny bit, then display the End menu */ void EndGame(); - /** Display the in-game menu, then unpause the game */ + /** Hide the main/pause menu, display the in-game menu, then unpause the game */ UFUNCTION(BlueprintCallable, Category = "MTL – UI") void StartOrResumeGame(); + /** Reset the playing field, score and remaining turns */ + UFUNCTION(BlueprintCallable, Category = "MTL – UI") + void ResetGame() const; + protected: /** Called when the game starts. */ virtual void BeginPlay() override; diff --git a/Source/MatchThreeLines/MTLPlayerState.cpp b/Source/MatchThreeLines/MTLPlayerState.cpp index be7468d..a51b34a 100644 --- a/Source/MatchThreeLines/MTLPlayerState.cpp +++ b/Source/MatchThreeLines/MTLPlayerState.cpp @@ -67,6 +67,28 @@ void AMTLPlayerState::AddTokenToSelected(AGameToken* Token) } } +void AMTLPlayerState::Init() +{ + AGameStateBase* GameStateBase = GetWorld()->GetGameState(); + if (GameStateBase != nullptr) + { + const AMTLGameMode* GameMode = GameStateBase->GetDefaultGameMode(); + if (GameMode != nullptr) + { + SetScore(0.f); + AmountOfRemainingTurns = GameMode->GetMaxAmountOfTurns(); + } + else + { + GEngine->AddOnScreenDebugMessage(1, 1.f, FColor::Red, TEXT("Couldn't get GameMode!")); + } + } + else + { + GEngine->AddOnScreenDebugMessage(1, 1.f, FColor::Red, TEXT("Couldn't get GameState!")); + } +} + void AMTLPlayerState::EndTurn() { SetIsSelecting(false); @@ -98,22 +120,5 @@ void AMTLPlayerState::BeginPlay() { Super::BeginPlay(); - AGameStateBase* GameStateBase = GetWorld()->GetGameState(); - if (GameStateBase != nullptr) - { - const AMTLGameMode* GameMode = GameStateBase->GetDefaultGameMode(); - if (GameMode != nullptr) - { - SetScore(0.f); - AmountOfRemainingTurns = GameMode->GetMaxAmountOfTurns(); - } - else - { - GEngine->AddOnScreenDebugMessage(1, 1.f, FColor::Red, TEXT("Couldn't get GameMode!")); - } - } - else - { - GEngine->AddOnScreenDebugMessage(1, 1.f, FColor::Red, TEXT("Couldn't get GameState!")); - } + Init(); } diff --git a/Source/MatchThreeLines/MTLPlayerState.h b/Source/MatchThreeLines/MTLPlayerState.h index 58a7776..d3745e1 100644 --- a/Source/MatchThreeLines/MTLPlayerState.h +++ b/Source/MatchThreeLines/MTLPlayerState.h @@ -64,6 +64,9 @@ class MATCHTHREELINES_API AMTLPlayerState : public APlayerState void AddTokenToSelected(AGameToken* Token); + /** Reset all members to default/initial values */ + void Init(); + /** Destroys all selected GameTokens, if more than three have been selected; then decrements AmountOfRemainingTurns */ void EndTurn();