1

というわけで、一手で基本的な Zork コンソール アプリケーション ゲームを作成しています。ドアは毎回ランダム化され(まだ完成していません)、プレーヤーは通過できるドアが1つだけで、どのドアを通過するかを推測する必要があります。ただし、ユーザーの入力を速くするために、カウントダウンタイマーで壁が近づいているような錯覚を与えたいと思っています。これがゼロになる前に何も入力しないと、「殺され」ますが、追加する方法がわかりませんカウントダウン タイマーだけでなく、移動に関するユーザーからの入力をコンソールでチェックします。これが私の現在のコードであり、まだ完成していないことを念頭に置いてください。

using System;
using System.Threading; 

namespace Prog4
{
    class program 
    {
        public static void Main(string[] args)
        {
           Random random = new Random();
           int north = random.Next(1,5);
           int south = random.Next(1,5);
           int east = random.Next(1,5);
           int west = random.Next(1,5);

           Console.WriteLine("You are in a room that is slowly closing in on you, it has only four exits." + Environment.NewLine +
                             "The four exits face: North, South, East and West. " + Environment.NewLine +
                             "Use n for North, s for South, e for East and w for West" + Environment.NewLine +
                             "Only one exit leads to outside, the rest lead to certain doooooooooooooom");
         }
    }
}
4

2 に答える 2

2

開始するには、このスレッドにアクセスしてください:リンク その後、それを見ることができます

using System;
using System.Timers;

namespace Prog4
{
    class program
    {
        private static int _countDown = 30; // Seconds
        private static bool waySelected = false;

        static void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            if (waySelected == false)
            {
                if (_countDown-- <= 0)
                    Console.WriteLine("You got crushed!");
                else
                {
                    Console.SetCursorPosition(0, 9);
                    Console.WriteLine(_countDown + " seconds until you are crushed");
                }
            }
        }

        static void Main(string[] args)
        {
            Timer aTimer = new Timer(1000);
            aTimer.Elapsed += OnTimedEvent;
            aTimer.Enabled = true;

            Random random = new Random();
            int north = random.Next(1, 5);
            int south = random.Next(1, 5);
            int east = random.Next(1, 5);
            int west = random.Next(1, 5);

            Console.WriteLine("You are in a room that is slowly closing in on you, it has only four exits.\n" +
                              "The four exits face: North, South, East and West. \n" +
                              "Press n for North, \n" +
                              "      s for South, \n" +
                              "      e for East, \n" +
                              "      w for West, \n" +
                              "Only one exit leads to outside, the rest lead to certain doooooooooooooom \n");

            Console.WriteLine("Press any key to continue...");

            ConsoleKeyInfo way = Console.ReadKey(true);
            waySelected = true;
            Console.Clear();

            switch (way.KeyChar)
            {
                case 'n':
                    Console.WriteLine("The Next room is looks like North ...");
                    break;
                case 's':
                    Console.WriteLine("The Next room is looks like South ...");
                    break;
                case 'e':
                    Console.WriteLine("The Next room is looks like East ...");
                    break;
                case 'w':
                    Console.WriteLine("The Next room is looks like West ...");
                    break;
                default:
                    Console.WriteLine("You choose wrong way, you got crushed!");
                    break;
            }

            Console.ReadKey(true);
        }
    }
}

完璧ではありませんが、機能します:)

于 2013-10-19T13:24:54.487 に答える