My main question is how would I add images to the game? Where would I put them? How would I make sure the suits are randomized, too?
New Code:
Public Class FRM_BlackJack
Private Sub FRM_BlackJack_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
'Global Variables
Dim PlayerCards(4) As Image
Dim PlayerTotal As Integer = 0
Dim DealerCards As Image
Dim DealerTotal As Integer = 0
Dim Count As Integer = 1
'This is supposed to randomize the cards A to K
'Will this randomize the images as well?
Dim CardRandomizer As Random
'End of Global Variables
'This function names and gives values to the cards
'Should I put the images in it, too?
Public Function AddCard()
Dim Name As String
'Limiting the randomizer to a minimum of 1 and a maximum of 10
Dim Value As Integer = CardRandomizer.Next(1, 11)
Select Case Value
Case 0
Name = "Two"
Value += 2
Case 1
Name = "Three"
Value += 3
Case 2
Name = "Four"
Value += 4
Case 3
Name = "Five"
Value += 5
Case 4
Name = "Six"
Value += 6
Case 5
Name = "Seven"
Value += 7
Case 6
Name = "Eight"
Value += 8
Case 7
Name = "Nine"
Value += 9
Case 8
Name = "Ten"
Value += 10
Case 9
Name = "Jack"
Value += 10
Case 10
Name = "Queen"
Value += 10
Case 11
Name = "King"
Value += 10
Case 12
Name = "Ace"
Value += 11
Case Else
Name = "Ace"
Value += 1
End Select
Return Value
End Function
Private Sub BTN_Deal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_Deal.Click
'Not sure if these Total variables are right at all; the dealer and the player are supposed to be dealt two cards each
DealerTotal = CardRandomizer.Next()
'By default, only the first two pictureboxes are shown
PB_DCard1.Show()
PB_DCard2.Show()
If (DealerTotal < 21) Then
AddCard()
End If
PlayerTotal = CardRandomizer.Next()
PB_PCard1.Show()
PB_PCard2.Show()
If PlayerTotal = 21 Then
LBL_PTotal.Text = "BLACKJACK!!"
LBL_PTotal.ForeColor = System.Drawing.Color.Lime
ElseIf PlayerTotal > 21 Then
LBL_PTotal.Text = "Busted"
LBL_PTotal.ForeColor = System.Drawing.Color.Orange
ElseIf PlayerTotal < 21 Then
LBL_PTotal.Text = PlayerTotal
LBL_PTotal.ForeColor = System.Drawing.Color.Lime
End If
End Sub
Private Sub BTN_Hit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_Hit.Click
'This button is supposed to show the next picturebox, add a card, and update the total of the pleyer's cards
Count += 1
PB_PCard1.Image = PlayerCards(Count)
PB_PCard2.Image = PlayerCards(Count)
PB_PCard3.Image = PlayerCards(Count)
'A simple message box that explains why there is a limit of 5 cards
If PlayerCards.Length > 4 Then
MessageBox.Show("To keep things easier for people with low vision, the number of cards per hand is limited to five")
End If
End Sub
'Simple betting functions
Private Sub PB_Bet10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PB_Bet10.Click
Dim Bet10 As Integer = 10
LBL_BetTotal.Text += 10
End Sub
Private Sub PB_Bet50_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PB_Bet50.Click
Dim Bet50 As Integer = 50
LBL_BetTotal.Text += 50
End Sub
Private Sub PB_Bet250_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PB_Bet250.Click
Dim Bet250 As Integer = 250
LBL_BetTotal.Text += 250
End Sub
Private Sub BTN_Stand_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_Stand.Click
LBL_BetTotal.Text += LBL_BankTotal.Text
LBL_BetTotal.Refresh()
'Clear player's hand
PB_PCard1.Refresh()
PB_PCard2.Refresh()
PB_PCard3.Refresh()
PB_PCard4.Refresh()
PB_PCard5.Refresh()
LBL_PTotal.Refresh()
'Clear dealer's hand
PB_DCard1.Refresh()
PB_DCard2.Refresh()
PB_DCard3.Refresh()
PB_DCard4.Refresh()
PB_DCard3.Refresh()
LBL_DTotal.Refresh()
End Sub
End Class
Old C# Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Isaak_BlackJack
{
class Program
{
static string[] strPlayerCards = new string[11];
static string strHitOrStand;
static int intTotal = 0, intCount = 1, intDealerTotal = 0;
static Random cardRandomizer = new Random();
static void Main(string[] args)
{
Console.WriteLine("Welcome to Blackjack!");
Start();
}
static void Start()
{
intDealerTotal = cardRandomizer.Next(15, 22);
strPlayerCards[0] = Deal();
strPlayerCards[1] = Deal();
do
{
Console.WriteLine("You were dealt {0} and {1}. \nYour total is {2} .\nWould you like to hit or stand?", strPlayerCards[0], strPlayerCards[1], intTotal);
strHitOrStand = Console.ReadLine().ToLower();
}
while (!strHitOrStand.Equals("hit") && !strHitOrStand.Equals("stand"));
Game();
}
static void Game()
{
if (strHitOrStand.Equals("hit"))
{
Hit();
}
else if (strHitOrStand.Equals("stand"))
{
if (intTotal > intDealerTotal && intTotal <= 21)
{
Console.WriteLine("\nWINNER! The dealer's total was {0}.\nWould you like to play again? Press \"Y\" for Yes or \"N\" for No", intDealerTotal);
PlayAgain();
}
else if (intTotal < intDealerTotal)
{
Console.WriteLine("\nLOOSER! The dealer's total was {0}.\nWould you like to play again? Press \"Y\" for Yes or \"N\" for No", intDealerTotal);
PlayAgain();
}
}
Console.ReadKey();
}
static string Deal()
{
string strCard;
int intCards = cardRandomizer.Next(1, 14);
switch (intCards)
{
case 1:
strCard = "Two"; intTotal += 2;
break;
case 2:
strCard = "Three"; intTotal += 3;
break;
case 3:
strCard = "Four"; intTotal += 4;
break;
case 4:
strCard = "Five"; intTotal += 5;
break;
case 5:
strCard = "Six"; intTotal += 6;
break;
case 6:
strCard = "Seven"; intTotal += 7;
break;
case 7:
strCard = "Eight"; intTotal += 8;
break;
case 8:
strCard = "Nine"; intTotal += 9;
break;
case 9:
strCard = "Ten"; intTotal += 10;
break;
case 10:
strCard = "Jack"; intTotal += 10;
break;
case 11:
strCard = "Queen"; intTotal += 10;
break;
case 12:
strCard = "King"; intTotal += 10;
break;
case 13:
strCard = "Ace"; intTotal += 10;
break;
default:
strCard = "Ace"; intTotal += 1;
break;
}
return strCard;
}
static void Hit()
{
intCount += 1;
strPlayerCards[intCount] = Deal();
Console.WriteLine("\nYou were dealt a(n) {0}.\nYour new total is {1}", strPlayerCards[intCount], intTotal);
if (intTotal.Equals(21))
{
Console.WriteLine("\nBLACKJACK!! The dealer's total was {0}.\nWould you like to play again?", intDealerTotal);
PlayAgain();
}
else if (intTotal > 21)
{
Console.WriteLine("\nYOU BUSTED! The dealer's total was {0}. \nWould you like to play again? Press \"Y\" for Yes and \"N\" for No.");
PlayAgain();
}
else if (intTotal < 21)
{
do
{
Console.WriteLine("\nWould you like to hit or stand?");
strHitOrStand = Console.ReadLine().ToLower();
}
while (!strHitOrStand.Equals("hit") && !strHitOrStand.Equals("stand"));
Game();
}
}
static void PlayAgain()
{
string strPlayAgain;
do
{
strPlayAgain = Console.ReadLine().ToLower();
}
while (!strPlayAgain.Equals("Y") && !strPlayAgain.Equals("N"));
if (strPlayAgain.Equals("Y"))
{
Console.WriteLine("\nPress enter to restart the game!");
strPlayAgain = Convert.ToString(Console.ReadKey());
Console.Clear();
intDealerTotal = 0;
intCount = 1;
intTotal = 0;
Start();
}
else if (strPlayAgain.Equals("N"))
{
Console.WriteLine("\nPress enter to close Blackjack.");
strPlayAgain = Convert.ToString(Console.ReadKey());
}
}
}
}

New Topic/Question
Reply




MultiQuote









|