我正在编写一个小游戏来练习自己,但我遇到了一个我无法修复的错误:S。这是一场悬疑游戏的开始。(不知道它的英文名称是否正确:))我需要从文件中取出一个单词,每行 1 个,并让玩家通过有限的尝试次数猜测该单词。
我认为我的错误与字符串/字符比较和操作有关,或者与我在文本标签中写的内容有关。我试图在互联网上找到一些已经解决的教程或问题,但没有什么和这个完全一样...... :(
我多次更改变量的类型,每行读取调试器行,但我从未发现有什么问题.. :S 如果你对 VB 有好处,请帮我解决这个问题:O(你也可以给出你的评论/改进)
谢谢,火焰
代码:
Imports System.IO
Public Class Pendu
Public Structure StructMot
Public MotSecret() As Char
Public LettreDecouverte() As Char
End Structure
Dim Mot As StructMot
Dim i As Integer = 0
Private Sub ButtonA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonA.Click, ButtonB.Click,
ButtonC.Click, ButtonD.Click, ButtonE.Click, ButtonF.Click, ButtonG.Click, ButtonH.Click, ButtonI.Click, ButtonJ.Click,
ButtonK.Click, ButtonL.Click, ButtonM.Click, ButtonN.Click, ButtonO.Click, ButtonP.Click, ButtonQ.Click, ButtonR.Click,
ButtonS.Click, ButtonT.Click, ButtonU.Click, ButtonV.Click, ButtonW.Click, ButtonX.Click, ButtonY.Click, ButtonZ.Click
i = i + 1
ActiveControl.Visible = False
PictureBox1.Image = ImageList1.Images(i - 1)
Dim j As Integer = 0
For j = 0 To Mot.MotSecret.Length - 1
If ActiveControl.Text = Mot.MotSecret(j) Then
Mot.LettreDecouverte(j) = Mot.MotSecret(j)
End If
Next j
Label1.Text = ""
For j = 0 To Mot.MotSecret.Length - 1
Label1.Text = Label1.Text + " "
If Mot.LettreDecouverte(j).Equals("") Then
Label1.Text = Label1.Text + "_"
Else
Label1.Text = Label1.Text + Mot.LettreDecouverte(j)
End If
Next j
End Sub
Private Sub JouerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles JouerToolStripMenuItem.Click
GenereMot()
End Sub
Private Sub Pendu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GenereMot()
End Sub
Function GenereMot()
Dim NbItems As Integer
Dim Aleatoire As New Random()
Dim NbAleatoire As Integer
ListBox1.Items.AddRange(System.IO.File.ReadAllLines("listemot.txt"))
NbItems = ListBox1.Items.Count
NbAleatoire = Aleatoire.Next(NbItems)
Mot.MotSecret = ListBox1.Items(NbAleatoire)
Return Mot
End Function
End Class