Simple Games using ncurses
Menu
// Cave Escape
#include <ncurses.h>
#include <stdlib.h>
#include <time.h>bool shield = false;
int clock_shield = 0;
int magic = 0;
struct Food
{
int x, y , clock;
};
Food apple={20,4,0};
int room = 0;
int c = 7;
int d = 4;
enum off_on
{
OFF=0,
ON=1
};
enum Move
{
NONE,
LEFT,
RIGHT,
UP,
DOWN
};
enum Colors
{
BK = 0,
RD = 1,
GN = 2,
YW = 3,
BE = 4,
MA = 5,
CN = 6,
WE = 7
};
struct Player
{
int dir, x, y, energy;
};
Player p={
NONE,
5,
8,
150,
};
struct Enemy
{
int dir, y, x;
};
Enemy ship = {
1,
6,
22
};
void ncurses()
{
srand(time(NULL));
initscr();
noecho();
curs_set(0);
keypad(stdscr, TRUE);
timeout(175);
}
void game_over()
{
mvprintw(6, 9, "GAME OVER ");
getch();
timeout(-1);
refresh();
endwin();
}
int main()
{
start:
ncurses();
start_color();
bkgd(COLOR_PAIR(1));
init_pair(1, BK, BK);
init_pair(2, WE, BK);
init_pair(3, CN, BK);
init_pair(4, BE, BK);
init_pair(5, RD, BK);
int getkey;
while (p.energy > 0)
{
getkey = getch();
switch (getkey)
{
case KEY_LEFT:
case 'q':
case 'w':
case 'a':
case 's':
case 'd':
p.dir = LEFT;
break;
case KEY_RIGHT:
case 'i':
case 'o':
case 'p':
case 'j':
case 'k':
case 'l':
p.dir = RIGHT;
break;
case KEY_UP:
case 'r':
case 't':
case 'y':
case 'u':
p.dir = UP;
break;
case KEY_DOWN:
case 'c':
case 'v':
case 'b':
case ' ':
p.dir = DOWN;
break;
case 10:
case ',':
case '.':
mvprintw(7, 12, "PAUSED");
refresh();
while (1)
{
getkey = getch();
if (getkey == 10)
{
break;
}
}
break;
}
switch (p.dir)
{
case 1:
p.x--;
break;
case 2:
p.x++;
break;
case 3:
p.y--;
break;
case 4:
p.y++;
break;
}
// directions of moving obstacles
switch (ship.dir)
{
case 1:
ship.x--;
break;
case 2:
ship.x++;
break;
case 3:
ship.y--;
break;
case 4:
ship.y++;
break;
// extra: 45 degree...down+left
case 5:
ship.x--;
ship.y++;
break;
// extra: 45 degree...down+right
case 6:
ship.x++;
ship.y++;
break;
}
bool collision_2 = false;
if (ship.x < 0 && p.x <= 12)
{
ship.x = 4 + rand() % 12 + 1;
ship.y = p.y;
}
if (ship.x < 0 && p.x >= 13)
{
ship.x = 17 + rand() % 11 + 1;
ship.y = p.y;
}
if (ship.x > 29 && p.x <= 12)
{
ship.x = 4 + rand() % 12 + 1;
ship.y = p.y;
}
if (ship.x < 0 && p.x >= 13)
{
ship.y = 17 + rand() % 11 + 1;
ship.y = p.y;
}
if (ship.y < 0)
{
ship.y = 8 + rand() % 2;
ship.x = p.x;
}
if (ship.y > 10)
{
ship.y = rand() % 2;
ship.x = p.x;
}
apple.clock++;
if (apple.clock >= 26 + rand() % 10)
{
apple.clock = 0;
apple.x = rand() % 29 + 1;
apple.y = 1 + rand() % 10 + 1;
p.energy-=10;
}
if (p.x == apple.x && p.y == apple.y)
{
apple.x = rand() % 29 + 1;
apple.y = 1 + rand() % 10 + 1;
p.energy+=5;
collision_2 = true;
magic++;
}
magic >= 3 ? shield = true : shield = false;
if (p.energy <= 0)
game_over();
erase();
attron(COLOR_PAIR(3));
attron(A_BOLD);
mvaddch(p.y, p.x, 'O');
if (ship.x < 0)
{
ship.x = 20 + rand() % 9;
ship.y = p.y;
}
if (ship.x > 29)
{
ship.x = rand() % 9;
ship.y = p.y;
}
if (ship.y < 0)
{
ship.y = 10;
ship.x = p.x;
}
if (ship.y > 10)
{
ship.y = 0;
ship.x = p.x;
}
bool collision = false;
if (ship.y == p.y && ship.x == p.x && shield == false)
collision = true;
if (collision)
{
mvprintw(p.y - 1, p.x, "x");
mvprintw(p.y + 1, p.x, "x");
mvprintw(p.y, p.x - 1, "x");
mvprintw(p.y, p.x + 1, "x");
p.energy -= 5;
}
if (room == 0)
{
p.x = 30;
p.y = 0;
attron(A_BOLD);
mvprintw(2, 9, "Cave Escape");
mvprintw(7, 5, "(Press [SPACE] Key To Start)");
if (getkey == ' ')
{
room = 1;
p.x = 4;
p.y = 4;
};
};
magic >= 2 ? shield = true : shield = false;
if (shield)
{
mvprintw(p.y - 1, p.x, "=");
mvprintw(p.y + 1, p.x, "=");
mvprintw(p.y, p.x - 1, "(");
mvprintw(p.y, p.x + 1, ")");
clock_shield++;
}
if (clock_shield >= 20)
{
clock_shield = 0;
shield = false;
magic = 0;
}
if (collision_2)
{
mvprintw(p.y - 1, p.x, "o");
mvprintw(p.y + 1, p.x, "o");
mvprintw(p.y, p.x - 1, "o");
mvprintw(p.y, p.x + 1, "o");
}
if (room == 1)
{
mvprintw(16, 0, "rm1");
ship.dir = 4;
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
mvprintw(ship.y, ship.x, "#");
attron(COLOR_PAIR(1));
attron(A_BOLD);
mvprintw(0, 0, "OxxxxxOOxxxOxxxoxooooOxxxOxxxO");
mvprintw(11, 0, "xxxxxxOxxxOxxxxxOxxOxxOooxxxxx");
if (p.x < -1)
{
p.x = 30;
room = 2;
}
if (p.x > 30)
{
p.x = -1;
room = 4;
}
if (p.y > 10)
p.dir = 3;
if (p.y < 2)
p.dir = 4;
}
// room 2
if (room == 2)
{
mvprintw(16, 0, "rm2");
ship.dir = 2;
mvprintw(apple. y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "ox)");
attron(COLOR_PAIR(1));
attron(A_BOLD);
mvprintw(0, 0, "oooxxxOOxxoooOOoxxxoOOxxxOoxxx");
mvprintw(11, 10, "OxxxxxxxoxxOxxOxxxxO");
if (p.x < 0)
p.dir = 2;
if (p.x > 30)
{
p.x = -1;
room = 1;
}
if (p.y < 1)
p.dir = DOWN;
if (p.y > 10 && p.x >= 11)
p.dir = UP;
if (p.y > 10 && p.x <= 10)
{
p.y = 0;
room = 3;
}
}
if (room == 3)
{
mvprintw(16, 0, "rm3");
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "#");
attron(COLOR_PAIR(1));
attron(A_BOLD);
mvprintw(1, 11, "xOxxxOoxxxxxOOoxxxx");
mvprintw(11, 0, "xxOoxxOOOxxxxxOOxxxxOOxxxxOOxxx");
if (p.y < 0 && p.x <= 10)
{
p.y = 10;
room = 2;
}
if (p.y < 0 && p.x >= 11)
p.dir = DOWN;
if (p.x < 0)
p.dir = RIGHT;
if (p.x > 29)
p.dir = LEFT;
if (p.y > 10)
p.dir = UP;
}
if (room == 4)
{
mvprintw(16, 0, "rm4");
ship.dir = 1;
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "oxo");
attron(COLOR_PAIR(1));
attron(A_BOLD);
mvprintw(0, 0, "OxxxxxOOO OxxxxxOOOOxxxxxOOOO");
mvprintw(11, 0, "xxxxxxOxxxOxxxxxOxOxxOoooxxxxx");
if (p.x > 29)
p.dir = LEFT;
if (p.x < -1)
{
p.x = 29;
room = 1;
}
if (p.y < 1 && p.x <= 8 || p.y < 1 && p.x >= 11)
p.dir = DOWN;
if (p.y < 0 && p.x >= 9 && p.x <= 10)
{
p.y = 10;
room = 5;
}
if (p.y > 10)
p.dir = UP;
}
if (room == 5)
{
mvprintw(16, 0, "rm5");
ship.dir = 5;
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "@");
for (int a = 0; a < 12; a++)
{
attron(COLOR_PAIR(1));
attron(A_BOLD);
mvprintw(a, 8, "0");
}
for (int b = 0; b < 12; b++)
{
mvprintw(b, 11, "0");
}
if (p.x < 9)
p.dir = RIGHT;
if (p.x > 10)
p.dir= LEFT;
if (p.y > 10 && p.x >= 9 && p.x <= 10)
{
p.y = 0;
room = 4;
}
if (p.y < 0)
{
p.y = 10;
room = 6;
}
}
if (room == 6)
{
mvprintw(16, 0, "rm6");
ship.dir = 1;
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "]x");
attron(COLOR_PAIR(1));
attron(A_BOLD);
mvprintw(2, 8, "xxxOOxxxOxxxxxO");
mvprintw(8, 11, " OoxxOxxxxxxOxxxOoo");
for (int a_6 = 2; a_6 < 12; a_6++)
{
mvprintw(a_6, 8, "0");
}
for (int b_6 = 8; b_6 < 12; b_6++)
{
mvprintw(b_6, 11, "0");
}
for (int c_6 = 0; c_6 < 9; c_6++)
{
mvprintw(c_6, 29, "0");
}
for (int d_6 = 0; d_6 < 3; d_6++)
{
mvprintw(d_6, 22, "0");
};
if (p.x < 9)
p.dir = RIGHT;
if (p.y < 3 && p.x < 23)
p.dir= DOWN;
if (p.x > 10 && p.y > 7)
p.dir = LEFT;
if (p.x > 29)
p.dir = LEFT;
if (p.x >= 11 && p.y > 7)
p.dir = UP;
if (p.x >= 9 && p.x <= 10 && p.y > 10)
{
p.y = 0;
room = 5;
}
if (p.y < 0)
{
p.y = 10;
room = 7;
ship.y = 1 + rand() % 2;
ship.x = 23 + rand() % 5;
ship.dir = 4;
}
}
if (room == 7)
{
mvprintw(16, 0, "rm7");
ship.dir = 4;
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "#");
for (int a_7 = 0; a_7 < 12; a_7++)
mvprintw(a_7, 22, "0");
for (int b_7 = 0; b_7 < 12; b_7++)
mvprintw(b_7, 29, "0");
if (p.x < 23)
p.dir = RIGHT;
if (p.x > 29)
p.dir=LEFT;
if (p.y > 11)
{
p.y = 0;
room = 6;
}
if (p.y < 0)
{
p.y = 10;
ship.dir = 1;
ship.y = 18 + rand() % 10;
ship.y = 4 + rand() % 3;
room = 8;
}
}
if (room == 8)
{
mvprintw(16, 0, "rm8");
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "@");
for (int a_8 = 0; a_8 < 12; a_8++)
mvprintw(a_8, 22, "@");
for (int b_8 = 0; b_8 < 12; b_8++)
mvprintw(b_8, 29, "@");
for (int c_8 = 23; c_8 < 29; c_8++)
mvprintw(5, c_8, ":");
for (int c_8 = 23; c_8 < 29; c_8++)
mvprintw(6, c_8, ":");
if (p.x < 23)
p.dir = RIGHT;
if (p.x > 29)
p.dir = LEFT;
if (p.y > 11)
{
p.y = 0;
room = 7;
}
if (p.y < 0)
{
p.y = 10;
room = 9;
}
}
if (room == 9)
{
mvprintw(16, 0, "Rm9");
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "#");
for (int a_9 = 11; a_9 > 3; a_9--)
mvprintw(a_9, 22, "@");
for (int b_9 = 22; b_9 < 30; b_9++)
mvprintw(4, b_9, "@");
for (int c_9 = 11; c_9 > 7; c_9--)
mvprintw(c_9, 29, "@");
if (p.x < 23)
p.dir = RIGHT;
if (p.x > 28 && p.y >= 8)
p.dir = LEFT;
if (p.x > 29 && p.y < 8)
{
p.x = 0;
room = 10;
}
if (p.y < 5)
p.dir = DOWN;
if (p.y > 10)
{
p.y = 0;
room = 8;
}
}
if (room == 10)
{
mvprintw(16, 0, "rm10");
mvprintw(apple.y, apple.x, "e");
mvprintw(ship.y, ship.x, "=");
for (int a_10 = 0; a_10 < 30; a_10++)
mvprintw(4, a_10, "@");
for (int b_10 = 0; b_10 < 30; b_10++)
mvprintw(8, b_10, "@");
for (int c_10 = 18; c_10 < 24; c_10++)
mvprintw(5, c_10, ":");
for (int c_10 = 18; c_10 < 24; c_10++)
mvprintw(6, c_10, ":");
for (int c_10 = 18; c_10 < 24; c_10++)
mvprintw(6, c_10, ":");
for (int c_10 = 18; c_10 < 24; c_10++)
mvprintw(7, c_10, ":");
if (p.x < 0)
{
p.x = 29;
room = 9;
}
if (p.x > 29)
{
p.x = 0;
room = 11;
}
if (p.y < 5)
p.dir = DOWN;
if (p.y > 7)
p.dir=UP;
}
if (room == 11)
{
mvprintw(16, 0, "rm11");
mvprintw(apple.y, apple.x, "e");
mvprintw(ship.y, ship.x, "@");
for (int a_11 = 0; a_11 < 30; a_11++)
mvprintw(4, a_11, "/");
for (int b_11 = 0; b_11 < 30; b_11++)
mvprintw(8, b_11, "/");
if ( p.x < 0)
{
p.x = 29;
room = 10;
}
if (p.y < 5)
p.dir = DOWN;
if (p.y > 7)
p.dir=UP;
}
}
game_over();
}
#include <ncurses.h>
#include <stdlib.h>
#include <time.h>bool shield = false;
int clock_shield = 0;
int magic = 0;
struct Food
{
int x, y , clock;
};
Food apple={20,4,0};
int room = 0;
int c = 7;
int d = 4;
enum off_on
{
OFF=0,
ON=1
};
enum Move
{
NONE,
LEFT,
RIGHT,
UP,
DOWN
};
enum Colors
{
BK = 0,
RD = 1,
GN = 2,
YW = 3,
BE = 4,
MA = 5,
CN = 6,
WE = 7
};
struct Player
{
int dir, x, y, energy;
};
Player p={
NONE,
5,
8,
150,
};
struct Enemy
{
int dir, y, x;
};
Enemy ship = {
1,
6,
22
};
void ncurses()
{
srand(time(NULL));
initscr();
noecho();
curs_set(0);
keypad(stdscr, TRUE);
timeout(175);
}
void game_over()
{
mvprintw(6, 9, "GAME OVER ");
getch();
timeout(-1);
refresh();
endwin();
}
int main()
{
start:
ncurses();
start_color();
bkgd(COLOR_PAIR(1));
init_pair(1, BK, BK);
init_pair(2, WE, BK);
init_pair(3, CN, BK);
init_pair(4, BE, BK);
init_pair(5, RD, BK);
int getkey;
while (p.energy > 0)
{
getkey = getch();
switch (getkey)
{
case KEY_LEFT:
case 'q':
case 'w':
case 'a':
case 's':
case 'd':
p.dir = LEFT;
break;
case KEY_RIGHT:
case 'i':
case 'o':
case 'p':
case 'j':
case 'k':
case 'l':
p.dir = RIGHT;
break;
case KEY_UP:
case 'r':
case 't':
case 'y':
case 'u':
p.dir = UP;
break;
case KEY_DOWN:
case 'c':
case 'v':
case 'b':
case ' ':
p.dir = DOWN;
break;
case 10:
case ',':
case '.':
mvprintw(7, 12, "PAUSED");
refresh();
while (1)
{
getkey = getch();
if (getkey == 10)
{
break;
}
}
break;
}
switch (p.dir)
{
case 1:
p.x--;
break;
case 2:
p.x++;
break;
case 3:
p.y--;
break;
case 4:
p.y++;
break;
}
// directions of moving obstacles
switch (ship.dir)
{
case 1:
ship.x--;
break;
case 2:
ship.x++;
break;
case 3:
ship.y--;
break;
case 4:
ship.y++;
break;
// extra: 45 degree...down+left
case 5:
ship.x--;
ship.y++;
break;
// extra: 45 degree...down+right
case 6:
ship.x++;
ship.y++;
break;
}
bool collision_2 = false;
if (ship.x < 0 && p.x <= 12)
{
ship.x = 4 + rand() % 12 + 1;
ship.y = p.y;
}
if (ship.x < 0 && p.x >= 13)
{
ship.x = 17 + rand() % 11 + 1;
ship.y = p.y;
}
if (ship.x > 29 && p.x <= 12)
{
ship.x = 4 + rand() % 12 + 1;
ship.y = p.y;
}
if (ship.x < 0 && p.x >= 13)
{
ship.y = 17 + rand() % 11 + 1;
ship.y = p.y;
}
if (ship.y < 0)
{
ship.y = 8 + rand() % 2;
ship.x = p.x;
}
if (ship.y > 10)
{
ship.y = rand() % 2;
ship.x = p.x;
}
apple.clock++;
if (apple.clock >= 26 + rand() % 10)
{
apple.clock = 0;
apple.x = rand() % 29 + 1;
apple.y = 1 + rand() % 10 + 1;
p.energy-=10;
}
if (p.x == apple.x && p.y == apple.y)
{
apple.x = rand() % 29 + 1;
apple.y = 1 + rand() % 10 + 1;
p.energy+=5;
collision_2 = true;
magic++;
}
magic >= 3 ? shield = true : shield = false;
if (p.energy <= 0)
game_over();
erase();
attron(COLOR_PAIR(3));
attron(A_BOLD);
mvaddch(p.y, p.x, 'O');
if (ship.x < 0)
{
ship.x = 20 + rand() % 9;
ship.y = p.y;
}
if (ship.x > 29)
{
ship.x = rand() % 9;
ship.y = p.y;
}
if (ship.y < 0)
{
ship.y = 10;
ship.x = p.x;
}
if (ship.y > 10)
{
ship.y = 0;
ship.x = p.x;
}
bool collision = false;
if (ship.y == p.y && ship.x == p.x && shield == false)
collision = true;
if (collision)
{
mvprintw(p.y - 1, p.x, "x");
mvprintw(p.y + 1, p.x, "x");
mvprintw(p.y, p.x - 1, "x");
mvprintw(p.y, p.x + 1, "x");
p.energy -= 5;
}
if (room == 0)
{
p.x = 30;
p.y = 0;
attron(A_BOLD);
mvprintw(2, 9, "Cave Escape");
mvprintw(7, 5, "(Press [SPACE] Key To Start)");
if (getkey == ' ')
{
room = 1;
p.x = 4;
p.y = 4;
};
};
magic >= 2 ? shield = true : shield = false;
if (shield)
{
mvprintw(p.y - 1, p.x, "=");
mvprintw(p.y + 1, p.x, "=");
mvprintw(p.y, p.x - 1, "(");
mvprintw(p.y, p.x + 1, ")");
clock_shield++;
}
if (clock_shield >= 20)
{
clock_shield = 0;
shield = false;
magic = 0;
}
if (collision_2)
{
mvprintw(p.y - 1, p.x, "o");
mvprintw(p.y + 1, p.x, "o");
mvprintw(p.y, p.x - 1, "o");
mvprintw(p.y, p.x + 1, "o");
}
if (room == 1)
{
mvprintw(16, 0, "rm1");
ship.dir = 4;
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
mvprintw(ship.y, ship.x, "#");
attron(COLOR_PAIR(1));
attron(A_BOLD);
mvprintw(0, 0, "OxxxxxOOxxxOxxxoxooooOxxxOxxxO");
mvprintw(11, 0, "xxxxxxOxxxOxxxxxOxxOxxOooxxxxx");
if (p.x < -1)
{
p.x = 30;
room = 2;
}
if (p.x > 30)
{
p.x = -1;
room = 4;
}
if (p.y > 10)
p.dir = 3;
if (p.y < 2)
p.dir = 4;
}
// room 2
if (room == 2)
{
mvprintw(16, 0, "rm2");
ship.dir = 2;
mvprintw(apple. y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "ox)");
attron(COLOR_PAIR(1));
attron(A_BOLD);
mvprintw(0, 0, "oooxxxOOxxoooOOoxxxoOOxxxOoxxx");
mvprintw(11, 10, "OxxxxxxxoxxOxxOxxxxO");
if (p.x < 0)
p.dir = 2;
if (p.x > 30)
{
p.x = -1;
room = 1;
}
if (p.y < 1)
p.dir = DOWN;
if (p.y > 10 && p.x >= 11)
p.dir = UP;
if (p.y > 10 && p.x <= 10)
{
p.y = 0;
room = 3;
}
}
if (room == 3)
{
mvprintw(16, 0, "rm3");
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "#");
attron(COLOR_PAIR(1));
attron(A_BOLD);
mvprintw(1, 11, "xOxxxOoxxxxxOOoxxxx");
mvprintw(11, 0, "xxOoxxOOOxxxxxOOxxxxOOxxxxOOxxx");
if (p.y < 0 && p.x <= 10)
{
p.y = 10;
room = 2;
}
if (p.y < 0 && p.x >= 11)
p.dir = DOWN;
if (p.x < 0)
p.dir = RIGHT;
if (p.x > 29)
p.dir = LEFT;
if (p.y > 10)
p.dir = UP;
}
if (room == 4)
{
mvprintw(16, 0, "rm4");
ship.dir = 1;
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "oxo");
attron(COLOR_PAIR(1));
attron(A_BOLD);
mvprintw(0, 0, "OxxxxxOOO OxxxxxOOOOxxxxxOOOO");
mvprintw(11, 0, "xxxxxxOxxxOxxxxxOxOxxOoooxxxxx");
if (p.x > 29)
p.dir = LEFT;
if (p.x < -1)
{
p.x = 29;
room = 1;
}
if (p.y < 1 && p.x <= 8 || p.y < 1 && p.x >= 11)
p.dir = DOWN;
if (p.y < 0 && p.x >= 9 && p.x <= 10)
{
p.y = 10;
room = 5;
}
if (p.y > 10)
p.dir = UP;
}
if (room == 5)
{
mvprintw(16, 0, "rm5");
ship.dir = 5;
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "@");
for (int a = 0; a < 12; a++)
{
attron(COLOR_PAIR(1));
attron(A_BOLD);
mvprintw(a, 8, "0");
}
for (int b = 0; b < 12; b++)
{
mvprintw(b, 11, "0");
}
if (p.x < 9)
p.dir = RIGHT;
if (p.x > 10)
p.dir= LEFT;
if (p.y > 10 && p.x >= 9 && p.x <= 10)
{
p.y = 0;
room = 4;
}
if (p.y < 0)
{
p.y = 10;
room = 6;
}
}
if (room == 6)
{
mvprintw(16, 0, "rm6");
ship.dir = 1;
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "]x");
attron(COLOR_PAIR(1));
attron(A_BOLD);
mvprintw(2, 8, "xxxOOxxxOxxxxxO");
mvprintw(8, 11, " OoxxOxxxxxxOxxxOoo");
for (int a_6 = 2; a_6 < 12; a_6++)
{
mvprintw(a_6, 8, "0");
}
for (int b_6 = 8; b_6 < 12; b_6++)
{
mvprintw(b_6, 11, "0");
}
for (int c_6 = 0; c_6 < 9; c_6++)
{
mvprintw(c_6, 29, "0");
}
for (int d_6 = 0; d_6 < 3; d_6++)
{
mvprintw(d_6, 22, "0");
};
if (p.x < 9)
p.dir = RIGHT;
if (p.y < 3 && p.x < 23)
p.dir= DOWN;
if (p.x > 10 && p.y > 7)
p.dir = LEFT;
if (p.x > 29)
p.dir = LEFT;
if (p.x >= 11 && p.y > 7)
p.dir = UP;
if (p.x >= 9 && p.x <= 10 && p.y > 10)
{
p.y = 0;
room = 5;
}
if (p.y < 0)
{
p.y = 10;
room = 7;
ship.y = 1 + rand() % 2;
ship.x = 23 + rand() % 5;
ship.dir = 4;
}
}
if (room == 7)
{
mvprintw(16, 0, "rm7");
ship.dir = 4;
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "#");
for (int a_7 = 0; a_7 < 12; a_7++)
mvprintw(a_7, 22, "0");
for (int b_7 = 0; b_7 < 12; b_7++)
mvprintw(b_7, 29, "0");
if (p.x < 23)
p.dir = RIGHT;
if (p.x > 29)
p.dir=LEFT;
if (p.y > 11)
{
p.y = 0;
room = 6;
}
if (p.y < 0)
{
p.y = 10;
ship.dir = 1;
ship.y = 18 + rand() % 10;
ship.y = 4 + rand() % 3;
room = 8;
}
}
if (room == 8)
{
mvprintw(16, 0, "rm8");
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "@");
for (int a_8 = 0; a_8 < 12; a_8++)
mvprintw(a_8, 22, "@");
for (int b_8 = 0; b_8 < 12; b_8++)
mvprintw(b_8, 29, "@");
for (int c_8 = 23; c_8 < 29; c_8++)
mvprintw(5, c_8, ":");
for (int c_8 = 23; c_8 < 29; c_8++)
mvprintw(6, c_8, ":");
if (p.x < 23)
p.dir = RIGHT;
if (p.x > 29)
p.dir = LEFT;
if (p.y > 11)
{
p.y = 0;
room = 7;
}
if (p.y < 0)
{
p.y = 10;
room = 9;
}
}
if (room == 9)
{
mvprintw(16, 0, "Rm9");
mvprintw(apple.y, apple.x, "e");
attron(COLOR_PAIR(2));
attron(A_BOLD);
mvprintw(ship.y, ship.x, "#");
for (int a_9 = 11; a_9 > 3; a_9--)
mvprintw(a_9, 22, "@");
for (int b_9 = 22; b_9 < 30; b_9++)
mvprintw(4, b_9, "@");
for (int c_9 = 11; c_9 > 7; c_9--)
mvprintw(c_9, 29, "@");
if (p.x < 23)
p.dir = RIGHT;
if (p.x > 28 && p.y >= 8)
p.dir = LEFT;
if (p.x > 29 && p.y < 8)
{
p.x = 0;
room = 10;
}
if (p.y < 5)
p.dir = DOWN;
if (p.y > 10)
{
p.y = 0;
room = 8;
}
}
if (room == 10)
{
mvprintw(16, 0, "rm10");
mvprintw(apple.y, apple.x, "e");
mvprintw(ship.y, ship.x, "=");
for (int a_10 = 0; a_10 < 30; a_10++)
mvprintw(4, a_10, "@");
for (int b_10 = 0; b_10 < 30; b_10++)
mvprintw(8, b_10, "@");
for (int c_10 = 18; c_10 < 24; c_10++)
mvprintw(5, c_10, ":");
for (int c_10 = 18; c_10 < 24; c_10++)
mvprintw(6, c_10, ":");
for (int c_10 = 18; c_10 < 24; c_10++)
mvprintw(6, c_10, ":");
for (int c_10 = 18; c_10 < 24; c_10++)
mvprintw(7, c_10, ":");
if (p.x < 0)
{
p.x = 29;
room = 9;
}
if (p.x > 29)
{
p.x = 0;
room = 11;
}
if (p.y < 5)
p.dir = DOWN;
if (p.y > 7)
p.dir=UP;
}
if (room == 11)
{
mvprintw(16, 0, "rm11");
mvprintw(apple.y, apple.x, "e");
mvprintw(ship.y, ship.x, "@");
for (int a_11 = 0; a_11 < 30; a_11++)
mvprintw(4, a_11, "/");
for (int b_11 = 0; b_11 < 30; b_11++)
mvprintw(8, b_11, "/");
if ( p.x < 0)
{
p.x = 29;
room = 10;
}
if (p.y < 5)
p.dir = DOWN;
if (p.y > 7)
p.dir=UP;
}
}
game_over();
}