[svn] r5862: nemerle/trunk/snippets/the-game: Makefile console.n dice.n generator.n map.n person.n territo...

malekith svnadmin at nemerle.org
Fri Oct 28 00:40:54 CEST 2005


Log:
Convert it to indentation syntax, as a bigger testcase.

Author: malekith
Date: Fri Oct 28 00:40:53 2005
New Revision: 5862

Modified:
   nemerle/trunk/snippets/the-game/Makefile
   nemerle/trunk/snippets/the-game/console.n
   nemerle/trunk/snippets/the-game/dice.n
   nemerle/trunk/snippets/the-game/generator.n
   nemerle/trunk/snippets/the-game/map.n
   nemerle/trunk/snippets/the-game/person.n
   nemerle/trunk/snippets/the-game/territory.n

Modified: nemerle/trunk/snippets/the-game/Makefile
==============================================================================
--- nemerle/trunk/snippets/the-game/Makefile	(original)
+++ nemerle/trunk/snippets/the-game/Makefile	Fri Oct 28 00:40:53 2005
@@ -1,2 +1,12 @@
-all:
-	ncc -o TheGame.exe console.n generator.n map.n person.n territory.n dice.n
+include ../../config.mak
+NCC = $(EXECUTE) ../../ncc/out.stage3/ncc.exe
+SOURCES = console.n generator.n map.n person.n territory.n dice.n
+
+all: TheGame.exe
+
+TheGame.exe: $(SOURCES)
+	$(NCC) -i -o $@ $(SOURCES)
+
+
+clean:
+	rm -f TheGame.exe

Modified: nemerle/trunk/snippets/the-game/console.n
==============================================================================
--- nemerle/trunk/snippets/the-game/console.n	(original)
+++ nemerle/trunk/snippets/the-game/console.n	Fri Oct 28 00:40:53 2005
@@ -1,127 +1,98 @@
-using System;
-using Nemerle;
+using System
+using Nemerle
 
-struct ColoredChar {
-  public Char : char;
-  public Foreground : ConsoleColor;
-  public Background : ConsoleColor;
+struct ColoredChar
+  public Char : char
+  public Foreground : ConsoleColor
+  public Background : ConsoleColor
 
   public this (ch : Char, 
                fg : ConsoleColor = ConsoleColor.Gray, 
                bg : ConsoleColor = ConsoleColor.Black)
-  {
-    this.Char = ch;
-    Foreground = fg;
-    Background = bg;
-  }
+    this.Char = ch
+    Foreground = fg
+    Background = bg
 
-  [OverrideObjectEquals]
+  [OverrideObjectEquals] \
   public Equals (other : ColoredChar) : bool
-  {
-    Char == other.Char && 
-    Foreground == other.Foreground && 
-    Background == other.Background
-  }
-}
+    Char == other.Char
+      && Foreground == other.Foreground
+      && Background == other.Background
 
 module ConsoleBuffer
-{
-  mutable current_fg : ConsoleColor = ConsoleColor.Gray;
-  mutable current_bg : ConsoleColor = ConsoleColor.Black;
+  mutable current_fg : ConsoleColor = ConsoleColor.Gray
+  mutable current_bg : ConsoleColor = ConsoleColor.Black
 
-  mutable cur_x : int;
-  mutable cur_y : int;
+  mutable cur_x : int
+  mutable cur_y : int
 
-  screen : array [2, ColoredChar];
-  real_screen : array [2, ColoredChar];
+  screen : array [2, ColoredChar]
+  real_screen : array [2, ColoredChar]
 
-  width : int;
-  height : int;
+  width : int
+  height : int
 
   public Flush () : void
-  {
-    for (mutable y = 0; y < height; ++y) {
-      mutable first_x = -1;
-      mutable last_x = -1;
-      
-      for (mutable x = 0; x < width; ++x) {
-        when (! screen [x, y].Equals (real_screen [x, y])) {
-          when (first_x == -1) first_x = x;
-          last_x = x;
-        }
-      }
-
-      when (last_x != -1) {
-        Console.SetCursorPosition (1 + first_x, y + 1);
-        while (first_x <= last_x) {
-          def ch = screen [first_x, y];
-          real_screen [first_x, y] = ch;
-          DoSetColor (ch.Foreground, ch.Background);
-          Console.Write (ch.Char);
-          first_x++;
-        }
-      }
-    }
+    for (mutable y = 0; y < height; ++y)
+      mutable first_x = -1
+      mutable last_x = -1
+      
+      for (mutable x = 0; x < width; ++x)
+        when (! screen [x, y].Equals (real_screen [x, y]))
+          when (first_x == -1) first_x = x
+          last_x = x
+
+      when (last_x != -1)
+        Console.SetCursorPosition (1 + first_x, y + 1)
+        while (first_x <= last_x)
+          def ch = screen [first_x, y]
+          real_screen [first_x, y] = ch
+          DoSetColor (ch.Foreground, ch.Background)
+          Console.Write (ch.Char)
+          first_x++
     
-    Console.SetCursorPosition (width - 1, height - 1);
-  }
+    Console.SetCursorPosition (width - 1, height - 1)
 
   public Clear () : void
-  {
     for (mutable y = 0; y < height; ++y)
       for (mutable x = 0; x < width; ++x)
-        screen [x, y] = ColoredChar (' ');
-  }
+        screen [x, y] = ColoredChar (' ')
 
   public Goto (x : int, y : int) : void
-  {
-    cur_x = x;
-    cur_y = y;
-  }
+    cur_x = x
+    cur_y = y
 
   public DrawChar (ch : ColoredChar) : void
-  {
-    screen [cur_x, cur_y] = ch;
-    cur_x++;
-    when (cur_x == width) {
-      cur_x = 0;
-      cur_y++;
+    screen [cur_x, cur_y] = ch
+    cur_x++
+    when (cur_x == width)
+      cur_x = 0
+      cur_y++
       when (cur_y == height)
-        cur_y = 0;
-    }
-  }
+        cur_y = 0
 
   public DrawString (s : string,
                      fg : ConsoleColor = ConsoleColor.Gray, 
                      bg : ConsoleColor = ConsoleColor.Black) : void
-  {
     foreach (ch in s)
       DrawChar (ColoredChar (ch, fg, bg))
-  }
 
   DoSetColor (fg : ConsoleColor, bg : ConsoleColor) : void
-  {
-    when (fg != current_fg) {
-      def is_high = fg :> int > ConsoleColor.Gray :> int;
+    when (fg != current_fg)
+      def is_high = fg :> int > ConsoleColor.Gray :> int
 
       when (!is_high)
-        Console.Write ("");
-      Console.ForegroundColor = fg;
+        Console.Write ("")
+      Console.ForegroundColor = fg
       when (is_high)
-        Console.Write ("");
-      current_fg = fg;
-    }
-    when (bg != current_bg) {
-      Console.BackgroundColor = fg;
-      current_bg = bg;
-    }
-  }
+        Console.Write ("")
+      current_fg = fg
+    when (bg != current_bg)
+      Console.BackgroundColor = fg
+      current_bg = bg
 
   this ()
-  {
-    width = Console.WindowWidth - 1;
-    height = Console.WindowHeight - 1;
-    screen = array (width, height);
-    real_screen = array (width, height);
-  }
-}
+    width = Console.WindowWidth - 1
+    height = Console.WindowHeight - 1
+    screen = array (width, height)
+    real_screen = array (width, height)

Modified: nemerle/trunk/snippets/the-game/dice.n
==============================================================================
--- nemerle/trunk/snippets/the-game/dice.n	(original)
+++ nemerle/trunk/snippets/the-game/dice.n	Fri Oct 28 00:40:53 2005
@@ -1,18 +1,12 @@
 module Dice
-{
-  rand : System.Random = System.Random ();
+  rand : System.Random = System.Random ()
 
   // 2d6 kind of stuff
   public Roll (amount : int, max : int) : int
-  {
     if (amount == 1)
       rand.Next (max) + 1
     else
       rand.Next (max) + 1 + Roll (amount - 1, max)
-  }
   
   public Roll (max : int) : int
-  {
     Roll (1, max)
-  }
-}

Modified: nemerle/trunk/snippets/the-game/generator.n
==============================================================================
--- nemerle/trunk/snippets/the-game/generator.n	(original)
+++ nemerle/trunk/snippets/the-game/generator.n	Fri Oct 28 00:40:53 2005
@@ -1,112 +1,90 @@
 
 class MapGenerator
-{
-  fork_pbb = 0.05;
-  turn_pbb = 0.05;
+  fork_pbb = 0.05
+  turn_pbb = 0.05
 
-  map : array [2, bool];
-  mutable room_locations : list [int * int] = [];
+  map : array [2, bool]
+  mutable room_locations : list [int * int] = []
 
-  rand : System.Random = System.Random ();
+  rand : System.Random = System.Random ()
 
   MaybeRoom (x : int, y : int) : void
-  {
     when (rand.NextDouble () < 0.9)
       room_locations ::= (x, y)
-  }
  
   Path (x : int, y : int, dir : int) : void
-  {
-    if (x < 1 || y < 1 || x > width - 2 || y > height - 2) {
+    if (x < 1 || y < 1 || x > width - 2 || y > height - 2)
       MaybeRoom (x, y)
-    } else if (map [x, y]) {
-    } else {
-      if (rand.NextDouble () < fork_pbb) {
+    else if (map [x, y]) {}
+    else
+      if (rand.NextDouble () < fork_pbb)
+        when (rand.NextDouble () < 0.5)
+          Path (x, y, dir + 1)
         when (rand.NextDouble () < 0.5)
-          Path (x, y, dir + 1);
-        when (rand.NextDouble () < 0.5) {
-          map [x, y] = false;
+          map [x, y] = false
           Path (x, y, dir + 3)
-        }
         when (rand.NextDouble () < 0.1)
-          MaybeRoom (x, y);
-        map [x, y] = false;
+          MaybeRoom (x, y)
+        map [x, y] = false
         Path (x, y, dir)
-      } else if (rand.NextDouble () < turn_pbb) {
+      else if (rand.NextDouble () < turn_pbb)
         if (rand.NextDouble () < 0.5)
           Path (x, y, dir + 1)
         else
           Path (x, y, dir + 3)
-      } else {
-        map [x, y] = true;
+      else
+        map [x, y] = true
         def (x, y) =
-          match (dir % 4) {
+          match (dir % 4)
             | 0 => (x + 1, y)
             | 1 => (x, y - 1)
             | 2 => (x - 1, y)
             | 3 => (x, y + 1)
             | _ => assert (false)
-          }
-        Path (x, y, dir);
+        Path (x, y, dir)
         when (rand.NextDouble () < 0.05)
           MaybeRoom (x, y)
-      }
-    }
-  }
 
-  width : int;
-  height : int;
+  width : int
+  height : int
 
   public this (w : int, h : int)
-  {
-    width = w;
-    height = h;
-    map = array (w, h);
-  }
+    width = w
+    height = h
+    map = array (w, h)
 
   MapOK () : bool
-  {
-    mutable free = 0;
+    mutable free = 0
     
     for (mutable i = 0; i < width; ++i)
       for (mutable j = 0; j < height; ++j)
-        when (map [i, j]) free++;
+        when (map [i, j]) free++
     
     if (free * 10 > width * height)
       true
-    else {
-      room_locations = [];
+    else
+      room_locations = []
       for (mutable i = 0; i < width; ++i)
         for (mutable j = 0; j < height; ++j)
-          map [i, j] = false;
+          map [i, j] = false
       false
-    }
-  }
 
   DigRooms () : void
-  {
-    def dig (x, y) {
+    def dig (x, y)
       when (x >= 1 && y >= 1 && x <= width - 2 && y <= height - 2)
         map [x, y] = true
-    }
     
-    foreach ((x, y) in room_locations) {
-      def rx = Dice.Roll (3, 3) - 2;
-      def ry = Dice.Roll (2, 3) - 2;
+    foreach ((x, y) in room_locations)
+      def rx = Dice.Roll (3, 3) - 2
+      def ry = Dice.Roll (2, 3) - 2
       for (mutable i = x - rx; i <= x + rx; ++i)
         for (mutable j = y - ry; j <= y + ry; ++j)
           dig (i, j)
-    }
-  }
 
   public Generate () : array [2, bool]
-  {
-    Path (width / 2, height / 2, rand.Next (4));
-    if (MapOK ()) {
-      DigRooms ();
+    Path (width / 2, height / 2, rand.Next (4))
+    if (MapOK ())
+      DigRooms ()
       map 
-    }
     else Generate ()
-  }
-}
 

Modified: nemerle/trunk/snippets/the-game/map.n
==============================================================================
--- nemerle/trunk/snippets/the-game/map.n	(original)
+++ nemerle/trunk/snippets/the-game/map.n	Fri Oct 28 00:40:53 2005
@@ -1,198 +1,155 @@
-using System;
-using Nemerle;
-using Nemerle.Utility;
+using System
+using Nemerle
+using Nemerle.Utility
 
 abstract class MapObject
-{
-  [Accessor]
-  mutable map : WorldMap;
-
-  [Accessor]
-  mutable x : int;
-  [Accessor]
-  mutable y : int;
+  [Accessor] \
+  mutable map : WorldMap
   
-  public abstract Draw () : void;
+  [Accessor] \
+  mutable x : int
+  [Accessor] \
+  mutable y : int
+  
+  public abstract Draw () : void
 
   public virtual Init (map : WorldMap, x : int, y : int) : void
-  {
-    this.map = map;
-    this.x = x;
-    this.y = y;
-    PostInit ();
-  }
+    this.map = map
+    this.x = x
+    this.y = y
+    PostInit ()
 
   protected virtual PostInit () : void {}
 
   public virtual CanEnter : bool
-  {
     get { false }
-  }
 
   public virtual MoveTo (x : int, y : int) : void
-  {
-    Map [this.x, this.y] = Map [this.x, this.y].Filter (_ != this : object);
-    this.x = x;
-    this.y = y;
-    Map [x, y] ::= this;
-  }
+    Map [this.x, this.y] = Map [this.x, this.y].Filter (_ != this : object)
+    this.x = x
+    this.y = y
+    Map [x, y] ::= this
 
   // returns distance squered
   public virtual DistanceTo (target : MapObject) : int
-  {
-    def dx = X - target.X;
-    def dy = Y - target.Y;
+    def dx = X - target.X
+    def dy = Y - target.Y
     dx * dx + dy * dy
-  }
   
-  public virtual PerformMove () : void
-  {
-  }
+  public virtual PerformMove () : void {}
 
   public abstract Name : string { get; }
 
   public virtual Attack (from : MapObject, _damage : int) : void
-  {
     when (from.IsPlayer)
-      Map.Message ($ "You attack the $(Name). It doesn't seem to be impressed.");
-  }
+      Map.Message ($ "You attack the $(Name). It doesn't seem to be impressed.")
 
   public virtual IsPlayer : bool { get { false } }
-}
 
-class WorldMap {
-  width = 78;
-  height = 20;
+class WorldMap
+  width = 78
+  height = 20
 
-  mutable status : string = "";
+  mutable status : string = ""
 
-  [Accessor (flags = WantSetter)]
-  mutable show_all : bool = false;
+  [Accessor (flags = WantSetter)] \
+  mutable show_all : bool = false
 
-  map : array [2, list [MapObject]];
+  map : array [2, list [MapObject]]
 
-  [Accessor]
-  mutable player : Player;
+  [Accessor] \
+  mutable player : Player
 
   public Item [x : int, y : int] : list [MapObject]
-  {
-    get {
+    get
       if (x < 0 || y < 0 || x >= width || y >= height)
         []
       else
         map [x, y]
-    }
     set { map [x, y] = value }
-  }
 
   public this ()
-  {
-    map = array (width, height);
-    ResetMap ();
-  }
+    map = array (width, height)
+    ResetMap ()
 
   public IterMap (f : MapObject -> void) : void
-  {
     for (mutable y = 0; y < height; ++y)
       for (mutable x = 0; x < width; ++x)
-        map [x, y].Iter (f);
-  }
+        map [x, y].Iter (f)
 
   public ResetMap () : void
-  {
-    def gen = MapGenerator (width, height);
-    def bool_map = gen.Generate ();
+    def gen = MapGenerator (width, height)
+    def bool_map = gen.Generate ()
     
     for (mutable x = 0; x < width; ++x)
-      for (mutable y = 0; y < height; ++y) {
+      for (mutable y = 0; y < height; ++y)
         def f = 
           if (bool_map [x, y])
             Floor ()
           else 
-            Wall ();
-        map [x, y] = [f];
-        f.Init (this, x, y);
-      }
-
-    player = Player ();
-    player.Init (this, width / 2, height / 2);
-    map [player.X, player.Y] ::= player;
+            Wall ()
+        map [x, y] = [f]
+        f.Init (this, x, y)
+
+    player = Player ()
+    player.Init (this, width / 2, height / 2)
+    map [player.X, player.Y] ::= player
 
-    def add_enemies (n) {
+    def add_enemies (n)
       if (n < 0) {}
-      else {
-        def x = Dice.Roll (width) - 1;
-        def y = Dice.Roll (height) - 1;
-        match (map [x, y]) {
+      else
+        def x = Dice.Roll (width) - 1
+        def y = Dice.Roll (height) - 1
+        match (map [x, y])
           | [_ is Floor] =>
-            def e = EnemyUnknown ();
-            map [x, y] ::= e;
-            e.Init (this, x, y);
+            def e = EnemyUnknown ()
+            map [x, y] ::= e
+            e.Init (this, x, y)
             add_enemies (n - 1)
           | _ => add_enemies (n)
-        }
-      }
-    }
 
-    add_enemies (5);
-  }
+    add_enemies (5)
 
   public Message (msg : string) : void
-  {
-    status += $"$msg ";
-  }
+    status += $"$msg "
 
   public Draw () : void
-  {
-    ConsoleBuffer.Clear ();
+    ConsoleBuffer.Clear ()
     for (mutable y = 0; y < height; ++y)
-      for (mutable x = 0; x < width; ++x) {
-        ConsoleBuffer.Goto (x + 1, y + 1);
-        map [x, y].Head.Draw ();
-      }
-    ConsoleBuffer.Goto(0, height);
+      for (mutable x = 0; x < width; ++x)
+        ConsoleBuffer.Goto (x + 1, y + 1)
+        map [x, y].Head.Draw ()
+    ConsoleBuffer.Goto(0, height)
     ConsoleBuffer.DrawString ($ 
       "Vit: $(player.Vitality)($(player.MaxVitality)) "
       "Str: $(player.Strength) "
-      "Sta: $(player.Stamina)", ConsoleColor.Green);
-    ConsoleBuffer.Goto(0, height + 1);
-    ConsoleBuffer.DrawString (status, ConsoleColor.Yellow);
-    status = "";
+      "Sta: $(player.Stamina)", ConsoleColor.Green)
+    ConsoleBuffer.Goto(0, height + 1)
+    ConsoleBuffer.DrawString (status, ConsoleColor.Yellow)
+    status = ""
 
-    ConsoleBuffer.Flush ();
-  }
+    ConsoleBuffer.Flush ()
 
   public PlayerCanSee (target : MapObject) : bool
-  {
     player.DistanceTo (target) < 15
-  }
 
   public PerformMove () : void
-  {
     IterMap (fun (x) {
       unless (x.IsPlayer)
         x.PerformMove ();
-    });
-    player.PerformMove ();
-  }
+    })
+    player.PerformMove ()
   
   public MainLoop () : void
-  {
-    try {
-      while (true) {
-        Draw ();
-        PerformMove ();
-      }
-    } catch {
+    try
+      while (true)
+        Draw ()
+        PerformMove ()
+    catch
       | e =>
-        Console.WriteLine (e);
-        _ = Console.ReadLine ();
-    }
-  }
+        Console.WriteLine (e)
+        _ = Console.ReadLine ()
 
   public static Main () : void
-  {
-    def world = WorldMap ();
-    world.MainLoop ();
-  }
-}
+    def world = WorldMap ()
+    world.MainLoop ()

Modified: nemerle/trunk/snippets/the-game/person.n
==============================================================================
--- nemerle/trunk/snippets/the-game/person.n	(original)
+++ nemerle/trunk/snippets/the-game/person.n	Fri Oct 28 00:40:53 2005
@@ -1,159 +1,119 @@
-using System;
-using Nemerle;
-using Nemerle.Utility;
+using System
+using Nemerle
+using Nemerle.Utility
 
 abstract class Person : MapObject
-{
-  [Accessor]
-  protected mutable stamina : int = Dice.Roll (5, 3);
-  [Accessor]
-  protected mutable strength : int = Dice.Roll (5, 3);
-  [Accessor]
-  protected mutable vitality : int = Dice.Roll (5, 3);
-  [Accessor]
-  protected mutable max_vitality : int = vitality;
+  [Accessor] \
+  protected mutable stamina : int = Dice.Roll (5, 3)
+  [Accessor] \
+  protected mutable strength : int = Dice.Roll (5, 3)
+  [Accessor] \
+  protected mutable vitality : int = Dice.Roll (5, 3)
+  [Accessor] \
+  protected mutable max_vitality : int = vitality
 
-  protected mutable healing_every : int = Dice.Roll (5, 3);
-  protected mutable healing_for : int;
+  protected mutable healing_every : int = Dice.Roll (5, 3)
+  protected mutable healing_for : int
 
   public virtual Health : string
-  {
-    get {
-      match (vitality * 4 / max_vitality) {
+    get
+      match (vitality * 4 / max_vitality)
         | 0 => "badly damaged"
         | 1 => "bleeding"
         | 2 => "damaged"
         | _ => "still OK"
-      }
-    }
-  }
 
   public virtual Die () : void
-  {
-    Map [X, Y] = Map [X, Y].Filter (_ != this : object);
-  }
+    Map [X, Y] = Map [X, Y].Filter (_ != this : object)
 
   public override Attack (from : MapObject, damage : int) : void
-  {
-    if (damage < stamina) {
+    if (damage < stamina)
       when (from.IsPlayer)
-        Map.Message ($ "You didn't even scratch $Name.");
-    } else {
-      healing_for = 0;
-      vitality -= damage - stamina;
-      if (vitality <= 0) {
+        Map.Message ($ "You didn't even scratch $Name.")
+    else
+      healing_for = 0
+      vitality -= damage - stamina
+      if (vitality <= 0)
         when (from.IsPlayer)
-          Map.Message ($ "You killed $Name.");
-        Die ();
-      } else {
+          Map.Message ($ "You killed $Name.")
+        Die ()
+      else
         when (from.IsPlayer)
-          Map.Message ($ "You hit $Name, it's $Health.");
-      }
-    }
-  }
+          Map.Message ($ "You hit $Name, it's $Health.")
 
   public override PerformMove () : void
-  {
-    when (vitality < max_vitality) {
-      if (healing_for >= healing_every) {
-        healing_for = 0;
-        vitality++;
-      } else
-        healing_for++;
-    }
-  }
+    when (vitality < max_vitality)
+      if (healing_for >= healing_every)
+        healing_for = 0
+        vitality++
+      else
+        healing_for++
 
   public MoveOrKill (x : int, y : int) : void
-  {
-    match (Map [x, y].Filter (fun (x) { ! x.CanEnter })) {
+    match (Map [x, y].Filter (fun (x) { ! x.CanEnter }))
       | [] => MoveTo (x, y)
       | x :: _ =>
         x.Attack (this, Strength / 2 + Dice.Roll (6))
-    } 
-  }
 
   public RandomMove () : void
-  {
-    def try_move (x, y) {
+    def try_move (x, y)
       MoveOrKill (x, y)
-    }
     
-    match (Dice.Roll (4)) {
+    match (Dice.Roll (4))
       | 1 => try_move (X - 1, Y)
       | 2 => try_move (X, Y - 1)
       | 3 => try_move (X + 1, Y)
       | _ => try_move (X, Y + 1)
-    }
-  }
-}
 
 class EnemyUnknown : Person
-{
-  mutable hostile : bool;
+  mutable hostile : bool
 
   public override Draw () : void
-  {
     when (Map.PlayerCanSee (this))
-      ConsoleBuffer.DrawChar (ColoredChar ('K', ConsoleColor.Red));
-  }
+      ConsoleBuffer.DrawChar (ColoredChar ('K', ConsoleColor.Red))
 
   public override PerformMove () : void
-  {
     if (hostile && DistanceTo (Map.Player) == 1)
       MoveOrKill (Map.Player.X, Map.Player.Y)
     else
-      RandomMove ();
-  }
+      RandomMove ()
 
   public override Attack (from : MapObject, damage : int) : void
-  {
     when (from.IsPlayer)
-      hostile = true;
+      hostile = true
     base.Attack (from, damage)
-  }
 
   public override Name : string { get { "enemy unknown" } }
-}
 
 class Player : Person
-{
   public override Draw () : void
-  {
-    ConsoleBuffer.DrawChar (ColoredChar ('@', ConsoleColor.Cyan));
-  }
+    ConsoleBuffer.DrawChar (ColoredChar ('@', ConsoleColor.Cyan))
 
   public override PerformMove () : void
-  {
     base.PerformMove (); // heal
 
-    def key = Console.ReadKey (true);
+    def key = Console.ReadKey (true)
     def (x, y) =
-      match (key.Key) {
+      match (key.Key)
         | LeftArrow => (X - 1, Y)
         | RightArrow => (X + 1, Y)
         | UpArrow => (X, Y - 1)
         | DownArrow => (X, Y + 1)
         | _ => (X, Y)
-      }
     if (x != X || y != Y)
       MoveOrKill (x, y)
     else
-      match (key.KeyChar) {
-        | 'r' => Map.ResetMap ();
-        | 's' => Map.ShowAll = ! Map.ShowAll;
-        | 'q' => System.Environment.Exit (0);
+      match (key.KeyChar)
+        | 'r' => Map.ResetMap ()
+        | 's' => Map.ShowAll = ! Map.ShowAll
+        | 'q' => System.Environment.Exit (0)
         | _ => 
           Map.Message ("Move with arrows, [h] for help!")
-      }
-  }
 
   public override Attack (from : MapObject, damage : int) : void
-  {
-    Map.Message ($ "The $(from.Name) attacks you.");
-    base.Attack (from, damage);
-  }
+    Map.Message ($ "The $(from.Name) attacks you.")
+    base.Attack (from, damage)
   
   public override Name : string { get { "player" } }
   public override IsPlayer : bool { get { true } }
-}
 

Modified: nemerle/trunk/snippets/the-game/territory.n
==============================================================================
--- nemerle/trunk/snippets/the-game/territory.n	(original)
+++ nemerle/trunk/snippets/the-game/territory.n	Fri Oct 28 00:40:53 2005
@@ -1,82 +1,59 @@
-using System;
-using Nemerle;
-using Nemerle.Utility;
+using System
+using Nemerle
+using Nemerle.Utility
 
 abstract class Territory : MapObject
-{
-  protected DisplayWhenVisible : ColoredChar;
-  protected DisplayWhenSeen : ColoredChar;
-  protected DisplayWhenUnseen : ColoredChar = ColoredChar (' ');
+  protected DisplayWhenVisible : ColoredChar
+  protected DisplayWhenSeen : ColoredChar
+  protected DisplayWhenUnseen : ColoredChar = ColoredChar (' ')
 
-  protected mutable ever_seen : bool;
+  protected mutable ever_seen : bool
   
   public override Draw () : void
-  {
-    if (Map.PlayerCanSee (this)) {
-      ever_seen = true;
+    if (Map.PlayerCanSee (this))
+      ever_seen = true
       ConsoleBuffer.DrawChar (DisplayWhenVisible)
-    } else if (ever_seen || Map.ShowAll)
+    else if (ever_seen || Map.ShowAll)
       ConsoleBuffer.DrawChar (DisplayWhenSeen)
     else
       ConsoleBuffer.DrawChar (DisplayWhenUnseen)
-  }
-}
 
 class Floor : Territory
-{
   public this ()
-  {
-    DisplayWhenVisible = ColoredChar ('.', ConsoleColor.Yellow);
-    DisplayWhenSeen = ColoredChar ('.', ConsoleColor.Gray);
-  }
+    DisplayWhenVisible = ColoredChar ('.', ConsoleColor.Yellow)
+    DisplayWhenSeen = ColoredChar ('.', ConsoleColor.Gray)
 
   public override CanEnter : bool
-  {
     get { true }
-  }
 
   public override Name : string
-  {
     get { "floor" }
-  }
-}
 
 class Wall : Territory
-{
   public this ()
-  {
-    DisplayWhenVisible = ColoredChar ('#', ConsoleColor.DarkYellow);
-    DisplayWhenSeen = DisplayWhenVisible;
-  }
+    DisplayWhenVisible = ColoredChar ('#', ConsoleColor.DarkYellow)
+    DisplayWhenSeen = DisplayWhenVisible
 
   Visible : bool
-  {
-    [Memoize]
-    get {
+    [Memoize] \
+    get
       def check (x, y) { Map [x, y].Exists (_.CanEnter) }
 
-      check (X - 1, Y - 1) ||
-      check (X + 1, Y - 1) ||
-      check (X - 1, Y + 1) ||
-      check (X + 1, Y + 1) ||
-      check (X - 1, Y) ||
-      check (X, Y - 1) ||
-      check (X, Y + 1) ||
-      check (X + 1, Y)
-    }
-  }
+      check (X - 1, Y - 1)
+        || check (X + 1, Y - 1)
+        || check (X - 1, Y + 1)
+        || check (X + 1, Y + 1)
+        || check (X - 1, Y)
+        || check (X, Y - 1)
+        || check (X, Y + 1)
+        || check (X + 1, Y)
   
 
   public override Draw () : void
-  {
     if (Visible)
       base.Draw ()
     else
-      ConsoleBuffer.DrawChar (DisplayWhenUnseen);
-  }
+      ConsoleBuffer.DrawChar (DisplayWhenUnseen)
 
   public override Name : string
-  {
     get { "wall" }
-  }
-}



More information about the svn mailing list