#include #include #include #include #include #include struct erow { int e[5]; unsigned short position; erow() { position = 0; for(int x=0;x<5;x++)e[x]=0; } }; struct tstruct { bool* t; erow* e; tstruct(bool *b, erow* er):t(b),e(er){} }; void printEn(unsigned short trc, erow* e) { attron(COLOR_PAIR(e->e[e->position])); unsigned short rc = trc%4; trc++; if(trc<5)//top { mvprintw((e->position+1),5+trc,"X"); } else if(trc<10)//right side { mvprintw(trc,15-(e->position),"X"); } else if(trc<15)//bottom { mvprintw(15-(e->position),(trc-10),"X"); } else { mvprintw(5+(trc-15),e->position,"X"); } attroff(COLOR_PAIR(e->e[e->position])); } void* genEn(void* tt) { tstruct* t = (tstruct*)tt; bool* flag = t->t; erow* e = t->e; unsigned short etype; unsigned short wer; while(!*flag) { wer = rand()%20; if(wer>20) { printf("ERROR"); } if((e+wer)->position>=5) { *flag=true; break; } etype= rand()%5; (e+wer)->e[(e+wer)->position]=++etype; (e+wer)->position++; printEn(wer, e); sleep(2); } } int main() { srand(time(NULL)); erow* enemies = new erow[20]; int cursorCOLOR = COLOR_WHITE; char *c = ">\0"; int ic; bool flag=false; int row, maxcol, col=0; unsigned short cy,cx,ly,lx; unsigned short counter=0; initscr(); halfdelay(1); noecho(); getmaxyx(stdscr,row,maxcol); printf("test"); for(int trow=0;trow<20;trow++) { //mvprintw(0,trow,"X"); //sleep(1); } cy=cx=7; mvprintw(cy,cx,c); tstruct *targ = new tstruct(&flag,enemies); pthread_t *pt; pthread_create(pt,NULL,&genEn,(void *) targ); while(!flag) { ic = getch(); if(ic)mvprintw(cy,cx," "); switch(ic) { case 'q': flag = true; break; case 'k': c="^"; //clear(); if(cy==0) cy=row; else cy--; //coord system is reversed break; case 'j': c="V"; //clear(); if(cy==row) cy=0; else cy++; break; case 'h': c="<"; //clear(); if(cx==0)cx=maxcol; else cx--; break; case 'l': c=">"; //clear(); if(cx==maxcol) cx=0; else cx++; break; } mvprintw(cy,cx,c); } endwin(); return 0; }