コード例 #1
0
 public ReplayViewModel Get([FromUri]string[] ids)
 {
     var heads = new[]
     {
         new Directed {X = 1, Y = 13, Direction = Direction.East},
         new Directed {X = 25, Y = 13, Direction = Direction.West},
         new Directed {X = 13, Y = 1, Direction = Direction.North},
         new Directed {X = 13, Y = 25, Direction = Direction.South}
     };
     var n = 0;
     var unique = new HashSet<string>(ids);
     var fighters = unique
         .Select(id => snakeStore.GetById(id))
         .Where(s => s != null)
         .Take(4)
         .Select(snake => new Fighter(snake.Id, snake.Chips, heads[n++]))
         .ToList();
     var tickCount = Environment.TickCount;
     var replay = new Replay(tickCount) { BattleField = new BattleField() };
     if (fighters.Count > 0)
     {
         var battleField = new BattleField();
         var battleManager = new BattleManager(fighters, replay, new FieldComparer(battleField), battleField, tickCount);
         battleManager.Fight(550); //original 550    
     }
     var model = Mapper.Map<Replay, ReplayViewModel>(replay);
     return model;
 }
コード例 #2
0
 public ReplayViewModel Get()
 {
     var heads = new[]
     {
         new Directed {X = 1, Y = 13, Direction = Direction.East},
         new Directed {X = 25, Y = 13, Direction = Direction.West},
         new Directed {X = 13, Y = 1, Direction = Direction.North},
         new Directed {X = 13, Y = 25, Direction = Direction.South}
     };
     var fighters = heads.Select(h => new Fighter(Guid.NewGuid().ToString(), new Collection<IEnumerable<ChipCell>>(), h)).ToList();
     var tickCount = Environment.TickCount;
     var replay = new Replay(tickCount) { BattleField = new BattleField() };
     var battleField = new BattleField();
     var battleManager = new BattleManager(fighters, replay, new FieldComparer(battleField), battleField, tickCount);
     battleManager.Fight(550); //original 550
     var model = Mapper.Map<Replay, ReplayViewModel>(replay);
     return model;
 }
コード例 #3
0
 internal static BattleField CreateFieldForFighters(IEnumerable<Fighter> fighters, params Cell<Content>[] additionFieldElements)
 {
     var battleField = new BattleField();
     foreach (var fighter in fighters)
     {
         foreach (var part in fighter.Body)
         {
             battleField[part.X, part.Y] = Content.Body;
         }
         if (fighter.Tail != null)
             battleField[fighter.Tail.X, fighter.Tail.Y] = Content.Tail;
         if (fighter.Head != null)
             battleField[fighter.Head.X, fighter.Head.Y] = Content.Head;
     }
     foreach (var cell in additionFieldElements)
     {
         battleField[cell.X, cell.Y] = cell.Content;
     }
     return battleField;
 }
コード例 #4
0
 internal static FieldComparer CreateFieldComparer(BattleField battleField)
 {
     return new FieldComparer(battleField);
 }
コード例 #5
0
ファイル: FieldComparer.cs プロジェクト: FoC-/SnakeBattle.Net
 public FieldComparer(BattleField field)
 {
     this.field = field;
 }