samedi 6 décembre 2014

How to change a character in C++ console that was printed to the screen earlier


Vote count:

0




I am in my second C++ class and I have to make a Video Poker game for my final. I want to have my game board printed to the screen and stay on the screen while only the characters that change are the only thing to change, while keeping the rest of the game board stays on the screen in the same place without clearing the screen and re-printing everything. The game I made more my final last class, I used the clear screen and it appeared to flash a lot because it was reprinting the entire screen each time a change was made. Instead of putting all of my code on here and so that someone else doesn't do my project for me I wrote the following code for an example of my question:



#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

const char * SUITS[] = { "HEARTS", "CLUBS", "DIAMONDS", "SPADES" };
const char * FACES[] = { "ACE", "TWO", "THREE", "FOUR", "FIVE", "SIX",
"SEVEN", "EIGHT", "NINE", "TEN", "JACK", "QUEEN", "KING" };

int main() {
char q = 'a';
do {
srand(time(0));

cout << "This is the card: " << endl;
cout << FACES[rand() % 13] << " of " << SUITS[rand() % 4] << endl;
cout << "Press any key to get another card, or q to quit: ";
cin >> q;

} while (q != 'q');
return 0;
}


How can I make it so that the only thing that changes above is this line when printed: FACES[rand() % 13] << " of " << SUITS[rand() % 4] << endl;


My actual code will just display a box with an char to show the face and a char to show the suit it will look like this when printed:



---------
| |
| A | (A is for Ace)
| |
| S | (S is for Spades)
| |
---------


How can I change just the A or the S without changing anything else? Or using the code above, How can I change just the FACES string and the SUITS string without changing the text above or below it?



asked 16 secs ago







How to change a character in C++ console that was printed to the screen earlier

Aucun commentaire:

Enregistrer un commentaire