Beispiel #1
0
        public static void UpdateBoard(Bitmap playField, Tile[ , ] board)
        {
            int tileWidth = 30;
            int tileHeight = 30;

            Color blue = Color.FromArgb(0,52,222);       // Colour of the one
            Color green = Color.FromArgb(15,149,13);     // Colour of the two
            Color red = Color.FromArgb(193,16,16);       // Colour of the three
            Color orange = Color.FromArgb(255,108,0);    // Colour of the four
            Color black = Color.FromArgb(0,0,0);         // Colour of bomb
            Color grey = Color.FromArgb(233,233,233);


            for (int i = 0; i < board.GetLength(0); i++)
            {
                for (int j = 0; j < board.GetLength(1); j++)
                {
                    if (ScreenShot.PixelInRange(black, playField, (i * tileWidth) + 10, (j * tileHeight) + 10, (i * tileWidth) + 20, (j * tileHeight) + 20) )
                    {
                        Console.WriteLine("hit a bomb");
                        Console.ReadLine();
                    }

                    else if (ScreenShot.PixelInRange(blue, playField, (i * tileWidth) + 10, (j * tileHeight) + 10, (i * tileWidth) + 20, (j * tileHeight) + 20) && board[i, j].GetTileType() == TileType.Unknown)
                    {
                        board[i,j] = new Tile(1,TileType.Clear,i,j);
                    }

                    else if (ScreenShot.PixelInRange(green, playField, (i * tileWidth) + 10, (j * tileHeight) + 10, (i * tileWidth) + 20, (j * tileHeight) + 20) && board[i, j].GetTileType() == TileType.Unknown)
                    {
                        board[i, j] = new Tile(2, TileType.Clear, i, j);
                    }

                    else if (ScreenShot.PixelInRange(red, playField, (i * tileWidth) + 10, (j * tileHeight) + 10, (i * tileWidth) + 20, (j * tileHeight) + 20) && board[i, j].GetTileType() == TileType.Unknown)
                    {
                        board[i, j] = new Tile(3, TileType.Clear, i, j);
                    }

                    else if (ScreenShot.PixelInRange(orange, playField, (i * tileWidth) + 10, (j * tileHeight) + 10, (i * tileWidth) + 20, (j * tileHeight) + 20) && board[i, j].GetTileType() == TileType.Unknown)
                    {
                        board[i, j] = new Tile(4, TileType.Clear, i, j);
                    }

                    else if (ScreenShot.PixelInRange(grey, playField, (i * tileWidth) + 10, (j * tileHeight) + 10, (i * tileWidth) + 20, (j * tileHeight) + 20) && board[i, j].GetTileType() == TileType.Unknown)
                    {
                        board[i, j] = new Tile(0, TileType.Clear, i, j);
                    }
                    //else
                    //{
                    //    board[i, j] = new Tile(TileType.Unknown, i, j);
                    //}
                }
            }

        }
Beispiel #2
0
 public void AddNeighbour(Tile Neighbour)
 {
     Neighbourhood.Add(Neighbour);
 }
Beispiel #3
0
 public static void FindNumberedTiles(Tile[,] board, List<Tile> numberedTiles)
 {
     numberedTiles.Clear();
     for (int i = 0; i < board.GetLength(0); i++)
     {
         for (int j = 0; j < board.GetLength(1); j++)
         {
             if (board[i, j].GetTileType().Equals(TileType.Clear) && board[i,j].GetNumber() > 0)
             {
                 numberedTiles.Add(board[i, j]);
                 FindAndAddNeighbours(board[i,j], board);
             }
         }
     }
     return;
 }
Beispiel #4
0
        static void Main(string[] args)
        {
            int tileWidth = 30;
            int tileHeight = 30;
            var handle = GetConsoleWindow();

            Console.SetWindowSize(100, 40);
            ShowWindow(handle, SW_HIDE);
            Thread.Sleep(300);
            
            ScreenShot screen = new ScreenShot();
            Bitmap playField = screen.GetPlayField();
            try
            {
                int boardWidth = playField.Size.Width / tileWidth;
                int boardHeight = playField.Size.Height / tileHeight;
                Console.WriteLine("Screen width: {0} Screen height: {1}", boardWidth, boardHeight);
                Tile[,] board = new Tile[boardWidth, boardHeight];
                List<Tile> numberedTiles = new List<Tile>();
                List<Tile> columns = new List<Tile>();

                for (int i = 0; i < board.GetLength(0); i++)
                {
                    for (int j = 0; j < board.GetLength(1); j++)
                    {
                        board[i, j] = new Tile(TileType.Unknown, i, j);
                    }
                }

                LeftMouseClick(screen.GetScreenLeft() + 15, screen.GetScreenTop() + 15);

                while (true)
                {
                    RemoveMouseFromPlay(screen.GetScreenLeft() - 30, screen.GetScreenTop() - 30);
                    screen.UpdateField();
                    UpdateBoard(screen.GetPlayField(), board);
                    ShowWindow(handle, SW_SHOW);
                    for (int i = 0; i < board.GetLength(1); i++)
                    {
                        for (int j = 0; j < board.GetLength(0); j++)
                        {
                            Console.Write(board[j, i]);
                        }
                        Console.Write("\n");
                    }
                    FindNumberedTiles(board, numberedTiles);
                    List<List<int>> solvingMatrix = BuildSolvingMatrix(columns, numberedTiles);
                    rref(solvingMatrix);
                    FindBombs(solvingMatrix, columns,numberedTiles, screen);

                    numberedTiles.Clear();
                    solvingMatrix.Clear();
                    columns.Clear();
                    //Console.ReadLine();
                }
            }
            catch (NullReferenceException)
            {
                Console.WriteLine("play field not found");
            }
            Console.ReadLine();   
        }
Beispiel #5
0
        public static void FindAndAddNeighbours(Tile numberedTile, Tile[,] board){
            int xpos = numberedTile.GetXpos();
            int ypos = numberedTile.GetYpos();

            if (xpos != 0)
            {
                if (board[xpos - 1, ypos].GetTileType().Equals(TileType.Unknown))
                {
                    numberedTile.AddNeighbour(board[xpos-1, ypos]);
                }
                if (ypos != 0)
                {
                    if (board[xpos - 1, ypos-1].GetTileType().Equals(TileType.Unknown))
                    {
                        numberedTile.AddNeighbour(board[xpos-1, ypos-1]);
                    }
                }
                if (ypos != board.GetLength(1) - 1)
                {
                    if (board[xpos - 1, ypos + 1].GetTileType().Equals(TileType.Unknown))
                    {
                        numberedTile.AddNeighbour(board[xpos - 1, ypos+1]);
                    }
                }
            }
            if (ypos != 0)
            {
                if (board[xpos, ypos-1].GetTileType().Equals(TileType.Unknown))
                {
                    numberedTile.AddNeighbour(board[xpos, ypos-1]);
                }
            }
            if (ypos != board.GetLength(1)-1)
            {
                if (board[xpos, ypos + 1].GetTileType().Equals(TileType.Unknown))
                {
                    numberedTile.AddNeighbour(board[xpos, ypos + 1]);
                }
            }
            if (xpos != board.GetLength(0))
            {
                if (board[xpos + 1, ypos].GetTileType().Equals(TileType.Unknown))
                {
                    numberedTile.AddNeighbour(board[xpos + 1, ypos]);
                }
                if (ypos != 0)
                {
                    if (board[xpos + 1, ypos - 1].GetTileType().Equals(TileType.Unknown))
                    {
                        numberedTile.AddNeighbour(board[xpos + 1, ypos - 1]);
                    }
                }
                if (ypos != board.GetLength(1) - 1)
                {
                    if (board[xpos + 1, ypos + 1].GetTileType().Equals(TileType.Unknown))
                    {
                        numberedTile.AddNeighbour(board[xpos + 1, ypos + 1]);
                    }
                }
            }
            return;
        }