我的目标是什么?
我正在尝试编写一个程序来保持简单的双人游戏得分(52张牌,13个可能的名字中的4个,所以没有笑话)。杰克,女王,国王和王牌都是我的高牌,有了他们,两名球员中的一个可以得分。甲板必须洗牌(所以从卡列表中随机选择)。玩家1首先转动一张卡,然后转动玩家B,依此类推。一旦使用了卡,它就无法重复使用,所以一旦拉出52张牌,游戏就结束了。比赛得分如下:
游戏玩法示例:
到目前为止我有什么代码?
- 在btnPLayer1_Click下每行的右侧,详细描述了该行中的代码。如果由于某种原因你没有得到它。类似的代码在btnPlayer2_Click
下使用Public Class Form1
'Variables used during btnPlayer1_Click and btnPlayer2_Click
Dim cards As New List(Of String) From {"two", "two", "two", "two", "three", "three", "three", "three", "four", "four", "four", "four", "five", _
"five", "five", "five", "six", "six", "six", "six", "seven", "seven", "seven", "seven", "eight", "eight", _
"eight", "eight", "nine", "nine", "nine", "nine", "ten", "ten", "ten", "ten", "jack", "jack", "jack", _
"jack", "queen", "queen", "queen", "queen", "king", "king", "king", "king", "ace", "ace", "ace", "ace"}
Dim btn1counter As Integer
Dim btn2counter As Integer
Dim jackscore1 As Integer
Dim queenscore1 As Integer
Dim kingscore1 As Integer
Dim acescore1 As Integer
Dim jackscore2 As Integer
Dim queenscore2 As Integer
Dim kingscore2 As Integer
Dim acescore2 As Integer
'What Happens when button 1 is clicked
Private Sub btnPlayer1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPlayer1.Click
Dim rnd = New Random() 'Set rnd as random generator
If cards.Count > 0 Then 'If all cards have been drawn then no more cards can be drawn
btn1counter += 1 'Add 1 to btn1counter every time btnPlayer1 is clicked
Dim randomcards = cards(rnd.Next(0, cards.Count)) 'Set randomcards as one randomly chosen (using rnd) card from cards list
lstbox1.Items.Add(randomcards) 'Add 1 randomly chosen card from cards list into lstbox1 each time btnPlayer1 is clicked
cards.Remove(randomcards) 'Remove the randomly generated card from cards list to reduce deck size. No card will be picked more than 4 times
If randomcards.EndsWith("jack") Then 'If the last card picked from cards list is jack then
Static jackcount As Integer 'Set jackcount as integer that will retain previous added value to it
jackcount += 1 'Add 1 to jackcount every time last card picked from cards list is jack (jackcount will never be more than 4)
jackscore1 = jackcount * 1 'jackscore1 = value of jackcount times 1 (1 because jack is worth 1 point) - If 3 jacks then 1*3 = 3points
ElseIf randomcards.EndsWith("queen") Then 'If it wasn't jack as last card but it was queen then
Static queencount As Integer 'Set queencount as integer that will retain previous added value to it
queencount += 1 'Add 1 to queencount everytime last card picked from cards list is queen (queencount will never be more than 4)
queenscore1 = queencount * 2 'queenscore1 = value of queencount times 2 (2 because queen is worth 2 points) - If 3 queens then 2*3 = 6points
ElseIf randomcards.EndsWith("king") Then 'If it wasn't jack or queen as last card but it was king then
Static kingcount As Integer 'Set kingcount as integer that will retain previous added value to it
kingcount += 1 'Add 1 to kingcount everytime last card picked from cards list is king (kingcount will never be more than 4)
kingscore1 = kingcount * 3 'kingscore1 = value of kingcount times 3 (3 because king is worth 3 points) - If 3 kings then 3*3 = 9points
ElseIf randomcards.EndsWith("ace") Then 'If it wasn't jack or queen or king as last card but it was ace then
Static acecount As Integer 'Set acecount as integer that will retain previous added value to it
acecount += 1 'Add 1 to acecount everytime last card picked from cards list is ace (acecount will never be more than 4)
acescore1 = acecount * 4 'acescore1 = value of acecount times 4 (4 because ace is worth 4 points) - If 3 aces then 4*3 = 12 points
End If
lblScore1.Text = jackscore1 + queenscore1 + kingscore1 + acescore1 'Add all the scores gotten from jacks, queens, kings and aces and add them together in lblScore1 (player 1 score)
End If
lstbox1.TopIndex = lstbox1.Items.Count - 1 'Automatically scroll down lstbox1 each time new item is added so players only see last played card (can still scroll up to see previous cards)
End Sub
'What happens when button 2 is clicked (see to right of btnPlayer1_Click code to understand each line here - same thing)
Private Sub btnPlayer2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPlayer2.Click
Dim rnd = New Random()
If cards.Count > 0 Then
btn2counter += 1
Dim randomcards = cards(rnd.Next(0, cards.Count))
lstbox2.Items.Add(randomcards)
cards.Remove(randomcards)
If randomcards.EndsWith("jack") Then
Static jackcount As Integer
jackcount += 1
jackscore2 = jackcount * 1
ElseIf randomcards.EndsWith("queen") Then
Static queencount As Integer
queencount += 1
queenscore2 = queencount * 2
ElseIf randomcards.EndsWith("king") Then
Static kingcount As Integer
kingcount += 1
kingscore2 = kingcount * 3
ElseIf randomcards.EndsWith("ace") Then
Static acecount As Integer
acecount += 1
acescore2 = acecount * 4
End If
lblScore2.Text = jackscore2 + queenscore2 + kingscore2 + acescore2
End If
lstbox2.TopIndex = lstbox2.Items.Count - 1
End Sub
'Button to restart program
Private Sub btnRestart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRestart.Click
Application.Restart()
End Sub
'Button to close program
Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
End
End Sub
End Class
我有什么问题?
刚刚开始 对于您的信息,我刚刚开始编程三周前。我从VB开始,一旦我变得更好,我将继续使用Python。我真的很想成为未来的游戏创造者,所以我所制作的所有程序都是这样的小游戏(超级简单)。现在我从一个游戏创意开始,绘制外观,设置我希望游戏遵循的规则,然后我编码,尊重我设置的规则。这是我迄今为止最具挑战性的比赛,而且我已经撞墙了。非常感谢帮助:)谢谢!
答案 0 :(得分:0)
我建议添加一个变量来跟踪哪张卡正在执行。
Dim rulingCard As String
'can be "ace", "king" etc... Reset when scored / a higher card pulled
Dim countUntilScore As Integer
'Start from 4 for "ace". -1 for each lower card pulled.
Dim rulingCardOwner As String
'Remember whether player1 or player2 scores when countUntilScore finished
是否有必要为每张卡分开分数?玩家1分和玩家2分数不够吗?