using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelapanLima
{
public class Card
{
private string face;
private string suit;
public Card(string cardFace, string cardSuit)
{
face = cardFace;
suit = cardSuit;
}
public override string ToString()
{
return face + "of" + suit;
}
}
public class DeckOfCards
{
private Card[] deck;
private int currentCard;
private const int NUMBER_OF_CARDS = 52;
private Random randomNumbers;
public DeckOfCards()
{
string[] faces = { "ace", "deuce", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "jack", "queen", "king" };
string[] suits = { "hearts", "diamonds", "clubs", "spades" };
deck = new Card[NUMBER_OF_CARDS];
currentCard = 0;
randomNumbers = new Random();
for (int count = 0; count < deck.Length; count++)
deck[count] = new Card(faces[count % 13], suits[count / 13]);
}
public void Shuffle()
{
currentCard = 0;
for (int first = 0; first < deck.Length; first++)
{
int second = randomNumbers.Next(NUMBER_OF_CARDS);
Card temp = deck[first];
deck[first] = deck[second];
deck[second] = temp;
}
}
public Card DealCard()
{
if (currentCard < deck.Length)
return deck[ currentCard++ ];
else
return null;
}
}
public class DeckCardsTest
{
public static void Main(string[] args)
{
DeckOfCards myDeckOfCards = new DeckOfCards();
myDeckOfCards.Shuffle();
for (int i = 0; i < 13; i++)
{
Console.WriteLine("{0,-20}{1,-20}{2,-20}{3,-20}", myDeckOfCards.DealCard(), myDeckOfCards.DealCard(), myDeckOfCards.DealCard(), myDeckOfCards.DealCard());
}
Console.WriteLine();
Console.ReadLine();
}
}
}
Saturday, November 28, 2009
at one night
hi...
this is just a blog, I never signed again since a year ago. Since through ten years when I was a freshman student, my life can't be aparted from internet until now , but just for this night at once time, at once moment I signed in this blog, which I avoided so far...
by the way, recently I m interested in C# programming language...so I'll try...why not?, better be late than not at all.
this is just a blog, I never signed again since a year ago. Since through ten years when I was a freshman student, my life can't be aparted from internet until now , but just for this night at once time, at once moment I signed in this blog, which I avoided so far...
by the way, recently I m interested in C# programming language...so I'll try...why not?, better be late than not at all.
Subscribe to:
Posts (Atom)