Example #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;
                }
            }
        }
Example #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();
 }
Example #3
0
 public void MoveBullet()
 {
     for (; Y >= 0; Y--)
     {
         AddingMethods.WriteTo(X, Y, '*');
         Thread.Sleep(100);
         AddingMethods.WriteTo(X, Y, ' ');
     }
     Program.bulletsem.Release();
 }
Example #4
0
 public void MoveRight()
 {
     AddingMethods.WriteTo(X, Y, ' ');
     X++;
     if (X > Console.BufferWidth - 1)
     {
         X = 0;
     }
     AddingMethods.WriteTo(X, Y, '|');
 }
Example #5
0
 public void MoveLeft()
 {
     AddingMethods.WriteTo(X, Y, ' ');
     X--;
     if (X == -1)
     {
         X = Console.BufferWidth - 1;
     }
     AddingMethods.WriteTo(X, Y, '|');
 }
Example #6
0
        static public void CreateBullet(object o)
        {
            int x = (int)o;

            if (AddingMethods.ReadTo(x, Console.BufferHeight - 2) == '*')
            {
                return;
            }
            if (!Program.bulletsem.WaitOne(0))
            {
                return;
            }
            new Thread(new Bullet(x).MoveBullet).Start();
        }
Example #7
0
 public Gun()
 {
     X = Console.BufferWidth / 2;
     Y = Console.BufferHeight - 1;
     AddingMethods.WriteTo(X, Y, '|');
 }