Beispiel #1
0
        public static bool check_colid(Ball ball, Wall [,] wall, int size, Form form)
        {
            int x = ball.Location.X;
            int y = ball.Location.Y;

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    if (wall[i, j] == null)
                    {
                        continue;
                    }
                    int target_x = wall[i, j].Location.X;
                    int target_y = wall[i, j].Location.Y;

                    if ((x < target_x + 100 && x > target_x) && (y > target_y && y < target_y + 25))
                    {
                        form.Controls.Remove(wall[i, j]);
                        wall[i, j].Dispose();
                        wall[i, j] = null;
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
    // Start is called before the first frame update
    void Start()
    {
        saveGame = GameObject.Find("GameManager").GetComponent <SaveGame>();

        if (saveGame.RoomsCompleted() == 3)
        {
            Time.timeScale = 0;
            GameObject.Find("Canvas").GetComponent <UIPanels>().enemyExplainPanel.SetActive(true);
        }

        length = Random.Range(minLength, maxLength);
        height = Random.Range(minHeight, maxHeight);
        //save the length and height of the dungeon as one "Coordinate"
        size = new Coordinate(length, height);
        //initialise grids for path and filler
        pathGrid   = new Wall[size.x, size.y];
        fillerGrid = new Ground[size.x, size.y];

        //create a path through the dungeon
        path = new List <Wall>();
        GeneratePath();
        GenerateFiller();
        GenerateBorders();
        GenerateContent();
    }
Beispiel #3
0
        protected void GenerateFarWinZoneEnter(Wall[,] field, RectZone winZone, Random random)
        {
            var fieldRect = new RectZone(0, 0, field.GetLength(1), field.GetLength(0));

            int[,] lengths = new int[fieldRect.Height, fieldRect.Width];
            Ololo(lengths, field, fieldRect, new Point(0, 0), 1);

            Move  bestMove  = null;
            Point?bestPos   = null;
            int   maxLength = 0;

            for (int y = winZone.Top; y < winZone.Top + winZone.Height; ++y)
            {
                for (int x = winZone.Left; x < winZone.Left + winZone.Width; ++x)
                {
                    foreach (var move in Moves)
                    {
                        var l = lengths[y + move.Direction.Y, x + move.Direction.X];
                        if (l >= maxLength)
                        {
                            maxLength = l;
                            bestMove  = move;
                            bestPos   = new Point(x, y);
                        }
                    }
                }
            }

            if (bestPos == null)
            {
                throw new Exception("bestPos not found");
            }

            DestroyWall(field, bestMove, bestPos.Value, bestPos.Value.Move(bestMove.Direction.X, bestMove.Direction.Y));
        }
Beispiel #4
0
        protected void EraseWinZone(Wall[,] field, RectZone winZone)
        {
            for (int y = 0; y < winZone.Height; ++y)
            {
                for (int x = 0; x < winZone.Width; ++x)
                {
                    int realX = x + winZone.Left;
                    int realY = y + winZone.Top;

                    if (y != 0)
                    {
                        field[realY, realX] &= (~Wall.Top);
                    }

                    if (y != winZone.Height - 1)
                    {
                        field[realY, realX] &= (~Wall.Bottom);
                    }

                    if (x != 0)
                    {
                        field[realY, realX] &= (~Wall.Left);
                    }

                    if (x != winZone.Width - 1)
                    {
                        field[realY, realX] &= (~Wall.Right);
                    }
                }
            }
        }
Beispiel #5
0
        private void Ololo(int[,] lengths, Wall[,] field, RectZone fieldZone, Point pos, int length)
        {
            if (fieldZone.Contains(pos) == false || lengths[pos.Y, pos.X] != 0)
            {
                return;
            }

            lengths[pos.Y, pos.X] = length;

            length++;
            Wall currentWall = field[pos.Y, pos.X];

            if ((currentWall & Wall.Top) == Wall.None)
            {
                Ololo(lengths, field, fieldZone, new Point(pos.X, pos.Y - 1), length);
            }

            if ((currentWall & Wall.Bottom) == Wall.None)
            {
                Ololo(lengths, field, fieldZone, new Point(pos.X, pos.Y + 1), length);
            }

            if ((currentWall & Wall.Left) == Wall.None)
            {
                Ololo(lengths, field, fieldZone, new Point(pos.X - 1, pos.Y), length);
            }

            if ((currentWall & Wall.Right) == Wall.None)
            {
                Ololo(lengths, field, fieldZone, new Point(pos.X + 1, pos.Y), length);
            }
        }
Beispiel #6
0
    public void BuildLevel(Board board)
    {
        var children = new List <GameObject>();

        foreach (Transform child in transform)
        {
            children.Add(child.gameObject);
        }
        children.ForEach(child => Destroy(child));

        originalMatrix = board.Grid;
        matrix         = PrepareMatrix(originalMatrix);
        int n = board.NoRooms;

        floors = new Floor[matrix.GetLength(0) - 2, matrix.GetLength(1) - 2];
        walls  = new Wall[matrix.GetLength(0) - 1, matrix.GetLength(1) - 1];
        Rooms  = new Room[n];
        graph  = new Graph();
        for (int i = 0; i < n; ++i)
        {
            Rooms[i] = new Room(i + 1, DefaultFloorMaterial);
        }
        RoomPropertiesPanel.InitializePanel(n);
        Vector3 shift = new Vector3(((matrix.GetLength(1) - 2) * unit) / 2, 0f, ((matrix.GetLength(0) - 2) * -unit) / 2);

        this.transform.position = shift;
        SpawnWalls();
        SpawnFloors();
        SpawnDoors();
        foreach (var room in Rooms)
        {
            room.SetRoomMaterial();
        }
        isSaved = false;
    }
Beispiel #7
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferHeight = PIXELWIDTH * PIXELSIZE;
            graphics.PreferredBackBufferWidth  = PIXELHEIGHT * PIXELSIZE;
            Content.RootDirectory = "Content";
            accountedKeys         = new List <Keys>();
            cursorPos             = new int[] { PIXELWIDTH *PIXELSIZE / 2, PIXELHEIGHT *PIXELSIZE / 2 };
            Mouse.SetPosition(PIXELWIDTH * PIXELSIZE / 2, PIXELHEIGHT * PIXELSIZE / 2);

            pm = new PictureManager();

            worldSize = new int[] { 20, 20 };
            map       = new Wall[worldSize[0], worldSize[1]];
            pos       = new double[] { 4, 4 };
            facing    = 0;

            for (int i = 0; i < worldSize[0]; i++)
            {
                map[0, i] = new Wall("stone_wall.pic");
                map[worldSize[0] - 1, i] = new Wall("stone_wall.pic");
                map[i, 0] = new Wall("stone_wall.pic");
                map[i, worldSize[0] - 1] = new Wall("stone_wall.pic");
            }

            map[2, 2] = new Wall("stone_wall.pic");
            map[2, 3] = new Wall("stone_wall.pic");
            map[2, 4] = new Wall("stone_wall.pic");
            map[3, 5] = new Wall("stone_wall.pic");
        }
Beispiel #8
0
 protected MazeAlgorithm(Wall[,] walls)
     : base()
 {
     this.walls = walls;
     rows       = walls.GetLength(0);
     columns    = walls.GetLength(1);
 }
Beispiel #9
0
    //called as constructor
    public void Awake()
    {
        //rows = 10;
        //columns = 10;
        entrance = new Vector2(-1, -1);
        exit = new Vector2(-1, -1);
        cases = new GameObject[columns, rows];
        walls = new Wall[columns, rows];
        deadends = new List<Vector2>();
        visited = new bool[columns, rows];

        for (int i = 0; i < columns; i++)
        {
            for (int j = 0; j < rows; j++)
            {
                visited[i, j] = false;
                walls[i, j] = Wall.RD;
            }
        }
        //Instantiate cells
        for (int i = 0; i < columns; i++)
        {
            for (int j = 0; j < rows; j++)
            {
                cases[i, j] = (GameObject) Instantiate(cell, new Vector3(i - 4.5f, 0f, j - 4.5f), Quaternion.identity);
            }
        }
    }
Beispiel #10
0
 public MazeSolver(Wall[,] field, int depth)
 {
     this.field = field;
     this.depth = depth;
     width      = field.GetLength(1);
     height     = field.GetLength(0);
 }
Beispiel #11
0
        /*
         * SetDirection
         * the ai player is given access to the gamegrid to calculate it's next direction, they are also
         * given the users current direction so they can try to match it.
         */
        public override void setDirection(Wall[,] matrix, Player.Direction userDirection)
        {
            // Set the users direction as the initially best one
            Player.Direction bestDirection = userDirection;
            int bestDistance = getDistance(userDirection, matrix);
            

            //Change direction only when the best direction is bad
            if (bestDistance <= threshold)
            {
                // Test all directions and set the best one
                Player.Direction nextDirection = Player.Direction.Up;
                int nextDistance = getDistance(nextDirection, matrix);
                if (nextDistance > bestDistance)
                    bestDirection = nextDirection;

                nextDirection = Player.Direction.Right;
                nextDistance = getDistance(nextDirection, matrix);
                if (nextDistance > bestDistance)
                    bestDirection = nextDirection;

                nextDirection = Player.Direction.Down;
                nextDistance = getDistance(nextDirection, matrix);
                if (nextDistance > bestDistance)
                    bestDirection = nextDirection;

                nextDirection = Player.Direction.Left;
                nextDistance = getDistance(nextDirection, matrix);
                if (nextDistance > bestDistance)
                    bestDirection = nextDirection;
            }
            // Change direction to the best one if close to hitting a wall
            if (getDistance(this.direction, matrix) <= threshold)
                this.direction = bestDirection;
        }
    public void BuildLevel(Board board)
    {
        var children = new List<GameObject>();
        foreach (Transform child in transform)
            children.Add(child.gameObject);
        children.ForEach(child => Destroy(child));

        originalMatrix = board.Grid;
        matrix = PrepareMatrix(originalMatrix);
        int n = board.NoRooms;
        floors = new Floor[matrix.GetLength(0)-2,matrix.GetLength(1)-2];
        walls = new Wall[matrix.GetLength(0)-1, matrix.GetLength(1)-1];
        Rooms = new Room[n];
        graph = new Graph();
        for (int i = 0; i < n; ++i)
        {
            Rooms[i] = new Room(i+1, DefaultFloorMaterial);
        }
        RoomPropertiesPanel.InitializePanel(n);
        Vector3 shift = new Vector3(((matrix.GetLength(1) - 2) * unit) / 2, 0f, ((matrix.GetLength(0) - 2) * -unit) / 2);
        this.transform.position = shift;
        SpawnWalls();
        SpawnFloors();
        SpawnDoors();
        foreach (var room in Rooms)
        {
            room.SetRoomMaterial();
        }
        isSaved = false;
    }
Beispiel #13
0
 /// <summary>
 /// Создаёт квадратное поле.
 /// </summary>
 /// <param name="dimension">Размер поля.</param>
 public Field(int dimension)
 {
     Dimension = dimension;
     walls = new Wall[dimension - 1, dimension - 1];
     GenerateGraph();
     GenerateEndOfPathes();
     ActivePlayer = 1;
 }
Beispiel #14
0
 /*
  * The Walls slots includes also the the edges of the board, which in practice can't hold walls.
  */
 public Slots()
 {
     _slotsMatrix = new Wall[Board.BoardSize, Board.BoardSize];
     for (int i = 0; i < Board.BoardSize; i++)
     {
         for (int j = 0; j < Board.BoardSize; j++)
         {
             _slotsMatrix[i, j] = null;
         }
     }
 }
Beispiel #15
0
        public override void Reset()
        {
            map = new Wall[collums, rows];

            for (int x = 0; x < collums; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    AddMap(x, y, 0);
                }
            }
        }
Beispiel #16
0
        private void DestroyWall(Wall[,] field, Move move, Point fromCell, Point toCell)
        {
            var width  = field.GetLength(1);
            var height = field.GetLength(0);


            field[fromCell.Y, fromCell.X] &= (~move.FromWall);
            field[toCell.Y, toCell.X]     &= (~move.ToWall);

            field[height - fromCell.Y - 1, width - fromCell.X - 1] &= (~move.ToWall);
            field[height - toCell.Y - 1, width - toCell.X - 1]     &= (~move.FromWall);
        }
Beispiel #17
0
    public Player()
    {
        game  = GameObject.Find("Game Generator").GetComponent <Game>();
        walls = game.GetWalls();

        player      = GameObject.Instantiate(game.playerObject, new Vector3(0f, 0f, 0f), Quaternion.identity);
        player.name = "Player";

        player.AddComponent <NavMeshAgent>();
        agent        = player.GetComponent <NavMeshAgent>();
        agent.radius = 0.55f;
    }
Beispiel #18
0
 public void SetUp(Vector2Int size)
 {
     walls   = new Wall[size.y, size.x];
     rows    = size.y;
     columns = size.x;
     for (int i = 0; i < size.y; ++i)
     {
         for (int j = 0; j < size.x; ++j)
         {
             walls[i, j] = null;
         }
     }
 }
Beispiel #19
0
    private void InitializeGame()
    {
        // Display text
        gameInfo.transform.position = new Vector3((float)Screen.width * 0.5f, (float)Screen.height * 0.9f, 0f);
        gameInfo.text = "";

        scoreInfo.transform.position = new Vector3((float)Screen.width * 0.85f, (float)Screen.height * 0.5f, 0f);
        scoreInfo.text = "Score\n" + score;

        // Game
        gameOver = false;
        win      = false;

        // Maze
        maze  = new Maze(rows, columns, wallObject, destructibleWallObject);
        walls = maze.getWalls();

        MazeAlgorithm ma = new RecursiveBacktrackingAlgorithm(walls);

        ma.CreateMaze();

        // Update NavMesh
        surface.BuildNavMesh();

        // Player
        player = new Player();

        // Camera
        camera = GameObject.Find("Main Camera");
        camera.transform.position = new Vector3(0f, 10f, -3f);
        camera.transform.rotation = Quaternion.Euler(new Vector3(60f, 0f, 0f));
        cameraOffset = camera.transform.position - player.player.transform.position;

        // Enemies
        enemies = new Enemy[enemyNumber];
        for (int i = 0; i < enemyNumber; i++)
        {
            enemies[i] = new Enemy(enemyObject, i);
        }

        // Coins
        coins = new List <Coin>();
        for (int i = 0; i < coinNumber; i++)
        {
            coins.Add(new Coin(i));
        }

        // Score
        score = 0;
    }
Beispiel #20
0
        /*
         * SetDirection
         * The user will ignore the information from the grid but use this method to change it's direction
         * Left has priority
         */
        public override void setDirection(Wall[,] matrix, Player.Direction userDirection)
        {
            if (turnLeft)
            {
                turnCounterClockwise();
            }
            else if (turnRight)
            {
                turnClockwise();
            }

            turnLeft  = false;
            turnRight = false;
        }
Beispiel #21
0
    private void Awake()
    {
        float aspect       = Camera.main.aspect;
        float cameraHeight = Camera.main.orthographicSize * 2;
        float cameraWidth  = cameraHeight * aspect;

        left  = -cameraWidth / 2;
        right = cameraWidth / 2;
        up    = cameraHeight / 2 + Camera.main.transform.position.y;
        down  = background.localPosition.y - background.localScale.y / 2;

        grid = new Wall[(int)cameraWidth, (int)up - (int)down];
        xOff = (int)cameraWidth / 2;
        yOff = -Mathf.FloorToInt(down);
    }
 public void generateWorld()
 {
     this.walls = new Wall[tunnelLength, tunnelDensity];
     for (int x = 0; x < tunnelLength; x++)
     {
         for (int a = 0; a < tunnelDensity; a++)
         {
             float ang = MathHelper.ToRadians(a * 10);
             Wall c = new Wall(new Vector3((float)Math.Cos(ang) * 100, (float)Math.Sin(ang) * 100, x * 10f));
             this.walls[x, a] = c;
         }
     }
     this.camera.position = Vector3.Up;
     this.camera.rotation = new Vector3(0, MathHelper.Pi, 0);
 }
Beispiel #23
0
 public Map(int width = 900, int height = 500)
 {
     // Init
     SizeX = width;
     SizeY = height;
     Types = new BlockType[30];
     WallTypes = new WallType[10];
     Blocks = new Block[SizeX, SizeY];
     Walls = new Wall[SizeX, SizeY];
     DroppedItems = new DroppedItemCollection();
     Fluids = new Fluid.FluidCollection();
     Entities = new EntityPackage();
     Flora = new FloraPackage();
     WallTypes[0] = new WallType(1, "Standard Wall", new Rectangle(0,0,24,24));
 }
Beispiel #24
0
        protected void GenerateWays(Wall[,] field, RectZone winZone, Random random)
        {
            var fieldRect = new RectZone(0, 0, field.GetLength(1), field.GetLength(0));
            int moveCount = (fieldRect.Width * fieldRect.Height - winZone.Width * winZone.Height - 2) / 2;

            var currentPos = new Point(0, 0);
            var latestMove = Moves[random.Next(4)];
            int count      = 0;

            while (moveCount > 0)
            {
                count++;
                if (count > 100000)
                {
                    throw new Exception("Слишком долго!");
                }

                var randNumber = random.Next(5);

                var move = randNumber < Moves.Length ? Moves[randNumber] : latestMove;
                latestMove = move;

                var newPos = currentPos.Move(move.Direction.X, move.Direction.Y);

                if (fieldRect.Contains(newPos) == false)
                {
                    continue;
                }

                bool notInWinZone    = winZone.Contains(newPos) == false && winZone.Contains(currentPos) == false;
                bool fromNotFullCell = field[currentPos.Y, currentPos.X] != Wall.Full;
                bool toFullCell      = field[newPos.Y, newPos.X] == Wall.Full;
                bool fromStartPoint  = currentPos.Y == 0 && currentPos.X == 0;

                if (notInWinZone && (fromNotFullCell || fromStartPoint) && toFullCell)
                {
                    DestroyWall(field, move, currentPos, newPos);
                    moveCount--;
                }

                currentPos = newPos;
            }

            //Console.WriteLine(count);
        }
Beispiel #25
0
    public void SetupWall(List <Wall> neighbours, bool root, Wall[,] grid, int x, int y)
    {
        this.neighbours = neighbours;
        //foreach (Wall wall in neighbours) {
        //    Debug.Log("Created With: " + wall.transform.localPosition.ToString());
        //}
        this.root = root;
        this.dead = false;
        this.grid = grid;
        this.x    = x;
        this.y    = y;

        dependants.Clear();
        criticalSupports.Clear();
        dependantLocSum.Set(0, 0, 0);

        CalcCriticalSupports();
    }
Beispiel #26
0
        public void Update(Wall[,] mazeField)
        {
            const float progressInTick = 0.3f;

            progress += progressInTick;
            if (progress > 1 || currentCommand == InputCommand.None)
            {
                pos = nextpos;
                if (Сommand == InputCommand.Down && (mazeField[pos.Y, pos.X] & Wall.Bottom) == 0)
                {
                    nextpos = pos.Move(0, 1);
                }

                if (Сommand == InputCommand.Up && (mazeField[pos.Y, pos.X] & Wall.Top) == 0)
                {
                    nextpos = pos.Move(0, -1);
                }

                if (Сommand == InputCommand.Left && (mazeField[pos.Y, pos.X] & Wall.Left) == 0)
                {
                    nextpos = pos.Move(-1, 0);
                }

                if (Сommand == InputCommand.Right && (mazeField[pos.Y, pos.X] & Wall.Right) == 0)
                {
                    nextpos = pos.Move(1, 0);
                }

                if (nextpos.Y != pos.Y || nextpos.X != pos.X)
                {
                    if (progress > 1)
                    {
                        progress -= 1;
                    }
                    currentCommand = Сommand;
                }
                else
                {
                    progress       = 0;
                    currentCommand = InputCommand.None;
                }
            }
        }
Beispiel #27
0
 public void Init()
 {
     //初始化数组 需要注意一下墙的有个索引是要加一的   因为两个格子是3堵墙 得+1
     cubes  = new Floor[X, Y];
     walls1 = new Wall[X, Y + 1];
     walls2 = new Wall[X + 1, Y];
     //两层for循环嵌套自动生成 地面 与 墙 的游戏物体
     CreateGround();
     CreateWall1();
     CreateWall2();
     //初始化一下每个地面元素里的两个数组, 并且找到地面元素相邻的地面 和自己的四堵墙
     foreach (var item in cubes)
     {
         item.neighborFloors = new Floor[4];
         item.neighborWalls  = new Wall[4];
         item.GetNeighborFloors();
         item.GetNeighborWalls();
     }
 }
        /*
         * Reset
         * restarts the Game Grid with user and enemies
         */
        private void reset()
        {
            // Reset the matrix
            matrix = new Wall[size, size];

            // Load a new blue player
            user = new User(size / 2, size - 1 - 2, Player.Direction.Up);

            // Load enemies
            enemies = new Enemy[level];

            for (int i = 0; i < level; i++)
            {
                enemies[i] = new Enemy(size / 2 + level / 2 - i, 2, Player.Direction.Down);
            }

            // Set living players
            livingPlayers = getLivingPlayers();
        }
Beispiel #29
0
    // Use this for initialization
    void Awake()
    {
//		lives = new int[numPlayers];
//		for(int k=0;k<numPlayers;k++){
//			lives[k] = 3;
//		}
        availableSpawns = new SortedList();
        players         = new List <Player>();
        xSize           = (int)mapBackground.renderer.bounds.size.x;
        ySize           = (int)mapBackground.renderer.bounds.size.y;
        grid            = new Wall[xSize, ySize];
        for (int k = 0; k < xSize; k++)
        {
            for (int c = 0; c < ySize; c++)
            {
                grid[k, c] = new Wall();
            }
        }
        transform.position = new Vector3(xSize / 2, ySize / 2, -10);
    }
Beispiel #30
0
        private void CreateWalls()
        {
            _wallsHorizontal = new Wall[_mapWidth, _mapHeight - 1];
            _wallsVertical   = new Wall[_mapWidth - 1, _mapHeight];

            for (int i = 0; i < _wallsHorizontal.GetLength(0); i++)
            {
                for (int j = 0; j < _wallsHorizontal.GetLength(1); j++)
                {
                    _wallsHorizontal[i, j] = CreateWall(i, j, true);
                }
            }

            for (int i = 0; i < _wallsVertical.GetLength(0); i++)
            {
                for (int j = 0; j < _wallsVertical.GetLength(1); j++)
                {
                    _wallsVertical[i, j] = CreateWall(i, j, false);
                }
            }
        }
Beispiel #31
0
    public static List <Wall> GetNeighbours(Wall[,] grid, int x, int y)
    {
        List <Wall> neighbours = new List <Wall>();

        for (int i = -1; i < 2; i++)
        {
            for (int j = -1; j < 2; j++)
            {
                if (Math.Abs(i) == Math.Abs(j) || x + i < 0 || y + j < 0 || x + i >= grid.GetLength(0) || y + j >= grid.GetLength(1))
                {
                    continue;
                }

                if (grid[x + i, y + j] != null && !grid[x + i, y + j].scheduledForDeath)
                {
                    neighbours.Add(grid[x + i, y + j]);
                }
            }
        }

        return(neighbours);
    }
Beispiel #32
0
        // Gets the distance from this players location to the nearest wall in a driection
        private int getDistance(Player.Direction dir, Wall[,] matrix)
        {
            int distance = 0;

            if (dir == Player.Direction.Left)
                for (int i = this.x - 1; i >= 0; i--)
                {
                    if (matrix[i, this.y] == null)
                        distance++;
                    else
                        return distance;
                }
            else if (dir == Player.Direction.Right)
                for (int i = this.x + 1; i < matrix.GetLength(0); i++)
                {
                    if (matrix[i, this.y] == null)
                        distance++;
                    else
                        return distance;
                }
            else if (dir == Player.Direction.Up)
                for (int i = this.y - 1; i >= 0; i--)
                {
                    if (matrix[this.x, i] == null)
                        distance++;
                    else
                        return distance;
                }
            else if (dir == Player.Direction.Down)
                for (int i = this.y + 1; i < matrix.GetLength(0); i++)
                {
                    if (matrix[this.x, i] == null)
                        distance++;
                    else
                        return distance;
                }

            return distance;
        }
Beispiel #33
0
    public Coin(int _number)
    {
        game  = GameObject.Find("Game Generator").GetComponent <Game>();
        walls = game.GetWalls();

        coin = GameObject.Instantiate(game.coinObject);
        int r = Random.Range(0, game.rows);
        int c = Random.Range(0, game.columns);

        // If the random position already contains a coin, generate a new position as the coin's position
        while (walls[r, c].hasCoin)
        {
            r = Random.Range(0, game.rows);
            c = Random.Range(0, game.columns);
        }
        walls[r, c].coin        = coin;
        walls[r, c].hasCoin     = true;
        coin.transform.position = walls[r, c].floor.transform.position + new Vector3(0f, 1.4f, 0f);
        coin.name             = "Coin " + _number;
        coin.layer            = 8;
        coin.transform.parent = GameObject.Find("Coins").transform;
    }
Beispiel #34
0
        protected void GenerateWinZoneEnter(Wall[,] field, RectZone winZone, Random random)
        {
            var fieldRect = new RectZone(0, 0, field.GetLength(1), field.GetLength(0));
            var curretPos = new Point(random.Next(winZone.Width) + winZone.Left, random.Next(winZone.Height) + winZone.Top);

            while (true)
            {
                var move    = Moves[random.Next(Moves.Length)];
                var nextPos = curretPos.Move(move.Direction.X, move.Direction.Y);

                if (winZone.Contains(nextPos) == false)
                {
                    if (fieldRect.Contains(nextPos))
                    {
                        DestroyWall(field, move, curretPos, nextPos);
                    }
                    return;
                }

                curretPos = nextPos;
            }
        }
Beispiel #35
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainForm"/> class.
        /// </summary>
        public MainForm()
        {
            wall_pic = new Bitmap("pics/" + "Green" + "Box.png");
            InitializeComponent();
            this.Width = RES_WIDTH + 325;
            this.Height = RES_HEIGHT + 40;

            PopLabel.Text = "Population: " + POPULATION.ToString();
            mutationLabel.Text = "Mutation Rate: " + mutationRate;
            crossoverLabel.Text = "Crossover Rate: " + crossoverRate.ToString();
            eliteLabel.Text = "Elitism (%): " + populationElitism.ToString();

            START_POSITION = new Point(LEN + LEN / 2, LEN + LEN / 2);
            walls = new Wall[RES_HEIGHT / LEN + 1, RES_WIDTH / LEN + 1];
            stepThroughWalls((int i, int j) => { walls[j, i] = new Wall(i * LEN, j * LEN, LEN, LEN); });
            GA_ENGINE = new GeneticAlgorithm(BITS_PER_CHROM, NUMB_STEPS, POPULATION, crossoverRate, mutationRate, populationElitism);
            PAUSE = true;
            DELAY_PAUSE = 0;
            cheese = new Cheese(new Point(), 1, 1, 1);
            cheese.location.X = LEN * ((RES_WIDTH / LEN) / 2) + LEN / 2;
            cheese.location.Y = LEN / 2;
            windowsGraphics = this.CreateGraphics();
            screen = new Bitmap(this.Width, this.Height);
            onScreenGraphics = Graphics.FromImage(screen);
            this.Paint += new PaintEventHandler(DrawGame);
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(cheese.KeyDown);
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(MainFormKeyDown);
            //this.KeyUp += new System.Windows.Forms.KeyEventHandler(cheese.KeyUp);
        }