Blackjack C# Example
Blackjack C# Example
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace blackjack
{
class Program
{
static void Main(string[] args)
{
int totaljuc=0,totalpc=0;
string raspuns="da";
while (raspuns == "da")
{
totaljuc +=adaugarecarte();
totalpc += adaugarecartepc();
Console.WriteLine("Aveti punctajul " + totaljuc);
Console.WriteLine("Mai trageti o carte? ");
raspuns = Console.ReadLine();
}
if(totaljuc==21)
{
Console.WriteLine("Ati castigat! :D " );
}
else if(totaljuc >21)
{
Console.WriteLine("Ati pierdut ! :(");
}
else if(21-totaljuc >= 21-totalpc)
{
Console.WriteLine("Ati castigat! :D Pc-ul a avut totalul " +
totalpc);
}
else
{
Console.WriteLine("Ati pierdut ! :(Pc-ul a avut totalul " +
totalpc);
}
Console.ReadKey();
}
static int adaugarecarte()
{
int totaljuc=0;
Random rand = new Random();
int carte = rand.Next(2, 13);
Console.WriteLine("Ati tras "+carte);
if (carte <= 10)
{
totaljuc += carte;
}
else
{
totaljuc += 10;
}
return totaljuc;
}
static int adaugarecartepc()
{
int totalpc=0;
Random rando = new Random();
int cartepc = rando.Next(2, 13);
cartepc = rando.Next(2, 13);
//Console.WriteLine("Pc a tras " + cartepc);
if (cartepc <= 10)
{
totalpc += cartepc;
}
else
{
totalpc += 10;
}
return totalpc;
}
}
}