本文介绍了我有这个子手的代码,但没有给我每个玩家的分数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Module Module1
'This program displays the word Computer as C ------ r and asks the user
'To guess letters. Each time you correctly guess the letter appears in the corresponding position
'Every time you make a mistake loses an opportunity-life.
'The game ends when either guess all the letters or zero opportunities-lives of the user
Public zoes As Byte 'The variable opportunities, lives the player has
Public ans As String
Public ans2 As String
Public pointspl1 As Integer
Public pointspl2 As Integer
Public complete As Integer
Public turn As String
Public t As String
Sub Main ()
Do
Console.writeline ("---------- HAngMAn ---------- ")
Dim Pl1 As String
Dim Pl2 As String
Dim word As String 'Initialize the secret word Computer
Dim display As String 'Create the word that appears in the user
Dim letter As String
console.writeline ("")
console.writeline ("Give me the name of the first player:")
Pl1 = console.readline ()
console.writeline ("")
console.writeline ("Give me the name of the second player:")
Pl2 = console.readline ()
Do
console.writeline ("")
console.writeline ("Who will give the word? (1 for player1 and 2 for player2)")
Do
t = console.readline
Loop Until t = 1 Or t = 2
If t = 1 Then
turn = Pl1
ElseIf t = 2 Then
turn = Pl2
End If
Do
console.writeline ("")
Console.WriteLine ("it's your turn player:" & turn)
If word <> "end" Or word <> "End" Then
console.writeline ("")
Console.Writeline ("Please enter keyword")
word = Console.ReadLine ()
display = MakeDisplay (word)
End If
zoes = Len (word) - 2 'Specify number of attempts, many lives are hidden words
complete = Len (word) - 2
Do
console.writeline ("")
Console.WriteLine ("Give a timetable for the word" & display)
letter = Console.ReadLine
Call FindLetters (word, letter, display, pointspl1, pointspl2)
Loop Until (word = display) Or zoes = 0 'This will be repeated until the word word be the same
'With the word display, ie the player to guess completely unknown word or to
'Life-chances are the player to run out
Loop Until (word = display) Or zoes = 0
console.writeline ("")
console.writeline ("Want another match?:")
ans = Console.ReadLine ()
Loop Until ans = "No"
console.writeline ("End")
console.writeline ("points" & Pl1 & ":" & pointspl1)
console.writeline ("points" & Pl1 & ":" & pointspl2)
If pointspl1> pointspl2 Then
Console.writeline ("The Winner is:" & Pl1)
Else
console.writeline ("The Winner is:" & Pl2)
End If
console.writeline ("")
console.writeline ("Want another Game?:")
ans2 = Console.ReadLine ()
Loop Until ans2 = "No"
End Sub
Public Function MakeDisplay (ByVal w As String) As String 'He makes the word of the gallows with the intermediate paflitses
Dim display As String, c As Byte
display = Left (w, 1)
For c = 2 To Len (w) - 1
display = display & "-"
Next
display = display & Right (w, 1)
Return display
End Function
Public Sub FindLetters (ByVal w As String, ByVal letter As String, ByRef display As String, ByVal pointspl1 As Integer, ByVal pointspl2 As Integer)
'Looking to find the letter in the word w and sets the current display, depending
'Also, if you do not find the character letter in the word w then reduces the lives of the player by 1
Dim c As Byte, found As Boolean
found = False 'flag is true when the letter letter found in the word w
For c = 2 To Len (w) - 1
If Mid (w, c, 1) = letter Then
display = Left (display, c - 1) & letter & Right (display, Len (display) - c)
'The new display is made by joining pieces: left (to position the letter letter)
'The letter letter found and
'The right (taking characters from the end of the word display letter by letter
found = True
complete = complete - 1
If t = 1 Then
pointspl2 = pointspl2 + 10
ElseIf t = 2 Then
pointspl1 = pointspl1 + 10
End If
End If
Next
If Not found Then
Console.WriteLine ("")
Console.WriteLine ("There is the letter" & letter)
zoes -= 1
Else
Console.WriteLine ("")
Console.WriteLine ("Good Guessing the letter" & letter)
End If
Console.WriteLine ("")
Console.WriteLine ("Do you still" & zoes & "lives!")
If zoes = 0 Then
Console.WriteLine ("")
Console.WriteLine ("Sorry you lost!")
End If
If complete = 0 Then
Console.WriteLine ("")
Console.WriteLine ("you have found the word!!")
If t = 1 Then
pointspl2 = pointspl2 + 50
ElseIf t = 2 Then
pointspl1 = pointspl1 + 50
End If
End If
End Sub
End Module
推荐答案
Module Module1
''This program displays the word Computer as C ------ r and asks the user
''To guess letters. Each time you correctly guess the letter appears in the corresponding position
''Every time you make a mistake loses an opportunity-life.
''The game ends when either guess all the letters or zero opportunities-lives of the user
Public zoes As Byte ''The variable opportunities, lives the player has
Public ans As String
Public ans2 As String
Public pointspl1 As Integer
Public pointspl2 As Integer
Public complete As Integer
Public turn As String
Public t As String
Sub Main ()
Do
Console.writeline ("---------- HAngMAn ---------- ")
Dim Pl1 As String
Dim Pl2 As String
Dim word As String ''Initialize the secret word Computer
Dim display As String ''Create the word that appears in the user
Dim letter As String
console.writeline ("")
console.writeline ("Give me the name of the first player:")
Pl1 = console.readline ()
console.writeline ("")
console.writeline ("Give me the name of the second player:")
Pl2 = console.readline ()
Do
console.writeline ("")
console.writeline ("Who will give the word? (1 for player1 and 2 for player2)")
Do
t = console.readline
Loop Until t = 1 Or t = 2
If t = 1 Then
turn = Pl1
ElseIf t = 2 Then
turn = Pl2
End If
Do
console.writeline ("")
Console.WriteLine ("it''s your turn player:" & turn)
If word <> "end" Or word <> "End" Then
console.writeline ("")
Console.Writeline ("Please enter keyword")
word = Console.ReadLine ()
display = MakeDisplay (word)
End If
zoes = Len (word) - 2 ''Specify number of attempts, many lives are hidden words
complete = Len (word) - 2
Do
console.writeline ("")
Console.WriteLine ("Give a timetable for the word" & display)
letter = Console.ReadLine
Call FindLetters (word, letter, display, pointspl1, pointspl2)
Loop Until (word = display) Or zoes = 0 ''This will be repeated until the word word be the same
''With the word display, ie the player to guess completely unknown word or to
''Life-chances are the player to run out
Loop Until (word = display) Or zoes = 0
console.writeline ("")
console.writeline ("Want another match?:")
ans = Console.ReadLine ()
Loop Until ans = "No"
console.writeline ("End")
console.writeline ("points" & Pl1 & ":" & pointspl1)
console.writeline ("points" & Pl1 & ":" & pointspl2)
If pointspl1> pointspl2 Then
Console.writeline ("The Winner is:" & Pl1)
Else
console.writeline ("The Winner is:" & Pl2)
End If
console.writeline ("")
console.writeline ("Want another Game?:")
ans2 = Console.ReadLine ()
Loop Until ans2 = "No"
End Sub
Public Function MakeDisplay (ByVal w As String) As String ''He makes the word of the gallows with the intermediate paflitses
Dim display As String, c As Byte
display = Left (w, 1)
For c = 2 To Len (w) - 1
display = display & "-"
Next
display = display & Right (w, 1)
Return display
End Function
Public Sub FindLetters (ByVal w As String, ByVal letter As String, ByRef display As String, ByVal pointspl1 As Integer, ByVal pointspl2 As Integer)
''Looking to find the letter in the word w and sets the current display, depending
''Also, if you do not find the character letter in the word w then reduces the lives of the player by 1
Dim c As Byte, found As Boolean
found = False ''flag is true when the letter letter found in the word w
For c = 2 To Len (w) - 1
If Mid (w, c, 1) = letter Then
display = Left (display, c - 1) & letter & Right (display, Len (display) - c)
''The new display is made by joining pieces: left (to position the letter letter)
''The letter letter found and
''The right (taking characters from the end of the word display letter by letter
found = True
complete = complete - 1
If t = 1 Then
pointspl2 = pointspl2 + 10
ElseIf t = 2 Then
pointspl1 = pointspl1 + 10
End If
End If
Next
If Not found Then
Console.WriteLine ("")
Console.WriteLine ("There is the letter" & letter)
zoes -= 1
Else
Console.WriteLine ("")
Console.WriteLine ("Good Guessing the letter" & letter)
End If
Console.WriteLine ("")
Console.WriteLine ("Do you still" & zoes & "lives!")
If zoes = 0 Then
Console.WriteLine ("")
Console.WriteLine ("Sorry you lost!")
End If
If complete = 0 Then
Console.WriteLine ("")
Console.WriteLine ("you have found the word!!")
If t = 1 Then
pointspl2 = pointspl2 + 50
ElseIf t = 2 Then
pointspl1 = pointspl1 + 50
End If
End If
End Sub
End Module
这篇关于我有这个子手的代码,但没有给我每个玩家的分数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!