Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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();   
        }
Ejemplo n.º 3
0
        public static void FindBombs(List <List <int> > solvingMatrix, List <Tile> columns, List <Tile> numberedTiles, ScreenShot screen)
        {
            int         rowSum         = 0;
            bool        negativeNumber = false;
            List <Tile> tilesInRow     = new List <Tile>();

            for (int i = 0; i < solvingMatrix[0].Count(); i++)
            {
                for (int j = 0; j < solvingMatrix.Count() - 1; j++)
                {
                    rowSum += solvingMatrix[j][i];
                    if (solvingMatrix[j][i] < 0)
                    {
                        negativeNumber = true;
                    }
                    if (solvingMatrix[j][i] != 0)
                    {
                        tilesInRow.Add(columns[j]);
                    }
                }
                if (rowSum == solvingMatrix[solvingMatrix.Count() - 1][i] && !negativeNumber)
                {
                    for (int j = 0; j < tilesInRow.Count(); j++)
                    {
                        tilesInRow[j].SetTileType(TileType.Mine);
                        RightMouseClick(screen.GetScreenLeft() + 15 + 30 * tilesInRow[j].GetXpos(), screen.GetScreenTop() + 15 + 30 * tilesInRow[j].GetYpos());
                        numberedTiles[i].DecrNumber();
                        if (numberedTiles[i].GetNumber() == 0)
                        {
                        }
                    }
                }
                if (solvingMatrix[solvingMatrix.Count() - 1][i] == 0 && tilesInRow.Count() == 1)
                {
                    LeftMouseClick(screen.GetScreenLeft() + 15 + 30 * tilesInRow[0].GetXpos(), screen.GetScreenTop() + 15 + 30 * tilesInRow[0].GetYpos());
                }

                tilesInRow.Clear();
                negativeNumber = false;
                rowSum         = 0;
            }
        }
Ejemplo n.º 4
0
        public static void FindBombs(List<List<int>> solvingMatrix, List<Tile> columns,List<Tile> numberedTiles, ScreenShot screen)
        {
            int rowSum = 0;
            bool negativeNumber = false;
            List<Tile> tilesInRow = new List<Tile>();
            for (int i = 0; i < solvingMatrix[0].Count(); i++)
            {
                for (int j = 0; j < solvingMatrix.Count() - 1; j++)
                {
                    rowSum += solvingMatrix[j][i];
                    if (solvingMatrix[j][i] < 0)
                    {
                        negativeNumber = true;
                    }
                    if (solvingMatrix[j][i] != 0)
                    {
                        tilesInRow.Add(columns[j]);
                    }
                }
                if (rowSum == solvingMatrix[solvingMatrix.Count()-1][i] && !negativeNumber)
                {
                    for (int j = 0; j < tilesInRow.Count(); j++) 
                    {
                        tilesInRow[j].SetTileType(TileType.Mine);
                        RightMouseClick(screen.GetScreenLeft() + 15 + 30 * tilesInRow[j].GetXpos(), screen.GetScreenTop() + 15 + 30 * tilesInRow[j].GetYpos());
                        numberedTiles[i].DecrNumber();
                        if (numberedTiles[i].GetNumber() == 0)
                        {

                        }
                    }
                        
                }
                if(solvingMatrix[solvingMatrix.Count()-1][i] == 0 && tilesInRow.Count() == 1)
                {
                    LeftMouseClick(screen.GetScreenLeft() + 15 + 30 * tilesInRow[0].GetXpos(), screen.GetScreenTop() + 15 + 30*tilesInRow[0].GetYpos());

                }

                tilesInRow.Clear();
                negativeNumber = false;
                rowSum = 0;
            }
        }