Пример #1
0
        public async Task <ActionResult> OnGet(int?levelStateId, int?col)
        {
            if (levelStateId == null)
            {
                var settings = SettingsHandler.GetSavedSettingsElseNew();

                LevelState = new LevelState(settings);
                await AddGameStateToDb(LevelState);
            }
            else
            {
                LevelState = RestoreGameStateFromDb((int)levelStateId);
            }

            // don't allow moves if there is a win or a tie
            if (LevelState.IsGameOver())
            {
                return(Page());
            }

            if (col != null)
            {
                LevelState = LevelUpdate.UpdateLevel(LevelState, LevelState.Turn, (int)col);
            }

            while (LevelState.GetCurrentPlayer().isAI)
            {
                LevelState = LevelUpdate.UpdateLevel(LevelState, LevelState.Turn);
            }

            await UpdateLevelStateInDb(LevelState);

            return(Page());
        }
Пример #2
0
        public void givenInputWherePlayer2WinsByBackwardSlash2_callingCheckWin_mustReturnTrue()
        {
            // ARRANGE
            const int strikeSize = 4;
            var       inputScene = new Scene(new[] {
                "| 2 ||   ||   ||   |",
                "--------------------",
                "| 1 || 2 ||   ||   |",
                "--------------------",
                "| 2 || 1 || 2 ||   |",
                "--------------------",
                "| 1 || 1 || 1 || 2 |",
                "--------------------"
            });

            var lastDisc = new Disc(0, 0);
            var state    = ParseScene(inputScene, true);

            state.StrikeSize = strikeSize;
            state.Turn       = 2;

            // ACT
            bool horizontalResult    = LevelUpdate.CheckHorizontal(state, lastDisc);
            bool verticalResult      = LevelUpdate.CheckVertical(state, lastDisc);
            bool forwardSlashResult  = LevelUpdate.CheckForwardSlash(state, lastDisc);
            bool backwardSlashResult = LevelUpdate.CheckBackwardSlash(state, lastDisc);

            // ASSERT
            horizontalResult.Should().BeFalse();
            verticalResult.Should().BeFalse();
            forwardSlashResult.Should().BeFalse();
            backwardSlashResult.Should().BeTrue();
        }
Пример #3
0
    public void Start()
    {
        currentPart = 0;
        GameEventSystem.OnGameEventRaised += HandleGameEvents;
        playerGO = GameObject.FindGameObjectWithTag("Player");
        if (playerGO == null)
        {
            Debug.LogError("Player GO is null in Level Controller");
        }
        else
        {
            playerGO.SetActive(false);
        }
        levelUpdate = GetComponent <LevelUpdate>();
        if (levelUpdate == null)
        {
            Debug.LogError("Level update is null. Is it attached in the same GO as Level Controller?");
        }
        if (levelDataSO == null)
        {
            Debug.LogError("Level Data SO is null");
        }
        else
        {
            localLevelData = LevelHelper.GetLocalLevelData(levelDataSO.levelData.id);
        }

        Invoke("StartLevel", 1f);
    }
Пример #4
0
    public void Start()
    {
        //References
        Application.targetFrameRate = 60;
        arcadeManager = ArcadeManager.instance;

        levelStart += new LevelUpdate(StartLevel);
    }
Пример #5
0
 /// <summary>
 /// Loads the level indicated by the <see cref="LevelUpdate"/> if
 /// that level is not yet loaded. If the same level is already loaded,
 /// this method does nothing.
 /// </summary>
 /// <param name="update">The level update.</param>
 public void OnLevelUpdate(LevelUpdate update)
 {
     if (this.CurrentLevelIndex != update.NextLevelIndex ||
         this.BoardSize != update.Size)
     {
         this.BoardSize = update.Size;
         this.LoadLevel(update.NextLevelIndex);
     }
 }
Пример #6
0
        /// <summary>
        /// Adjusts the center point of the remote camera to point to the updated board center.
        /// </summary>
        /// <param name="level">The <see cref="LevelUpdate"/>.</param>
        public void OnLevelUpdate(LevelUpdate level)
        {
            Vector3 newCenter    = new Vector3(level.Size.x / 2, 0, -level.Size.y / 2);
            float   maxDimension = Math.Max(level.Size.x, level.Size.y);

            this.ViewDistance = maxDimension;

            Debug.Log("Remote center changed to: " + newCenter);
            this.center = newCenter;
        }
Пример #7
0
 /// <summary>
 /// Handles the given <see cref="LevelUpdate"/>.
 /// </summary>
 /// <param name="level">The <see cref="LevelUpdate"/>.</param>
 public void OnLevelUpdate(LevelUpdate level)
 {
     if (this.initialized)
     {
         this.FinishLevel(level.TimeTaken, level.NextLevelIndex);
     }
     else
     {
         this.CurrentLevel = level.NextLevelIndex;
         this.initialized  = true;
     }
 }
Пример #8
0
        private static void Play(LevelState state)
        {
            int cursorPos = 1;

            while (state.GetWinnerElseNull() == null && !state.IsTie)
            {
                var scene         = RenderScene(state);
                var currentPlayer = state.GetCurrentPlayer();
                PrintBoard(state, cursorPos, scene, currentPlayer);

                if (currentPlayer.isAI)
                {
                    state = LevelUpdate.UpdateLevel(state, state.Turn);
                    Thread.Sleep(500);                     // add delay for dramatic effect
                    continue;
                }

                Key input;
                while ((input = GetUserDirectionInput()) != Key.Down)
                {
                    switch (input)
                    {
                    case Key.Left:
                        cursorPos = cursorPos <= 1 ? cursorPos : cursorPos - 1;
                        break;

                    case Key.Right:
                        cursorPos = cursorPos >= state.Width ? cursorPos : cursorPos + 1;
                        break;

                    case Key.Save:
                        Console.Clear();
                        SaveGame(state);
                        break;

                    case Key.Exit:
                        goto ExitLoop;
                    }

                    PrintBoard(state, cursorPos, scene, currentPlayer);
                }

                state = LevelUpdate.UpdateLevel(state, state.Turn, cursorPos);
            }

ExitLoop:

            PrintBoard(state, cursorPos);
            PrintWinMessage(state);
        }
Пример #9
0
 /// <summary>
 /// Updates the board size with the size in the argument.
 /// </summary>
 /// <param name="level">The level update.</param>
 public void OnLevelUpdate(LevelUpdate level)
 {
     Debug.Log("Applying Board Size: " + level.Size);
     this.StartCoroutine(this.UpdateBoardSize(level.Size));
 }
Пример #10
0
 private void Start()
 {
     lev   = FindObjectOfType <LevelUpdate>();
     state = FindObjectOfType <GameState>();
 }
Пример #11
0
        private void UpdateGame()
        {
            //Pre game timer
            if (mPreGameTime > 0)
            {
                mPreGameTime--;

                if (mPreGameTime == 0)
                {
                    mPlaying = true;
                    ClearASCII();
                    WriteASCIICentred("PAUSED", mASCIISize.Width / 2, mASCIISize.Height / 2);
                }
                else
                {
                    ClearASCII();

                    string[] lns = mLevel.Name.Split('|');

                    for (int i = 0; i < lns.Length; i++)
                    {
                        WriteASCIICentred(lns[i], mASCIISize.Width / 2, (mASCIISize.Height * (i + 1)) / (lns.Length + 1));
                    }
                }
            }

            if (mPlaying && !mPaused)
            {
                //Update all the snakes
                UpdateSnakes();

                //Check block at bottom
                //if (GetTileAt(BottomDoorLocation) == TileType.Null) {
                //    if (!IsThereSnakeAt(BottomDoorLocation)) {
                //        SetTileAt(BottomDoorLocation, TileType.Wall);
                //    }
                //}

                if (mMode == Mode.Normal)
                {
                    //mLevelTime--;
                    if (mLevelTime == 0)
                    {
                        AddRandomFood(mInitialFood - GetRemainingFoodCount());
                        mLevelTime = InitialLevelTime;
                    }
                }
            }

            if (LevelUpdate != null)
            {
                LevelUpdate.Invoke(this, EventArgs.Empty);
            }

            //Repaint
            Invalidate();

            //Callback functions
            switch (mCallbackState)
            {
            case CallbackState.WinGame:
                mPlaying = false;

                if (LevelComplete != null)
                {
                    LevelComplete.Invoke(this, EventArgs.Empty);
                }
                break;

            case CallbackState.LoseGame:
                mPlaying = false;
                if (LevelFail != null)
                {
                    LevelFail.Invoke(this, EventArgs.Empty);
                }
                break;
            }

            //Reset callback
            mCallbackState = CallbackState.Null;

            //Update the update counter
            mUpdateCnt = (mUpdateCnt + 1) % UpdatesPerSecond;
        }