示例#1
0
        static void Main(string[] args)
        {
            MineSweeper    juego = new MineSweeper(10);
            MineSweeperGUI g     = new MineSweeperGUI(juego);

            Jugar(g);
        }
示例#2
0
        //----------------------------------------------------------------------------------
        //MineSweeper
        //----------------------------------------------------------------------------------
        static void MineSweeper_ColocarMinas(MineSweeper mineSweeper)
        {
            int minasColocadas = 0;

            mineSweeper.Celdas = new Celda[mineSweeper.CantMinas, mineSweeper.CantMinas];

            while (minasColocadas < mineSweeper.CantMinas)
            {
                for (int fila = 0; fila < mineSweeper.Celdas.GetLength(0); fila++)
                {
                    for (int col = 0; col < mineSweeper.Celdas.GetLength(1); col++)
                    {
                        bool esMina = (minasColocadas < mineSweeper.CantMinas && MineSweeper_DebeColocarMina(mineSweeper));

                        if (mineSweeper.Celdas[fila, col] == null)
                        {
                            mineSweeper.Celdas[fila, col] = new Celda(esMina);
                            if (esMina)
                            {
                                minasColocadas++;
                            }
                        }
                        else if (esMina && !mineSweeper.Celdas[fila, col].EsMina)
                        {
                            minasColocadas++;
                            mineSweeper.Celdas[fila, col].EsMina = esMina;
                        }
                    }
                }
            }
        }
示例#3
0
        static void MineSweeper_DescubrirCelda(MineSweeper mineSweeper, int fil, int col)
        {
            if (!MineSweeper_EsCoordValida(mineSweeper, fil, col))
            {
                return;
            }

            if (mineSweeper.Celdas[fil, col].TieneBandera)
            {
                return;
            }

            if (mineSweeper.Celdas[fil, col].EsMina)
            {
                mineSweeper.Jugando    = false;
                mineSweeper.EsVictoria = false;
                MineSweeper_DescubrirMinas(mineSweeper);
                return;
            }

            int minasCerca = 0;

            for (int f = fil - 1; f <= fil + 1; f++)
            {
                for (int c = col - 1; c <= col + 1; c++)
                {
                    if ((f != fil || c != col) && MineSweeper_EsCoordValida(mineSweeper, f, c) && mineSweeper.Celdas[f, c].EsMina)
                    {
                        minasCerca++;
                    }
                }
            }

            mineSweeper.Celdas[fil, col].CantMinasCerca = minasCerca;
            Celda_Descubrir(mineSweeper.Celdas[fil, col]);
            mineSweeper.CasillerosCubiertos--;

            if (mineSweeper.Celdas[fil, col].CantMinasCerca == 0)
            {
                for (int f = fil - 1; f <= fil + 1; f++)
                {
                    for (int c = col - 1; c <= col + 1; c++)
                    {
                        if ((f != fil || c != col) && MineSweeper_EsCoordValida(mineSweeper, f, c) && !mineSweeper.Celdas[f, c].EsMina)
                        {
                            if (mineSweeper.Celdas[f, c].EstaCubierta)
                            {
                                MineSweeper_DescubrirCelda(mineSweeper, f, c);
                            }
                        }
                    }
                }
            }
        }
示例#4
0
 static void MineSweeper_DescubrirMinas(MineSweeper mineSweeper)
 {
     for (int fila = 0; fila < mineSweeper.Celdas.GetLength(0); fila++)
     {
         for (int col = 0; col < mineSweeper.Celdas.GetLength(1); col++)
         {
             if (mineSweeper.Celdas[fila, col].EsMina)
             {
                 Celda_Descubrir(mineSweeper.Celdas[fila, col]);
             }
         }
     }
 }
示例#5
0
        static void MineSweeper_UbicarBandera(MineSweeper mineSweeper, int fil, int col)
        {
            if (!MineSweeper_EsCoordValida(mineSweeper, fil, col))
            {
                return;
            }

            if (!mineSweeper.Celdas[fil, col].TieneBandera && mineSweeper.CantBanderasRestantes > 0)
            {
                mineSweeper.CantBanderasRestantes--;
                mineSweeper.CasillerosCubiertos--;
                mineSweeper.Celdas[fil, col].TieneBandera = true;
            }
            else if (mineSweeper.Celdas[fil, col].TieneBandera)
            {
                mineSweeper.CantBanderasRestantes++;
                mineSweeper.CasillerosCubiertos++;
                mineSweeper.Celdas[fil, col].TieneBandera = false;
            }
        }
示例#6
0
        static void MineSweeper_ValidarTablero(MineSweeper mineSweeper)
        {
            if (mineSweeper.CasillerosCubiertos == 0)
            {
                mineSweeper.Jugando    = false;
                mineSweeper.EsVictoria = true;

                for (int fila = 0; fila < mineSweeper.Celdas.GetLength(0) && mineSweeper.EsVictoria; fila++)
                {
                    for (int col = 0; col < mineSweeper.Celdas.GetLength(1) && mineSweeper.EsVictoria; col++)
                    {
                        if (mineSweeper.Celdas[fila, col].EsMina && !mineSweeper.Celdas[fila, col].TieneBandera)
                        {
                            mineSweeper.EsVictoria = false;
                        }
                    }
                }

                if (!mineSweeper.EsVictoria)
                {
                    MineSweeper_DescubrirMinas(mineSweeper);
                }
            }
        }
示例#7
0
 public MineSweeperGUI(MineSweeper juego)
 {
     this.Juego = juego;
     this.Input = new Input();
 }
示例#8
0
 static bool MineSweeper_EsVictoria(MineSweeper mineSweeper)
 {
     return(mineSweeper.EsVictoria);
 }
示例#9
0
 static bool MineSweeper_EsFinDelJuego(MineSweeper mineSweeper)
 {
     return(!mineSweeper.Jugando || mineSweeper.EsVictoria);
 }
示例#10
0
 static bool MineSweeper_EsCoordValida(MineSweeper mineSweeper, int fil, int col)
 {
     return(fil >= 0 && fil < mineSweeper.Celdas.GetLength(0) && col >= 0 && col < mineSweeper.Celdas.GetLength(1));
 }
示例#11
0
 static bool MineSweeper_DebeColocarMina(MineSweeper mineSweeper)
 {
     return(mineSweeper.RNG.Next(0, 100) > 90);
 }