Can you please make this in VBA? I\'m very new to it. The card game War consists
ID: 3799405 • Letter: C
Question
Can you please make this in VBA? I'm very new to it.
The card game War consists of two players who each have a deck of cards. For each hand, each player turns over the top card in his or her deck. The higher card wins that round of play and the winner takes both cards. The game continues until one person has all the cards. Create a program that simulates a modified game of War. The computer will play both hands, as Player One and Player Two. For each round the program will generate two random numbers and compare them. If the first number is higher, Player One's score is increased by 1 and if the second is higher, Player Two's score is increased by 1. If there is a tie, no score is incremented. When one player reaches a score of 10, that player is deemed the winner and the game ends. The range of numbers should be 1-13 to simulate the values of cards in a deck. Display on a worksheet the hand number, Player One's card, Player Two's card, Player One's score, and Player Two's score for the entire game.Explanation / Answer
Private Sub gameOfWar()
Dim card1 As Integer
Dim card2 As Integer
Dim player1 As Integer
Dim player2 As Integer
Dim Hand As Integer
Hand = 1
Cells(1, 1).Value = "Hand"
Cells(1, 2).Value = "Card 1"
Cells(1, 3).Value = "Card 2"
Cells(1, 4).Value = "Player 1 Score"
Cells(1, 5).Value = "Player 2 Score"
While (player1 < 10 And player2 < 10)
card1 = Int((13 - 1 + 1) * Rnd + 1)
card2 = Int((13 - 1 + 1) * Rnd + 1)
If card1 > card2 Then
player1 = player1 + 1
ElseIf card1 < card2 Then
player2 = player2 + 1
Else
End If
Cells(Hand + 1, 1).Value = Hand
Cells(Hand + 1, 2).Value = card1
Cells(Hand + 1, 3).Value = card2
Cells(Hand + 1, 4).Value = player1
Cells(Hand + 1, 5).Value = player2
Hand = Hand + 1
Wend
End Sub