Esempio n. 1
0
 public override void Execute(Dwarf d, World w)
 {
     int rocks = w.Cave[d.Position].Rocks;
     if (d.Rocks > rocks)
     {
         new Dump().Execute(d, w);
     }
 }
Esempio n. 2
0
 public override bool Execute(Dwarf dwarf, World world)
 {
     dwarf.Position -= 1;
     if (dwarf.Position == 0)
     {
         Trace.WriteLine(dwarf.Name + " walked into magma and perished");
         return false;
     }
     return true;
 }
Esempio n. 3
0
        public void ShortParse(string s)
        {
            routines = new Dictionary<string, List<Instruction>>();
            dwarves = new List<Dwarf>();

            var currentRoutine = "";
            int name = 1;

            foreach (char c in s.ToLowerInvariant())
            {
                if (c == '+')
                {
                    string newname = name.ToString();
                    List<Instruction> instructions = new List<Instruction>();
                    Dwarf d = new Dwarf(newname, instructions);
                    dwarves.Add(d);
                    routines.Add(newname, instructions);
                    currentRoutine = newname;
                    name++;
                }
                else if (c == '-')
                {
                    string newname = name.ToString();
                    List<Instruction> instructions = new List<Instruction>();
                    routines.Add(newname, instructions);
                    currentRoutine = newname;
                    name++;
                }
                else if (c == '>')
                {
                    routines[currentRoutine].Add(new MoveRight());
                }
                else if (c == '<')
                {
                    routines[currentRoutine].Add(new MoveLeft());
                }
                else if (c == 'm')
                {
                    routines[currentRoutine].Add(new Mine());
                }
                else if (c == 'd')
                {
                    routines[currentRoutine].Add(new Dump());
                }
                else if (c == 'w')
                {
                    routines[currentRoutine].Add(new Work());
                }
            }

            foreach (var d in dwarves)
            {
                d.Instructions = d.Instructions.ToList();
            }
        }
Esempio n. 4
0
        internal void CreateWorkshop(Dwarf dwarf)
        {
            switch(dwarf.Rocks)
            {
                case 1: Cave[dwarf.Position].Workshop = new Trader(); break;
                case 2: Cave[dwarf.Position].Workshop = new ManagerOffice(); break;
                case 3: Cave[dwarf.Position].Workshop = new Appraiser(); break;
                default: Trace.WriteLine(dwarf.Name + " failed to create a workshop with " + dwarf.Rocks + " rocks and went stark raving mad!"); dwarf.Dead = true; return;
            }

            dwarf.Rocks = 0;
        }
Esempio n. 5
0
 public override void Execute(Dwarf d, World w)
 {
     int rocks = w.Cave[d.Position].Rocks;
     if (rocks > 0)
     {
         List<Instruction> toInsert = w.Routines[rocks.ToString()];
         d.Instructions.InsertRange(0, toInsert);
     }
     else
     {
         w.Cave[d.Position].Workshop = null;
     }
 }
Esempio n. 6
0
        public override bool Execute(Dwarf dwarf, World world)
        {
            if (dwarf.Rocks > 0)
            {
                int placeToDrop = dwarf.Position - 1;
                if (placeToDrop > 0)
                {
                    world.Cave[placeToDrop].Rocks += 1;
                }
                dwarf.Rocks -= 1;
            }

            return true;
        }
Esempio n. 7
0
        internal void CreateWorkshop(Dwarf dwarf)
        {
            switch (dwarf.Rocks)
            {
            case 1: Cave[dwarf.Position].Workshop = new Trader(); break;

            case 2: Cave[dwarf.Position].Workshop = new ManagerOffice(); break;

            case 3: Cave[dwarf.Position].Workshop = new Appraiser(); break;

            default: Trace.WriteLine(dwarf.Name + " failed to create a workshop with " + dwarf.Rocks + " rocks and went stark raving mad!"); dwarf.Dead = true; return;
            }

            dwarf.Rocks = 0;
        }
Esempio n. 8
0
 public override bool Execute(Dwarf dwarf, World world)
 {
     lock (world.Cave[dwarf.Position].workLock)
     {
         if (world.Cave[dwarf.Position].Workshop == null)
         {
             world.CreateWorkshop(dwarf);
         }
         else
         {
             world.Cave[dwarf.Position].Workshop.Execute(dwarf, world);
         }
     }
     return(true);
 }
Esempio n. 9
0
 public override void Execute(Dwarf d, World w)
 {
     if (d.Rocks > 0)
     {
         w.WriteChar((char)d.Rocks);
         d.Rocks = 0;
     }
     else
     {
         d.Rocks = w.ReadChar();
         if (d.Rocks == 0)
         {
             Trace.WriteLine(d.Name + " was killed by the traders!");
             d.Dead = true;
         }
     }
 }
Esempio n. 10
0
 public override void Execute(Dwarf d, World w)
 {
     if (d.Rocks > 0)
     {
         w.WriteChar((char)d.Rocks);
         d.Rocks = 0;
     }
     else
     {
         d.Rocks = w.ReadChar();
         if (d.Rocks == 0)
         {
             Trace.WriteLine(d.Name + " was killed by the traders!");
             d.Dead = true;
         }
     }
 }
Esempio n. 11
0
        public override bool Execute(Dwarf dwarf, World world)
        {
            if (dwarf.Rocks > 0)
            {
                int placeToDrop = dwarf.Position - 1;
                if (placeToDrop > 0)
                {
                    lock (world.Cave[placeToDrop].rockLock)
                    {
                        world.Cave[placeToDrop].Rocks += 1;
                    }
                }
                dwarf.Rocks -= 1;
            }

            return(true);
        }
Esempio n. 12
0
        public override bool Execute(Dwarf dwarf, World world)
        {
            int placeToMine = dwarf.Position + 1;

            if (world.Cave[placeToMine].Rocks != 0)
            {
                if (world.Cave[placeToMine].Rocks == -1)
                {
                    world.Cave[placeToMine].Rocks = 64;
                    world.Cave.Add(new Tile(){ Rocks= -1});
                }

                world.Cave[placeToMine].Rocks -= 1;
                dwarf.Rocks += 1;
            }

            return true;
        }
Esempio n. 13
0
        public void ShortParse(string s)
        {
            routines = new Dictionary <string, List <Instruction> >();
            dwarves  = new List <Dwarf>();

            var currentRoutine = "";
            int name           = 1;

            foreach (char c in s.ToLowerInvariant())
            {
                if (c == '+')
                {
                    string             newname      = name.ToString();
                    List <Instruction> instructions = new List <Instruction>();
                    Dwarf d = new Dwarf(newname, instructions);
                    dwarves.Add(d);
                    routines.Add(newname, instructions);
                    currentRoutine = newname;
                    name++;
                }
                else if (c == '-')
                {
                    string             newname      = name.ToString();
                    List <Instruction> instructions = new List <Instruction>();
                    routines.Add(newname, instructions);
                    currentRoutine = newname;
                    name++;
                }
                else
                {
                    var order = ParseChar(c);
                    if (order != null)
                    {
                        routines[currentRoutine].Add(order);
                    }
                }
            }

            foreach (var d in dwarves)
            {
                d.Instructions = d.Instructions.ToList();
            }
        }
Esempio n. 14
0
        public void ShortParse(string s)
        {
            routines = new Dictionary<string, List<Instruction>>();
            dwarves = new List<Dwarf>();

            var currentRoutine = "";
            int name = 1;

            foreach (char c in s.ToLowerInvariant())
            {
                if (c == '+')
                {
                    string newname = name.ToString();
                    List<Instruction> instructions = new List<Instruction>();
                    Dwarf d = new Dwarf(newname, instructions);
                    dwarves.Add(d);
                    routines.Add(newname, instructions);
                    currentRoutine = newname;
                    name++;
                }
                else if (c == '-')
                {
                    string newname = name.ToString();
                    List<Instruction> instructions = new List<Instruction>();
                    routines.Add(newname, instructions);
                    currentRoutine = newname;
                    name++;
                }
                else
                {
                    var order = ParseChar(c);
                    if (order != null)
                    {
                        routines[currentRoutine].Add(order);
                    }
                }
            }

            foreach (var d in dwarves)
            {
                d.Instructions = d.Instructions.ToList();
            }
        }
Esempio n. 15
0
        public override bool Execute(Dwarf dwarf, World world)
        {
            int placeToMine = dwarf.Position + 1;

            if (world.Cave[placeToMine].Rocks != 0)
            {
                if (world.Cave[placeToMine].Rocks == -1)
                {
                    world.Cave[placeToMine].Rocks = 64;
                    world.Cave.Add(new Tile()
                    {
                        Rocks = -1
                    });
                }

                world.Cave[placeToMine].Rocks -= 1;
                dwarf.Rocks += 1;
            }

            return(true);
        }
Esempio n. 16
0
 public abstract bool Execute(Dwarf dwarf, World world);
Esempio n. 17
0
 public override bool Execute(Dwarf dwarf, World world)
 {
     lock (world.Cave[dwarf.Position].workLock)
     {
         if (world.Cave[dwarf.Position].Workshop == null)
         {
             world.CreateWorkshop(dwarf);
         }
         else
         {
             world.Cave[dwarf.Position].Workshop.Execute(dwarf, world);
         }
     }
     return true;
 }
Esempio n. 18
0
        public override bool Execute(Dwarf dwarf, World world)
        {
            var tile = world.Cave[dwarf.Position + 1];

            if (tile.Rocks != -1)
            {
                dwarf.Position += 1;
                return true;
            }

            Trace.WriteLine(dwarf.Name + " ran into a wall and perished");
            return false;
        }
Esempio n. 19
0
 public abstract bool Execute(Dwarf dwarf, World world);
Esempio n. 20
0
 public abstract void Execute(Dwarf d, World w);
Esempio n. 21
0
 public abstract void Execute(Dwarf d, World w);
Esempio n. 22
0
 private void DoTurn(Dwarf d, int turn)
 {
     d.Turn(this);
     if (turn > 1000000)
     {
         d.Dead = true;
         Trace.WriteLine(d.Name + " went berserk: infinite loop?");
     }
 }