-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefence.c
159 lines (137 loc) · 3.41 KB
/
defence.c
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
/*
* defense.c
*
* Created on: 20.06.2019
* Author: rafael
*/
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#define ARR_SIZE(arr) ( sizeof((arr)) / sizeof((arr[0])) )
#define ss (unsigned char) 225
#define AE (unsigned char) 142
#define ae (unsigned char) 132
#define OE (unsigned char) 153
#define oe (unsigned char) 148
#define UE (unsigned char) 154
#define ue (unsigned char) 129
typedef struct c_wuerfel {
struct colors {
unsigned int rosa[6];
unsigned int gruen[6];
unsigned int weis[6];
unsigned int schwarz[6];
} colors;
unsigned int result;
unsigned int color[6];
unsigned int count;
char color_c;
} c_wuerfel;
void roll_colored_dice (c_wuerfel* w) {
srand(time(NULL));
for (int i = 0; i < w->count; i++) {
w->result += w->color[rand() % ARR_SIZE(w->color)];
}
}
c_wuerfel* create_colored_dice (const char* color, int amount) {
c_wuerfel* act = malloc(sizeof (c_wuerfel));
act->result = 0;
act->color_c = ' ';
act->count = 0;
act->colors.rosa[0] = 0;
act->colors.rosa[1] = 0;
act->colors.rosa[2] = 0;
act->colors.rosa[3] = 1;
act->colors.rosa[4] = 1;
act->colors.rosa[5] = 2;
act->colors.gruen[0] = 0;
act->colors.gruen[1] = 0;
act->colors.gruen[2] = 1;
act->colors.gruen[3] = 1;
act->colors.gruen[4] = 2;
act->colors.gruen[5] = 2;
act->colors.weis[0] = 0;
act->colors.weis[1] = 1;
act->colors.weis[2] = 2;
act->colors.weis[3] = 2;
act->colors.weis[4] = 2;
act->colors.weis[5] = 3;
act->colors.schwarz[0] = 0;
act->colors.schwarz[1] = 1;
act->colors.schwarz[2] = 2;
act->colors.schwarz[3] = 2;
act->colors.schwarz[4] = 3;
act->colors.schwarz[5] = 4;
act->count = amount;
if (color[0] == 'r' || color[0] == 'R') {
for (int i = 0; i < 6; i++) {
act->color[i] = act->colors.rosa[i];
}
act->color_c = 'r';
} else if (color[0] == 'g' || color[0] == 'G') {
for (int i = 0; i < 6; i++) {
act->color[i] = act->colors.gruen[i];
}
act->color_c = 'g';
} else if (color[0] == 'w' || color[0] == 'W') {
for (int i = 0; i < 6; i++) {
act->color[i] = act->colors.weis[i];
}
act->color_c = 'w';
} else if (color[0] == 's' || color[0] == 'S') {
for (int i = 0; i < 6; i++) {
act->color[i] = act->colors.schwarz[i];
}
act->color_c = 's';
} else {
#ifdef WINDOWS
printf("Unbekannte W%crfelfarbe %s\n", ue, color);
printf("Rosa wurde automatisch ausgew%chlt", ae);
#else
printf("Unbekannte Würfelfarbe %s\n", color);
printf("Rosa wurde automatisch ausgewählt");
#endif
for (int i = 0; i < 6; i++) {
act->color[i] = act->colors.rosa[i];
}
act->color_c = 'r';
}
return act;
}
void print_result (c_wuerfel* w) {
switch (w->color_c) {
#ifdef WINDOWS
case 'r':
printf("Rosa W%crfel: %u\n", ue, w->result);
break;
case 'g':
printf("Gr%cner W%crfel: %u\n", ue, ue, w->result);
break;
case 'w':
printf("Wei%cer W%crfel: %u\n", ss, ue, w->result);
break;
case 's':
printf("Schwarzer W%crfel: %u\n", ue, w->result);
break;
default:
printf("How did I got to this point? %c\n", w->color_c);
break;
#else
case 'r':
printf("Rosa Würfel: %u\n", w->result);
break;
case 'g':
printf("Gruener Würfel: %u\n", w->result);
break;
case 'w':
printf("Weißer Würfel: %u\n", w->result);
break;
case 's':
printf("Schwarzer Würfel: %u\n", w->result);
break;
default:
printf("How did I got to this point? %c\n", w->color_c);
break;
#endif
}
}