Example #1
0
 // Update is called once per frame
 void Update()
 {
     if (Clear)
     {
         Panel.ClearLED();
         Clear      = false;
         Redraw     = false;
         RedrawLock = false;
     }
     if (Redraw || RedrawLock)
     {
         Redraw = false;
         LEDRendering.Graph(GraphType, Panel, startX, startY, count, invertX, invertY);
     }
 }
Example #2
0
        private IEnumerator Game()
        {
            var continueMission = true;
            var currentMission  = SetCurrentMission(currentMissionIndex);

            yield return(StartCoroutine(MissionChosen(currentMission)));

            // coroutine to show deducting the cost
            ProgressPanel.ToggleMenu();

            currentMission.OverallResult.Reset();
            if (currentMission.UseOverallTime)
            {
                currentMission.OverallResult.TimeRemaining = currentMission.TotalSeconds;
            }

            Debug.LogFormat("starting mission with {0} seconds.", currentMission.OverallResult.TimeRemaining);

            yield return(StartCoroutine(StageStart()));

            var roundResult = new RoundResultInfo(currentMission);

            switch (currentMission.MissionType)
            {
            case MissionTypes.Sprint:
                break;

            case MissionTypes.Survival:
                break;
            }
            Round = 1;
            while (continueMission)
            {
                mCurrentRoundData = GameProgression.GetRound(PlayerData.Level, PlayerData.Stage, Round, LED1.LEDArraySize);
                yield return(StartCoroutine(RoundStart(mCurrentRoundData)));

                var         highMessage  = mCurrentRoundData.High ? "     HIGHER!   " : "     LOWER!   "; // change this to an event or setter call
                ButtonState correctBtn   = mCurrentRoundData.Led1Right ? ButtonState.LEFT : ButtonState.RIGHT;
                ButtonState incorrectBtn = correctBtn == ButtonState.LEFT ? ButtonState.RIGHT : ButtonState.LEFT;
                LEDRendering.Graph(mCurrentRoundData.LEDInfo[0].graphType, LED1,
                                   mCurrentRoundData.LEDInfo[0].StartX, mCurrentRoundData.LEDInfo[0].StartY,
                                   mCurrentRoundData.LEDInfo[0].Count,
                                   mCurrentRoundData.LEDInfo[0].InvertX, mCurrentRoundData.LEDInfo[0].InvertY);

                LEDRendering.Graph(mCurrentRoundData.LEDInfo[1].graphType, LED2,
                                   mCurrentRoundData.LEDInfo[1].StartX, mCurrentRoundData.LEDInfo[1].StartY,
                                   mCurrentRoundData.LEDInfo[1].Count,
                                   mCurrentRoundData.LEDInfo[1].InvertX, mCurrentRoundData.LEDInfo[1].InvertY);

                float timeAdjustment = roundResult.TimeAdjustment;
                roundResult.Reset(Round);

                currentMission.OverallResult.StartTime = Time.time;
                var loop = true;
                ClearButtonState();
                var _gameState        = FinishState.None;
                int progressDashCount = 16;
                updateTimer = true;
                while (loop)
                {
                    //currentMission.TimerTick(mCurrentRoundData);

                    currentTimeValues.SetValues(currentMission.OverallResult.MissionTime, currentMission.OverallResult.Progress, currentMission.UseOverallTime);
                    yield return(StartCoroutine(TimerUpdate(currentTimeValues)));

                    progressDashCount = 16 - (Mathf.RoundToInt(16 * currentMission.OverallResult.Progress));
                    var progressMessage = progressDashCount > 0 ? new string('-', progressDashCount) : "";

                    //              Debug.LogFormat("progress: {0}", progress);
                    if (currentMission.OverallResult.Progress >= 1)
                    {
                        loop       = false;
                        _gameState = FinishState.Timeout;
                        continue;
                    }
                    if (_buttonState == ButtonState.MID)
                    {
                        //Debug.Log("exit");
                        loop       = false;
                        _gameState = FinishState.Quit;
                    }
                    else if (_buttonState == correctBtn)
                    {
                        //Debug.Log("right");
                        loop       = false;
                        _gameState = FinishState.Right;
                    }
                    else if (_buttonState == incorrectBtn)
                    {
                        //Debug.Log("wrong");
                        loop       = false;
                        _gameState = FinishState.Wrong;
                    }
                    yield return(null);
                }
                updateTimer       = false;
                _buttonState      = ButtonState.NONE;
                roundResult.State = _gameState;

                continueMission = currentMission.ProcessRoundResult(roundResult, ref Round);
                yield return(StartCoroutine(RoundComplete(currentMission, roundResult)));
            }
            if (currentMission.OverallResult.ResultType == MissionResultType._Unknown)
            {
                // if at this point it's still unknown, then nothing bad happened.  Success!
                currentMission.OverallResult.ResultType = MissionResultType.Complete;
            }
            yield return(StartCoroutine(StageComplete(currentMission, roundResult)));

            yield return(null);
        }
Example #3
0
    private IEnumerator Game()
    {
        var playingRound = true;

        OnStageStart.Invoke();
        while (playingRound)
        {
            var roundData = GameProgression.GetRound(PlayerData.Level, PlayerData.Stage, Round, LED1.LEDArraySize);
            OnRoundStart.Invoke();
            if (Round == 1)
            {
                if (roundData.IntroText != null && roundData.IntroText.Any())
                {
                    int lastLcv = -1;
                    for (int lcv = 0, length = roundData.IntroText.Count; lcv < length; lcv++)
                    {
                        string s1, s2;
                        if (lastLcv < 0)
                        {
                            s1 = "";
                        }
                        else
                        {
                            s1 = roundData.IntroText[lastLcv];
                        }
                        s2 = roundData.IntroText[lcv];
                        LcdWrite(s1, s2);
                        lastLcv++;
                        yield return(new WaitForSeconds(2f));
                    }
                    yield return(new WaitForSeconds(2f));
                }
            }

            var         highMessage  = roundData.High ? "     HIGHER!   " : "     LOWER!   ";
            ButtonState correctBtn   = roundData.Led1Right ? ButtonState.LEFT : ButtonState.RIGHT;
            ButtonState incorrectBtn = correctBtn == ButtonState.LEFT ? ButtonState.RIGHT : ButtonState.LEFT;
            LEDRendering.Graph(roundData.LEDInfo[0].graphType, LED1,
                               roundData.LEDInfo[0].StartX, roundData.LEDInfo[0].StartY,
                               roundData.LEDInfo[0].Count,
                               roundData.LEDInfo[0].InvertX, roundData.LEDInfo[0].InvertY);

            LEDRendering.Graph(roundData.LEDInfo[1].graphType, LED2,
                               roundData.LEDInfo[1].StartX, roundData.LEDInfo[1].StartY,
                               roundData.LEDInfo[1].Count,
                               roundData.LEDInfo[1].InvertX, roundData.LEDInfo[1].InvertY);

            float startTime      = Time.time;
            var   currentSeconds = roundData.WaitSeconds;
            var   loop           = true;
            ClearButtonState();
            var _gameState        = FinishState.None;
            int progressDashCount = 16;
            while (loop)
            {
                currentSeconds = Time.time - startTime;
                float progress = currentSeconds / roundData.WaitSeconds;
                progressDashCount = 16 - (Mathf.RoundToInt(16 * progress));
                var progressMessage = progressDashCount > 0 ? new string('-', progressDashCount) : "";
                LcdWrite(highMessage, progressMessage);
                if (progressDashCount <= 0)
                {
                    loop       = false;
                    _gameState = FinishState.Timeout;
                    continue;
                }
                if (_buttonState == ButtonState.MID)
                {
                    Debug.Log("exit");
                    loop       = false;
                    _gameState = FinishState.Quit;
                }
                else if (_buttonState == correctBtn)
                {
                    Debug.Log("right");
                    loop       = false;
                    _gameState = FinishState.Right;
                }
                else if (_buttonState == incorrectBtn)
                {
                    Debug.Log("wrong");
                    loop       = false;
                    _gameState = FinishState.Wrong;
                }
                yield return(null);
            }
            _buttonState = ButtonState.NONE;
            Debug.Log("round complete");
            switch (_gameState)
            {
            case FinishState.Right:
                LcdWrite("Great job", "");
                var earnedPoints = 100;
                earnedPoints += (progressDashCount * 20);
                Round++;
                if (Round > GameProgression.ROUND_COUNT)     // TODO: make variable for max rounds
                {
                    //PlayerData.Stage++;  // for now, let's not auto progress the stage.
                    if (PlayerData.Stage > GameProgression.STAGE_COUNT)
                    {
                        PlayerData.Level++;
                        earnedPoints    += 5000;
                        PlayerData.Stage = 1;
                    }
                    earnedPoints      += 1000;
                    playingRound       = false;
                    PlayerData.Points += earnedPoints;
                    PlayerData.Push();
                    yield return(StartCoroutine(StageComplete(earnedPoints)));
                }
                break;

            case FinishState.Wrong:
                LcdWrite("you suck", "");
                playingRound = false;
                yield return(StartCoroutine(StageFailed()));

                break;

            case FinishState.Timeout:
                LcdWrite("Time's up", "");
                playingRound = false;
                yield return(StartCoroutine(StageFailed()));

                break;

            case FinishState.Quit:
                LcdWrite("Exiting", "");
                playingRound = false;
                yield return(StartCoroutine(StageQuit()));

                break;
            }
            OnRoundEnd.Invoke();
        }
        OnStageEnd.Invoke();
        yield return(null);
    }