Beispiel #1
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(80, 25);
            Console.SetBufferSize(80, 25);
            Console.CursorVisible = false;
            AddingMethods.score();
            Gun gun = new Gun();

            new Thread(BadGuys.CreateBadguys).Start();
            while (true)
            {
                ConsoleKeyInfo key = Console.ReadKey(false);
                switch (key.Key)
                {
                case ConsoleKey.Spacebar:
                    new Thread(Bullet.CreateBullet).Start(gun.X);
                    Thread.Sleep(100);
                    break;

                case ConsoleKey.LeftArrow:
                    startgame.Set();
                    gun.MoveLeft();
                    break;

                case ConsoleKey.RightArrow:
                    startgame.Set();
                    gun.MoveRight();
                    break;
                }
            }
        }
Beispiel #2
0
 public void MoveBadgays()
 {
     while ((dir == 1 && X != Console.BufferWidth) || (dir == -1 && X != 0))
     {
         bool hitme = false;
         AddingMethods.WriteTo(X, Y, badchar[X % 4]);
         for (int i = 0; i < 15; i++)
         {
             Thread.Sleep(40);
             if (AddingMethods.ReadTo(X, Y) == '*')
             {
                 hitme = true;
                 break;
             }
         }
         AddingMethods.WriteTo(X, Y, ' ');
         if (hitme)
         {
             Console.Beep();
             Interlocked.Increment(ref Program.hit);
             AddingMethods.score();
             Thread.CurrentThread.Abort();
         }
         X += dir;
     }
     Interlocked.Increment(ref Program.miss);
     AddingMethods.score();
 }