"Bestimmte" Ein- und Ausgaben löschen
-
Hallo!
Es handelt sich um folgenden Code:#include "stdafx.h" #include <iostream> #include <conio.h> #include <math.h> #include <windows.h> #include "ctime" using namespace std; void gotoxy(int x,int y) { HANDLE hConsole; COORD cursorLoc; std::cout.flush(); cursorLoc.X = x; cursorLoc.Y = y; hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hConsole, cursorLoc); } int _tmain(int argc, _TCHAR* argv[]) { int x,y,i; int field [41] [41]; // 1 mehr als gewünschtes Spielfeld, weil für die Grenzen auch 2 Felder benötigt werden srand((unsigned) time(NULL)); // Initialisieren des Zufallszahlengenerators for(x=0; x<42; x++) // x-Grenzen: 0 bis 41 { gotoxy(0,x); cout<<"#"; // obere x-Grenze gotoxy(41,x); cout<<"#"; // untere x-Grenze } for(y=0; y<42; y++) // y-Grenzen: 0 bis 41 { gotoxy(y,0); // linke y-Grenze cout<<"#"; gotoxy(y,41); // rechte y-Grenze cout<<"#"; } gotoxy(1,1); // Feldinneres obenlinks for(x=1; x<41; x++) { for(y=1; y<41; y++) { gotoxy(x,y); cout << "~"; } } for(i=1; i<6; i++) { x = rand() %40 + 1; y = rand() %40 + 1; if(x>0 && y<42 && y>0 && y<42) { field [x][y] = 1; gotoxy(x,y); /*cout << "S";*/ // Schiffe verstecken } else { i--; } } gotoxy(0,42); cout << x << endl; cout << y << endl; // kommt weg, wenn Spiel fertig int xcoord, ycoord; Eingabe: cout << "Geben Sie eine X-Koordinate ein:"; cin >> xcoord; cout << "Geben Sie eine Y-Koordinate ein:"; cin >> ycoord; if(field[xcoord][ycoord] == 1) { cout << "Getroffen!"; getch(); field[xcoord][ycoord] == 0; gotoxy(xcoord, ycoord); cout << "X"; gotoxy(0,42); } else { goto Eingabe; } if(field[x][y] == 1) { goto Eingabe; } getch(); return 0; }
Am besten führt ihr es aus, damit ich ihr meine Frage nachvollziehen könnt.
Habe es auf MVS 2008 erstellt, und bei "Debuggen" auf 2010 muss ich oben auf "Release" stellen, sonst kommt eine Fehlermeldung - egal, ist nicht das Problem.Problem:
Nachdem ich ein Schiff (S) getroffen habe, möchte ich, dass alle vorherigen Eingaben und Ausgaben, außer das Spielfeld mit den Schiffen S und dem Treffer X gelöscht werden.
Wie stell ich das an?PS: Ich weiß, ich sollte kein goto usw. benutzen, aber darum geht's gerade nicht.
lg
-
Dieser Thread wurde von Moderator/in SeppJ aus dem Forum C++ (auch C++0x und C++11) in das Forum WinAPI verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.