示例#1
0
文件: Program.cs 项目: bfog/project
        static void Main(string[] args)
        {
            string name, desc, command = "";

            string[] aCommand;

            Console.WriteLine("Welcome to Swin-Adventure! Type 'Quit' or 'q' to quit the game\n***************************\n");
            Console.Write("Please enter your player name: ");
            name = Console.ReadLine();

            Console.Write("Please enter a player description: ");
            desc = Console.ReadLine();

            Player myPlayer = new Player(name, desc);

            Bag       bag = new Bag(new string[] { "bag" }, "a bag", "a bag");
            Item      gem = new Item(new string[] { "gem" }, "a gem", "a shiny ruby");
            Item      sword = new Item(new string[] { "sword" }, "a sword", "a bronze sword");
            Item      rock = new Item(new string[] { "rock" }, "a rock", "a small rock");
            Item      shovel = new Item(new string[] { "shovel" }, "a shovel", "a rusty shovel");
            Location  loc = new Location("Hallway", "This is a long well lit hallway.\nThere are exits to the south.\n");
            Inventory myInventory, bagInventory, locInventory;

            myInventory  = myPlayer.Inventory;
            bagInventory = bag.Inventory;

            myInventory.Put(gem);
            myInventory.Put(bag);
            bagInventory.Put(rock);

            myPlayer.Location = loc;
            locInventory      = loc.Inventory;
            locInventory.Put(shovel);
            locInventory.Put(sword);

            Console.WriteLine("\n"); //space between player description and commands.

            LookCommand look = new LookCommand(new string[] { "look" });

            do
            {
                Console.Write("Command -> ");
                command = Console.ReadLine();

                aCommand = command.ToLower().Split();


                if (aCommand[0] == "look")
                {
                    Console.WriteLine(look.Execute(myPlayer, aCommand));
                }
                else if (command.ToLower() != "quit" && command.ToLower() != "q")
                {
                    Console.WriteLine("I don't understand " + command);
                }
            } while (command.ToLower() != "quit" && command.ToLower() != "q");

            Console.WriteLine("\nThanks for playing Swin-Adventure!");
            System.Threading.Thread.Sleep(2000);
        }
示例#2
0
        public void SetUp()
        {
            newPlayer       = new Player("me", "inventory");
            bag             = new Bag(new string[] { "bag" }, "a bag", "A bag which contains items");
            playerInventory = newPlayer.Inventory;
            bagInventory    = bag.Inventory;
            gem             = new Item(new string[] { "gem" }, "a gem", "A shiny red gem");
            look            = new LookCommand(new string[] { "look" });

            playerInventory.Put(bag);
            playerInventory.Put(gem);
        }
示例#3
0
        public void SetUp()
        {
            myPlayer    = new Player("me", "inventory");
            myInventory = myPlayer.Inventory;
            gem         = new Item(new string[] { "gem" }, "a gem", "A shiny red gem");
            look        = new LookCommand(new string[] { "look" });
            location    = new Location("Hallway", "This is a long well lit hallway.\nThere are exits to the south.\n");

            myPlayer.Location = location;

            locInventory = location.Inventory;

            locInventory.Put(gem);
        }
示例#4
0
        static void Main(string[] args)
        {
            IdentifiableObject id = new IdentifiableObject(new string[] { "id1", "id2" });

            Console.WriteLine("Welcome to Swin-Adventure");
            Console.WriteLine("Swin-Adventure is a fantasy adventure game that consists of a number of interconnected locations.");
            Console.WriteLine();
            Console.WriteLine("Let's begin with your name");
            string name = Console.ReadLine();

            Console.WriteLine("Right... So your name is " + name);
            Console.WriteLine("How would you describe yourself?");
            string description = Console.ReadLine();

            Console.WriteLine(name + ", " + description + ", your very own Swin-Adventure legend is about to unfold!");

            Player   p     = new Player(name, description);
            Bag      bag   = new Bag(new string[] { "small", "black", "bag" }, "bag", "A small black bag");
            Item     sword = new Item(new string[] { "sword" }, "bronze", "This is a very cheap sword");
            Item     coin  = new Item(new string[] { "coin" }, "ancient", "This coin holds no value at all");
            Item     gem   = new Item(new string[] { "gem" }, "red", "This is a very red gem");
            Location start = new Location("room", "This place stinks");

            p.Inventory.Put(sword);
            p.Inventory.Put(bag);
            bag.Inventory.Put(gem);
            start.Inventory.Put(coin);
            p.Location = start;

            Command l = new LookCommand();

            Console.WriteLine();
            Console.WriteLine("Please enter your command");

            while (true)
            {
                string input = Console.ReadLine();


                if (input.Equals("exit"))
                {
                    break;
                }

                Console.WriteLine(l.Execute(p, input.Split()));
                Console.WriteLine();
            }
        }
        public override string Execute(Player p, string[] text)
        {
            Command c;

            switch (text[0].ToLower())
            {
            case "look":
                c = new LookCommand();
                break;

            case "move":
                c = new MoveCommand();
                break;

            case "go":
                c = new MoveCommand();
                break;

            default:
                c = new LookCommand();
                break;
            }
            return(c.Execute(p, text));
        }