221V 3 days ago
parent
commit
beaa01f5a4
1 changed files with 46 additions and 37 deletions
  1. 46 37
      exercises/038_structs2.zig

+ 46 - 37
exercises/038_structs2.zig

@@ -8,47 +8,55 @@
 //
 //
 const std = @import("std");
 const std = @import("std");
 
 
-const Role = enum {
-    wizard,
-    thief,
-    bard,
-    warrior,
+const Role = enum{
+  wizard,
+  thief,
+  bard,
+  warrior,
 };
 };
 
 
-const Character = struct {
-    role: Role,
-    gold: u32,
-    health: u8,
-    experience: u32,
+const Character = struct{
+  role: Role,
+  gold: u32,
+  health: u8,
+  experience: u32,
 };
 };
 
 
-pub fn main() void {
-    var chars: [2]Character = undefined;
-
-    // Glorp the Wise
-    chars[0] = Character{
-        .role = Role.wizard,
-        .gold = 20,
-        .health = 100,
-        .experience = 10,
-    };
-
-    // Please add "Zump the Loud" with the following properties:
-    //
-    //     role       bard
-    //     gold       10
-    //     health     100
-    //     experience 20
-    //
-    // Feel free to run this program without adding Zump. What does
-    // it do and why?
-
-    // Printing all RPG characters in a loop:
-    for (chars, 0..) |c, num| {
-        std.debug.print("Character {} - G:{} H:{} XP:{}\n", .{
-            num + 1, c.gold, c.health, c.experience,
-        });
-    }
+pub fn main() void{
+  var chars: [2]Character = undefined;
+  
+  // Glorp the Wise
+  chars[0] = Character{
+    .role = Role.wizard,
+    .gold = 20,
+    .health = 100,
+    .experience = 10,
+  };
+  
+  // Zump the Loud
+  chars[1] = Character{
+    .role = Role.bard,
+    .gold = 10,
+    .health = 100,
+    .experience = 20,
+  };
+  
+  // Please add "Zump the Loud" with the following properties:
+  //
+  //     role       bard
+  //     gold       10
+  //     health     100
+  //     experience 20
+  //
+  // Feel free to run this program without adding Zump. What does
+  // it do and why?
+  
+  // Printing all RPG characters in a loop:
+  for(chars, 0..) |c, num|{
+    std.debug.print("Character {} - G:{} H:{} XP:{}\n", .{
+      num + 1, c.gold, c.health, c.experience,
+    });
+  }
 }
 }
 
 
 // If you tried running the program without adding Zump as mentioned
 // If you tried running the program without adding Zump as mentioned
@@ -56,3 +64,4 @@ pub fn main() void {
 // (which is the default), Zig writes the repeating pattern "10101010"
 // (which is the default), Zig writes the repeating pattern "10101010"
 // in binary (or 0xAA in hex) to all undefined locations to make them
 // in binary (or 0xAA in hex) to all undefined locations to make them
 // easier to spot when debugging.
 // easier to spot when debugging.
+