VB.NET

단어넣기 게임

2014.06.23

* Public Class Form1
Private answer As String = "안녕하세요" '정답

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim word() As Char = answer.ToCharArray() '정답을 문자열로 변환
Dim rnd As New Random()

'문자의 배치를 바꾼다
For i As Integer = 1 To 10
Dim n1 As Integer = rnd.Next(5)
Dim n2 As Integer = rnd.Next(5)
Dim w As Char = word(n1)
word(n1) = word(n2)
word(n2) = w
Next
Button1.Text = word(0)
Button2.Text = word(1)
Button3.Text = word(2)
Button4.Text = word(3)
Button5.Text = word(4)

'답란을 초기화
Label2.Text = ""
End Sub

Private Sub btns_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click
Dim btn As Button = CType(sender, Button)
Label2.Text &= btn.Text
btn.Visible = False
If Label2.Text = answer Then
MsgBox("축하합니다!", 0, "정답")

ElseIf Label2.Text.Length >= answer.Length Then
MsgBox("안됐군요!", 0, "오답")
End If
End Sub


End Class 

aa.png

* 단어를 무작위로 정렬하여 순서대로 버튼을 클릭해서 맞추는 게임이다

 

* 추가로 넣을수 있는 기능이 있는지 알아보자