Exemple #1
0
        public void shoot(player p, ConsoleKeyInfo click)
        {
            bullet b;

            switch (click.Key)
            {
            case ConsoleKey.W:
            case ConsoleKey.UpArrow:
                b = new bullet("|", p.location[0] - 1, p.location[1]);
                //Thread movingbullet = new Thread(() => movebullet(b, "up")); https://stackoverflow.com/questions/1314155/returning-a-value-from-thread
                while (b != null)
                {
                    b = movebullet(b, "up");
                }
                break;

            case ConsoleKey.S:
            case ConsoleKey.DownArrow:
                b = new bullet("|", p.location[0] + 1, p.location[1]);
                while (b != null)
                {
                    b = movebullet(b, "down");
                }
                break;

            case ConsoleKey.A:
            case ConsoleKey.LeftArrow:
                b = new bullet("-", p.location[0], p.location[1] - 1);
                while (b != null)
                {
                    b = movebullet(b, "left");
                }
                break;

            case ConsoleKey.D:
            case ConsoleKey.RightArrow:
                b = new bullet("-", p.location[0], p.location[1] + 1);
                while (b != null)
                {
                    b = movebullet(b, "right");
                }
                break;
            }
        }
Exemple #2
0
        public bullet movebullet(bullet b, string direction)
        {
            updatemap(b.location[0], b.location[1], b.icon);
            Console.Clear();
            printmap();
            Thread.Sleep(180);
            switch (direction)
            {
            case "up":
                if (b.location[0] != 0)
                {
                    if (layuot[b.location[0] - 1, b.location[1]] == "#")
                    {
                        getpoints(1);
                    }
                    updatemap(b.location[0], b.location[1], "*");
                    b.location[0] -= 1;
                }
                else
                {
                    updatemap(b.location[0], b.location[1], "*");
                    return(null);
                }
                break;

            case "down":
                if (b.location[0] < layuot.GetLength(0) - 1)
                {
                    if (layuot[b.location[0] + 1, b.location[1]] == "#")
                    {
                        getpoints(1);
                    }
                    updatemap(b.location[0], b.location[1], "*");
                    b.location[0] += 1;
                }
                else
                {
                    updatemap(b.location[0], b.location[1], "*");
                    return(null);
                }
                break;

            case "left":
                if (b.location[1] != 0)
                {
                    if (layuot[b.location[1], b.location[1] - 1] == "#")
                    {
                        getpoints(1);
                    }
                    updatemap(b.location[0], b.location[1], "*");
                    b.location[1] -= 1;
                }
                else
                {
                    updatemap(b.location[0], b.location[1], "*");
                    return(null);
                }
                break;

            case "right":
                if (b.location[1] < layuot.GetLength(1) - 1)
                {
                    if (layuot[b.location[1], b.location[1] + 1] == "#")
                    {
                        getpoints(1);
                    }
                    updatemap(b.location[0], b.location[1], "*");
                    b.location[1] += 1;
                }
                else
                {
                    updatemap(b.location[0], b.location[1], "*");
                    return(null);
                }
                break;
            }
            return(b);
        }