# MiniGameWin Logic

There are 2 different versions of MiniGState below. Version 1 always loads the EndScene, Version 2 loads the next scene depending on consequences of winning or losing the MiniGame.

## VERSION 1 - Always Executes: LoadEndScene( )

When the onMiniGame Event occurs, it triggers loading of the EndScene.

```
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEngine.Events;

public class MiniGState : IStateBase {

    Button btnOption1;
    LevelManager levelManager;

    /// <summary>
    /// The scene.
    /// </summary>
    private GameScene scene;

    /// <summary>
    /// Gets the scene number - enum
    /// </summary>
    /// <value>The scene.</value>
    public GameScene Scene
    {
        get { return scene; }
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="T:MiniGState"/> class.
    /// </summary>
    public MiniGState()
    {
        scene = GameScene.MiniGame;
    }


    public void InitializeObjectRefs()
    {
        btnOption1 = GameObject.Find("ButtonOption1").GetComponent<Button>();
        btnOption1.onClick.AddListener(LoadEndScene);

        levelManager = Object.FindObjectOfType<LevelManager>();
        levelManager.onMiniGameOver.AddListener(LoadEndScene);

    }


    public void LoadEndScene()
    {
        SceneManager.LoadScene("EndScene");
        StateManager.instanceRef.SwitchState(new EndState());
    }
}
```

## VERSION 2 - Conditional Logic Determines next Scene to Load

The code below shows how you can use the LevelManager custom UnityEvent: onMiniGameEnd. In the example code below, when the event occurs, then the MiniGameOver method is executed, it checks GameData, to determine if the player won or lost the MiniGame, and it determines the next scene based on that logic.

```java
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEngine.Events;

public class MiniGState : IStateBase {

    Button btnOption1;
    LevelManager levelManager;

    /// <summary>
    /// The scene.
    /// </summary>
    private GameScene scene;

    /// <summary>
    /// Gets the scene number - enum
    /// </summary>
    /// <value>The scene.</value>
    public GameScene Scene
    {
        get { return scene; }
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="T:MiniGState"/> class.
    /// </summary>
    public MiniGState()
    {
        scene = GameScene.MiniGame;
    }


    public void InitializeObjectRefs()
    {
        btnOption1 = GameObject.Find("ButtonOption1").GetComponent<Button>();
        btnOption1.onClick.AddListener(LoadEndScene);

        //Connect with LevelManager Event: onMiniGameOver
        levelManager = Object.FindObjectOfType<LevelManager>();
        levelManager.onMiniGameEnd.AddListener(MiniGameOver);

    }

    public void MiniGameOver()
    {
        if (GameData.instanceRef.miniGameWinner) //check GameData
        {
            LoadWinScene(); //true: player won
        }
        else
        {
            LoadLoseScene(); //false: player lost
        }

    }

    public void LoadWinScene()
    {
        SceneManager.LoadScene("WinScene");
        StateManager.instanceRef.SwitchState(new WinState());
    }

    public void LoadLoseScene()
    {
        SceneManager.LoadScene("LoseScene");
        StateManager.instanceRef.SwitchState(new LoseState());
    }

}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kdoore.gitbook.io/cs2335/f20_bkup_v2/project-3-code-mods/project-3-code/minigamewin-logic.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
