Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
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 |
#include "CGame.hpp" #include <iostream> using namespace std; int main() { int players=0; int humanPlayers=0; int kiPlayers=0; int lifes=0; bool badInput=false; cout << "I welcome you to a new game of Kosmosgeballer" << endl; do { badInput=false; cout << "How many Humans want to fight out in Space today, sir? (0 to 2):"; cin >> humanPlayers; if (cin.fail() || cin.bad()) { cin.clear(); while (cin.get() != '\n'); cout << "Bad Input, my Dear" << endl; badInput=true; } if (humanPlayers < 0 || humanPlayers > 2) { cout << "No Sir, wrong Number!" << endl; badInput=true; } } while (badInput); do { badInput=false; cout << "Good! And how much of those robotic Idiots? (0 to "<< (4 - humanPlayers)<<"):"; cin >> kiPlayers; if (cin.fail() || cin.bad()) { cin.clear(); while (cin.get() != '\n'); cout << "Bad Input, my Dear" << endl; badInput=true; } if (kiPlayers < 0 || kiPlayers > (4 - humanPlayers)) { cout << "No Sir, wrong Number!" << endl; badInput=true; } } while (badInput); do { badInput=false; cout << "Excellent! And how much Lifes do all the players get? (1 to 20):"; cin >> lifes; if (cin.fail() || cin.bad()) { cin.clear(); while (cin.get() != '\n'); cout << "Bad Input, my Dear" << endl; badInput=true; } if (lifes < 1 || lifes > 20) { cout << "No Sir, wrong Number!" << endl; badInput=true; } } while (badInput); players=humanPlayers + kiPlayers; CGame game(players, humanPlayers, lifes); game.run(); return 0; } |
C-/C++-Quelltext |
|
1 2 |
std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); |
Zitat
Das game wird erstellt, inkl. Render-Window, ...
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Nein, das klappt leider nicht.
C-/C++-Quelltext
1 2 std::cin.clear(); std::cin.ignore(std::numeric_limits::max(), '\n');
Vllt hilfts.
Aber den Code von höherer Relevanz zu sehen wär vllt auch hilfreich. (=> Der wo die sf::RenderWindow-Instanz benutzt wird)
MfG
Check
Ok, aber wie schließe ich sie wieder, bevor ich das neue Fenster öffne?Nein, Check. Wenn die Konsole offen ist, ist sie offen und verschwindet nicht einfach wieder von allein.
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
CGame::CGame(int players, int humanPlayers, int lifes) : _timePerFrame(sf::seconds(1.f/60.f)) , _window(sf::VideoMode::getDesktopMode(), "Kosmosgeballer beta - v0.1", sf::Style::Fullscreen) , _view(sf::FloatRect(0.f,0.f,1920.f,1080.f)) { _gameOver=false; _humanPlayerCount=humanPlayers; _backgroundTexture.loadFromFile("Media/Textures/Background2.png"); _backgroundImage.setTexture(_backgroundTexture); _window.setView(_view); if ((_window.getSize().x / _window.getSize().y) <= (16.f/9.f)) _view.setViewport(sf::FloatRect(0.f, ((_window.getSize().y/2.f)-((_window.getSize().x/(16.f/9.f))/2.f))/_window.getSize().y, 1.f, (_window.getSize().x/(16.f/9.f))/_window.getSize().y)); else _view.setViewport(sf::FloatRect(((_window.getSize().x/2.f)-((_window.getSize().y*(16.f/9.f))/2.f))/_window.getSize().x, 0.f, (_window.getSize().y*(16.f/9.f))/_window.getSize().x, 1.f)); for (int i=0; i<players; i++) { _playerlist.emplace_back (_window, i, lifes); _playerlist.back().reset(_playerlist, 0); if (i >= humanPlayers) _mutterlist.emplace_back (i, _playerlist); } } |
Werbeanzeige