-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
269 lines (247 loc) · 4.3 KB
/
main.c
File metadata and controls
269 lines (247 loc) · 4.3 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#include <stdlib.h>
#include <stdio.h>
#include <ncurses.h>
#include "rect.h"
#include "tri.h"
#include "shapes.h"
#include "dalton.h"
#include "screen.h"
//defines
#define EMPTY 0;
#define RECT 1;
#define TRIANGEL_1 2;
#define TRIANGLE_2 3
#define TRAPEZ 4;
#define DALTON 5
#define CIRCLE 6;
#define BIOHAZARD 7;
int main()
{
// needed variables
WINDOW * win;
node *start,*temp;// to linked list
start = (node *)malloc(sizeof(node));
temp = start;
temp -> next = NULL;// to create list for future
shapes sShape;
int size=4;//first size
int shape;//to determine the shape
int ch = getch();//the listener
int rows = 24, cols = 80;//screen size
int full = 0;//full shape or empty?
int x = (cols - size) / 2;// first place to draw
int y = (rows - (size+2)) / 2;// first place to draw
//screen size and menu size
int sWidth = (cols-1), sHeight = (rows-7);// shapes screen
int color = 1;//initial color
//initialize the screen
if ( (win = initscr()) == NULL ) {
fprintf(stderr, "Error initializing ncurses.\n");
exit(EXIT_FAILURE);
}
start_color();
curs_set(0);
noecho();
keypad(win,TRUE);
//start
//opening screen
initScreen(win,sWidth,sHeight);
setScreen(win,cols,rows);
// listening to the user's choice via keyboard
while ( ((ch = getch()) != 'q'))
{
clear();
switch ( ch )
{
case KEY_UP:
if(shape==3)//triangle
{
if ( y-size/2> 0 )
--y;
}
else if ( y > 1 )
--y;
break;
case KEY_DOWN:
if(shape==4)//case its Trp
{
if ( y< (sHeight-(size-1)/3) )
++y;
}
else
if(shape==5)// case its a Dalton
{
if ( y < (sHeight-size)+1 )
++y;
}
else if ( y < (sHeight-size) )
++y;
break;
case KEY_LEFT:
if(shape == 5)//case its Dalton
{
if ( (x-2*size)>1)
{
--x;
}
}
if(shape == 6)//case its a circle
{
if ( x-size-1>1)
{
--x;
} }
else if ( x > 1 )
--x;
break;
case KEY_RIGHT:
if(shape==4)//case its Trp
{
if ( x< (sWidth-3*size)-3)
++x;
}
if(shape==5)//case its Dalton
{
if ( x<=sWidth-(3*(size/2)))
++x;
}
if(shape==6)//case its Circle
{
if ( x< (sWidth-(size/2)-1))
++x;
}
else
if ( x < (sWidth-size)-1)
++x;
break;
case KEY_HOME:
x = 0;
y = 0;
break;
case KEY_END:
x = (sWidth-size);
y = (sHeight-size);
break;
case 'c':
color ++;
if (full == 1)
{
if (color>=12)
color = 1;
}
if(full==0)
{
if (color >=7)
color = 1;
}
break;
case '1':
size = 4;
shape = RECT;
break;
case '2':
size = 4;
shape = TRIANGEL_1;
break;
case '3':
size = 4;
shape = TRIANGLE_2;
break;
case '4':
size = 4;
shape = TRAPEZ;
break;
case '5':
size = 4;
shape =DALTON;
break;
case '6':
size = 4;
shape = CIRCLE;
break;
case '7':
shape = BIOHAZARD;
size = 4;
break;
case '+':
if (shape == 4)//case its a Trp which built differently
{
if((x+size)<sWidth&&(y+(size-1)/3)<sHeight)
{
size+=3;
}
}
if(shape == 6)// case its a Circle
{
if((sWidth-(size/2)-1)<sWidth&&(y+(size-1))<sHeight)
{
size+=3;
}
}
else
if((x+size)<sWidth&&(y+size)<sHeight)
{
size+=2;
}
break;
case '-':
if (shape == 4 || shape == 6)//case its a Trp or Circle which built differently
{
if(size>6)
size-=3;
}
else
if(size>3)
size-=2;
break;
case 's':
sShape= saveShape(x,y,size,shape,color,full);
insert(start, sShape);
break;
case 'a':
do{
print(win ,start->next, rows, cols);
}
while((ch = getch()) != 'b');
clear();
break;
case 'n':
shape = EMPTY;
Delete(start);
start = (node *)malloc(sizeof(node));
break;
case 'f':
if(full == 0)
full =1;
else
full = 0;
break;
}
onScreen(win,shape,x,y,size,color, full);// print the shape
refresh();
}
bool canBeDrawnUp(int x,int y, int size, int shape)
{
if(shape==3)//triangle
{
if ( y-size/2> 0 )
return TRUE;
}
else if ( y > 1 )
return TRUE;
}
bool canBeDrawnDown(int x,int y, int size, int shape)
{
}
bool canBeDrawnRight(int x,int y, int size, int shape)
{
}
bool canBeDrawnLeft(int x,int y, int size, int shape)
{
}
/*cleanup..*/
delwin(win);
endwin();
refresh();
return EXIT_SUCCESS;
}