I'm very new to c# and programming in general, so excuse my poor knowledge.
For school we have to create a blackjack game using windows form. I had to store the images of each card into a sorted list so i created a class called cardList and created a constructor which contained the the sorted list called cards. So it looks kinda like this:
Now I'm trying to call one of the cards to put into a picture box using a method called dealDealer in a different class called Form1:
There's probably a few other errors, I'm still trying to figure this whole c# thing out. All i need right now is for some one to please explain to me why the error tells me (on the line that contains c.cards.GetByIn dex(cardNumber) ;) that cards is inaccessible due the its protection level.
Much appreciated
For school we have to create a blackjack game using windows form. I had to store the images of each card into a sorted list so i created a class called cardList and created a constructor which contained the the sorted list called cards. So it looks kinda like this:
Code:
public class cardList : Form1
{
SortedList cards = new SortedList();
public cardList()
{
cards.Add(Image.FromFile("C:\\Users\\Lulu\\Documents\\cards\\club02.png"), 0);
cards.Add(Image.FromFile("C:\\Users\\Lulu\\Documents\\cards\\club03.png"), 1);
cards.Add(Image.FromFile("C:\\Users\\Lulu\\Documents\\cards\\club04.png"), 2);
cards.Add(Image.FromFile("C:\\Users\\Lulu\\Documents\\cards\\club05.png"), 3);
...
// the ellipses represents the other 49 cards
}
}
Code:
public void dealDealer(int cardsDealt)
{
Random number = new Random();
int randomCard = number.Next(1, 52);
for (int b = 0; b < cardsDealt;)
if (randomCard == cardNumber)
{
cardList c = new cardList();
dealer2.Image = c.cards.GetByIndex(cardNumber);
}
}
Much appreciated
Comment