maulem
Vaak hier
- Lid geworden
- 23 feb 2017
- Berichten
- 649
- Waarderingsscore
- 29
Misschien kun je een screenshot maken en uploaden op imgdumper.nl. Want deze is namelijk erg onduidelijk. Daarna de directe url kopiëren en aan je bericht toevoegen, via Koppeling invoegen, URL.
Dit is de volledige code.
Dit is de volledige code.
C#:
using System;
using System.Collections.Generic;
using System.Text;
namespace Kaartspel
{
static class Game
{
public static int aantalSpelers;
public static int aantalKaarten;
}
class Program
{
static void Main(string[] args)
{
DeckOfCards doc = new DeckOfCards();
doc.setUpDeck();
Console.WriteLine("Deck:");
Console.WriteLine("");
doc.PrintDeck();
Console.WriteLine("Aantal spelers:");
string input1 = Console.ReadLine();
Game.aantalSpelers = Int32.Parse(input1);
Console.WriteLine("Aantal kaarten:");
string input2 = Console.ReadLine();
Game.aantalKaarten = Int32.Parse(input2);
Console.WriteLine("");
Console.WriteLine("Shuffle:");
Console.WriteLine("");
doc.Shuffle();
doc.Deal();
Console.ReadLine();
}
}
class Cards
{
public enum Suit
{
HEARTS,
DIAMONDS,
SPADES,
CLUBS
}
public enum Value
{
Ace = 1, Two, Three, Four, Five, Six, Seven, Eight,
Nine, Ten, Jack, Queen, King
}
public Suit MySuit { get; set; }
public Value MyValue { get; set; }
}
class DeckOfCards : Cards
{
const int Total_Cards = 52; //number of all cards
private Cards[] deck; //array of all playing cards
private Cards[,] dealed; //two-dimensional array of all dealed cards
static Random r = new Random();
public DeckOfCards()
{
deck = new Cards[Total_Cards];
}
public Cards[] getDeck { get { return deck; } } //get current deck
//create deck of 52 cards: 13 Values each, with 4 suits
public void setUpDeck()
{
int i = 0;
foreach (Suit s in Enum.GetValues(typeof(Suit)))
{
foreach (Value v in Enum.GetValues(typeof(Value)))
{
deck[i] = new Cards { MySuit = s, MyValue = v };
i++;
}
}
}
//print all 52 cards
public void PrintDeck()
{
for (int i = 0; i < 52; i++)
{
Console.WriteLine($"{deck[i].MySuit} {deck[i].MyValue}");
}
Console.WriteLine("");
}
//print dealed cards for every player
public void PrintDealed()
{
for (int x = 0; x < Game.aantalSpelers; x++)
{
int a = x + 1;
Console.WriteLine("speler " + a + ":");
Console.WriteLine("");
for (int y = 0; y < Game.aantalKaarten; y++)
{
Console.WriteLine($"{dealed[x,y].MySuit} {dealed[x,y].MyValue}");
}
Console.WriteLine("");
}
}
//shuffle all 52 cards
public void Shuffle()
{
for (int n = deck.Length - 1; n > 0; --n)
{
int k = r.Next(n + 1);
Cards temp = deck[n];
deck[n] = deck[k];
deck[k] = temp;
}
PrintDeck();
}
//fill two-dimensional array with cards from shuffled deck array
public void Deal()
{
int total = Game.aantalSpelers * Game.aantalKaarten;
if (!(total > 52)) {
dealed = new Cards[Game.aantalSpelers, Game.aantalKaarten];
int i = 0;
for (int x = 0; x < Game.aantalSpelers; x++)
{
for (int y = 0; y < Game.aantalKaarten; y++)
{
dealed[x, y] = deck[i];
i++;
}
}
Console.WriteLine("");
PrintDealed();
}
else
{
Console.WriteLine("");
Console.WriteLine("Niet genoeg kaarten beschikbaar voor dit spel, teveel spelers of kaarten opgegeven.");
}
}
}
}