![]() |
| ||
| Making War card game Hey I have to make the game War (card game: http://en.wikipedia.org/wiki/War_(card_game) ) in C. Im not sure where (how...) to start. My basic thoughts/ideas/etc: Its a 40 (4 times 10) card version with 2 players. A way to do it would be set up a structure with 4 faces values: a, b, c, and d. Now I need that each has a value of 1 - 10 (a1, a2, a3....a10) but nonchanging. After this each player has a another structure (or array (?) ) holding 20 cards. Now out of the 40 card deck structure we have to randomly pick them out and assign them to the 2 players (this is one of the 2 big problems; No idea how to randomly pick) The game afterwards is pretty simple: Simply each player puts out a card. If the card is larger, that player gets his card back (in a seperete deck) and the other players card. If the card is smaller, the player looses his card. If tie, player puts 2 cards with hidden value and a third card with value revelaed. That shouldnt be too hard. The game is ended when a player is without cards Now here a hard part: There will be a clock running during the game. If someone beats the game and is in the top 10 of the fastest, his name will be added to the ranking. This is saved/loaded from a simple text file. I have no clue on how to do this. I hope I can get some help because Ive thought about it and honestly I dont even know where to start. |
| ||
| Re: Making War card game Look into the time functions in timer.h for ways to do the counters. If you need help in other areas, please be specific. |
| ||
| Re: Making War card game Quote:
|
| ||
| Re: Making War card game I hope you understand what I ment with my last post. |
| ||
| Re: Making War card game I just wanna know if the idea is right or not. |
| ||
| Re: Making War card game You should be able to store the data for each card within an integer. You could then get the suit as card / 10 and you could get the rank as card % 10. I find this approach simplifies things a little. You could then have an array size 40 to hold the cards, which would be shuffled when you start the game. Instead of passing structs around between the deck an the players you keep an index of the stack position in the deck. Every time you deal a card copy the card value at the stack position to the players hand and increment the stack position. When you reach the end of the deck the you can reshuffle the cards or something. Heres crude example of how to get a random number: #include <stdio.h> A simple way to time the game would be to call clock() at the start of the game and save the return value. At the end of the game call clock again and subtract the start time from the end time. You then might want to convert the result tom minutes and seconds. To write to files look up fopen and fprintf. |
| ||||||
| Re: Making War card game Quote:
Quote:
Quote:
Structs is something Im use to working with. Quote:
Quote:
Quote:
Thanks alot mike_g for the help. I hope to hear from you soon :) |
| ||
| Re: Making War card game Quote:
int card = 39; Quote:
|
| ||
| Re: Making War card game every time i see this title Making War in the list, i think of that segment from the movie "Clerks" ... you know, the Russian metal head dude who sings his "Berserker" song for Dante's girlfriend after Jay and Silent Bob encourage him: Quote:
oh well :P . |
| All times are GMT -4. The time now is 12:13 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC