-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_screen.h
114 lines (108 loc) · 2.46 KB
/
client_screen.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// Created by jason on 2022/1/3.
//
#ifndef CLIENT_FCLIENT_H
#define CLIENT_FCLIENT_H
#include<curses.h>
#include<unistd.h>
#include <signal.h>
#define BALL "O"
#define BLANK " "
#define V_END "You found the hidden treasure! You win the game!\n\t\t\t\tOther players only have one move left!\n\t\t\t\tThis game is finished!\n\t\t\t\tPress CTRL + C to exit!"
#define L_END "You miss your last shot! Other client found the hidden treasure before you!\n\t\t\t\tThis game is finished!\n\t\t\t\tPress CTRL + C to exit!"
void v_f(){
initscr();
crmode();
noecho();
clear();
move(20,20);
addstr(V_END);
refresh();
}
void l_f(){
initscr();
crmode();
noecho();
clear();
move(20,20);
addstr(L_END);
refresh();
}
void notice(){
initscr();
crmode();
noecho();
clear();
move(0,0);
char notice[]="You need to control you ball with : w,a,s,d\n"
"Explore the world (the console) to find a hidden treasure\n"
"if other player find it before you, you lose\n"
"this notice will exist 10 seconds, and the game will begin!";
addstr(notice);
refresh();
}
void screen(int pipe_fd)
{
signal(2,v_f);
signal(3,l_f);
char buf[1];
int x=20;
int y=20;
int c;
notice();
sleep(10);
clear();
move(y,x);
addstr(BALL);
while(1){
c = getch();
if(c =='a'){
x--;
move(y,x);
addstr(BLANK);
move(y,x);
addstr(BALL);
buf[0] = c;
write(pipe_fd,buf,sizeof(buf));
refresh();
}
if(c =='w'){
x--;
move(y,x);
addstr(BLANK);
x++;
y--;
move(y,x);
addstr(BALL);
buf[0] = c;
write(pipe_fd,buf,sizeof(buf));
refresh();
}
if(c == 's'){
x--;
move(y,x);
addstr(BLANK);
x++;
y++;
move(y,x);
addstr(BALL);
buf[0] = c;
write(pipe_fd,buf,sizeof(buf));
refresh();
}
if(c == 'd'){
x--;
move(y,x);
addstr(BLANK);
x++;
x++;
move(y,x);
addstr(BALL);
buf[0] = c;
write(pipe_fd,buf,sizeof(buf));
refresh();
}
}
endwin();
}
#endif //CLIENT_FCLIENT_H