GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-May-2004, 21:32
Pravda Pravda is offline
New Member
 
Join Date: May 2004
Posts: 3
Pravda is on a distinguished road

Card Game Help!


I'm very frustrated, my teacher doesn't give me any clue whatsoever on how i'm supposed to complete this. I'm supposed to write two functions, one to deal the cards, and one to play war with them. All the game is supposed to tell the player is how many cards he won, and how many cards the computer won (ties don't count) then it tells the player who won by whoever got the most cards. please point me in the right direction.
CPP / C++ / C Code:
#include <iostream.h>
#include <stdlib.h>
#include <time.h>

enum Suit{Spade, Heart, Diamond, Club};

enum Rank{Ace = 1, Two, Three, Four, Five, Six
, Seven, Eight, Nine, Ten, Jack, Queen, King};

struct Card
{
	Suit suit;
	Rank number;
};

const int deckSize = 52;

Card deck[52];

void initDeck();

void printDeck();

void printCard(int index, Card theDeck[]);

void shuffle();

struct hand
{
	Card cards[26];
	int numCards;
} you, me;

void dealCards();

void playWar();

int main()
{
	initDeck();
	shuffle();
	dealCards();
	playWar();
	return 0;
}

void dealCards()
{
	WRITE THIS FUNCTION
}

void playWar()
{
             AND THIS ONE
}

void initDeck()
{
	for(int i = 0; i < deckSize; i++)
	{
		switch (i % 4)
		{
		case Spade:
			deck[i].suit = Spade;
			break;
		case Heart:
			deck[i].suit = Heart;
			break;
		case Diamond:
			deck[i].suit = Diamond;
			break;
		case Club:
			deck[i].suit = Club;
			break;
		}

		switch (i % 13 + 1)
		{
		case Ace:
			deck[i].number = Ace;
			break;
		case Two:
			deck[i].number = Two;
			break;
		case Three:
			deck[i].number = Three;
			break;
		case Four:
			deck[i].number = Four;
			break;
		case Five:
			deck[i].number = Five;
			break;
		case Six:
			deck[i].number = Six;
			break;
		case Seven:
			deck[i].number = Seven;
			break;
		case Eight:
			deck[i].number = Eight;
			break;
		case Nine:
			deck[i].number = Nine;
			break;
		case Ten:
			deck[i].number = Ten;
			break;
		case Jack:
			deck[i].number = Jack;
			break;
		case Queen:
			deck[i].number = Queen;
			break;
		case King:
			deck[i].number = King;
			break;
		}
	}
}

void printCard(int index, Card theDeck[])
{
	cout << "(";
	switch (theDeck[index].number)
	{
	case Ace:
		cout << "Ace";
		break;
	case Jack:
		cout << "Jack";
		break;
	case Queen:
		cout << "Queen";
		break;
	case King:
		cout << "King";
		break;
	default:
		cout << theDeck[index].number;
	}

	cout << ", ";
	switch(theDeck[index].suit)
	{
	case Spade:
		cout << "Spade";
		break;
	case Heart:
		cout << "Heart";
		break;
	case Diamond:
		cout << "Diamond";
		break;
	case Club:
		cout << "Club";
		break;
	}
	cout << ")";
}

void printDeck()
{
	int count =1;
	for(int j= 0; j < deckSize; j++)
	{
		printCard(j, deck);
		cout << "\t";
		if(count == 4)
		{
			cout << endl;
			count = 0;
		}
		count++;
	}
}

void shuffle()
{
	srand(time(0));

	Card temp;
	int r;
	for(int i = 1; i <= 10000; i++)
	{
		r = rand() % 52;
		temp = deck[0];
		deck[0] = deck[r];
		deck[r] = deck[51];
		deck[51] = temp;
	}
}
Last edited by JdS : 28-May-2004 at 05:17. Reason: Please enclose c code in [c] & [/c] for syntax highlighting
  #2  
Old 27-May-2004, 23:52
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,243
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Pravda
I'm very frustrated, my teacher doesn't give me any clue whatsoever on how i'm supposed to complete this. I'm supposed to write two functions, one to deal the cards, and one to play war with them. All the game is supposed to tell the player is how many cards he won, and how many cards the computer won (ties don't count) then it tells the player who won by whoever got the most cards. please point me in the right direction.
Start by not explaining just what the assignment is, but what you are having trouble with. What is it you don't understand about dealing? What do you have when ready to deal? Are the cards ready for the deal?

And look at the sticky at the top for information on how to post code.
__________________

Age is unimportant -- except in cheese
  #3  
Old 28-May-2004, 00:55
Pravda Pravda is offline
New Member
 
Join Date: May 2004
Posts: 3
Pravda is on a distinguished road
Quote:
Originally Posted by WaltP
Start by not explaining just what the assignment is, but what you are having trouble with. What is it you don't understand about dealing? What do you have when ready to deal? Are the cards ready for the deal?

And look at the sticky at the top for information on how to post code.
Well, I don't even understand the assignment. Oh well. I'll take the F.
  #4  
Old 28-May-2004, 01:54
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Quote:
Originally Posted by Pravda
Well, I don't even understand the assignment. Oh well. I'll take the F.

You took your effort to ask your question here and youre saying to give up now when people in this forum is willing to help you out??

I don't know what war game is.. if you explaine how it is played, maybe we can help you out... now, come on. Don't You Give Up.
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #5  
Old 28-May-2004, 08:40
Pravda Pravda is offline
New Member
 
Join Date: May 2004
Posts: 3
Pravda is on a distinguished road
Quote:
Originally Posted by Max Payne
You took your effort to ask your question here and youre saying to give up now when people in this forum is willing to help you out??

I don't know what war game is.. if you explaine how it is played, maybe we can help you out... now, come on. Don't You Give Up.
I wouldn't be so quik to give up if I had more time to do this problem. My other classes along with work took all of my time. Since it's due today, I'm not able to finish it. Thanks for your willingness to help me. Before this quarter, I was compleately excited about programming. 2nd quarter, we learned how to program in VB. Once my class switched teachers to learn about C++, the teachers make me feel like I'm stupid. They have no buisiness teaching. I'm thinking of dropping out because I think I can learn more on my own than they could ever teach me, since they havn't taught me a thing at all. Everything I've learned about C++, I've learned on my own. Thanks again for your willingness to help me, so far, you've shown more effort than my C++ teacher.
 
 

Recent GIDBlogToyota - 2008 September Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Worst pc game ever enyalives Computer Software Forum - Games 10 20-Dec-2004 20:06
Thoughts on Software Piracy pcxgamer Computer Software Forum - Games 9 23-Apr-2004 06:36
want to add a pause in a game. Help jjj93421 C++ Forum 1 11-Feb-2004 09:33
Tips for game troubleshooting pcxgamer Computer Software Forum - Games 0 02-Jan-2004 05:27
can't solve the sum ryz C++ Forum 0 30-Oct-2003 18:55

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:40.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.