Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*==============================
- Brandon Tishendorf
- CardSuperFun
- 11*23*2014
- Create an array with 52 slots simulating a deck, then do some basic card
- function like shuffle, show cards etc.
- ================================*/
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- #include <utility>
- using namespace std;
- //Prototype the function
- void initializeDeck(int deck[]);
- void dumpDeck(const int deck[52], int size);
- void shuffle(int deck[], int size, int high, int low, int randNum, int randNum2);
- void main()
- {
- int deck;
- int deck [52];
- cin.get();
- cin.ignore();
- }
- void initializeDeck(int deck[])
- {
- //Assign all 52 values in the array
- int deck [52] = { 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
- 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213,
- 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313,
- 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413};
- }
- void dumpDeck(const int deck[52], int size)
- {
- for (int i = 0; i < size; i++)
- {
- cout << deck[i] << endl;
- }
- }
- void shuffle(int deck[], int size, int high, int low, int randNum, int randNum2)
- {
- low = 0;
- high =52;
- for (int i = 0; i < 300; i++)
- {
- randNum = rand() % (high-low+1) + low;
- randNum2= rand() % (high-low+1) + low;
- swap(deck[randNum], deck[randNum2]);
- }
- }
- void showCard(int card, int deck[], int& randNum)
- {
- card = deck[randNum];
- if (card > 100 || card < 200)
- {
- if ((card - 100) <= 10 && (card - 100) != 1)
- {
- cout << (card - 100);
- }
- else if (card = 101)
- {
- cout << "A";
- }
- else if (card = 111)
- {
- cout << "J";
- }
- else if (card = 112)
- {
- cout << "Q";
- }
- else if (card = 113)
- {
- cout << "K";
- }
- cout << static_cast<char>(3);
- }
- else if (card > 200 || card < 300)
- {
- if ((card - 200) <= 10 && (card - 200) != 1)
- {
- cout << (card - 100);
- }
- else if (card = 201)
- {
- cout << "A";
- }
- else if (card = 211)
- {
- cout << "J";
- }
- else if (card = 212)
- {
- cout << "Q";
- }
- else if (card = 213)
- {
- cout << "K";
- }
- cout << static_cast<char>(4);
- }
- else if (card > 300 || card < 400)
- {
- if ((card - 300) <= 10 && (card - 300) != 1)
- {
- cout << (card - 300);
- }
- else if (card = 301)
- {
- cout << "A";
- }
- else if (card = 311)
- {
- cout << "J";
- }
- else if (card = 312)
- {
- cout << "Q";
- }
- else if (card = 313)
- {
- cout << "K";
- }
- cout << static_cast<char>(5);
- }
- else
- {
- if ((card - 400) <= 10 && (card - 400) != 1)
- {
- cout << (card - 400);
- }
- else if (card = 401)
- {
- cout << "A";
- }
- else if (card = 411)
- {
- cout << "J";
- }
- else if (card = 412)
- {
- cout << "Q";
- }
- else if (card = 413)
- {
- cout << "K";
- }
- cout << static_cast<char>(6);
- }
- }
- void showCards(const int deck, int& size, bool hideFirstCard)
- {
- }
- int getRandomNumber(int low, int high)
- {
- static bool firstTime=true;
- int randNum;
- //if first time called, seed random number generator
- if (firstTime)
- {
- srand( static_cast<unsigned int>(time(NULL)) );
- firstTime=false;
- }
- //generate random number between given low and high values (inclusive)
- randNum = rand() % (high-low+1) + low;
- return randNum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement