napisalem gre magazynier troszke kodu posiagalem z netu ale prosba jest moja taka musze zrobic jeszcze ekran powitalny do tej gry lecz mam problem bo nie chce mi dzialac chodz jest potencjalnie prawidlowo wstawiony na dole jest kod programu czekam na sugestie
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <sstream>
#include <conio.h>
using namespace std;
const int x = 10;
const int y = 10;
char oGrid[ x ][ y ];
bool main_menu( bool, int & );
char load_level( char[ x ][ y ], int &, int &, int &, int &, int &, string );
void draw_level( char[ x ][ y ], int & );
char move( char[ x ][ y ], bool &, int &, int &, int &, int & );
std::string itos( int arg );
int main()
{
char grid[ x ][ y ];
int eTotal;
int eAmount;
int moves;
bool level_finished, play_game = true;
int pusherX, pusherY;
string level;
int n = 1;
while( play_game )
{
play_game = main_menu( play_game, n );
if( play_game )
{
level_finished = false;
level = "levels\\level";
level += itos( n );
level += ".txt";
load_level( grid, pusherX, pusherY, eTotal, eAmount, moves, level );
}
else
level_finished = true;
while( !level_finished )
{
draw_level( grid, moves );
move( grid, level_finished, pusherX, pusherY, eTotal, moves );
if( eTotal == eAmount )
{
n++;
draw_level( grid, moves );
cout << "Gratuluje przeszedles level! - nacisnij dowolny guzik by grac dalej.\n\n\n";
getch();
cout << endl << level << endl;
level = "levels\\level";
level += itos( n );
level += ".txt";
load_level( grid, pusherX, pusherY, eTotal, eAmount, moves, level );
}
}
}
return 0;
}
bool main_menu( bool play_game, int & level )
{
bool exit = false;
int ch = 0;
play_game = false;
while( !exit )
{
cout << "\n cultowa gra magazynier - Menu\n";
cout << "********************\n";
cout << "1) Zalacz ta odlotowa gre\n";
cout << "2) wybierz poziom\n";
cout << "3) Krotka instrukcja\n";
cout << "4) Wyjscie\n";
do { ch = _getch(); }
while( ch != '1' &&
ch != '2' &&
ch != '3' &&
ch != '4' );
switch( ch )
{
case '1':
ch = - 1;
play_game = true;
exit = true;
break;
case '2':
ch = - 1;
cout << "wybierz poziom od (1-5): ";
cin >> level;
break;
case '3':
ch = - 1;
cout << endl << endl <<
"................. jest to program zaliczeniowy\n"
"na zajecia Metody i Jezyki programowania II. \n"
"\n"
"magazynier.cpp\n"
"versja pierwsza i chyba ostatnia\n"
"kompilowany pod: Windows\n"
"\n"
"\n"
"To jest teks ktory wyjasni co i jak- otwarles gre magazynier w ktora mozesz grac w konsoli\n"
"\n"
"Na planszy jestes jako litera 'a'. Musisz tak manewrowac literka zeby przepchac wszystkie diamenty w miejsc 'o' .\n"
"\n"
"Robisz to raz jesli przeszeldes poziom przechodzisz do nastepnego poziomu.\n"
"\n"
"gra jest bardzo prosta mam nadzieje ze bedzie Ci sie podobac i bedziesz sie milo i fajnie bawic. \n"
"\n"
"Powodzenia i milej gry!\n"
"\n"
"\n"
"Poruszanie sie: strzalka w gore (ruch w gore), strzalka w dol (ruch w dol), lewa strzalka (ruch w lewo),\n"
"prawa strzalka (ruch w prawo), esc (oznacza jednoznaczne wyjscie).\n\n";
break;
case '4':
ch = - 1;
exit = true;
play_game = false;
break;
default:
break;
}
}
return play_game;
}
char load_level( char grid[ x ][ y ], int & pusherX, int & pusherY,
int & eTotal, int & eAmount, int & moves, string level )
{
int i, j;
eTotal = 0;
eAmount = 0;
moves = 0;
for( i = 0; i < 10; i++ ) {
for( j = 0; j < 10; j++ ) {
oGrid[ i ][ j ] = ' ';
}
}
char key;
string moo;
ifstream file;
file.open( level.c_str() );
do
{
file.get( key );
if( int( key ) >= 32 && int( key ) <= 126 ) {
moo += key;
}
} while( !file.eof() );
file.close();
for( i = 0; i < 10; i++ ) {
for( j = 0; j < 10; j++ ) {
grid[ i ][ j ] = moo.at(( i * 10 ) + j );
if( grid[ i ][ j ] == 'a' )
{
pusherX = i;
pusherY = j;
}
if( grid[ i ][ j ] == 'e' )
eAmount++;
if(( grid[ i ][ j ] == 'o' ) ||( grid[ i ][ j ] == '@' ) )
oGrid[ i ][ j ] = 'o';
if(( grid[ i ][ j ] == '@' ) )
{
oGrid[ i ][ j ] = 'o';
eTotal++;
eAmount++;
}
}
}
return grid[ x ][ y ];
}
void draw_level( char grid[ x ][ y ], int & moves )
{
int i, j;
system( "cls" );
for( i = 0; i < 10; i++ ) {
for( j = 0; j < 10; j++ ) {
switch( grid[ i ][ j ] ) {
case ' ':
cout << setw( 2 ) << " ";
break;
case '|':
cout << setw( 2 ) << "|";
break;
case '-':
cout << setw( 2 ) << "-";
break;
case '*':
cout << setw( 2 ) << "*";
break;
case 'e':
cout << setw( 2 ) << char( 4 );
break;
case 'o':
cout << setw( 2 ) << "o";
break;
case '@':
cout << setw( 2 ) << char( 15 );
break;
case 'a':
cout << setw( 2 ) << "a";
break;
case '/':
cout << setw( 2 ) << "/";
break;
}
} cout << endl;
}
cout << "\n\n\nMoves: " << moves << "\n";
}
char move( char grid[ x ][ y ], bool & quit, int & pusherX, int & pusherY,
int & eTotal, int & moves )
{
char ch, direction, go_or_not;
int tempX, tempY;
int xPosition, yPosition;
int i, j, ch2;
i = pusherX;
j = pusherY;
do { ch = _getch();
ch2 = int( ch ); }
while( ch2 != 72 &&
ch2 != 75 &&
ch2 != 80 &&
ch2 != 77 &&
ch2 != 27 );
switch( ch2 )
{
case 72:
ch = - 1;
xPosition = - 1;
yPosition = 0;
tempX = pusherX + xPosition;
tempY = pusherY + yPosition;
direction = 'w';
break;
case 80:
ch = - 1;
xPosition = 1;
yPosition = 0;
tempX = pusherX + xPosition;
tempY = pusherY + yPosition;
direction = 's';
break;
case 75:
ch = - 1;
yPosition = - 1;
xPosition = 0;
tempY = pusherY + yPosition;
tempX = pusherX + xPosition;
direction = 'a';
break;
case 77:
ch = - 1;
yPosition = 1;
xPosition = 0;
tempY = pusherY + yPosition;
tempX = pusherX + xPosition;
direction = 'd';
break;
case 27:
ch = - 1;
quit = true;
cout << "Wychodzeni...\n";
return 0;
break;
default:
break;
}
if( grid[ tempX ][ tempY ] == 'e' )
{
if(( grid[ tempX + xPosition ][ tempY + yPosition ] == ' ' ) ||( grid[ tempX + xPosition ][ tempY + yPosition ] == 'o' ) )
{
if( grid[ tempX + xPosition ][ tempY + yPosition ] == 'o' )
{
grid[ tempX + xPosition ][ tempY + yPosition ] = '@';
grid[ tempX ][ tempY ] = ' ';
eTotal++;
}
else
{
grid[ tempX + xPosition ][ tempY + yPosition ] = 'e';
grid[ tempX ][ tempY ] = ' ';
}
}
}
if( grid[ tempX ][ tempY ] == '@' )
{
if(( grid[ tempX + xPosition ][ tempY + yPosition ] == ' ' ) ||( grid[ tempX + xPosition ][ tempY + yPosition ] == 'o' ) )
{
if( grid[ tempX + xPosition ][ tempY + yPosition ] == 'o' )
{
grid[ tempX + xPosition ][ tempY + yPosition ] = '@';
grid[ tempX ][ tempY ] = ' ';
}
else
{
grid[ tempX + xPosition ][ tempY + yPosition ] = 'e';
grid[ tempX ][ tempY ] = ' ';
eTotal--;
}
}
}
if(( grid[ tempX ][ tempY ] == ' ' ) ||( grid[ tempX ][ tempY ] == 'o' ) )
{
go_or_not = direction;
moves++;
}
switch( go_or_not )
{
case 'n':
break;
case 'w':
grid[ pusherX ][ pusherY ] = ' ';
grid[ pusherX - 1 ][ pusherY ] = 'a';
pusherX--;
xPosition++;
break;
case 's':
grid[ pusherX ][ pusherY ] = ' ';
grid[ pusherX + 1 ][ pusherY ] = 'a';
pusherX++;
xPosition--;
break;
case 'a':
grid[ pusherX ][ pusherY ] = ' ';
grid[ pusherX ][ pusherY - 1 ] = 'a';
pusherY--;
yPosition++;
break;
case 'd':
grid[ pusherX ][ pusherY ] = ' ';
grid[ pusherX ][ pusherY + 1 ] = 'a';
pusherY++;
xPosition--;
break;
default:
break;
}
if(( oGrid[ i ][ j ] == 'o' ) &&( grid[ i ][ j ] == ' ' ) )
grid[ i ][ j ] = 'o';
return grid[ x ][ y ];
}
std::string itos( int arg )
{
std::ostringstream buffer;
buffer << arg;
return buffer.str();
}