Via Tastendruck nochmal Würfeln?
-
Hallo liebes Forum,
kurze Erklärung zu meinem Programm ich habe 2 Würfel die eine Zahl von
1-6 zufällig generieren. Die Zwei zahlen werden verglichen und die Zahl
die höher ist hat gewonnen. Nun möchte ich das wenn ich zum Beispiel Enter
drücke dass neu gewürfelt wird und ein neuer Sieger ermittelt wird könnt ihr
mir da weiter helfen ?#include <iostream> #include <conio> using namespace std; class Wuerfel { private: int positionx,positiony; public: int augenzahl; Wuerfel(int, int); ~Wuerfel(); void zeige(void); int wuerfeln(void); }; //-------------------------------------------------------------------- //-------------------------------------------------------------------- Wuerfel::Wuerfel(int x, int y)//Konstruktor { positionx=x; positiony=y; wuerfeln(); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- Wuerfel::~Wuerfel()//Destruktor {} void Wuerfel::zeige(void){ gotoxy(positionx, positiony); cout<<"\xDA\xC4\xC4\xC4\xBF"; gotoxy(positionx,positiony+1);cout<<"\xB3 " << augenzahl << " \xB3"; gotoxy(positionx,positiony+2);cout<<"\xC0\xC4\xC4\xC4\xD9"; } //-------------------------------------------------------------------- //-------------------------------------------------------------------- int Wuerfel::wuerfeln()//Methode wuerfeln { augenzahl=rand()%6+1; return augenzahl; } //-------------------------------------------------------------------- //-------------------------------------------------------------------- int main() { gotoxy(30,1);cout << "W u e r f e l d e m o"; gotoxy(30,2);cout << "====================="; gotoxy(10,10);cout<<"Wuerfel Eins"; gotoxy(50,10);cout<<"Wuerfel Zwei"; srand(time(0)); Wuerfel w1(10,11); Wuerfel w2(50,11); w1.zeige(); w2.zeige(); if (w1.augenzahl==w2.augenzahl) {gotoxy(30,14);cout<<"Unentschieden";} if (w2.augenzahl>w1.augenzahl) {gotoxy(50,14);cout<<"Gewonnen";} if (w1.augenzahl>w2.augenzahl) {gotoxy(10,14);cout<<"Gewonnen";} getchar(); return 0; }
-
Du suchst getline