View Single Post
Join Date: May 2008
Posts: 82
Reputation: riahc3 is an unknown quantity at this point 
Solved Threads: 0
riahc3 riahc3 is offline Offline
Junior Poster in Training

Re: Making War card game

 
0
  #7
Aug 20th, 2008
Originally Posted by mike_g View Post
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.
Not getting this fully. The suit and the rank is where you lost me

Originally Posted by mike_g View Post
You could then have an array size 40 to hold the cards, which would be shuffled when you start the game.
This was one of my ideas. Actually two seperate arrays; one with the organized get and another with the unorganized deck with would get it from the organized one.


Originally Posted by mike_g View Post
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.
Im sorry but here I honestly have no idea what you are talking about.

Structs is something Im use to working with.

Originally Posted by mike_g View Post
Heres crude example of how to get a random number:
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main()
  6. {
  7. srand(time(NULL)); //seed randomisation only once at start of game
  8.  
  9. printf("Random number (0 - 39): %d\n", rand() % 40); // print a random umber
  10. return 0;
  11. }
Ah yes. Thats what it was. Thank you very much.

Originally Posted by mike_g View Post
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.
Very easy and very effective. Didn't know about clock so my apoligies for asking such a simple question.

Originally Posted by mike_g View Post
To write to files look up fopen and fprintf.
I used fseek, fopen, fclose, etc but I seem to always do a pointer/memory violation as a popup window the red X pops up always when it gets to saving/opening. Some tips or pages with examples would be nice


Thanks alot mike_g for the help. I hope to hear from you soon
Reply With Quote