private void OnProcessedCellHandler(AbstractMazeCell <TSOMazeData> cell)
        {
            // get wall configuration
            cell.CellData.Wall_Config = AbstractMazeGenerator <TSOMazeData> .GetWallConfig(cell);

            // choose a color from available pools
            if (AllColorPools.Count > 1)
            {
                int index = Rng.Next(0, AllColorPools.Count);
                cell.CellData.Color = AllColorPools[index].Color;
                AllColorPools[index].Remaining--;

                // if the pool is dry, remove it as an option
                if (AllColorPools[index].Remaining == 0)
                {
                    AllColorPools.RemoveAt(index);
                }
            }
            else // only one color left
            {
                cell.CellData.Color = AllColorPools[0].Color;
            }

            // push the cell into the correct list to send to the UIEOD
            var colorIndex = (int)cell.CellData.Color;

            if (colorIndex < 4)
            {
                ColorCells[colorIndex].Add(cell);
            }
        }
Exemplo n.º 2
0
    static int CountExits(int x, int y, int[,] maze)
    {
        int cnt = 0;

        for (int i = 0; i < 4; i++)
        {
            if (AbstractMazeGenerator.CanMove(x, y, AbstractMazeGenerator.directions[i], maze))
            {
                cnt++;
            }
        }
        return(cnt);
    }
        private void Reset()
        {
            MazeGenerated         = false;
            MazeSolved            = false;
            LogicPlayerHasInit    = false;
            CharismaPlayerHasInit = false;

            // indeces: 0 for blue, 1 for green, 2 for red, 3 for yellow as seen in enum: VMEODTwoPersonJobObjectMazePluginCellColors
            ColorCells = new List <AbstractMazeCell <TSOMazeData> >[] { new List <AbstractMazeCell <TSOMazeData> >(MAX_COLORS),
                                                                        new List <AbstractMazeCell <TSOMazeData> >(MAX_COLORS), new List <AbstractMazeCell <TSOMazeData> >(MAX_COLORS + 1),
                                                                        new List <AbstractMazeCell <TSOMazeData> >(MAX_COLORS + 1) };

            // build color pools
            int blanksPerPool = (MAX_ROWS * MAX_COLUMNS - MAX_COLORS * 4) - 2;

            blanksPerPool /= 8;
            AllColorPools  = new List <ColorPool>()
            {
                new ColorPool(VMEODTwoPersonJobObjectMazePluginCellColors.Blank, blanksPerPool),
                new ColorPool(VMEODTwoPersonJobObjectMazePluginCellColors.Blank, blanksPerPool),
                new ColorPool(VMEODTwoPersonJobObjectMazePluginCellColors.Blue, MAX_COLORS),
                new ColorPool(VMEODTwoPersonJobObjectMazePluginCellColors.Blank, blanksPerPool),
                new ColorPool(VMEODTwoPersonJobObjectMazePluginCellColors.Blank, blanksPerPool),
                new ColorPool(VMEODTwoPersonJobObjectMazePluginCellColors.Green, MAX_COLORS),
                new ColorPool(VMEODTwoPersonJobObjectMazePluginCellColors.Blank, blanksPerPool),
                new ColorPool(VMEODTwoPersonJobObjectMazePluginCellColors.Blank, blanksPerPool),
                new ColorPool(VMEODTwoPersonJobObjectMazePluginCellColors.Red, MAX_COLORS + 1),
                new ColorPool(VMEODTwoPersonJobObjectMazePluginCellColors.Blank, blanksPerPool),
                new ColorPool(VMEODTwoPersonJobObjectMazePluginCellColors.Blank, blanksPerPool),
                new ColorPool(VMEODTwoPersonJobObjectMazePluginCellColors.Yellow, MAX_COLORS + 1),
            };

            if (CurrentMaze == null) // first run
            {
                CurrentMaze = AbstractMazeGenerator <TSOMazeData> .GetEmptyMaze(MAX_ROWS, MAX_COLUMNS);

                CurrentMaze.OnMazeGenerated       += MazeGeneratedHandler;
                CurrentMaze.OnFinalProcessingCell += OnProcessedCellHandler;
            }
            // random origin from the 5 choices of enum: BuildFromOrigins
            var origin = Rng.Next(0, (int)BuildFromOrigins.Dead_Center + 1);

            // also resets previous mazes
            CurrentMaze.BuildFromOrigin(origin);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="state"></param>
        private void GotoState(FreeSOMazeStates state)
        {
            GameState = state;
            Tock      = 0;
            switch (state)
            {
            case FreeSOMazeStates.Lobby:
            {
                ChosenMazeDifficulty = FreeSOMazeDifficulties.Unselected;
                CharismaPlayer?.Reset();
                if (CharismaPlayer?.IsLoaded ?? false)
                {
                    SendLobbyInfoEvent(CharismaPlayer, LogicPlayer);
                }
                LogicPlayer?.Reset();
                if (LogicPlayer?.IsLoaded ?? false)
                {
                    SendLobbyInfoEvent(LogicPlayer, CharismaPlayer);
                }

                if (CurrentMaze != null)
                {
                    CurrentMaze.OnMazeGenerated       -= MazeGeneratedHandler;
                    CurrentMaze.OnFinalProcessingCell -= OnProcessedCellHandler;
                    CurrentMaze.OnDeadEndCreation     -= OnDeadEndHandler;
                    Solution          = null;
                    RawMaze           = null;
                    MazeTimeRemaining = 0;
                    BroadcastSharedEvent("FreeSOMaze_time", BitConverter.GetBytes(MazeTimeRemaining));
                }
                else
                {
                    EveryDeadEndCell = new List <AbstractMazeCell <FreeSOMazeData> >();
                }
                break;
            }

            case FreeSOMazeStates.GeneratingMaze:
            {
                CurrentMaze = AbstractMazeGenerator <FreeSOMazeData> .GetEmptyMaze(MazeSizes[ChosenMazeDifficulty], MazeSizes[ChosenMazeDifficulty]);

                CurrentMaze.OnMazeGenerated       += MazeGeneratedHandler;
                CurrentMaze.OnFinalProcessingCell += OnProcessedCellHandler;
                CurrentMaze.OnDeadEndCreation     += OnDeadEndHandler;
                var origin = ThankU.Next(0, (int)BuildFromOrigins.Dead_Center + 1);
                CurrentMaze.BuildFromOrigin(origin);
                BroadcastSharedEvent("FreeSOMaze_goto_maze", BitConverter.GetBytes((int)ChosenMazeDifficulty));
                break;
            }

            case FreeSOMazeStates.LoadingMaze:
            {
                MazeTimeRemaining = 0;
                int cardinal = 0;
                if (CharismaPlayer != null)
                {
                    cardinal = GetSolutionCardinal(CharismaPlayer);
                    CharismaPlayer.CurrentFacingCardinal = (FreeSOMazeCardinals)Enum.ToObject(typeof(FreeSOMazeCardinals), cardinal);
                    CharismaPlayer.Send("FreeSOMaze_show_maze", CharismaPlayer.GetLocationData((int)FreeSOMazeCardinals.Invalid));
                }
                if (LogicPlayer != null)
                {
                    cardinal = GetSolutionCardinal(LogicPlayer);
                    LogicPlayer.CurrentFacingCardinal = (FreeSOMazeCardinals)Enum.ToObject(typeof(FreeSOMazeCardinals), cardinal);
                    LogicPlayer.Send("FreeSOMaze_show_maze", LogicPlayer.GetLocationData((int)FreeSOMazeCardinals.Invalid));
                }
                break;
            }

            case FreeSOMazeStates.NavigatingMaze:
            {
                CharismaPlayer.Cooldown = GLOBAL_COOLDOWN;
                LogicPlayer.Cooldown    = GLOBAL_COOLDOWN;
                SendAllowMazeEvent(CharismaPlayer, false);
                SendAllowMazeEvent(LogicPlayer, false);
                MazeTimeRemaining = RoundTimes[ChosenMazeDifficulty];
                BroadcastSharedEvent("FreeSOMaze_time", BitConverter.GetBytes(MazeTimeRemaining));
                break;
            }

            case FreeSOMazeStates.Gameover:
            {
                MazeTimeRemaining = 0;
                break;
            }
            }
        }