0% found this document useful (0 votes)
286 views2 pages

Blackjack C# Example

This document contains the code for a basic blackjack game. It initializes the total scores for the player and PC to 0. It then enters a loop to continually draw cards until the player chooses to stop. It draws a card for the player and PC by calling functions that generate random card values. After each round it displays the player's score and asks if they want another card. After the loop it checks who won based on getting 21 or having the score closer to 21.

Uploaded by

Bogdan Belciug
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
286 views2 pages

Blackjack C# Example

This document contains the code for a basic blackjack game. It initializes the total scores for the player and PC to 0. It then enters a loop to continually draw cards until the player chooses to stop. It draws a card for the player and PC by calling functions that generate random card values. After each round it displays the player's score and asks if they want another card. After the loop it checks who won based on getting 21 or having the score closer to 21.

Uploaded by

Bogdan Belciug
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

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;
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy