public override void Execute(Dwarf d, World w) { int rocks = w.Cave[d.Position].Rocks; if (d.Rocks > rocks) { new Dump().Execute(d, w); } }
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; }
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(); } }
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; }
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; } }
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; }
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; }
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); }
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; } } }
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); }
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; }
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(); } }
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(); } }
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); }
public abstract bool Execute(Dwarf dwarf, World world);
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; }
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; }
public abstract void Execute(Dwarf d, World w);
private void DoTurn(Dwarf d, int turn) { d.Turn(this); if (turn > 1000000) { d.Dead = true; Trace.WriteLine(d.Name + " went berserk: infinite loop?"); } }