using System.Linq;
using System.Collections.Generic;
namespace BlackJack_Game
{
internal class Program
{
private static List<int> cards = new List<int>
{
11,2,3,4,5,6,7,8,9,10,10,10,10
};
private static List<int> userCards = new List<int>
{
};
private static List<int> computerCards = new List<int>
{
};
static Random rnd = new Random(); //Create an instance of Random class somewhere. Note that it's pretty important not to create a new instance each time you need a random number.
//You should reuse the old instance to achieve uniformity in the generated numbers. You can have a static field somewhere (be careful about thread safety issues):
//This static field allows all static methods to use this random object as a field
static void Main(string[] args)
{
userStartingCards();
static void userStartingCards()
{
for(int i = 0; i < 2; i++)
{
int randomStartingNumberUser = rnd.Next(cards.Count);
userCards.Add(cards[randomStartingNumberUser]);
}
Console.WriteLine("Your cards are [{0}, {1}], current score {2}", userCards[0], userCards[1], userCards.Sum());
}
using System.Linq;
using System.Collections.Generic;
namespace BlackJack_Game
{
internal class Program
{
private static List<int> cards = new List<int>
{
11,2,3,4,5,6,7,8,9,10,10,10,10
};
private static List<int> userCards = new List<int>
{
};
private static List<int> computerCards = new List<int>
{
};
static Random rnd = new Random(); //Create an instance of Random class somewhere. Note that it's pretty important not to create a new instance each time you need a random number.
//You should reuse the old instance to achieve uniformity in the generated numbers. You can have a static field somewhere (be careful about thread safety issues):
//This static field allows all static methods to use this random object as a field
static void Main(string[] args)
{
userStartingCards();
static void userStartingCards()
{
for(int i = 0; i < 2; i++)
{
int randomStartingNumberUser = rnd.Next(cards.Count);
userCards.Add(cards[randomStartingNumberUser]);
}
Console.WriteLine("Your cards are [{0}, {1}], current score {2}", userCards[0], userCards[1], userCards.Sum());
}