War Card Game

I am new at programming and have been struggling for days on creating this program. I have to basically create the game of war. I have to create 2 arrays... player0 and player1 each able to store 52 cards.
I've gotten that part: player0[52] player1[52]. I then have to shuffle a deck and deal out the cards between the two players. I have to loop the game until one player has all the cards. Deck goes from two to Ace.
I am having trouble with the functions, I have to create 6.


(1) load the deck into an array.
(2) Shuffle the deck.
(3) remove a card from the top of a player's hand.
(4) move a card to the bottom of a player's hand.
(5) check if one card is greater than another based on face value.
(6) handle equal faceValue wars.

Someone please help me.


this is what I have so far:


#include <iostream>
#include <string>
#include <ctime>
using namespace std;

string FACEVALUE0 [13] = {"Two","Three","Four","Five","Six","Seven",
"Eight","Nine","Ten","Jack","Queen","King","Ace"};
string SUIT0[4] = {"Hearts", "Diamods", "Spades", "Clubs"};

struct card
{
int facevalue;
string suit;
};





int main()

{
string player0 [52];
string player1 [52];
srand(time(NULL));

for (int i=0; i < 52; ++i)
{

card.facevalue[i]= FACEVALUE0 [i % 13];
card.suit[i] = SUIT0[i/13];


}

return EXIT_SUCCESS;
}
Last edited on
closed account (18hRX9L8)
Well, here is something I came up with. Just a crude form but I hope it gives you ideas.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include "simpio.h"
#include "genlib.h"
#include "strlib.h"
#include <ctime>

string GetCard(int randomcard);

string GetCard(int randomcard)
{
       string randomcard_str;
       
       switch(randomcard)
       {
            case 2: randomcard_str="Two"; break;
            case 3: randomcard_str="Three"; break;
            case 4: randomcard_str="Four"; break;
            case 5: randomcard_str="Five"; break;
            case 6: randomcard_str="Six"; break;
            case 7: randomcard_str="Seven"; break;
            case 8: randomcard_str="Eight"; break;
            case 9: randomcard_str="Nine"; break;
            case 10: randomcard_str="Ten"; break;
            case 11: randomcard_str="Jack"; break;
            case 12: randomcard_str="Queen"; break;
            case 13: randomcard_str="King"; break;
            case 14: randomcard_str="Ace"; break;
            default: randomcard_str="NULL"; break;
       }
       return(randomcard_str);
}

main()
{
	  srand(time(NULL));
      int randomcard_pl1,randomcard_pl2,tot1,tot2,i;
      string whatcard_pl1,whatcard_pl2;
      
      tot1=0;
      tot2=0;
      
      printf ("Lets play war!\n");
      printf ("1st player, press enter to shuffle your deck!\n");
      getchar();
      printf ("2nd player, press enter to shuffle your deck!\n");
      getchar();
      printf ("Get ready. Press enter every time the turn is over.\n");
      getchar();
      
      
      for (i=1;i<=52;i++)
      {
           randomcard_pl1=rand()%13+2;
           randomcard_pl2=rand()%13+2;
           whatcard_pl1=GetCard(randomcard_pl1);
           whatcard_pl2=GetCard(randomcard_pl2);
           tot1=tot1+randomcard_pl1;
           tot2=tot2+randomcard_pl2;
           printf ("-------------------------------------------------------------------------------\n\n");
           printf ("Turn %d: Player 1 drawed a %s. Player 2 drawed a %s. Total P1: %d. Total P2: %d.\n",i,whatcard_pl1,whatcard_pl2,tot1,tot2);
           printf ("-------------------------------------------------------------------------------\n\n");
           getchar();
      }

      if (tot1>tot2)
      {
           printf ("__________________________________\n\n");
           printf ("| Player 1 wins with %d points! |\n\n",tot1);
           printf ("**********************************\n");
      }
      else if (tot2>tot1)
      {
           printf ("__________________________________\n\n");
           printf ("| Player 2 wins with %d points! |\n\n",tot2);
           printf ("**********************************\n");
      }
      else
      {
           printf ("__________________________________\n\n");
           printf ("|      TIE with %d points!      |\n\n",tot1);
           printf ("**********************************\n");
      }
getchar();
}
Last edited on
Topic archived. No new replies allowed.