xplshn
·
2025-09-14
enums3.bx
Bx
1extrn printf;
2
3type enum Color {
4 RED,
5 GREEN,
6 BLUE,
7 YELLOW
8};
9
10type struct Shape {
11 shape_color Color;
12 x_pos int;
13 y_pos int;
14};
15
16Shape create_shape(c Color, x int, y int) {
17 new_shape := Shape{};
18 new_shape.shape_color = c;
19 new_shape.x_pos = x;
20 new_shape.y_pos = y;
21 return (new_shape);
22}
23
24void print_shape(s Shape) {
25 color_names := []*byte{ "RED", "GREEN", "BLUE", "YELLOW" };
26 printf("Shape: %s at (%d, %d)\n",
27 color_names[s.shape_color], s.x_pos, s.y_pos);
28}
29
30void move_shape(s *Shape, dx int, dy int) {
31 s.x_pos = s.x_pos + dx;
32 s.y_pos = s.y_pos + dy;
33}
34
35int get_shape_x(s Shape) {
36 return (s.x_pos);
37}
38
39int main() {
40 printf("Creating a RED shape...\n");
41
42 auto sp = create_shape(RED, 10, 20);
43 print_shape(sp);
44
45 printf("\nMoving shape...\n");
46 move_shape(&sp, 5, -5);
47 print_shape(sp);
48
49 printf("\nChanging color...\n");
50 colors := []Color{ RED, GREEN, BLUE, YELLOW };
51 sp.shape_color = colors[(int(sp.shape_color) + 1) % 4];
52 print_shape(sp);
53
54 printf("\nFinal X position: %d\n", get_shape_x(sp));
55
56 return (0);
57}