-
Notifications
You must be signed in to change notification settings - Fork 1
/
moving_a_point.cpp
63 lines (60 loc) · 1.04 KB
/
moving_a_point.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<iostream>
#include<ncurses.h>
#include<stdlib.h>
#include <unistd.h>
using namespace std;
int main()
{ int x=10;
int y=10;
int z;
int k=3;
initscr();
start_color();
init_pair(1, COLOR_BLACK, COLOR_RED);
for(;;)
{ WINDOW*win=newwin(75, 75, 3, 2);
wrefresh(win);
wmove(win,y,x);
raw();
noecho();
attron(COLOR_PAIR(1));
wprintw(win,"*");
wrefresh(win);
usleep(600000);
wmove(win,y,x);
wprintw(win," "); //prints space at the coordinates of point where it has earlier print *
wrefresh(win);
keypad(stdscr,TRUE);
nodelay(stdscr,TRUE);
z=getch();
switch(z)
{
case KEY_UP:k=5;
break;
case KEY_DOWN:k=2;
break;
case KEY_RIGHT:k=3;
break;
case KEY_LEFT:k=1;
break;
}
if(k==5)
{
y-=1;
}
if(k==2)
{
y+=1;
}
if(k==3)
{
x+=1;
}
if(k==1)
{
x-=1;
}
}
endwin();
return 0;
}