Exemplo n.º 1
0
        protected override void Initialize()
        {
            if (nDirections == 8)
            {
                isOctaboard = true;
            }

            playsCount = lossCount = winCount = 0;
            Board  board;
            Player player;

            new RNG(4);
            lossCount = winCount = 0;
            //setting first keyboard states
            state         = Keyboard.GetState();
            previousState = state;

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            if (fileON)
            {
                board = LoadLevel(out player);
                foreach (Obstacle obs in board.obstacles)
                {
                    obs.board = board;
                }
            }
            else
            {
                //Create a game board
                if (nDirections == 6) //Hexaboard
                {
                    board = new HexaBoard(width, height, nHoles, nBoxes, nCollectibles, nEnemies, nPortals, nLasers, nDirections, this);
                }
                else if (nDirections == 4) //Quadboard
                {
                    board = new QuadBoard(width, height, nHoles, nBoxes, nCollectibles, nEnemies, nPortals, nLasers, nDirections, this);
                }
                else //Octaboard
                {
                    board = new OctaBoard(width, height, nHoles, nBoxes, nCollectibles, nEnemies, nPortals, nLasers, nDirections, this);
                }

                //player is placed on the first tile if it isn't a hole
                if (board[0, 0] != null)
                {
                    //create a player
                    player = new Player(board, board[0, 0].position);
                }
                else
                {
                    player = new Player(board, board[1, 0].position);
                }
                currentGameState = new GameState(board, player);
            }

            Moves = board.GetKeysDirection(BoardInfo.nDirections);

            if (MCTSPlayer)
            {
                treeRootMTCS = new NodeMCTS(currentGameState);
            }

            baseObstaclePos = new Vector2[board.obstacles.Count];

            for (int i = 0; i < board.obstacles.Count; i++)
            {
                baseObstaclePos[i] = board.obstacles[i].position;
            }

            base.Initialize();
        }
Exemplo n.º 2
0
        Board LoadLevel(out Player player)
        {
            string[] file = File.ReadAllLines(Content.RootDirectory + "/level.txt");
            width  = file[0].Length;
            height = file.Length;
            List <Obstacle>    obstacles = new List <Obstacle>();
            List <WinObject>   winObjects = new List <WinObject>();
            List <EnemyObject> enemyObjects = new List <EnemyObject>();
            Vector2            playerPos = new Vector2();
            int holesCount = 0, boxCount = 0, enemyCount = 0, collectibleCount = 0;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    // Hole
                    if (file[i][j] == '#')
                    {
                        holesCount++;
                    }
                    //Box
                    else if (file[i][j] == 'B')
                    {
                        boxCount++;
                    }
                    //Enemy
                    else if (file[i][j] == 'E')
                    {
                        enemyCount++;
                    }
                    //Collectible
                    else if (file[i][j] == 'C')
                    {
                        collectibleCount++;
                    }
                }
            }

            Board tempBoard = new HexaBoard(width, height, holesCount, boxCount, enemyCount, nPortals, nLasers, nCollectibles, nDirections, this);

            Vector2[] holesPosition = new Vector2[holesCount];
            holesCount = 0;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    // Player
                    if (file[y][x] == 'P')
                    {
                        playerPos = new Vector2(x, y);
                    }
                    //Box
                    else if (file[y][x] == 'B')
                    {
                        Box box = new Box(tempBoard, this)
                        {
                            position = new Vector2(x, y)
                        };
                        obstacles.Add(box);
                    }
                    //Toggle
                    else if (file[y][x] == 'T')
                    {
                        Toggle toggle = new Toggle(this);
                        toggle.position = new Vector2(x, y);
                        winObjects.Add(toggle);
                    }
                    //Collectible
                    else if (file[y][x] == 'C')
                    {
                        Collectible collectible = new Collectible(this);
                        collectible.position = new Vector2(x, y);
                        winObjects.Add(collectible);
                    }
                    //Hole
                    else if (file[y][x] == '#')
                    {
                        holesPosition[holesCount] = new Vector2(x, y);
                        holesCount++;
                    }
                    //Enemy
                    else if (file[y][x] == 'E')
                    {
                        Spike spike = new Spike(this);
                        spike.position = new Vector2(x, y);
                        enemyObjects.Add(spike);
                    }
                }
            }

            Board board = new HexaBoard(width, height, holesPosition, obstacles, enemyObjects, winObjects, nDirections, this);

            if (nDirections == 4)
            {
                board = new QuadBoard(width, height, holesPosition, obstacles, enemyObjects, winObjects, nDirections, this);
            }

            player           = new Player(board, playerPos);
            currentGameState = new GameState(board, player);
            return(board);
        }