コード例 #1
0
        public void addPlayer(Player player)
        {
            Int32Point pos = startPos[players.Count];
            player.gridX = pos.x;
            player.gridY = pos.y;
            Children.Add(player);

            Utility.MW.stkPlayerInfoPanel.Children.Add(player.infoPanel);
            players.Add(player);
        }
コード例 #2
0
        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;
        }