Tasm-Devil
Erfahrenes Mitglied
Hi Leute ich hab mal zum Spass das Microsoft Game Minesweeper unter C++ nach programmiert. Für DOS.
Wenn ihr wollt könnt ihrs euch ja mal anschauen und nachkompilieren. Leider geht es nicht es in Dev-C++ zu kompilieren. Aber im Borland C++ Builder geht es einwandfrei.
hier ist der code:
leider habe ich eine sache noch nicht behoben bekommen und zwar das automatische Aufdecken der Felder wenn man auf ein lehres Feld klickt. Ihr wisst schon -> Das wo sich alles öffnet am Anfang.
Naja wenn ihr wollt könnt ihr ja noch n bisschen am code feilen.
Wenn ihr wollt könnt ihrs euch ja mal anschauen und nachkompilieren. Leider geht es nicht es in Dev-C++ zu kompilieren. Aber im Borland C++ Builder geht es einwandfrei.
hier ist der code:
Code:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
cout << " Minesweeper for DOS by Pascal Deneaux " << endl;
cout << " Version 1.0 " << endl;
cout << " +-------------------+ " << endl;
cout << " | X o o o o o o o o | " << endl;
cout << " | o o o o o o o o o | " << endl;
cout << " | o o o o o o o o o | " << endl;
cout << " | o o o o o o o o o | " << endl;
cout << " | o o o o o o o o o | " << endl;
cout << " | o o o o o o o o o | " << endl;
cout << " | o o o o o o o o o | " << endl;
cout << " | o o o o o o o o o | " << endl;
cout << " | o o o o o o o o o | " << endl;
cout << " +-------------------+ " << endl;
cout << " Pfeiltaste druecken zum bewegen des Cursors " << endl;
cout << " Leertaste zum markieren. " << endl;
cout << " Und Eingabetaste um auszuwaehlen. " << endl;
/*
0 1 2 3 . . .
+-----------------> X
1|O o o o
2|o o o o
3|o o o o
|
|
\/
Y
*/
int MienenAnz = 10;
int chr;
int Zufallszahlen[11];
const int X_MAX = 9;
const int Y_MAX = X_MAX;
int X,Y;
int AllePositionen [X_MAX+1][Y_MAX+1]; // -1 = Miene 0 = nichts (Leer) 1= eine MIne in der nähe ...
int Cursor_X = 1;
int Cursor_Y = 1;
char Verdeckt = 'o';
char Cursor = 'X';
char Aufgedeckt = ' ';
char Miene = 'M';
int Felder [X_MAX+1][Y_MAX+1]; // 0 = Nicht aufgedeckt 1 = Aufgedeckt 2 = Als Miene markiert 3 = Als ? markiert
bool Explosion = false;
bool WON = false;
int Richtige = 0; // Notiert wieviele Mienen der Benutzer gefunden hat WENN Richtige == MienenAnz DANN gewonnen!
for(int y=1; y <= Y_MAX; y++)
{
for(int x=1; x <= X_MAX; x++)
{
AllePositionen[x][y] = 0;
Felder[x][y] = 0;
}
}
randomize(); // Zufallsgenerator wird aktiviert
int counter1 = 1, counter2 = 1, Zahl = 0;
while (counter1 <= MienenAnz) // Zufallszahöen werden ermittelt
{
Zahl = (rand() % (X_MAX*Y_MAX)) + 1;
while (counter2 < MienenAnz)
{
if (Zahl != Zufallszahlen[counter2] )
{
counter2++;
}
else
{
Zahl = (rand() % (X_MAX*Y_MAX)) + 1;
counter2 = 1;
}
}
Zufallszahlen[counter1] = Zahl;
counter1++;
counter2 = 1;
}
//cout << "Y_Max: " << Y_MAX << endl << "X_MAX: " << X_MAX << endl << endl;
//Zufallszahlen[1] = 81;
for (int i=1; i<= MienenAnz; i++)
{
//cout << "Zahl " << i << ": " << Zufallszahlen[i]; // Zufallszahlen anzeigen
if (Zufallszahlen[i]%X_MAX != 0)
X = Zufallszahlen[i]/X_MAX+1;
else
X = Zufallszahlen[i]/X_MAX;
//cout << " X-Position: " << X;
if (Zufallszahlen[i]%Y_MAX != 0)
Y = Zufallszahlen[i]%Y_MAX;
else
Y = Y_MAX;
//cout << " Y-Position: " << Y << endl << endl;
AllePositionen [X][Y] = -1;
}
for(int y=1; y <= Y_MAX; y++)
{
for(int x=1; x <= X_MAX; x++)
{
if (AllePositionen[x][y] == -1) // -1 bedeutet "Miene hier"
{
if (AllePositionen[x-1][y] != -1) // x-1 heißt soviel wie links nebenan
{
AllePositionen[x-1][y]++;
}
if (AllePositionen[x+1][y] != -1) // rechts nebenan
{
AllePositionen[x+1][y]++;
}
if (AllePositionen[x][y-1] != -1) // oben drüber
{
AllePositionen[x][y-1]++;
}
if (AllePositionen[x][y+1] != -1) // unter
{
AllePositionen[x][y+1]++;
}
if (AllePositionen[x-1][y-1] != -1) // links oben drüber
{
AllePositionen[x-1][y-1]++;
}
if (AllePositionen[x-1][y+1] != -1) // links unter drunter
{
AllePositionen[x-1][y+1]++;
}
if (AllePositionen[x+1][y-1] != -1) // rechts oben drüber
{
AllePositionen[x+1][y-1]++;
}
if (AllePositionen[x+1][y+1] != -1) // rechts unter drunter
{
AllePositionen[x+1][y+1]++;
}
}
}
}
do
{
chr = getch();
switch(chr)
{
case 72:
if (Cursor_Y != 1) Cursor_Y--; break; // Nach oben gedrueckt
case 80:
if (Cursor_Y != Y_MAX) Cursor_Y++; break; //Nach unten gedrueckt
case 75:
if (Cursor_X != 1) Cursor_X--; break; //Nach Links gedrueckt
case 77:
if (Cursor_X != X_MAX) Cursor_X++; break; //Nach rechts gedrueckt
case 13: //Return gedrückt
Felder[Cursor_X][Cursor_Y] = 1; // 1 bedeutet aufgedeckt
if (AllePositionen[Cursor_X][Cursor_Y] == -1) Explosion = true;
break;
case 32: //Leertaste zum markieren
if (Felder[Cursor_X][Cursor_Y] != 1)
{
switch (Felder[Cursor_X][Cursor_Y])
{
case 0: Felder[Cursor_X][Cursor_Y] = 2; break;
case 2: Felder[Cursor_X][Cursor_Y] = 3; break;
case 3: Felder[Cursor_X][Cursor_Y] = 0; break;
}
}
break;
}
clrscr();
cout << " Minesweeper for DOS by Pascal Deneaux " << endl;
cout << " Version 1.0 " << endl;
cout << " +";
for (int i=1; i <=Y_MAX; i++)
cout << "--";
cout << "-+" << endl;
for(int y=1; y <= Y_MAX; y++)
{
cout << " | ";
for(int x=1; x <= X_MAX; x++)
{
if(Cursor_X == x && Cursor_Y == y) cout << Cursor << " ";
else
{
if(Felder[x][y] == 1)
{
if(AllePositionen[x][y] == 0)
cout << Aufgedeckt << " ";
else
cout << AllePositionen[x][y] << " ";
}
else if(Felder[x][y] == 0)
cout << Verdeckt << " ";
else if(Felder[x][y] == 2)
cout << Miene << " ";
else if(Felder[x][y] == 3)
cout << "? ";
}
}
cout << "|" << endl;
}
cout << " +";
for (int i=1; i <=Y_MAX; i++)
cout << "--";
cout << "-+" << endl;
// Jetzt soll getestet werden ob der User schon gewonnen hat.
Richtige = 0;
for(int y=1; y <= Y_MAX; y++)
{
for(int x=1; x <= X_MAX; x++)
{
if ((Felder[x][y] == 2 || Felder[x][y] == 0)&& AllePositionen[x][y] == -1)
Richtige++;
else if ((Felder[x][y] == 2 || Felder[x][y] == 0)&& AllePositionen[x][y] != -1)
Richtige--;
}
}
if (Richtige == MienenAnz)
{
WON = true;
cout << endl << endl << endl << " Gewonnen!" << endl;
getch();
}
if (Explosion == true)
{
cout << endl << endl << endl << " Miene getroffen" << endl;
cout << " Game over" << endl;
getch();
}
}
while (!(Explosion == true || WON == true));
}
//---------------------------------------------------------------------------
leider habe ich eine sache noch nicht behoben bekommen und zwar das automatische Aufdecken der Felder wenn man auf ein lehres Feld klickt. Ihr wisst schon -> Das wo sich alles öffnet am Anfang.
Naja wenn ihr wollt könnt ihr ja noch n bisschen am code feilen.