VB.Net战争游戏

我在课堂上一直在研究“ WAR”纸牌游戏。我似乎大多数设置都正确,但是,单击交易按钮时,在将2张新卡出售到图像框中时遇到一些问题。

我需要绘制按钮来完成的确切事情是 按下“抽奖”按钮后,洗牌后的前两张牌 应该出现,一个在左边,一个在右边。中间卡将是 “左赢”,“右赢”或“并列”图像,并正确指示谁赢了( 卡)。此外,获胜者的分数应增加1分。

我将包含表单的屏幕截图,以使您了解我正在使用什么以及应该使用“交易”按钮去哪里。我的猜测是,当我第二次单击交易按钮时,它分别将值重置为0和26。

enter image description here

公开课表格1

'WAR

Dim cardarray(52) As Image
Dim valuearray(52) As Integer
Dim cardval1, cardval2 As Integer
Dim card1, card2 As Integer
Dim P1, P2 As Integer


Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
    Close()
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


    pct1.Image = My.Resources.back
    pct2.Image = My.Resources.back
    pct3.Image = My.Resources.back

    'Needed to generate a random number/card
    Randomize()

    'create 52 card element array
    CardArray(0) = My.Resources.twoc
    CardArray(1) = My.Resources.twod
    CardArray(2) = My.Resources.twoh
    CardArray(3) = My.Resources.twos
    CardArray(4) = My.Resources.threec
    CardArray(5) = My.Resources.threed
    CardArray(6) = My.Resources.threeh
    CardArray(7) = My.Resources.threes
    CardArray(8) = My.Resources.fourc
    CardArray(9) = My.Resources.fourd
    CardArray(10) = My.Resources.fourh
    CardArray(11) = My.Resources.fours
    CardArray(12) = My.Resources.fivec
    CardArray(13) = My.Resources.fived
    CardArray(14) = My.Resources.fiveh
    CardArray(15) = My.Resources.fives
    CardArray(16) = My.Resources.sixc
    CardArray(17) = My.Resources.sixd
    CardArray(18) = My.Resources.sixh
    CardArray(19) = My.Resources.sixs
    CardArray(20) = My.Resources.sevenc
    CardArray(21) = My.Resources.sevend
    CardArray(22) = My.Resources.sevenh
    CardArray(23) = My.Resources.sevens
    CardArray(24) = My.Resources.eightc
    CardArray(25) = My.Resources.eightd
    CardArray(26) = My.Resources.eighth
    CardArray(27) = My.Resources.eights
    CardArray(28) = My.Resources.ninec
    CardArray(29) = My.Resources.nined
    CardArray(30) = My.Resources.nineh
    CardArray(31) = My.Resources.nines
    CardArray(32) = My.Resources.tenc
    CardArray(33) = My.Resources.tend
    CardArray(34) = My.Resources.tenh
    CardArray(35) = My.Resources.tens
    CardArray(36) = My.Resources.jackc
    CardArray(37) = My.Resources.jackd
    CardArray(38) = My.Resources.jackh
    CardArray(39) = My.Resources.jacks
    CardArray(40) = My.Resources.queenc
    CardArray(41) = My.Resources.queend
    CardArray(42) = My.Resources.queenh
    CardArray(43) = My.Resources.queens
    CardArray(44) = My.Resources.kingc
    CardArray(45) = My.Resources.kingd
    CardArray(46) = My.Resources.kingh
    CardArray(47) = My.Resources.kings
    CardArray(48) = My.Resources.acec
    CardArray(49) = My.Resources.aced
    CardArray(50) = My.Resources.aceh
    CardArray(51) = My.Resources.aces

    '52 integer value array

    valueArray(0) = 1
    valueArray(1) = 1
    valueArray(2) = 1
    valueArray(3) = 1
    valueArray(4) = 2
    valueArray(5) = 2
    valueArray(6) = 2
    valueArray(7) = 2
    valueArray(8) = 3
    valueArray(9) = 3
    valueArray(10) = 3
    valueArray(11) = 3
    valueArray(12) = 4
    valueArray(13) = 4
    valueArray(14) = 4
    valueArray(15) = 4
    valueArray(16) = 5
    valueArray(17) = 5
    valueArray(18) = 5
    valueArray(19) = 5
    valueArray(20) = 6
    valueArray(21) = 6
    valueArray(22) = 6
    valueArray(23) = 6
    valueArray(24) = 7
    valueArray(25) = 7
    valueArray(26) = 7
    valueArray(27) = 7
    valueArray(28) = 8
    valueArray(29) = 8
    valueArray(30) = 8
    valueArray(31) = 8
    valueArray(32) = 9
    valueArray(33) = 9
    valueArray(34) = 9
    valueArray(35) = 9
    valueArray(36) = 10
    valueArray(37) = 10
    valueArray(38) = 10
    valueArray(39) = 10
    valueArray(40) = 11
    valueArray(41) = 11
    valueArray(42) = 11
    valueArray(43) = 11
    valueArray(44) = 12
    valueArray(45) = 12
    valueArray(46) = 12
    valueArray(47) = 12
    valueArray(48) = 13
    valueArray(49) = 13
    valueArray(50) = 13
    valueArray(51) = 13
End Sub

Public Sub shuffel()



    Dim switch As Integer
    Dim tempcard As Image
    Dim number_of_cards, tempval As Integer
    number_of_cards = 52
    'Go through the deck one card at a time:
    For i = 0 To number_of_cards - 1
        'Get a random card number from the deck
        switch = Int(Rnd() * number_of_cards)
        'Switch the current card’s value with the random card’s value
        tempval = valuearray(i)
        valuearray(i) = valuearray(switch)
        valuearray(switch) = tempval
        'Switch the current card’s image with the random card’s image
        tempcard = cardarray(i)
        cardarray(i) = cardarray(switch)
        cardarray(switch) = tempcard
    Next
End Sub

Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles BtnClear.Click


    'shuffle deck and set scores to 0
    Call shuffel()

    txtP1.Text = 0
    txtP2.Text = 0


End Sub

Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles txtP2.TextChanged

End Sub

Private Sub btnShuffle_Click(sender As Object, e As EventArgs) Handles btnShuffle.Click

    'shuffle deck and change card backs
    Call shuffel()

    pct1.Image = My.Resources.back
    pct2.Image = My.Resources.back
    pct3.Image = My.Resources.back


End Sub

Private Sub btnDraw_Click(sender As Object, e As EventArgs) Handles btnDraw.Click

    'set interger values for starting points
    cardval1 = 0
    cardval2 = 26

    'load those starting points into image boxes
    pct1.Image = cardarray(cardval1)
    pct3.Image = cardarray(cardval2)

    'increase card values by 1
    cardval1 = (cardval1 + 1)
    cardval2 = (cardval2 + 1)
End Sub

最终班