Foros aprenderaprogramar.com
Aprender a programar => C, C++, C#, Java, Visual Basic, HTML, PHP, CSS, Javascript, Ajax, Joomla, MySql y más => Mensaje iniciado por: Chacorta en 30 de Abril 2015, 20:58
-
Ayuda porfavor!
Tengo el juego del memorama puedo jugar solo pero loq ue quiero es que juege contra la computadora y que los movimientos que yo hago se guarden el la base de datos. Si es mi turno y volteo una carta se tiene que guardar en la base de datos para cuando sea el turno de la computadora ella recuerde dond esta esa carta y la eliga y pueda ganar solo eso.
El programa que usi en visual studio 2013
Tengan en cuenta que no uso picturebox, solo label.
A qui esta el codigo que llevo
Public Class Form1
Dim j1, j2, ganador As String
Private random As New Random
Private icons =
New List(Of String) From {"!", "!", "N", "N", ",", ",", "k", "k",
"b", "b", "v", "v", "w", "w", "z", "z"}
Private firstClicked As Label = Nothing
Private secondClicked As Label = Nothing
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AssignIconsToSquares()
Label1.Visible = False
Label2.Visible = False
Label3.Visible = False
Label4.Visible = False
Label5.Visible = False
Label6.Visible = False
Label7.Visible = False
Label8.Visible = False
Label9.Visible = False
Label10.Visible = False
Label11.Visible = False
Label12.Visible = False
Label13.Visible = False
Label14.Visible = False
Label15.Visible = False
Label16.Visible = False
'desabilita los botones al inicio
Button2.Visible = False
Button3.Visible = False
End Sub
Private Sub AssignIconsToSquares()
For Each control In TableLayoutPanel1.Controls
Dim iconLabel = TryCast(control, Label)
If iconLabel IsNot Nothing Then
Dim randomNumber = random.Next(icons.Count)
iconLabel.Text = icons(randomNumber)
iconLabel.ForeColor = iconLabel.BackColor
icons.RemoveAt(randomNumber)
End If
Next
End Sub
Private Sub label_Click(sender As Object, e As EventArgs) Handles Label9.Click, Label8.Click, Label7.Click, Label6.Click, Label5.Click, Label4.Click, Label3.Click, Label2.Click, Label16.Click, Label15.Click, Label14.Click, Label13.Click, Label12.Click, Label11.Click, Label10.Click, Label1.Click
If Timer1.Enabled Then Exit Sub
Dim clickedLabel = TryCast(sender, Label)
If clickedLabel IsNot Nothing Then
If clickedLabel.ForeColor = Color.Black Then Exit Sub
If firstClicked Is Nothing Then
firstClicked = clickedLabel
firstClicked.ForeColor = Color.Black
Exit Sub
End If
secondClicked = clickedLabel
secondClicked.ForeColor = Color.Black
CheckForWinner()
If firstClicked.Text = secondClicked.Text Then
firstClicked = Nothing
secondClicked = Nothing
Exit Sub
End If
Timer1.Start()
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Stop()
firstClicked.ForeColor = firstClicked.BackColor
secondClicked.ForeColor = secondClicked.BackColor
firstClicked = Nothing
secondClicked = Nothing
End Sub
Private Sub CheckForWinner()
For Each control In TableLayoutPanel1.Controls
Dim iconLabel = TryCast(control, Label)
If iconLabel IsNot Nothing AndAlso
iconLabel.ForeColor = iconLabel.BackColor Then Exit Sub
Next
MessageBox.Show("Ganaste puto", "Congratulashiions!")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
j1 = InputBox("Jugardor", "Nombre")
'habilita los label
Label1.Visible = True
Label2.Visible = True
Label3.Visible = True
Label4.Visible = True
Label5.Visible = True
Label6.Visible = True
Label7.Visible = True
Label8.Visible = True
Label9.Visible =
Label10.Visible = True
Label11.Visible = True
Label12.Visible = True
Label13.Visible = True
Label14.Visible = True
Label15.Visible = True
'desabilita botones
Label16.Visible = True
Button1.Visible = False
Button2.Visible = True
Button3.Visible = False
ganador = ""
Label18.Text = j1
End Sub
Private Sub juego_reset()
Label1.Visible = False
Label2.Visible = False
Label3.Visible = False
Label4.Visible = False
Label5.Visible = False
Label6.Visible = False
Label7.Visible = False
Label8.Visible = False
Label9.Visible = False
Label10.Visible = False
Label11.Visible = False
Label12.Visible = False
Label13.Visible = False
Label14.Visible = False
Label15.Visible = False
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
juego_reset()
Button1.Visible = True
Button3.Visible = True
End Sub
End Class
-
Hola Chacorta! Como siempre para los nuevos en el foro, pedirte que para pegar código lo hagas según se explica en este post.
Por lo que veo usas Visual Basic
¿Puedes explicar cómo debe desarrollarse el juego? (Ten en cuenta que no todos conocemos el juego, si lo explicas nos facilitas poder entender y ayudar)
Saludos!!