خب تونتسم دشمنان خودم رو اسپاون کنم ولی نه اونطوری که دوست داشتم:( :
#include <stdio.h>
#include <ncurses.h>
#include <time.h>
#include <stdlib.h>
struct posions
{
int colmn;
int lines;
};
void spawn(int);
void enemy_spawn(int);
int main()
{
struct posions* player = NULL;
initscr();
int playing = TRUE;
player = malloc(sizeof(*player));
player->colmn = COLS /2;
player->lines = LINES /2;
clear();
cbreak();
noecho();
curs_set(0);
refresh();
char ch;
while (playing)
{
spawn(30);
enemy_spawn(10);
ch = getchar();
switch (ch)
{
case 'w':
player->lines -= 1;
break;
case 's':
player->lines += 1;
break;
case 'a':
player->colmn -= 1;
break;
case 'd':
player->colmn += 1;
break;
case 'q':
playing = FALSE;
break;
default:
continue;
}
clear();
mvprintw(player->lines, player->colmn, "*");
refresh();
}
getch();
free(player);
endwin();
return 0;
}
void spawn(int count)
{
start_color();
init_pair(1, COLOR_BLUE, COLOR_BLACK);
attrset(A_BOLD | COLOR_PAIR(1) | A_CHARTEXT);
srandom(COLS && LINES);
int x, y;
const int spawn_x = COLS /2;
const int spawn_y = LINES /2;
for(int i = 0; i<count; i++)
{
sp_x:
x = rand() % (COLS -2);
if(x == spawn_x)
goto sp_x;
sp_y:
y = rand() % (LINES -2);
if(y == spawn_y)
goto sp_y;
mvprintw(y, x, ".");
}
refresh();
attroff(A_BOLD | COLOR_PAIR(1) | A_CHARTEXT);
}
void enemy_spawn(int count)
{
srandom(LINES && COLS);
start_color();
init_pair(2, COLOR_RED, COLOR_BLACK);
attrset(A_BOLD | COLOR_PAIR(2) | A_PROTECT);
int x, y;
const int spawn_x = COLS /2;
const int spawn_y = LINES /2;
char dot, asterik;
dot = '.';
asterik = '*';
for(int i = 0; i < count; i++)
{
spawn:
y = rand() % (LINES -2);
x = rand()% (COLS -2);
if((x || y) != dot || asterik || spawn_x || spawn_y)
{
mvprintw(y, x, "&");
} else {
goto spawn;
}
}
refresh();
attroff(A_BOLD | COLOR_PAIR(2) | A_PROTECT);
}