コード例 #1
0
ファイル: Workshop.cs プロジェクト: tswaugh/Armok
 public override void Execute(Dwarf d, World w)
 {
     int rocks = w.Cave[d.Position].Rocks;
     if (d.Rocks > rocks)
     {
         new Dump().Execute(d, w);
     }
 }
コード例 #2
0
ファイル: Instruction.cs プロジェクト: iamnilay3/Armok
 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;
 }
コード例 #3
0
ファイル: Language.cs プロジェクト: iamnilay3/Armok
        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();
            }
        }
コード例 #4
0
ファイル: World.cs プロジェクト: iamnilay3/Armok
        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;
        }
コード例 #5
0
ファイル: Workshop.cs プロジェクト: tswaugh/Armok
 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;
     }
 }
コード例 #6
0
ファイル: Instruction.cs プロジェクト: iamnilay3/Armok
        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;
        }
コード例 #7
0
ファイル: World.cs プロジェクト: iamnilay3/Armok
        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;
        }
コード例 #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);
 }
コード例 #9
0
ファイル: Workshop.cs プロジェクト: tswaugh/Armok
 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;
         }
     }
 }
コード例 #10
0
ファイル: Workshop.cs プロジェクト: iamnilay3/Armok
 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;
         }
     }
 }
コード例 #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);
        }
コード例 #12
0
ファイル: Instruction.cs プロジェクト: iamnilay3/Armok
        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;
        }
コード例 #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();
            }
        }
コード例 #14
0
ファイル: Language.cs プロジェクト: tswaugh/Armok
        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();
            }
        }
コード例 #15
0
ファイル: Instruction.cs プロジェクト: iamnilay3/Armok
        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);
        }
コード例 #16
0
ファイル: Instruction.cs プロジェクト: tswaugh/Armok
 public abstract bool Execute(Dwarf dwarf, World world);
コード例 #17
0
ファイル: Instruction.cs プロジェクト: tswaugh/Armok
 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;
 }
コード例 #18
0
ファイル: Instruction.cs プロジェクト: tswaugh/Armok
        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;
        }
コード例 #19
0
ファイル: Instruction.cs プロジェクト: iamnilay3/Armok
 public abstract bool Execute(Dwarf dwarf, World world);
コード例 #20
0
ファイル: Workshop.cs プロジェクト: iamnilay3/Armok
 public abstract void Execute(Dwarf d, World w);
コード例 #21
0
ファイル: Workshop.cs プロジェクト: tswaugh/Armok
 public abstract void Execute(Dwarf d, World w);
コード例 #22
0
ファイル: World.cs プロジェクト: tswaugh/Armok
 private void DoTurn(Dwarf d, int turn)
 {
     d.Turn(this);
     if (turn > 1000000)
     {
         d.Dead = true;
         Trace.WriteLine(d.Name + " went berserk: infinite loop?");
     }
 }