C++ Schleifen Problem



  • Hallo liebe Com 🙂

    Ich hoffe mir kann hier jemand helfen 🙂 Aus Langeweile hab ich in C++ eine Konsolenanwendung geschrieben wo das Javascript Spiel Cookie Clicker nachgestellt wird.

    #include <iostream>
    #include <windows.h>
    /* \/stand beim beispiel des Scrips zur Maustasten erkennung mit bei*/
    #include <cstring> 
    #include <cmath>
    #include <conio.h>
    
    using namespace std;
    
    int main (int argc, char* argv[]){
    int weiter=1;
    int Mouse=1;
    long long Cookies=0;
    long long Cin,Shop;
    long int Cursor=70,Cursoranzahl=0,Cursorwert=1;
    long int Grandma=500,Grandmaanzahl=0,Grandmawert=2;
    long int Farm=1800,Farmanzahl=0,Farmwert=4;
    long int Factory=6000,Factoryanzahl=0,Factorywert=8;
    long int Mine=9000,Mineanzahl=0,Minewert=16;
    long int Ship=23000,Shipanzahl=0,Shipwert=32;
    long int Lab=60000,Labanzahl=0,Labwert=64;
    
    	cout <<"CMD Cookie Clicker alpha v0.1.6\n";
    	do{
    
    	cout <<"\nMenue\n\n1- Cookies 'klicken'\n2- Shop\n3- Cookies\n0- Beenden\n";
    	cin >> Cin;
    
    		if (Cursoranzahl != 0)
    		{
    		Cookies = Cookies+(Cursoranzahl*Cursorwert);
    		}
    		if(Grandmaanzahl != 0)
    		{
    		Cookies = Cookies+(Grandmaanzahl*Grandmawert);
    		}
    		if(Farmanzahl !=0)
    		{
    		Cookies = Cookies+(Farmanzahl*Farmwert);
    		}
    		if(Factory !=0)
    		{
    		Cookies = Cookies+(Factoryanzahl*Factorywert);
    		}
    		if(Mine !=0)
    		{
    		Cookies = Cookies+(Mineanzahl*Minewert);
    		}
    		if(Ship !=0)
    		{
    		Cookies = Cookies+(Shipanzahl*Shipwert);
    		}
    		if(Lab !=0)
    		{
    		Cookies = Cookies+(Labanzahl*Labwert);
    		}
    
    		if(Cin >=1111)
    		{
    		weiter=2;
    		}
    //------------------------------------------------------------------------------------------------------------------------------------------------
    		if (Cin == 1)
    		{
    		cout <<"Linke Maustaste in der Konsole druecken um Cookies zu generieren, \ndruecke das Mausrad um ins Menue zurueck gelangen\n";
    		Sleep(4000);
    		goto clicker;
    
    		INPUT_RECORD inRec;
    
    		HANDLE hcon = GetStdHandle(STD_INPUT_HANDLE);
    
    		clicker: do
    		{
    
    		DWORD nCnt = 0;
    		BOOL bOK = ReadConsoleInput(hcon, &inRec, 1, &nCnt);
    
    		if(bOK && nCnt == 1)
    		{
    		if(inRec.EventType == MOUSE_EVENT)
    		{
    		if(inRec.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED)
    
    		Cookies++;
    		Sleep(50);
    		cout <<Cookies<<" Cookies\n";
    
    		if(inRec.Event.MouseEvent.dwButtonState == FROM_LEFT_2ND_BUTTON_PRESSED)
    
    		Mouse = 2;
    
    		}
    		}
    		}while(Mouse == 1);
    		}
    //------------------------------------------------------------------------------------------------------------------------------------------------
    
    		if(Cin ==2){
    		cout <<"1- Cursor / Ein Cursor kostet "<<Cursor<<" Cookies\n";
    		cout <<"2- Grandma / Eine Grandma kostet "<<Grandma<<" Cookies\n";
    		cout <<"3- Farm / Eine Farm kostet "<<Farm<<" Cookies\n";
    		cout <<"4- Factory / Eine Factory kostet "<<Factory<<" Cookies\n";
    		cout <<"5- Mine / Eine Mine kostet "<<Mine<<" Cookies\n";
    		cout <<"6- Shipment / Ein Shipment kostet "<<Ship<<" Cookies\n";
    		cout <<"7- Alchemy Lab / Ein Alchemy Lab kostet: "<<Lab<<" Cookies\n";
    		cout <<"0- Zurueck\n";
    		cin >> Shop;
    			if (Shop == 1 && Cookies >=Cursor)
    			{
    			Cookies = Cookies - Cursor;
    			Cursor=Cursor*2;
    			Cursoranzahl = Cursoranzahl+1;
    			Shop = 0;
    			}
    			else if (Shop == 2 && Cookies >=Grandma)
    			{
    			Cookies = Cookies - Grandma;
    			Grandma=Grandma*2;
    			Grandmaanzahl = Grandmaanzahl+1;
    			Shop = 0;
    			}
    			else if(Shop == 3 && Cookies >=Farm)
    			{
    			Cookies = Cookies - Farm;
    			Farm=Farm*2;
    			Farmanzahl = Farmanzahl+1;
    			Shop = 0;
    			}
    			else if(Shop == 4 && Cookies >=Factory)
    			{
    			Cookies = Cookies - Factory;
    			Factory=Factory*2;
    			Factoryanzahl = Factoryanzahl+1;
    			Shop = 0;
    			}
    			else if(Shop == 5 && Cookies >=Mine)
    			{
    			Cookies = Cookies - Mine;
    			Mine=Mine*2;
    			Mineanzahl = Mineanzahl+1;
    			Shop = 0;
    			}
    			else if(Shop == 6 && Cookies >=Ship)
    			{
    			Cookies = Cookies - Ship;
    			Ship=Ship*2;
    			Shipanzahl = Shipanzahl+1;
    			Shop = 0;
    			}
    			else if(Shop == 7 && Cookies >= Lab)
    			{
    			Cookies = Cookies - Lab;
    			Lab=Lab*2;
    			Labanzahl = Labanzahl+1;
    			Shop = 0;
    			}
    
    			else if (Shop == 0)
    			{
    			Cookies = Cookies+0;
    			}
    			else
    			{
    			cout << "Nicht genug Cookies\n\n\n\n\n";
    			}
    			}
    //-------------------------------------------------------------------------------------------------------------------------------------------------
    
    			if(Cin ==3)
    			{
    			cout <<"\n\n\n";
    			cout <<"Deine Cookies betragen: "<<Cookies<<endl<<endl;
    
    			}
    //-------------------------------------------------------------------------------------------------------------------------------------------------
    			if(Cin == 0)
    			{
    			weiter=2;
    
    			}	
    
    	}while(weiter == 1);
    
    return 0;
    

    SO in der if(cin ==1) ist eine Erkennung der linken Maustaste IN der Konsole wenn man dort klickt gibt es einen Cookie +1,so wenn man dann aber mit dem Drücken des Mausrads aus der Schleife sich entfernt und in den Shop geht mit if(Cin==2) um dort etwas zu kaufen UND DANACH wieder auf die 1 geht um Cookies zu clicken kommt er nicht zurück in die Schleife.Also er geht in den Code die Ausgabe mit dem Das man die Linke Maustaste drücken soll kommt aber dann fleigt er zurück ins menü. Ich bin mit meinem C++ am ende und meine Kollegen auf der Arbeit ebenfalls.

    Ich hoffe mir kann jemand helfen, ich hänge meine Kompilierte Exe hiermal hin :
    http://www.uploadarea.de/upload/mrrt1jfo2zi2lu9xmmnp9q3hl.html

    Virustotal:https://www.virustotal.com/de/file/e6668326eb9a17491588a731d6b06a30744ed10d43b05de5dac82ec5dc91acdd/analysis/1379670751/

    MfG Sheo



  • Sry hier mal mit der Einrückung!

    #include <iostream>
    #include <windows.h>
    #include <cstring>
    #include <cmath>
    #include <conio.h>
    
    using namespace std;
    
    int main (int argc, char* argv[]){
    int weiter=1;
    int Mouse=1;
    long long Cookies=0;
    long long Cin,Shop;
    long int Cursor=70,Cursoranzahl=0,Cursorwert=1;
    long int Grandma=500,Grandmaanzahl=0,Grandmawert=2;
    long int Farm=1800,Farmanzahl=0,Farmwert=4;
    long int Factory=6000,Factoryanzahl=0,Factorywert=8;
    long int Mine=9000,Mineanzahl=0,Minewert=16;
    long int Ship=23000,Shipanzahl=0,Shipwert=32;
    long int Lab=60000,Labanzahl=0,Labwert=64;
    
    	cout <<"CMD Cookie Clicker alpha v0.1.6\n";
    	do{
    
    	cout <<"\nMenue\n\n1- Cookies 'klicken'\n2- Shop\n3- Cookies\n0- Beenden\n";
    	cin >> Cin;
    
    		if (Cursoranzahl != 0)
    		{
    		Cookies = Cookies+(Cursoranzahl*Cursorwert);
    		}
    			if(Grandmaanzahl != 0)
    			{
    			Cookies = Cookies+(Grandmaanzahl*Grandmawert);
    			}
    				if(Farmanzahl !=0)
    				{
    				Cookies = Cookies+(Farmanzahl*Farmwert);
    				}
    					if(Factory !=0)
    					{
    					Cookies = Cookies+(Factoryanzahl*Factorywert);
    					}
    						if(Mine !=0)
    						{
    						Cookies = Cookies+(Mineanzahl*Minewert);
    						}
    							if(Ship !=0)
    							{
    							Cookies = Cookies+(Shipanzahl*Shipwert);
    							}
    								if(Lab !=0)
    								{
    								Cookies = Cookies+(Labanzahl*Labwert);
    								}
    
    									if(Cin >=1111)
    									{
    									weiter=2;
    									}
    //------------------------------------------------------------------------------------------------------------------------------------------------
    		if (Cin == 1)
    		{goto clicker;
    		cout <<"Linke Maustaste in der Konsole druecken um Cookies zu generieren, \ndruecke das Mausrad um ins Menue zurueck gelangen\n";
    		Sleep(4000);
    
    		clicker: do
    			{
    			INPUT_RECORD inRec;
    			HANDLE hcon = GetStdHandle(STD_INPUT_HANDLE);
    			DWORD nCnt = 0;
    			BOOL bOK = ReadConsoleInput(hcon, &inRec, 1, &nCnt);
    				if(bOK && nCnt == 1)
    				{
    					if(inRec.EventType == MOUSE_EVENT)
    					{
    					if(inRec.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED)
    					Cookies++;
    					Sleep(50);
    					cout <<Cookies<<" Cookies\n";
    					if(inRec.Event.MouseEvent.dwButtonState == FROM_LEFT_2ND_BUTTON_PRESSED)
    					Mouse = 2;
    					}
    				}
    			}while(Mouse == 1);
    		}
    //------------------------------------------------------------------------------------------------------------------------------------------------
    
    		if(Cin ==2){
    			cout <<"1- Cursor / Ein Cursor kostet "<<Cursor<<" Cookies\n";
    			cout <<"2- Grandma / Eine Grandma kostet "<<Grandma<<" Cookies\n";
    			cout <<"3- Farm / Eine Farm kostet "<<Farm<<" Cookies\n";
    			cout <<"4- Factory / Eine Factory kostet "<<Factory<<" Cookies\n";
    			cout <<"5- Mine / Eine Mine kostet "<<Mine<<" Cookies\n";
    			cout <<"6- Shipment / Ein Shipment kostet "<<Ship<<" Cookies\n";
    			cout <<"7- Alchemy Lab / Ein Alchemy Lab kostet: "<<Lab<<" Cookies\n";
    			cout <<"0- Zurueck\n";
    			cin >> Shop;
    				if (Shop == 1 && Cookies >=Cursor)
    					{
    					Cookies = Cookies - Cursor;
    					Cursor=Cursor*2;
    					Cursoranzahl = Cursoranzahl+1;
    					Shop = 0;
    					}
    					else if (Shop == 2 && Cookies >=Grandma)
    							{
    							Cookies = Cookies - Grandma;
    							Grandma=Grandma*2;
    							Grandmaanzahl = Grandmaanzahl+1;
    							Shop = 0;
    							}
    							else if(Shop == 3 && Cookies >=Farm)
    									{
    									Cookies = Cookies - Farm;
    									Farm=Farm*2;
    									Farmanzahl = Farmanzahl+1;
    									Shop = 0;
    									}
    									else if(Shop == 4 && Cookies >=Factory)
    											{
    											Cookies = Cookies - Factory;
    											Factory=Factory*2;
    											Factoryanzahl = Factoryanzahl+1;
    											Shop = 0;
    											}
    											else if(Shop == 5 && Cookies >=Mine)
    													{
    													Cookies = Cookies - Mine;
    													Mine=Mine*2;
    													Mineanzahl = Mineanzahl+1;
    													Shop = 0;
    													}
    													else if(Shop == 6 && Cookies >=Ship)
    															{
    															Cookies = Cookies - Ship;
    															Ship=Ship*2;
    															Shipanzahl = Shipanzahl+1;
    															Shop = 0;
    															}
    															else if(Shop == 7 && Cookies >= Lab)
    																	{
    																	Cookies = Cookies - Lab;
    																	Lab=Lab*2;
    																	Labanzahl = Labanzahl+1;
    																	Shop = 0;
    																	}
    
    																	else if (Shop == 0)
    																			{
    																			Cookies = Cookies+0;
    																			}
    																			else
    																				{
    																				cout << "Nicht genug Cookies\n\n\n\n\n";
    																				}
    }
    //-------------------------------------------------------------------------------------------------------------------------------------------------
    
    			if(Cin ==3)
    			{
    			cout <<"\n\n\n";
    			cout <<"Deine Cookies betragen: "<<Cookies<<endl<<endl;
    
    			}
    //-------------------------------------------------------------------------------------------------------------------------------------------------
    			if(Cin == 0)
    			{
    			weiter=2;
    
    			}	
    
    	}while(weiter == 1);
    
    return 0;
    }
    


  • Kannst du dein Problem bitte reduzieren. Keine Sau liest sich 200 Zeilen Quellcode durch. 😉



  • Steht ja in dem ersten Post 🙂


  • Mod

    xxlorddi schrieb:

    Steht ja in dem ersten Post 🙂

    Und du meinst, das wäre eine passende Erwiderung auf It0101s Einwand?

    - "Ich will Hilfe."
    - "Wie würden dir gerne helfen, aber es geht nicht, weil XYZ."
    - "Doch!"
    😕



  • xxlorddi schrieb:

    SO in der if(cin ==1) ist eine Erkennung der linken Maustaste IN der Konsole wenn man dort klickt gibt es einen Cookie +1,so wenn man dann aber mit dem Drücken des Mausrads aus der Schleife sich entfernt und in den Shop geht mit if(Cin==2) um dort etwas zu kaufen UND DANACH wieder auf die 1 geht um Cookies zu clicken kommt er nicht zurück in die Schleife.Also er geht in den Code die Ausgabe mit dem Das man die Linke Maustaste drücken soll kommt aber dann fleigt er zurück ins menü. Ich bin mit meinem C++ am ende und meine Kollegen auf der Arbeit ebenfalls.

    Ich hoffe mir kann jemand helfen, ich hänge meine Kompilierte Exe hiermal hin :
    http://www.uploadarea.de/upload/mrrt1jfo2zi2lu9xmmnp9q3hl.html

    Virustotal:https://www.virustotal.com/de/file/e6668326eb9a17491588a731d6b06a30744ed10d43b05de5dac82ec5dc91acdd/analysis/1379670751/

    MfG Sheo

    @SeppJ



  • @Fuchs

    ja, er hat das Problem beschrieben. Trotzdem hat hier niemand Lust, sich in 200 Zeilen Code auf die Suche nach dem beschriebenen Fehler zu machen...



  • Für sowas ist ein Debugger da, da sieht man was passiert und guckt man sich die Werte der Variablen an, merkt man auch warum das passiert.



  • Ok Zeilen wären ganz Praktisch. 😃



  • xxlorddi schrieb:

    Sry hier mal mit der Einrückung!

    if (Cursoranzahl != 0)
    		{
    		Cookies = Cookies+(Cursoranzahl*Cursorwert);
    		}
    			if(Grandmaanzahl != 0)
    			{
    			Cookies = Cookies+(Grandmaanzahl*Grandmawert);
    			}
    				if(Farmanzahl !=0)
    				{
    				Cookies = Cookies+(Farmanzahl*Farmwert);
    				}
    					if(Factory !=0)
    					{
    					Cookies = Cookies+(Factoryanzahl*Factorywert);
    					}
    						if(Mine !=0)
    						{
    						Cookies = Cookies+(Mineanzahl*Minewert);
    						}
    							if(Ship !=0)
    							{
    							Cookies = Cookies+(Shipanzahl*Shipwert);
    							}
    								if(Lab !=0)
    								{
    								Cookies = Cookies+(Labanzahl*Labwert);
    								}
    		
    }
    

    😃 👎


Anmelden zum Antworten