视觉工作室使角色移动使用类而不是图片框

时间:2018-04-16 17:49:22

标签: c# visual-studio

我试图让角色在没有图片框的VS中移动,我似乎越来越近了,但是当我试图按下按键时,key.keycodes的键下面有一条红线,我的公共线下有一条红线enum方向,我不知道为什么。这是我的代码,它不是完全完整的,但你可能会得到这个想法。所以我简单地问一下,为什么我不能输入密钥代码,为什么我的枚举方向代码加下划线。

public enum Direction { Up, Right, Down, Left }
public class Cat
{
    public Direction currentDirection = Direction.Up;
    public PictureBox CatImage = new PictureBox();
    public int mouseSize = 25;

    public int maxScreenX;
    public int maxScreenY;

    private ImageList CatImages = new ImageList();

    public Cat(Form formInstance)
    {
        maxScreenX = formInstance.Width - 50;
        maxScreenY = formInstance.Height - 80;


        // start with mouse in the centre of the screen
        CatImage.Location = new System.Drawing.Point(maxScreenX / 2, maxScreenY / 2);

        // we'll add the mouse images
        CatImages.Images.Add(Properties.Resources.catUp);
        CatImages.Images.Add(Properties.Resources.catRight);
        CatImages.Images.Add(Properties.Resources.catDown);
        CatImages.Images.Add(Properties.Resources.catLeft);

        formInstance.Controls.Add(CatImage);
        CatImage.BringToFront();
    }

    public void MoveMouse()
    {



        if (!canMove)
        {



        }

        // Change the mouse image to match the new direction
        CatImage.Image = CatImages.Images[(int)currentDirection];

        if (canMove)
        {


            if (key.KeyCode == Keys.W)
            {
                CatImage.Top -= 5;
            }
            if (key.KeyCode == Keys.S)
            {
                CatImage.Top += 5;
            }
            if (key.KeyCode == Keys.A)
            {
                CatImage.Left -= 5;
            }
            if (key.KeyCode == Keys.D)
            {
                CatImage.Left += 5;
            }

        }
        }
    }

0 个答案:

没有答案