gpt4 book ai didi

vb.net - VB.NET 中的囚徒困境 - 与 "Else If"相关的编译错误

转载 作者:行者123 更新时间:2023-12-02 04:58:13 24 4
gpt4 key购买 nike

我正在尝试在 VB.NET 中为一个学校项目构建一个囚徒困境游戏,但我发现这种奇怪的行为我不明白。

我有 2 个用于播放器的按钮,“Co-op”和“Defect”都具有相同的代码结构:

Private Sub btnDefect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDefect.Click
Oponent()
MovePlayer = "Defect"

If MoveOponent = "Coop" Then
scorePlayer += 50
scoreOponent -= 50
Else
If MoveOponent = "Defect" Then
scorePlayer -= 10
scoreOponent -= 10
End If
End If


scores()

End Sub

我知道 ELSE - IF 是不必要的,但我这样写是为了更清晰、更易读。问题是,如果两个按钮都有 ELSE - 如果我收到编译错误并且无法从 Visual Studio 运行游戏(虽然 bin 文件夹中的 .exe 工作正常)。现在,如果我从 中删除 ELSE - IF要么 按钮,只需留下一个常规的 ELSE 即可完美运行。但是,如果我从两者中删除它,则会发生相同的错误。

我得到的错误是:

Could not copy the file "obj\x86\Debug\PrisonersDilemma.exe" because it was not found. PrisonersDilemma



但我寻找那个 .exe 文件,它就在那里!

知道为什么会这样吗?我可以通过只留下一个 ELSE - IF 来让它工作,但我想知道出了什么问题。

这是完整的代码供引用:
Public Class Form1
Dim MovePlayer As String
Dim MoveOponent As String
Dim scorePlayer As Integer
Dim scoreOponent As Integer

Sub scores()
lblscoreOponent.Text = scoreOponent
lblscorePlayer.Text = scorePlayer
End Sub
Sub Oponent()
If MovePlayer = "" Then
MoveOponent = "Coop"
Else
MoveOponent = MovePlayer
End If

lblMoveOponent.Text = MoveOponent
lblMoveOponent.Visible = True
End Sub

Private Sub btnCoop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCoop.Click
Oponent()
MovePlayer = "Coop"

If MoveOponent = "Coop" Then
scorePlayer += 10
scoreOponent += 10
Else
scorePlayer += 50
scoreOponent -= 50
End If

scores()

End Sub

Private Sub btnDefect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDefect.Click
Oponent()
MovePlayer = "Defect"

If MoveOponent = "Coop" Then
scorePlayer += 50
scoreOponent -= 50
Else
If MoveOponent = "Defect" Then
scorePlayer -= 10
scoreOponent -= 10
End If
End If


scores()

End Sub
End Class

谢谢!!

最佳答案

1:编译时,如果出现错误,你的bin文件夹下的EXE不会被替换。您的 EXE 是最后一次成功的构建,这就是为什么您会收到这样的问题:“构建过程中出现错误,您要运行最后一次成功的构建吗?”如果你说是,这将运行该 EXE。

2:似乎我在 2012 中有时会看到“找不到”错误,我认为这是 Visual Studio 的问题。通常我会再试一次,这很好。如果您从 bin 文件夹运行 EXE,请确保在编译之前它没有运行。它将阻止复制它的能力。

3:如果您需要帮助找出出现编译错误的原因,您必须显示该代码,而不是有效的代码!

关于vb.net - VB.NET 中的囚徒困境 - 与 "Else If"相关的编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19508451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com