So i am writing a code for a project, but i can't seem to make it work. It;s supposed to transition from title screen to game area when i press any button, but the button just ends the code instead.
#include <stdio.h>
#define MAPX 20
#define MAPY 20
//function prototypes
void welcome_screen(void); //function to display welcome screen
void init_world(void); //function to initialize world map with player and enemies
void update_world(int currentScore); //function to initialize world map with player and enemies
void player_move(void); //function to control player's move
void victory_message(int winningScore); //function to display victory message
void defeat_message(int finalScore); //function to display defeat message
//global variables
char world[MAPY][MAPX]; //the world consists of 20 by 20 squares
char player = 'A'; //player
char enemy = 'E'; //enemy (needs one gunshot to destroy)
char enemyShielded = 'S'; //shielded enemy (needs two gunshots to destroy shield and enemy)
char playerGun = '+'; //player's gunshot
char enemyGun = '-'; //enemy's gunshot
char explosion = 'X'; //explosion when enemy is shot
int GunReady = 1; //player's gun's readiness is set to 1; needs greater than 2 to fire;reset to 0 after firing
int enemyReady = 0; //enemy's gun is not ready
int totalEnemies = 0; //total number of enemies is initialized to zero
void main()
{
welcome_screen();
}
void welcome_screen(void)
{
printf("\n \n Welcome soldier! \n \n");
Sleep(1000);
printf("\n \n Defeat the computer INVADERS and come back as a hero. \n \n");
Sleep(1000);
printf("\n \n Your computer's' life is depending on you. \n \n");
Sleep(1000);
printf("\n \n Good luck!!! \n \n \n ");
Sleep(1000);
printf("\n \n \n Direction \n Left - Press 'a' \n Right - Press 'd' \n Gun - Press 'm' \n Press any key to continue. ");
getch();
}
void init_world(void)
{
int x,y;
for (x = 0; x < MAPX; x ++) { //loop from left to right on the world map
for (y = 0; y < MAPY; y ++) { //loop from top to bottom on the world map
if (y % 2 == 1 && y < 7 && x > 4 && x < MAPX - 5 && x % 2 ==0) {
//if x and y coordinates match those for enemies, then
world[y][x] = enemy; // place enemy 'E’
totalEnemies ++; //increment total number of enemies
}
elseif (y==7 && x > 4 && x < MAPX - 5 && x % 2 ==0){
//else if x and y coordinates match those for shielded enemies, then
world[y][x] = enemyShielded; // place shielded enemies; first layer is shield S
totalEnemies = totalEnemies + 2; // increment by 2 due to shield plus enemy
}
else {
world[y][x] = player ; // no enemies at other coordinates, so put empty space
}
}
}
// Part 2: position of the player in the centre map x and last row of y
}