0

我正在学习如何制作 C# rougelike,我遇到了这个错误:当我的玩家 ( @) 失败时,任务提供者 ( G) 与我一起失败,反之亦然。但是当我侧身(左右)时,他不会移动并停留在同一个位置。当我试图通过按下E任何东西来触发他的任务时。这是我的代码:

using System;
using System.Collections.Generic;

namespace Tutorial
{
    public class RougeLike
    {
        static bool isGameAlive = true;
        static Player player;
        static QuestGiver qGiver;
        static SpeechBubble speechBubble;
        static List<Item> items;
        static System.Timers.Timer World;
        static short xMin = 0;
        static short yMin = 0;
        static short xMax = 19;
        static short yMax = 9;
        public class Player
        {
            public char CHR = '@'; //Chracter
            public vector position; //X, Y Coordinate
            public string Name = "";
            public short Health = 25;
            public short Mana = 25;
            public short Exp = 0;
            public bool hasItem = false;
            public Player() //Player Constructor
            {
                position  = new vector(1, 1);
            }
            public void Update()
            {
                char ckInfo = Console.ReadKey().KeyChar;

                switch (ckInfo)
                {
                    case 'e':
                    case 'E':
                        if (player.position.X == qGiver.position.X && player.position.Y == qGiver.position.Y)
                        {
                            if (!player.hasItem)
                                qGiver.MakeQuest();
                            else
                            {
                                speechBubble = new SpeechBubble("Congrats on the Quest!");
                                Exp++;
                            }
                        }
                        for (int intRep = 0; intRep < items.Count; intRep++)
                        {
                            if (items[intRep].position.X == player.position.X && items[intRep].position.Y == player.position.Y)
                            {
                                items.Remove(items[intRep]);
                                player.hasItem = true;
                            }
                        }
                        break;
                    case 'w':
                    case 'W':
                        player.position.Y--;
                        break;
                    case 'a':
                    case 'A':
                        player.position.X--;
                        break;
                    case 's':
                    case 'S':
                        player.position.Y++;
                        break;
                    case 'd':
                    case 'D':
                        player.position.X++;
                        break;
                }
                if (player.position.X > xMax)
                    player.position.X = xMax;
                if (player.position.X < xMin)
                    player.position.X = xMin;
                if (player.position.Y > yMax)
                    player.position.Y = yMax;
                if (player.position.Y < yMin)
                    player.position.Y = yMin;
            }
        }
        public class AI
        {

        }
        public class SpeechBubble
        {
            public string Speech;
            public short SpeechTime;
            public SpeechBubble()
            {
                this.Speech = "";
                SpeechTime = 75;
            }
            public SpeechBubble(string str)
            {
                this.Speech = str;
                SpeechTime = 75;
            }
            public SpeechBubble(string str, string str2)
            {
                this.Speech = str + "\n" + str2;
                SpeechTime = 75;
            }
            public SpeechBubble(string str, string str2, string str3)
            {
                this.Speech = str + "\n" + str2 + "\n" + str3;
                SpeechTime = 75;
            }
        }
        public class QuestGiver
        {
            public bool hasQuest = true;
            public vector position;

            public QuestGiver()
            {
                this.position = new vector((short)(xMax - 1), (short)1);
            }

            public void MakeQuest()
            {
                Random rand;
                rand = new Random();

                items.Add(new Item(0, rand.Next(xMax),
                    (yMax - 1)));
                speechBubble = new SpeechBubble("Can you go get that item for me? It's down there!");

            }
        }
        public class Item
        {
            public int itemID;
            public vector position;

            public Item(int itemID, int X, int Y)
            {
                this.position = new vector(X, Y);
                this.itemID = itemID;
            }
        }
        public class Tree
        {

        }
        public class vector
        {
            public short X;
            public short Y;
            public vector(short X, short Y)
            {
                this.X = X;
                this.Y = Y;
            }
            public vector()
            {
                this.X = 0;
                this.Y = 0;
            }
            public vector(int X, int Y)
            {
                this.X = (short)X;
                this.Y = (short)Y;
            }
        }
        static void Main(string[] args)
        {
            Initialize();
            do
            {
                player.Update();
            } while (isGameAlive);
        }
        static void Initialize()
        {
            Console.CursorVisible = false;
            World = new System.Timers.Timer(50);
            World.Elapsed += new System.Timers.ElapsedEventHandler(Draw);
            World.Start();
            player = new Player();
            qGiver = new QuestGiver();
            items = new List<Item>();
            speechBubble = new SpeechBubble();
        }
        static void Draw(object sender, System.Timers.ElapsedEventArgs e)
        {
            Console.Clear();
            Console.WriteLine("####################"); //20 spaces
            Console.WriteLine("#------------------#");
            Console.WriteLine("#------------------#");
            Console.WriteLine("#------------------#");
            Console.WriteLine("#------------------#");
            Console.WriteLine("#------------------#");
            Console.WriteLine("#------------------#");
            Console.WriteLine("#------------------#");
            Console.WriteLine("#------------------#");
            Console.WriteLine("####################");
            Console.WriteLine("-{0} HP: {1} MP: {2} XP: {3}", player.Name, player.Health, player.Mana, player.Exp);

            Console.SetCursorPosition(qGiver.position.X, player.position.Y);
            Console.Write("G");

            Console.SetCursorPosition(xMax + 5, 0);
            if (speechBubble.SpeechTime > 0)
            {
                Console.Write(speechBubble.Speech);
                speechBubble.SpeechTime--;
            }
            foreach (Item i in items)
            {
                Console.SetCursorPosition(i.position.X, i.position.Y);
                Console.Write("I");
            }

            Console.SetCursorPosition(player.position.X, player.position.Y);
            Console.Write(player.CHR);
            Console.SetCursorPosition((yMax + 4), xMax );
        }
        static void updateworld() //Update non-player, non-antagonist
        {

        }
    }
}

请帮忙。;)

4

0 回答 0