• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
% ncurses program which simulates a robot movment% by Anwar Al assaf #include<stdio.h>#include <ncurses.h>#include<stdlib.h>#include<signal.h>//define PrototypeWINDOW *inwin(int height, int width, int starty, int startx,int n);WINDOW *dwin(int height, int width, int starty, int startx,int n);//Global Variable Declerationint count=0;int flag=0;int a,b;int i=1,j=3;int k,l;char d='x' ;int x1=0,y1=0,x2=0,y2=0;int x[1000],y[1000];//End Global Variable Decleration//Function to check If Colloison Occure//Main Function Declerationvoid check(){}int main(int argc, char *argv[]){WINDOW *my_win;int startx, starty, width, height;int ch;int score=0;int c,r;initscr(); /* Start curses mode */cbreak();keypad(stdscr, TRUE);start_color();height = 1;width = 3;srand(17894); printw("\nSelect (16 X 16) OR more \n "); printw("\nEnter No of Rows (Even Numbers): ");scanw("%d",&r); printw("\nEnter No of Colomns (Even Numbers): ");scanw("%d",&c); printw("\n");refresh();clear(); printw("Press F2 to exit\n");
 
refresh();int ac;init_pair(0,COLOR_RED,COLOR_GREEN);init_pair(1,COLOR_BLACK,COLOR_WHITE);init_pair(2,COLOR_RED,COLOR_WHITE);init_pair(3,COLOR_BLUE,COLOR_YELLOW); bkgd(COLOR_PAIR(3));refresh();//print Game Windowfor(i=4;i<=( (r) * 1);i+=1){for(j=3;j<=((c+1) *3 );j+=3){my_win = inwin(height, width, i, j,2);}}i=10; j=21;my_win = inwin(height, width, i, j,3);i=10; j=51;my_win = inwin(height, width, i, j,3);i=16; j=39;my_win = inwin(height, width, i, j,3);i=15; j=21;my_win = inwin(height, width, i, j,4);wrefresh(my_win);x1=x2=0;y1=y2=0;y[y2]=i;x[x2]=j;y[y1]=i;x[x1]=j;while(1 ){ac = rand() %4;switch(ac){case 0://test for boundaryif(j == 27 && (i == 10 || i == 11)) break;if(j == 45 && (i == 16 || i == 17)) break;if(j == 57 && (i == 10 || i == 11)) break;
 
if(j < 6) break;//test for collisonif(d == 'r') break;d='l';my_win = dwin(height, width, y[y1],x[x1],2);y1++;x1++; j=j-3;y2++;x2++;y[y2]=i;x[x2]=j;my_win = inwin(height, width, y[y2],x[x2],4);//j=j-3;//y[++y2]=i;//x[++x2]=j;/*my_win = inwin(height, width, y[y2],x[x2],4);*/++score;usleep(200000); break;case 1:check();if(j == 18 && (i ==10 || i == 11)) break;if(j == 36 && (i ==16 || i == 17)) break;if(j == 48 && (i ==10 || i == 11)) break;if(j >= ((c+1) * 3)) break;//test for collisonif(d == 'l') break;d='r';my_win = dwin(height, width, y[y1],x[x1],2);y1++;x1++; j=j+3;y2++;x2++;y[y2]=i;x[x2]=j;my_win = inwin(height, width, y[y2],x[x2],4);/*j=j+3;y[++y2]=i;x[++x2]=j;my_win = inwin(height, width, y[y2],x[x2],4);*/++score;
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...