Im 헤드가 현재 회전 중입니다.'Rock, Paper, scissor'로직을 사용하여 vb.net에서 루프, 또는 명령문을 사용하여 'Win, Lose, Draw'를 얻으십시오.
저는 각 게임/라운드마다 정확한 결과를 제공하는 VB.NET의 'Rock, Paper, scissor'프로그램을 보유하고 있습니다. 내가 가진 문제는 'Win, Loose, Draw'일 수있는 MATCH 결과를 결정할 때입니다. 일치 항목은 Best-of-3 (1 ~ 2) 및 Best-of-5 (1 ~ 3)입니다. 경기의 결과가 연신 될 수있는 바와 같이, 이는 다양한 조합/같은 순열 가지고, W
- W, L, D
- L, W, D
- L, D를
- D, L, W
- W, D, L, ... 등 ...
I가 지금까지 다음 코드를
Public Class GameForm
Private humanScore As Integer = 0
Private compScore As Integer = 0
Private drawScore As Integer = 0
Private totalGames As Integer = 0
Private totalGamesForWin As Integer = 0
Private totalGamesPlayed As Integer = 0
Private player1 = New PlayerHumanPlayer()
Private player2 = New PlayerComputerRandom()
Private Sub GameForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If GameTypeForm.cmboMatchDuration.SelectedItem = 0 Then
totalGames = 3
totalGamesForWin = 2
lblMatchInfor.Text = GlobalVariables.MatchTypeBestOf3Message
ElseIf (GameTypeForm.cmboMatchDuration.SelectedItem = 1) Then
totalGames = 5
totalGamesForWin = 3
lblMatchInfor.Text = GlobalVariables.MatchTypeBestOf5Message
End If
End Sub
Private Sub btnRock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRock.Click
findGameWinner("HumanPlayer", "Rock", "RandomComputer")
End Sub
Private Sub btnPaper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPaper.Click
findGameWinner("HumanPlayer", "Paper", "RandomComputer")
End Sub
Private Sub btnScissors_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnScissors.Click
findGameWinner("HumanPlayer", "Scissors", "RandomComputer")
End Sub
Public Sub findGameWinner(ByVal p1name As String, ByVal p1WeaponSelected As String, ByVal p2Name As String)
player1.Name = p1name
player1.pickWeapon(p1WeaponSelected) ' Should I be using the Rock Class???
player2.Name = p2Name
player2.pickWeapon()
Dim winner As Integer = player1.getWeapon().compareTo(player2.getWeapon())
Select Case winner
Case 1
updateScores(True, False)
findMatchWinner()
Case -1
updateScores(False, True)
findMatchWinner()
Case 0
updateScores(False, False)
findMatchWinner()
End Select
End Sub
Public Function updateScores(ByVal humanWon As Boolean, ByVal compWon As Boolean) As Integer
If humanWon = True Then
humanScore = humanScore + 1
'Update Human labels
lblPlayerScore.Text = humanScore.ToString()
'txtCompChoice.Text = txtCompChoice.Text + Environment.NewLine + Type.GetType(player2.pWeapon.ToString()).ToString()
txtCompChoice.Text = txtCompChoice.Text + Environment.NewLine + player2.pWeapon.ToString()
txtGameStatus.Text = txtGameStatus.Text + Environment.NewLine + player1.Name() + " wins!"
ElseIf compWon = True Then
compScore = compScore + 1
'Update Computer labels
lblCompScore.Text = compScore.ToString()
'txtCompChoice.Text = txtCompChoice.Text + Environment.NewLine + Type.GetType(player2.pWeapon.ToString()).ToString()
txtCompChoice.Text = txtCompChoice.Text + Environment.NewLine + player2.pWeapon.ToString()
txtGameStatus.Text = txtGameStatus.Text + Environment.NewLine + player2.Name() + " wins!"
Else
drawScore = drawScore + 1
'Update Draw labels
lblDrawGame.Text = drawScore.ToString()
'txtCompChoice.Text = txtCompChoice.Text + Environment.NewLine + Type.GetType(player2.pWeapon.ToString()).ToString()
txtCompChoice.Text = txtCompChoice.Text + Environment.NewLine + player2.pWeapon.ToString()
txtGameStatus.Text = txtGameStatus.Text + Environment.NewLine + "Draw!"
End If
totalGamesPlayed = totalGamesPlayed + 1
Return totalGamesPlayed
End Function
Public Function findMatchWinner() As String
If totalGamesPlayed <> totalGames Then
If humanScore = totalGamesForWin Then
lblMatchInfor.Text = GlobalVariables.HumanMacthWinMessage
clearForm()
ElseIf compScore = totalGamesForWin Then
lblMatchInfor.Text = GlobalVariables.CompMacthWinMessage
clearForm()
ElseIf totalGamesPlayed = totalGames - 1 Then
lblMatchInfor.Text = GlobalVariables.DeciderGameMessage
End If
ElseIf humanScore = totalGamesForWin Then
lblMatchInfor.Text = GlobalVariables.HumanMacthWinMessage
clearForm()
ElseIf compScore = totalGamesForWin Then
lblMatchInfor.Text = GlobalVariables.CompMacthWinMessage
clearForm()
ElseIf (drawScore = totalGamesPlayed) Then
lblMatchInfor.Text = GlobalVariables.DrawMacthWinMessage
clearForm()
End If
Return "Human OR Computer"
End Function
Public Sub clearForm()
End Sub
End Class
나는 Draw/Tie를 완전히 잊었다는 것을 기억하기 전까지 나는 잘하고 있다고 생각했다. 그때 이후로 내 머리가 반복되어 누군가 findMatchWinner() 함수를 제대로 작동시키는 방법에 대해 친절하게 알려줄 수 있습니까?
도움을 주시면 감사하겠습니다. 사전에
Manys 감사
대단히 감사합니다. 너무 바보 같아 .Lol – AJsStack