Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

War

CindexCindex Posts: 27Member
This is a game, but very basic so I put in the basic questions section.

I'm trying to make a game of War like you play with cards. It shows you the cards and then you can draw again. The problem is things aren't showing up right. Numbers and letters will show up wrong. For example, sometimes when I'm supposed to get a number I'll get a heart or club.

I think the problem may be that I'm trying to change an int value into a string. Such as:
[code]card = show;[/code]
and
[code]ocard = show2;[/code]

Is there a better way to do this? Here is the full code:
[code]#include
#include
#include
using namespace std;
int main() {
srand(time(NULL));
int p1, p2;
int choose, card, ocard;
string show, show2;
cout<<"Welcome to War!
You will be playing with a 52 card deck.
Press enter to continue.";
cin.get();
system("cls");
p1 = 26;
p2 = 26;
restart:
cout<<"Player one has "<<p1<<" points. Player two has "<<p2<<" points.
";
cout<<"Press enter to start.";
cin.get();
system("cls");
cout<<"Player one has "<<p1<<" points. Player two has "<<p2<<" points.
";
draw:
card = (rand() % 12 + 2);
ocard = (rand() % 12 + 2);
if (card == 11) {
show = "J";
goto p2;
}
if (card == 12) {
show = "Q";
goto p2;
}
if (card == 13) {
show = "K";
goto p2;
}
if (card == 14) {
show = "A";
goto p2;
}
if (card < 11) {
show = card;
goto p2;
}
p2:
if (ocard == 11) {
show2 = "J";
goto done;
}
if (ocard == 12) {
show2 = "Q";
goto done;
}
if (ocard == 13) {
show2 = "K";
goto done;
}
if (ocard == 14) {
show2 = "A";
goto done;
}
if (ocard < 11) {
show2 = ocard;
}
done:
if (card > ocard) {
p1 = p1 + 1;
p2 = p2 - 1;
goto scored;
}
if (ocard > card) {
p1 = p1 - 1;
p2 = p2 + 1;
goto scored;
}
scored:
system ("cls");
cout<<"Player one has "<<p1<<" points. Player two has "<<p2<<" points.
";
cout<<"*********** ***********
*"<<show<<" * *"<<show2<<" *
* * * *
* * * *
* * * *
* * * *
* * * *
* "<<show<<"* * "<<show2<<"*
*********** ***********
";
Sleep(2000);
cout<<"Player one has "<<p1<<" points. Player two has "<<p2<<" points.
";
cout<<"Press enter to draw again.";
cin.get();
if (p1 == 0) {
system("cls");
cout<<"Player two wins!!!
Press enter to play again!";
cin.get();
goto restart;
}
if (p2 == 0) {
cout<<"Player one wins!!!
Press enter to play again!";
cin.get();
goto restart;
}
goto draw;
}[/code]

I'm using Dev Bloodshed C++, I don't know if that makes a difference now or not.
=======================================
Noob programmer at Actionscript and C++.

. ~Always needing help~ .

Comments

  • IDKIDK Posts: 1,784Member
    : This is a game, but very basic so I put in the basic questions
    : section.
    :
    : I'm trying to make a game of War like you play with cards. It shows
    : you the cards and then you can draw again. The problem is things
    : aren't showing up right. Numbers and letters will show up wrong.
    : For example, sometimes when I'm supposed to get a number I'll get a
    : heart or club.
    :
    : I think the problem may be that I'm trying to change an int value
    : into a string. Such as:
    : [code]: card = show;[/code]:
    : and
    : [code]: ocard = show2;[/code]:
    :

    Yepp, thats the prob.

    You could do like this: show = card+'0';

    Look at the ascii table to find out why and how this works.
  • CindexCindex Posts: 27Member
    Thank you! It works exactly the way I want it to now!
    =======================================
    Noob programmer at Actionscript and C++.

    . ~Always needing help~ .
Sign In or Register to comment.