public void addShelter(Shelter shelter,int row,int column) { shelter.SetValue(Grid.ColumnProperty, column); shelter.SetValue(Grid.RowProperty, row); shelters[row, column] = shelter; shelterPositions[shelter] = new Int32Point(column, row); Children.Add(shelter); }
public void addBox(Box box,int row,int column) { if (boxes[row, column] == null) { //box.HorizontalAlignment = HorizontalAlignment.Left; //box.VerticalAlignment = VerticalAlignment.Top; box.RenderTransform = new TranslateTransform(0,0); box.SetValue(Grid.ColumnProperty, column); box.SetValue(Grid.RowProperty, row); boxes[row, column] = box; boxPositions[box] = new Int32Point(column, row); Children.Add(box); } }
public RoleLayer(Int32Point[] startPos) : base() { this.startPos = startPos; this.players = new List<Player>(); }
public bool moveBoxOne(Box box,WalkDirection dir,Player player) { Int32Point boxPos = boxPositions[box]; if (boxPos == null) { return false; } Int32Point newBoxPos = new Int32Point(boxPos.x, boxPos.y); Box neighborBox = null; switch (dir) { case WalkDirection.DOWN: if (boxPos.y + 1 < boxes.GetLength(0) && scene.obstacleLayer.obstacles[boxPos.y+1,boxPos.x]==null) { if (boxes[boxPos.y + 1, boxPos.x] != null && boxes[boxPos.y + 1, boxPos.x].canKick) { neighborBox = boxes[boxPos.y + 1, boxPos.x]; } } else { return false; } break; case WalkDirection.UP: if (boxPos.y - 1 >= 0 && scene.obstacleLayer.obstacles[boxPos.y - 1, boxPos.x] == null) { if (boxes[boxPos.y - 1, boxPos.x] != null && boxes[boxPos.y - 1, boxPos.x].canKick) { neighborBox = boxes[boxPos.y - 1, boxPos.x]; } } else { return false; } break; case WalkDirection.LEFT: if (boxPos.x - 1 >= 0 && scene.obstacleLayer.obstacles[boxPos.y,boxPos.x-1]==null) { if (boxes[boxPos.y, boxPos.x - 1] != null && boxes[boxPos.y, boxPos.x - 1].canKick) { neighborBox = boxes[boxPos.y, boxPos.x - 1]; } } else { return false; } break; case WalkDirection.RIGHT: if (boxPos.x + 1 < boxes.GetLength(1) && scene.obstacleLayer.obstacles[boxPos.y,boxPos.x+1]==null) { if (boxes[boxPos.y, boxPos.x + 1] != null && boxes[boxPos.y, boxPos.x + 1].canKick) { neighborBox = boxes[boxPos.y, boxPos.x + 1]; } } else { return false; } break; } if (neighborBox != null ) { if (!moveBoxOne(neighborBox, dir, player)) { return false; } } box.canKick = false; DoubleAnimation ani = null; switch (dir) { case WalkDirection.DOWN: case WalkDirection.UP: ani = createBoxMoveAni(box, dir, player.speed, scene.tileHeight); break; case WalkDirection.RIGHT: case WalkDirection.LEFT: ani = createBoxMoveAni(box, dir, player.speed, scene.tileWidth); break; } Storyboard stb = new Storyboard(); stb.Children.Add(ani); ani.Completed+=delegate(object sender,EventArgs e) { switch (dir) { case WalkDirection.DOWN: newBoxPos.y += 1; break; case WalkDirection.UP: newBoxPos.y -= 1; break; case WalkDirection.LEFT: newBoxPos.x -= 1; break; case WalkDirection.RIGHT: newBoxPos.x += 1; break; } box.RenderTransform = new TranslateTransform(0, 0); box.SetValue(Grid.RowProperty,newBoxPos.y); box.SetValue(Grid.ColumnProperty, newBoxPos.x); boxes[boxPos.y, boxPos.x] = null; boxes[newBoxPos.y, newBoxPos.x] = box; boxPositions[box] = newBoxPos; box.canKick = true; }; stb.Begin(); return true; }