Roulette Spiel



  • Hallo,

    irgendwie scheint mein Roulette Spiel nicht so zu wollen, wie ich. Entweder es wird tatsächlich immer die gleiche Zufallszahl in dem Array abgespeichert oder ich greife immer auf die gleiche Zahl zu. Lieder seh ich den Fehler nicht -.-

    Roulette.h

    class Roulette
    {
    	public:
    		Roulette();
    		Roulette(int numberOfGames);
    		~Roulette();
    		int playOneGame();
    		void playRotation();
    		void printRotation();
    		void sortRotation();
    		int differentInRotation();
    		long getNumberofRotations();
    
    	private:
    		static const int ARRAY_SIZE = 37;
    		int rotation[ARRAY_SIZE];
    		long numberOfRotations;
    };
    

    Roulette.cpp

    #include <iostream>
    #include <ctime>
    #include "Roulette.h"
    using namespace std;
    
    Roulette::Roulette(int numberOfGames)
    {
    	numberOfRotations =0;
    	for (int i =1; i<=numberOfGames; i++)
    	{
    		playRotation();
    		printRotation();
    	}
    }
    
    Roulette::~Roulette()
    {
    	cout << numberOfRotations << endl;
    }
    
    int Roulette::playOneGame()
    {
    	srand(time(0));
    	int winnerOfGame=0;
    	winnerOfGame= rand()%37;
    
    	return winnerOfGame;
    }
    
    void Roulette::playRotation()
    {
    	for (int i=0; i<=36; i++)
    	{
    		rotation[i] = playOneGame();
    	}
    	++numberOfRotations;
    }
    
    void Roulette::printRotation()
    {
    	cout << "Rotaion: " << numberOfRotations << endl << endl;
    	for (int i =0; i<=36; i++)
    	{
    		cout << "Die " << i+1 << "ausgepielte Zahl ist eine " << rotation[i] <<endl;
    	}
    	cout <<  endl << endl;
    }
    

    main.cpp

    #include <iostream>
    #include <ctime>
    #include "Roulette.h"
    using namespace std;
    
    int main()
    {
    	Roulette myGame(5);
    
    	system("PAUSE");
    
    	return 0;
    }
    

    ist der seed für den Rand an der falschen Stelle, oder lese ich eventuell falsch aus, doer was?

    P.S fü+r die die Sich wundern, eine Rotation, soll genau aus 37 einzelnen Spielen bestehen.



  • pack mal srand in den Konstruktor, damit die funktion nur einmal gerufen wird.




Anmelden zum Antworten