Programación VB para Buscaminas
Sub privado Form_Load()Init_FormEnd Sub
Sub privado Form_MouseUp(Botón como entero, Mayús como entero, x como único, y como único)Atenuar x1 como entero, y1 como enterox1 = Fix((x - x0) / a): y1 = Fix((y - y0) / a)Si (x - x0) > ((Col_Num + 1) * a) O (y - y0) > ((Col_Num + 1) * a) Luego salga de SubIf x < x0 O y < y0 Luego salga de SubIf x < x0 + x1 * a + 2 O _x > x0 + x1 * a + a - 4 O _y < y0 + y1 * a + 2 O _y > y0 + y1 * a + a - 4 _Entonces salir SubIf Button = 1 ThenIf Map(x1, y1) = 0 ThenCall fan(x1, y1)ElseIf Map(x1, y1) = 1 ThenCall lostEnd IfElseIf Button = 2 ThenCall draw_flg (x1, y1)Fin SiDim n como entero = 0Dim i como entero, j como enteroPara i = 0 a Col_NumPara j = 0 a Row_NumSi Map(i, j) = -2 Entonces n = n + 1Siguiente jSiguiente iSi n = (Col_Num + 1) * (Row_Num + 1) - Ant_Num ThenBeepCurrentX = (Col_Num / 2) * a + x0CurrentY = (Row_Num / 2) * a + y0Call sub1a = Form1.FontSizeForm1.FontSize = 80'Form1.ForeColor = vbBlackPrint "tú ganas "Form1.FontSize = aEnd IfEnd Sub
Sub fan(x como entero, y como entero)Dim i como entero, j como enteroDim n como enteroPara i = -1 a 1Para j = -1 a 1Si j * i = 0 Y Map(x + i, y + j) = 0 ThenMap(x + i, y + j) = -2n = Counts(x + i, y + j)Form1.Line (x0 + (i + x) * a + 2, y0 + (j + y) * a + 2)-Step(a - 4, a - 4), Form1.BackColor, BF
Si n <> 0 ThenCurrentX = (x + i) * a + 2 + x0CurrentY = (y + j) * a + 2 + y0Seleccione caso nCase Is = 1Form1.ForeColor = vbWhiteCase Is = 2Form1.ForeColor = vbYellowCase Is > 2For
m1.ForeColor = vbRedEnd SelectPrint nElseIf n = 0 Then
Llamar a fan(x + i, y + j)End IfEnd IfNext jNext iEnd Sub
La función cuenta (x como entero, y Como entero) Como enteroDim i Como entero, j Como enteroPara i = -1 a 1Para j = -1 a 1Si Map(x + i, y + j) = 1 Entonces Cuenta = Cuenta + 1SiguienteNextEnd FunciónSub perder()Atenuar i como entero , j As IntegerFor i = 0 To Row_NumFor j = 0 To Col_NumIf Map(j, i) = 1 ThenForm1.FillColor = vbBlackForm1.FillStyle = 0Form1.Circle (x0 + j * a + a / 2, y0 + i * a + a / 2), a / 3, vbBlack, , , 0.8Form1.Line (x0 + j * a, y0 + i * a)-Step(a, a), vbWhiteForm1.Line (x0 + j * a + a, y0 + i * a)-Step(-a, a), vbWhite
ElseIf Map(j, i) = 0 ThenForm1.Line (x0 + j * a + 2, y0 + i * a + 2)-Paso(a - 4, a - 4), Form1.BackColor, BFCurrentX = j * a + x0CurrentY = i * a + y0Print Counts(j, i)End IfNext j
Siguiente iBeepa = Form1.FontSizeForm1.FontSize = 80'Form1.ForeColor = vbBlackPrint "pierdes"Form1.FontSize = aEnd SubSub draw_flg(x como entero, y como entero)CurrentX = x * a + x0 + 2CurrentY = y * a + y0 + 2Print "?"End Sub
Public Sub Init_Form()
Form1.ClsForm1.ScaleMode = 3Form1.Width = 8000Form1.Height = 6000Form1.BackColor = vbGreenForm1.AutoRedraw = Trueform1.caption= "Un simple juego de buscaminas" Col_Num = 10 'Obtiene el número de columnas Row_Num = 10 'Obtiene el número de filas a = 20 'Ancho (alto) de la unidad Ant_Num = 40 'El número de minas ReDim Map(-1 To Col_Num + 1 , -1 a Row_Num + 1)Dim i como entero, j como enteroPara i = -1 a Row_Num + 1
Para j = -1 a Col_Num + 1Form1.Line (x0 + j * a, y0 + i * a )-Paso(a, a), 0, BForm1.Line (x0
+ j * a + 2, y0 + i * a + 2)-Step(a - 4, a - 4), vbRed, BFMap(j, i) = 0 'La marca de posición de inicialización es el espacio 0Si i = -1 O i = Row_Num + 1 O j = -1 O j = Row_Num + 1 ThenForm1.Line (x0 + j * a + 1, y0 + i * a + 1)-Step(a - 2, a - 2), RGB(100 , 120, 100), BF 'Dibuja las paredes circundantes Map(j, i) = -1 'Marca las posiciones circundantes como paredes: -1End IfNext j
Siguiente iDim x As Integer, y As IntegerFor i = 1 To Ant_Num1000Randomizex = Rnd * Col_Numy = Rnd * Row_NumDoEventsIf Map(x, y) <> 0 Then GoTo 1000Map(x, y) = 1NextEnd Sub
Sub sub1()
Dim i como entero, j como enteroPara i = 0 Para Row_NumFor j = 0 Para Col_NumIf Map(j, i) = 1 ThenForm1.FillColor = vbBlackForm1.FillStyle = 0Form1.Circle (x0 + j * a + a / 2, y0 + i * a + a / 2), a / 3, vbBlack, , , 0.8ElseIf Map(j, i) = 0 ThenForm1.Line (x0 + j * a + 2, y0 + i * a + 2)-Step( a - 4, a - 4), Form1.BackColor, BFCurrentX = j * a + x0CurrentY = i * a + y0Print Counts(j, i)End IfNext j
Siguiente iEnd Sub