Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub Bet(ByVal betValue As Integer)
- Try
- Me._game.CurrentPlayer.IncreaseBet(New Decimal(betValue))
- Me.ShowBankValue
- Catch exception1 As Exception
- ProjectData.SetProjectError(exception1)
- Dim exception As Exception = exception1
- Interaction.MsgBox(exception.Message, MsgBoxStyle.OkOnly, Nothing)
- ProjectData.ClearProjectError
- End Try
- End Sub
- Private Sub ClearBetBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
- Me._game.CurrentPlayer.ClearBet
- Me.ShowBankValue
- End Sub
- Private Sub ClearTable()
- Dim index As Integer = 0
- Do While (index < 6)
- Me._dealerCards(index).Image = Nothing
- Me._dealerCards(index).Visible = False
- Me._playerCards(index).Image = Nothing
- Me._playerCards(index).Visible = False
- Math.Min(Interlocked.Increment((index)), (index - 1))
- Loop
- End Sub
- Private Sub DblDwnBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
- Try
- Me._game.CurrentPlayer.DoubleDown
- Me.UpdateUIPlayerCards
- Me.ShowBankValue
- If Me._game.CurrentPlayer.HasBust Then
- Me.EndGame(EndResult.PlayerBust)
- Else
- Me._game.DealerPlay
- Me.UpdateUIPlayerCards
- Me.EndGame(Me.GetGameResult)
- End If
- Catch exception1 As Exception
- ProjectData.SetProjectError(exception1)
- Dim exception As Exception = exception1
- Interaction.MsgBox(exception.Message, MsgBoxStyle.OkOnly, Nothing)
- ProjectData.ClearProjectError
- End Try
- End Sub
- Private Sub DealBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
- Try
- If ((Decimal.Compare(Me._game.CurrentPlayer.Bet, Decimal.Zero) = 0) And (Decimal.Compare(Me._game.CurrentPlayer.Balance, Decimal.Zero) > 0)) Then
- Interaction.MsgBox("You must place a bet before the dealer deals.", MsgBoxStyle.Information, "Error")
- Else
- Me._game.CurrentPlayer.PlaceBet
- Me.ShowBankValue
- Me.ClearTable
- Me.SetUpGameInPlay
- Me._game.DealNewGame
- Me.UpdateUIPlayerCards
- If Me._game.CurrentPlayer.HasBlackJack Then
- Me.EndGame(EndResult.PlayerBlackJack)
- End If
- End If
- Catch exception1 As Exception
- ProjectData.SetProjectError(exception1)
- Dim exception As Exception = exception1
- Interaction.MsgBox(exception.Message, MsgBoxStyle.OkOnly, Nothing)
- ProjectData.ClearProjectError
- End Try
- End Sub
- Private Sub EndGame(ByVal endState As EndResult)
- Dim currentPlayer As Player
- Select Case CInt(endState)
- Case 0
- Me.gameOverTextBox.Text = "Dealer BlackJack!"
- Me._game.PlayerLose
- Exit Select
- Case 1
- Me.gameOverTextBox.Text = "BlackJack!"
- currentPlayer = Me._game.CurrentPlayer
- currentPlayer.Balance = Decimal.Add(currentPlayer.Balance, Decimal.Multiply(Me._game.CurrentPlayer.Bet, 2.5))
- currentPlayer = Me._game.CurrentPlayer
- currentPlayer.Wins += 1
- Exit Select
- Case 2
- Me.gameOverTextBox.Text = "You Bust!"
- Me._game.PlayerLose
- Exit Select
- Case 3
- Me.gameOverTextBox.Text = "Dealer Bust!"
- Me._game.PlayerWin
- Exit Select
- Case 4
- Me.gameOverTextBox.Text = "Push"
- currentPlayer = Me._game.CurrentPlayer
- currentPlayer.Push += 1
- currentPlayer = Me._game.CurrentPlayer
- currentPlayer.Balance = Decimal.Add(currentPlayer.Balance, Me._game.CurrentPlayer.Bet)
- Exit Select
- Case 5
- Me.gameOverTextBox.Text = "You Won!"
- Me._game.PlayerWin
- Exit Select
- Case 6
- Me.gameOverTextBox.Text = "Dealer Won!"
- Me._game.PlayerLose
- Exit Select
- End Select
- Me.winTextBox.Text = Me._game.CurrentPlayer.Wins.ToString
- Me.lossTextBox.Text = Me._game.CurrentPlayer.Losses.ToString
- Me.tieTextBox.Text = Me._game.CurrentPlayer.Push.ToString
- Me.SetUpNewGame
- Me.ShowBankValue
- Me.gameOverTextBox.Show
- If (Decimal.Compare(Me._game.CurrentPlayer.Balance, Decimal.Zero) = 0) Then
- Interaction.MsgBox("Out of Money. Please create a new game to play again.", MsgBoxStyle.OkOnly, Nothing)
- Me.Close
- End If
- End Sub
- Private Sub ExitBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
- Me.Close
- End Sub
- Private Sub FiftyBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
- Me.Bet(50)
- End Sub
- Private Function GetGameResult() As EndResult
- If ((Me._game.CurrentDealer.Hand.NumCards = 2) AndAlso Me._game.CurrentDealer.HasBlackJack) Then
- Return EndResult.DealerBlackJack
- End If
- If Me._game.CurrentDealer.HasBust Then
- Return EndResult.DealerBust
- End If
- If (Me._game.CurrentDealer.Hand.CompareFaceValue(Me._game.CurrentPlayer.Hand) > 0) Then
- Return EndResult.DealerWin
- End If
- If (Me._game.CurrentDealer.Hand.CompareFaceValue(Me._game.CurrentPlayer.Hand) = 0) Then
- Return EndResult.Push
- End If
- Return EndResult.PlayerWin
- End Function
- Private Sub HitBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
- Me._firstTurn = False
- Me._game.CurrentPlayer.Hit
- Me.UpdateUIPlayerCards
- If Me._game.CurrentPlayer.HasBust Then
- Me.EndGame(EndResult.PlayerBust)
- End If
- End Sub
- Private Sub HundredBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
- Me.Bet(100)
- End Sub
- Private Sub LoadCard(ByVal pb As PictureBox, ByVal c As Card)
- Try
- Dim builder As New StringBuilder
- Select Case c.Suit
- Case Suit.Diamonds
- builder.Append("di")
- Exit Select
- Case Suit.Spades
- builder.Append("sp")
- Exit Select
- Case Suit.Clubs
- builder.Append("cl")
- Exit Select
- Case Suit.Hearts
- builder.Append("he")
- Exit Select
- End Select
- Select Case CInt(c.FaceVal)
- Case 2
- builder.Append("2")
- Exit Select
- Case 3
- builder.Append("3")
- Exit Select
- Case 4
- builder.Append("4")
- Exit Select
- Case 5
- builder.Append("5")
- Exit Select
- Case 6
- builder.Append("6")
- Exit Select
- Case 7
- builder.Append("7")
- Exit Select
- Case 8
- builder.Append("8")
- Exit Select
- Case 9
- builder.Append("9")
- Exit Select
- Case 10
- builder.Append("10")
- Exit Select
- Case 11
- builder.Append("j")
- Exit Select
- Case 12
- builder.Append("q")
- Exit Select
- Case 13
- builder.Append("k")
- Exit Select
- Case 14
- builder.Append("1")
- Exit Select
- End Select
- builder.Append(MySettingsProperty.Settings.CardGameImageExtension)
- Dim cardGameImagePath As String = MySettingsProperty.Settings.CardGameImagePath
- Dim cardGameImageSkinPath As String = MySettingsProperty.Settings.CardGameImageSkinPath
- builder.Insert(0, cardGameImagePath)
- If Not c.IsCardUp Then
- builder.Replace(builder.ToString, cardGameImageSkinPath)
- End If
- pb.Image = New Bitmap(builder.ToString)
- Catch exception1 As Exception
- ProjectData.SetProjectError(exception1)
- Interaction.MsgBox("Card images are not loading correctly. Make sure all card images are in the right location.", MsgBoxStyle.OkOnly, Nothing)
- ProjectData.ClearProjectError
- End Try
- End Sub
- Private Sub LoadCardSkinImages()
- Try
- Dim image As Image = Image.FromFile(MySettingsProperty.Settings.CardGameImageSkinPath)
- Me.deckCard1PictureBox.Image = image
- Me.deckCard2PictureBox.Image = image
- Me.deckCard3PictureBox.Image = image
- Catch exception1 As OutOfMemoryException
- ProjectData.SetProjectError(exception1)
- Dim exception As OutOfMemoryException = exception1
- Interaction.MsgBox("Card skin images are not loading correctly. Make sure the card skin images are in the correct location.", MsgBoxStyle.OkOnly, Nothing)
- ProjectData.ClearProjectError
- End Try
- Me._playerCards = New PictureBox() { Me.playerCard1PictureBox, Me.playerCard2PictureBox, Me.playerCard3PictureBox, Me.playerCard4PictureBox, Me.playerCard5PictureBox, Me.playerCard6PictureBox }
- Me._dealerCards = New PictureBox() { Me.dealerCard1PictureBox, Me.dealerCard2PictureBox, Me.dealerCard3PictureBox, Me.dealerCard4PictureBox, Me.dealerCard5PictureBox, Me.dealerCard6PictureBox }
- End Sub
- Private Sub SetUpGameInPlay()
- Me.tenButton.Enabled = False
- Me.twentyFiveButton.Enabled = False
- Me.fiftyButton.Enabled = False
- Me.hundredButton.Enabled = False
- Me.clearBetButton.Enabled = False
- Me.standButton.Enabled = True
- Me.hitButton.Enabled = True
- Me.gameOverTextBox.Hide
- Me.playerTotalLabel.Show
- Me.dealButton.Enabled = False
- If Me._firstTurn Then
- Me.doubleDownButton.Enabled = True
- End If
- End Sub
- Private Sub SetUpNewGame()
- Me.photoPictureBox.ImageLocation = MySettingsProperty.Settings.PlayerImage
- Me.photoPictureBox.Visible = True
- Me.playerNameLabel.Text = MySettingsProperty.Settings.PlayerName
- Me.dealButton.Enabled = True
- Me.doubleDownButton.Enabled = False
- Me.standButton.Enabled = False
- Me.hitButton.Enabled = False
- Me.clearBetButton.Enabled = True
- Me.tenButton.Enabled = True
- Me.twentyFiveButton.Enabled = True
- Me.fiftyButton.Enabled = True
- Me.hundredButton.Enabled = True
- Me.gameOverTextBox.Hide
- Me.playerTotalLabel.Hide
- Me._firstTurn = True
- Me.ShowBankValue
- End Sub
- Private Sub ShowBankValue()
- Me.myBetTextBox.Text = ("$" & Me._game.CurrentPlayer.Bet.ToString)
- Me.myAccountTextBox.Text = ("$" & Me._game.CurrentPlayer.Balance.ToString)
- End Sub
- Private Sub StandBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
- Me._game.DealerPlay
- Me.UpdateUIPlayerCards
- Me.EndGame(Me.GetGameResult)
- End Sub
- Private Sub TenBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
- Me.Bet(10)
- End Sub
- Private Sub TwentyFiveBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
- Me.Bet(&H19)
- End Sub
- Private Sub UpdateUIPlayerCards()
- Dim num As Integer
- Me.playerTotalLabel.Text = Me._game.CurrentPlayer.Hand.GetSumOfHand.ToString
- Dim cards As List(Of Card) = Me._game.CurrentPlayer.Hand.Cards
- num
- For num = 0 To cards.Count - 1
- Me.LoadCard(Me._playerCards(num), cards.Item(num))
- Me._playerCards(num).Visible = True
- Me._playerCards(num).BringToFront
- Next num
- Dim list As List(Of Card) = Me._game.CurrentDealer.Hand.Cards
- num
- For num = 0 To list.Count - 1
- Me.LoadCard(Me._dealerCards(num), list.Item(num))
- Me._dealerCards(num).Visible = True
- Me._dealerCards(num).BringToFront
- Next num
- End Sub
- Public Sub DealerPlay()
- Me._dealer.Hand.Cards.Item(1).IsCardUp = True
- If (Me._dealer.Hand.GetSumOfHand < &H11) Then
- Me._dealer.Hit
- Me.DealerPlay
- End If
- End Sub
- Public Sub DealNewGame()
- Me._deck = New Deck
- Me._deck.Shuffle
- Me._player.NewHand
- Me._dealer.NewHand
- Dim i As Integer
- For i = 0 To 2 - 1
- Dim item As Card = Me._deck.Draw
- Me._player.Hand.Cards.Add(item)
- Dim card2 As Card = Me._deck.Draw
- If (i = 1) Then
- card2.IsCardUp = False
- End If
- Me._dealer.Hand.Cards.Add(card2)
- Next i
- Me._player.CurrentDeck = Me._deck
- Me._dealer.CurrentDeck = Me._deck
- End Sub
- Public Sub PlayerLose()
- Dim player As Player = Me._player
- player.Losses += 1
- End Sub
- Public Sub PlayerWin()
- Dim player As Player = Me._player
- player.Balance = Decimal.Add(player.Balance, Decimal.Multiply(Me._player.Bet, 2))
- player = Me._player
- player.Wins += 1
- End Sub
- Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As EventArgs)
- MySettingsProperty.Settings.Reload
- Me.Close
- End Sub
- Private Sub btnOK_Click(ByVal sender As Object, ByVal e As EventArgs)
- MySettingsProperty.Settings.PlayerName = Me.playerNameTextBox.Text
- MySettingsProperty.Settings.Save
- Me.Close
- End Sub
- Private Sub OptionsForm_Load(ByVal sender As Object, ByVal e As EventArgs)
- Try
- Me.playerPictureBox.Image = Image.FromFile(MySettingsProperty.Settings.PlayerImage)
- Dim key As String = MySettingsProperty.Settings.DefaultImage1
- Dim str2 As String = MySettingsProperty.Settings.DefaultImage2
- Dim str3 As String = MySettingsProperty.Settings.DefaultImage3
- Dim str4 As String = MySettingsProperty.Settings.DefaultImage4
- Me.defaultImageList.Images.Add(key, Image.FromFile(key))
- Me.defaultImageListView.Items.Add(key, key)
- Me.defaultImageList.Images.Add(str2, Image.FromFile(str2))
- Me.defaultImageListView.Items.Add(str2, str2)
- Me.defaultImageList.Images.Add(str3, Image.FromFile(str3))
- Me.defaultImageListView.Items.Add(str3, str3)
- Me.defaultImageList.Images.Add(str4, Image.FromFile(str4))
- Me.defaultImageListView.Items.Add(str4, str4)
- Me.defaultImageListView.Items.Item(0).Text = ""
- Me.defaultImageListView.Items.Item(1).Text = ""
- Me.defaultImageListView.Items.Item(2).Text = ""
- Me.defaultImageListView.Items.Item(3).Text = ""
- Catch exception1 As OutOfMemoryException
- ProjectData.SetProjectError(exception1)
- Dim exception As OutOfMemoryException = exception1
- Interaction.MsgBox("Images did not load properly. Verify that images are in the correct location", MsgBoxStyle.OkOnly, Nothing)
- ProjectData.ClearProjectError
- End Try
- End Sub
- Private Sub PlayerDefaultImageList_ItemActivate(ByVal sender As Object, ByVal e As EventArgs)
- Dim selectedItems As SelectedListViewItemCollection = Me.defaultImageListView.SelectedItems
- MySettingsProperty.Settings.PlayerImage = selectedItems.Item(0).ImageKey
- Me.playerPictureBox.Image = Image.FromFile(MySettingsProperty.Settings.PlayerImage)
- End Sub
- Public Sub ClearBet()
- Me._betProp = New Decimal
- End Sub
- Public Sub DoubleDown()
- Me.IncreaseBet(Me._betProp)
- Me._balanceProp = Decimal.Subtract(Me._balanceProp, Decimal.Divide(Me._betProp, 2))
- Me.Hit
- End Sub
- Public Function HasBlackJack() As Boolean
- Return (Me._handProp.GetSumOfHand = &H15)
- End Function
- Public Function HasBust() As Boolean
- Return (Me._handProp.GetSumOfHand > &H15)
- End Function
- Public Sub Hit()
- Dim item As Card = Me._currentDeckProp.Draw
- Me._handProp.Cards.Add(item)
- End Sub
- Public Sub IncreaseBet(ByVal amt As Decimal)
- If (Decimal.Compare(Decimal.Subtract(Me._balanceProp, Decimal.Add(Me._betProp, amt)), Decimal.Zero) < 0) Then
- Throw New Exception("You do not have enough money to make this bet.")
- End If
- Me._betProp = Decimal.Add(Me._betProp, amt)
- End Sub
- Public Function NewHand() As BlackJackHand
- Me._handProp = New BlackJackHand
- Return Me._handProp
- End Function
- Public Sub PlaceBet()
- If (Decimal.Compare(Decimal.Subtract(Me._balanceProp, Me._betProp), Decimal.Zero) < 0) Then
- Throw New Exception("You do not have enough money to place this bet.")
- End If
- Me._balanceProp = Decimal.Subtract(Me._balanceProp, Me._betProp)
- End Sub
- Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
- Interaction.MsgBox("Il Gioco E' Stato Creato Interamente Da Ds It" & ChrW(224) & "lian Team, Il Team Di IlMacio. Su Sciax2 Fonzi98, Contattaci Su Skype : Macio4949", MsgBoxStyle.OkOnly, Nothing)
- End Sub
- Private Sub ExitBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
- Application.Exit
- Interaction.MsgBox("Grazie Per Averci Scelto, Contact Us : Macio4949 (Skype)", MsgBoxStyle.OkOnly, Nothing)
- End Sub
- Private Sub NewGameBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
- Using form As BlackJackForm = New BlackJackForm
- Me.Hide
- form.ShowDialog
- Me.Show
- End Using
- End Sub
- Private Sub OptionsBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
- Using form As OptionsForm = New OptionsForm
- Me.Hide
- form.ShowDialog
- Me.Show
- End Using
- End Sub
- Private Sub StartForm_Load(ByVal sender As Object, ByVal e As EventArgs)
- Interaction.MsgBox("Black Jack, E' Solo Una Prova ( BETA VERSION ) Stiamo lavorando Per Fixare Dei Bug.", MsgBoxStyle.OkOnly, Nothing)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement