how to deal cards to multiple players card game C
![Multi tool use Multi tool use](http://sgv.ssvwv.com/sg/ssvwvcomimagb.png)
Multi tool use
I am trying to make a card game in c, I am a bit stuck on how to deal the cards to a selected amount of players. Could anyone give me some guidelines on how to do this? I will post the code below, Thanks in advance and happy new year!!!
#include<stdio.h>
#include <stdlib.h> //random number generator functions
#include <string.h>
#include <time.h>
#include <ctype.h>
#define CARDS 52
int playerAmount;
int deckAmount;
int drawPosition = 0;
int deckPosition = 0;
char gamePlay;
int handNumber = 0;
int players;
const char *numeric = { "Two","Three","Four","Five","Six","Seven",
"Eight","Nine","Ten","Queen", "Jack","King","Ace" };
const char *suits = { "Diamonds","Hearts","Clubs","Spades"};
const char *P1[5];
const char *P2[5];
// function to shuffle the deck
int Shuffle(int *deck)
{
int i, temp, card;
printf("nShuffling...nn");
for (i = CARDS - 1; i > 0; i--)
{
card = rand() % i;
temp = deck[i];
deck[i] = deck[card];
deck[card] = temp;
}
return 0;
}
// program entry point
int main(void)
{
int deck[CARDS]; // deck
int card = 53; // card
int fDisplay, sDisplay; // face and suit
int i; // counter
char ch = 0; // keyboard
printf("Welcome to 25, Please enter the number of players");
scanf("%d", &players);
printf("Player Amount is: ", players);
// Declare player amount-dependant arrays...
//initialize the deck
for (i = 0; i < CARDS; i++)
deck[i] = i;
// deal cards
do
{
if (card >= CARDS)
card = Shuffle(deck);
// face and suit
fDisplay = deck[card] % 13;
sDisplay = deck[card] / 13;
player1 = deck[card] % 13 *5;
player2 = deck[card] % 13 *5;
// display the card
printf("%2d > %s of %stt", card, numeric [player1], suits[player1]);
card++;
printf("(Enter to deal, L to Leave)n");
ch = getchar();
} while (toupper(ch) != 'L');
return 0;
}
c
New contributor
Keith Nolan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I am trying to make a card game in c, I am a bit stuck on how to deal the cards to a selected amount of players. Could anyone give me some guidelines on how to do this? I will post the code below, Thanks in advance and happy new year!!!
#include<stdio.h>
#include <stdlib.h> //random number generator functions
#include <string.h>
#include <time.h>
#include <ctype.h>
#define CARDS 52
int playerAmount;
int deckAmount;
int drawPosition = 0;
int deckPosition = 0;
char gamePlay;
int handNumber = 0;
int players;
const char *numeric = { "Two","Three","Four","Five","Six","Seven",
"Eight","Nine","Ten","Queen", "Jack","King","Ace" };
const char *suits = { "Diamonds","Hearts","Clubs","Spades"};
const char *P1[5];
const char *P2[5];
// function to shuffle the deck
int Shuffle(int *deck)
{
int i, temp, card;
printf("nShuffling...nn");
for (i = CARDS - 1; i > 0; i--)
{
card = rand() % i;
temp = deck[i];
deck[i] = deck[card];
deck[card] = temp;
}
return 0;
}
// program entry point
int main(void)
{
int deck[CARDS]; // deck
int card = 53; // card
int fDisplay, sDisplay; // face and suit
int i; // counter
char ch = 0; // keyboard
printf("Welcome to 25, Please enter the number of players");
scanf("%d", &players);
printf("Player Amount is: ", players);
// Declare player amount-dependant arrays...
//initialize the deck
for (i = 0; i < CARDS; i++)
deck[i] = i;
// deal cards
do
{
if (card >= CARDS)
card = Shuffle(deck);
// face and suit
fDisplay = deck[card] % 13;
sDisplay = deck[card] / 13;
player1 = deck[card] % 13 *5;
player2 = deck[card] % 13 *5;
// display the card
printf("%2d > %s of %stt", card, numeric [player1], suits[player1]);
card++;
printf("(Enter to deal, L to Leave)n");
ch = getchar();
} while (toupper(ch) != 'L');
return 0;
}
c
New contributor
Keith Nolan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
Welcome to Code Review! I'm afraid your question is now well-suited for our site. We only answer questions about code that is working as intended, as explained in our help center. You may be able to receive help at Stack Overflow, though be sure to read their How to ask page before asking.
– Graham
12 mins ago
add a comment |
I am trying to make a card game in c, I am a bit stuck on how to deal the cards to a selected amount of players. Could anyone give me some guidelines on how to do this? I will post the code below, Thanks in advance and happy new year!!!
#include<stdio.h>
#include <stdlib.h> //random number generator functions
#include <string.h>
#include <time.h>
#include <ctype.h>
#define CARDS 52
int playerAmount;
int deckAmount;
int drawPosition = 0;
int deckPosition = 0;
char gamePlay;
int handNumber = 0;
int players;
const char *numeric = { "Two","Three","Four","Five","Six","Seven",
"Eight","Nine","Ten","Queen", "Jack","King","Ace" };
const char *suits = { "Diamonds","Hearts","Clubs","Spades"};
const char *P1[5];
const char *P2[5];
// function to shuffle the deck
int Shuffle(int *deck)
{
int i, temp, card;
printf("nShuffling...nn");
for (i = CARDS - 1; i > 0; i--)
{
card = rand() % i;
temp = deck[i];
deck[i] = deck[card];
deck[card] = temp;
}
return 0;
}
// program entry point
int main(void)
{
int deck[CARDS]; // deck
int card = 53; // card
int fDisplay, sDisplay; // face and suit
int i; // counter
char ch = 0; // keyboard
printf("Welcome to 25, Please enter the number of players");
scanf("%d", &players);
printf("Player Amount is: ", players);
// Declare player amount-dependant arrays...
//initialize the deck
for (i = 0; i < CARDS; i++)
deck[i] = i;
// deal cards
do
{
if (card >= CARDS)
card = Shuffle(deck);
// face and suit
fDisplay = deck[card] % 13;
sDisplay = deck[card] / 13;
player1 = deck[card] % 13 *5;
player2 = deck[card] % 13 *5;
// display the card
printf("%2d > %s of %stt", card, numeric [player1], suits[player1]);
card++;
printf("(Enter to deal, L to Leave)n");
ch = getchar();
} while (toupper(ch) != 'L');
return 0;
}
c
New contributor
Keith Nolan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I am trying to make a card game in c, I am a bit stuck on how to deal the cards to a selected amount of players. Could anyone give me some guidelines on how to do this? I will post the code below, Thanks in advance and happy new year!!!
#include<stdio.h>
#include <stdlib.h> //random number generator functions
#include <string.h>
#include <time.h>
#include <ctype.h>
#define CARDS 52
int playerAmount;
int deckAmount;
int drawPosition = 0;
int deckPosition = 0;
char gamePlay;
int handNumber = 0;
int players;
const char *numeric = { "Two","Three","Four","Five","Six","Seven",
"Eight","Nine","Ten","Queen", "Jack","King","Ace" };
const char *suits = { "Diamonds","Hearts","Clubs","Spades"};
const char *P1[5];
const char *P2[5];
// function to shuffle the deck
int Shuffle(int *deck)
{
int i, temp, card;
printf("nShuffling...nn");
for (i = CARDS - 1; i > 0; i--)
{
card = rand() % i;
temp = deck[i];
deck[i] = deck[card];
deck[card] = temp;
}
return 0;
}
// program entry point
int main(void)
{
int deck[CARDS]; // deck
int card = 53; // card
int fDisplay, sDisplay; // face and suit
int i; // counter
char ch = 0; // keyboard
printf("Welcome to 25, Please enter the number of players");
scanf("%d", &players);
printf("Player Amount is: ", players);
// Declare player amount-dependant arrays...
//initialize the deck
for (i = 0; i < CARDS; i++)
deck[i] = i;
// deal cards
do
{
if (card >= CARDS)
card = Shuffle(deck);
// face and suit
fDisplay = deck[card] % 13;
sDisplay = deck[card] / 13;
player1 = deck[card] % 13 *5;
player2 = deck[card] % 13 *5;
// display the card
printf("%2d > %s of %stt", card, numeric [player1], suits[player1]);
card++;
printf("(Enter to deal, L to Leave)n");
ch = getchar();
} while (toupper(ch) != 'L');
return 0;
}
c
c
New contributor
Keith Nolan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Keith Nolan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Keith Nolan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 17 mins ago
Keith Nolan
11
11
New contributor
Keith Nolan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Keith Nolan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Keith Nolan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
Welcome to Code Review! I'm afraid your question is now well-suited for our site. We only answer questions about code that is working as intended, as explained in our help center. You may be able to receive help at Stack Overflow, though be sure to read their How to ask page before asking.
– Graham
12 mins ago
add a comment |
2
Welcome to Code Review! I'm afraid your question is now well-suited for our site. We only answer questions about code that is working as intended, as explained in our help center. You may be able to receive help at Stack Overflow, though be sure to read their How to ask page before asking.
– Graham
12 mins ago
2
2
Welcome to Code Review! I'm afraid your question is now well-suited for our site. We only answer questions about code that is working as intended, as explained in our help center. You may be able to receive help at Stack Overflow, though be sure to read their How to ask page before asking.
– Graham
12 mins ago
Welcome to Code Review! I'm afraid your question is now well-suited for our site. We only answer questions about code that is working as intended, as explained in our help center. You may be able to receive help at Stack Overflow, though be sure to read their How to ask page before asking.
– Graham
12 mins ago
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Keith Nolan is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210640%2fhow-to-deal-cards-to-multiple-players-card-game-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Keith Nolan is a new contributor. Be nice, and check out our Code of Conduct.
Keith Nolan is a new contributor. Be nice, and check out our Code of Conduct.
Keith Nolan is a new contributor. Be nice, and check out our Code of Conduct.
Keith Nolan is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210640%2fhow-to-deal-cards-to-multiple-players-card-game-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4 y2fBKJGzDr1W6wbsMLBSK6h3bdh5XHDwim,CurjMoY
2
Welcome to Code Review! I'm afraid your question is now well-suited for our site. We only answer questions about code that is working as intended, as explained in our help center. You may be able to receive help at Stack Overflow, though be sure to read their How to ask page before asking.
– Graham
12 mins ago