S
danke wird gelesen
//EDIT
Es nimmt gestalt an!
#include <stdio.h>
#include <stdlib.h>
//Showig the number of turns and the stage you are in
int turn=0;
int stage=1;
//the map
char map [10][10]={
{'#','#','#','#','#','#','#','#','#','#'},
{'#',' ','#',' ',' ',' ',' ',' ',' ','#'},
{'#',' ','#',' ',' ',' ','#',' ',' ','#'},
{'#',' ','#',' ',' ',' ','#',' ',' ','#'},
{'#',' ','#',' ','&',' ','#',' ',' ','#'},
{'#',' ','#',' ',' ',' ','#',' ',' ','#'},
{'#',' ','#','#','#','#','#',' ',' ','#'},
{'#',' ',' ',' ',' ',' ',' ',' ',' ','#'},
{'#',' ',' ',' ',' ',' ',' ',' ',' ','#'},
{'#','#','#','#','#','#','#','#','#','#'}, };
//x an y show the position of the '@', the character you play
int x=1;
int y=1;
void map_initialisation(int x, int y){
map [x][y]= '@';
//printing the map
int a;
int b;
for(a=0;a<10;a++){
for(b=0;b<10;b++){
if(b<9){
printf("%c",map[a][b]);
}
if(b==9){
printf("%c\n",map[a][b]);
}
}
}
}
void moveLEFT(){
switch(map[x][y-1]){
case '#': printf("Don't tun against the wall");
break;
case ' ': y-=1;
map[x][y+1]=' ';
break;
case '&': printf("Do you want to enter the next stage?\nY/N?\n\n");
char nextStage=getchar();
if(nextStage=='Y'||'y'){
stage++;
break;
}
}
}
void moveUP(){
switch(map[x-1][y]){
case '#': printf("Don't tun against the wall");
break;
case ' ': x-=1;
map[x+1][y]=' ';
break;
case '&': printf("Do you want to enter the next stage?\nY/N?\n\n");
char nextStage=getchar();
if(nextStage=='Y'){
stage++;
break;
}
}
}
void moveRIGH(){
switch(map[x][y+1]){
case '#': printf("Don't tun against the wall");
break;
case ' ': y+=1;
map[x][y-1]=' ';
break;
case '&': printf("Do you want to enter the next stage?\nY/N?\n\n");
char nextStage=getchar();
if(nextStage=='Y'){
stage++;
break;
}
}
}
void moveDOWN(){
switch(map[x+1][y]){
case '#': printf("Don't tun against the wall");
break;
case ' ': x+=1;
map[x-1][y]=' ';
break;
case '&': printf("Do you want to enter the next stage?\nY/N?\n\n");
char nextStage=getchar();
if(nextStage=='Y'){
stage++;
break;
}
}
}
int main(){
unsigned int life=100;
while(life!=0){
if(life<0){
break;
}
if(turn==0){
printf("I hope you enjoy the game! :)\n\n");
system("Pause");
}
else{
//printing the map and claring the screen
system("cls");
printf("Stage %d Turn%d\n",stage, turn);
map_initialisation(x,y);
//declaring the actions you can perform, f.e moving
char action=getchar();
switch(action){
case 'a':moveLEFT(); break;
case 'w':moveUP(); break;
case 'd':moveRIGH(); break;
case 's':moveDOWN(); break;
}
}
turn++;
}
printf("You have lost!\n");
system("pause");
return 0;
}