예제 #1
0
        public NormalZombie(Pause pause) : base(pause)
        {
            Health         = 10;
            MaxHealth      = 10;
            WalkSpeed      = 1000;
            AttackDamage   = 10;
            AttackSpeed    = 1000;
            IsPushable     = true;
            Direction      = Direction.DOWN;
            ZombieModel    = new NormalZombieModel(GameData.NormalZombieModel);
            ZombiePosition = FindSpawnPosition();
            ZombieState    = new NormalState();
            GameData.AddZombieAtPosition(ZombiePosition, this);
            Thread zombieThread = new Thread(() => LiveTemplateMethod());

            GameData.AddThread(zombieThread);
            this.ZombieThread = zombieThread;
            zombieThread.Start();
        }
예제 #2
0
        public void TrackDrop(Position position, Drop drop)
        {
            int appearTime = drop.GetAppearTime();

            try
            {
                int pom = 1;
                while (appearTime > 0)
                {
                    if (IsPaused)
                    {
                        GameData.PauseGameEvent.Reset();
                        GameData.PauseGameEvent.WaitOne();
                    }

                    Thread.Sleep(1000);
                    appearTime -= 1000;
                    if (appearTime <= 4000)
                    {
                        if (pom == 1)
                        {
                            drop.GetModel().ModelColor = ConsoleColor.White;
                            pom = 0;
                        }
                        else
                        {
                            drop.GetModel().ModelColor = drop.GetModel().ModelBaseColor;
                            pom = 1;
                        }
                        GameData.DisplayModelAtPosition(position, position, drop.GetModel(), 0, false);
                    }
                }
            }
            catch (ThreadInterruptedException)
            {
            }
            GameData.RemoveDropAtPosition(position);
            Pause.Detach(this);
        }
예제 #3
0
 public void LiveTemplateMethod()
 {
     try
     {
         do
         {
             if (IsPaused)
             {
                 GameData.PauseGameEvent.Reset();
                 GameData.PauseGameEvent.WaitOne();
             }
             FollowPlayer();
             Thread.Sleep(WalkSpeed);
         } while (Health > 0);
     }
     catch (ThreadInterruptedException) { }
     if (drop == true)
     {
         DropGoodies();
     }
     AddScore();
     Pause.Detach(this);
 }
예제 #4
0
 public DropTracker(Pause pause)
 {
     pause.Attach(this);
     this.Pause = pause;
     IsPaused   = pause.GetState();
 }
예제 #5
0
 public override void Update()
 {
     IsPaused = Pause.GetState();
 }
예제 #6
0
 public void ResumeGame()
 {
     Pause.SetState();
 }
예제 #7
0
 public void PauseGame()
 {
     Pause.SetState();
     Menus.PauseMenu();
 }
예제 #8
0
 public Mechanics(Pause pause)
 {
     pause.Attach(this);
     this.Pause = pause;
     IsPaused   = pause.GetState();
 }
예제 #9
0
        public void Jump(Direction direction, HunterZombie zombie)
        {
            bool     isDone = false;
            int      jumpRange = zombie.JumpRange;
            Position zombiePositionCopy = new Position(zombie.ZombiePosition);
            int      verticalShift = 0, horizontalShift = 0;

            switch (direction)
            {
            case Direction.UP:
                verticalShift   = 0;
                horizontalShift = -1;
                break;

            case Direction.RIGHT:
                verticalShift   = 1;
                horizontalShift = 0;
                break;

            case Direction.DOWN:
                verticalShift   = 0;
                horizontalShift = 1;
                break;

            case Direction.LEFT:
                verticalShift   = -1;
                horizontalShift = 0;
                break;
            }

            try
            {
                while (!isDone && jumpRange > 0)
                {
                    if (IsPaused)
                    {
                        GameData.PauseGameEvent.Reset();
                        GameData.PauseGameEvent.WaitOne();
                    }

                    lock (GameData.ConsoleAccessObject)
                    {
                        switch (GameData.CheckForCollision(new Position(zombie.ZombiePosition.X + verticalShift, zombie.ZombiePosition.Y + horizontalShift)))
                        {
                        case Collision.NONE:
                            zombiePositionCopy.Y += horizontalShift;
                            zombiePositionCopy.X += verticalShift;
                            jumpRange            -= 1;
                            break;

                        case Collision.PLAYER:
                            lock (GameData.PlayerHealthAccess)
                            {
                                GameData.GameMechanics.HitPlayer(zombie.AttackDamage);
                                GameData.PlayerHealthStatusEvent.Set();
                            }
                            isDone = true;
                            break;

                        case Collision.WALL:
                            isDone = true;
                            break;

                        case Collision.ZOMBIE:
                            isDone = true;
                            break;

                        case Collision.DROP:
                            zombiePositionCopy.Y += horizontalShift;
                            zombiePositionCopy.X += verticalShift;
                            jumpRange            -= 1;
                            GameData.RemoveDropAtPosition(zombiePositionCopy);
                            break;
                        }
                        GameData.DisplayModelAtPosition(zombiePositionCopy, zombie.ZombiePosition, zombie.ZombieModel, direction, true);
                    }
                    Thread.Sleep(50);
                }
            }
            catch (ThreadInterruptedException)
            {
            }
            GameData.JumpWait.Set();
            Pause.Detach(this);
        }
예제 #10
0
        public static void InitializeGame()
        {
            Console.Clear();

            IDifficulty difficulty;

            if (GameData.Difficulty == "Hard")
            {
                difficulty = new HardDifficulty();
            }
            else if (GameData.Difficulty == "Medium")
            {
                difficulty = new MediumDifficulty();
            }
            else
            {
                GameData.Difficulty = "Easy";
                difficulty          = new EasyDifficulty();
            }

            IInterfaceBuilder interfaceBuilder;

            if (GameData.InterfaceBuilder == "Mathemathics")
            {
                interfaceBuilder = new MathemathicsInterfaceBuilder();
            }
            else if (GameData.InterfaceBuilder == "Rainbow")
            {
                interfaceBuilder = new RainbowInterfaceBuilder();
            }
            else
            {
                interfaceBuilder = new DefaultInterfaceBuilder();
            }

            GameData.pause = new Pause();

            GameData.GameMechanics = new Mechanics(GameData.pause);

            PlayerStatusTracker playerStatusTracker = new PlayerStatusTracker(GameData.pause);

            GameData.SetGraphics(interfaceBuilder);
            Console.SetCursorPosition(105, 22);
            Console.Write("Difficulty: " + difficulty.ToString());
            Console.CursorVisible = false;

            GameData.gameMap = new char[50, 130];
            for (int i = 0; i < 50; i++)
            {
                for (int j = 0; j < 130; j++)
                {
                    GameData.gameMap[i, j] = ' ';
                }
            }

            GameData.TankZombieModel = new TankZombieModel(new char[4] {
                '¥', '¥', '¥', '¥'
            }, ConsoleColor.Green, GameData.BackgroundColor);
            GameData.NormalZombieModel = new NormalZombieModel(new char[4] {
                '@', '@', '@', '@'
            }, ConsoleColor.Green, GameData.BackgroundColor);
            GameData.HunterZombieModel = new HunterZombieModel(new char[4] {
                'x', 'x', 'x', 'x'
            }, ConsoleColor.Green, GameData.BackgroundColor);
            GameData.HealthPackModel = new HealthPackModel(new char[4] {
                '+', '+', '+', '+'
            }, ConsoleColor.Red, GameData.BackgroundColor);
            GameData.AmmoPackModel = new AmmoPackModel(new char[4] {
                '#', '#', '#', '#'
            }, ConsoleColor.Red, GameData.BackgroundColor);
            GameData.Ak47Model = new AK47Model(new char[4] {
                'A', 'A', 'A', 'A'
            }, ConsoleColor.Red, GameData.BackgroundColor);
            GameData.SniperRifleModel = new SniperRifleModel(new char[4] {
                'S', 'S', 'S', 'S'
            }, ConsoleColor.Red, GameData.BackgroundColor);
            GameData.PistolBulletModel = new PistolBulletModel(new char[4] {
                '.', '.', '.', '.'
            }, ConsoleColor.White, GameData.BackgroundColor);
            GameData.AK47BulletModel = new AK47BulletModel(new char[4] {
                '°', '°', '°', '°'
            }, ConsoleColor.White, GameData.BackgroundColor);
            GameData.SniperRifleBulletModel = new SniperRifleBulletModel(new char[4] {
                '│', '─', '│', '─'
            }, ConsoleColor.White, GameData.BackgroundColor);
            GameData.PlayerModel = new PlayerModel(new char[4] {
                '^', '>', 'v', '<'
            }, ConsoleColor.Green, GameData.BackgroundColor);

            GameData.ZombieAtPosition = new Dictionary <Position, Zombie>();
            GameData.DropAtPosition   = new Dictionary <Position, Drop>();

            GameData.Player = Player.GetPlayer();

            Player.Name        = GameData.PlayerName;
            Player.PlayerModel = new PlayerModel(new char[4] {
                '^', '>', 'v', '<'
            }, ConsoleColor.Green, GameData.BackgroundColor);
            Player.Score     = 0;
            Player.Position  = new Position(65, 25);
            Player.Health    = 100;
            Player.Direction = Direction.DOWN;
            Player.Weapons   = new List <Weapon>()
            {
                new Pistol()
            };
            Player.CurrentWeapon = Player.Weapons.ElementAt(0);
            GameData.DisplayModelAtPosition(Player.Position, Player.Position, Player.PlayerModel, Direction.DOWN, true);

            GameData.ReloadEvent                    = new ManualResetEvent(false);
            GameData.JumpWait                       = new ManualResetEvent(false);
            GameData.PauseGameEvent                 = new ManualResetEvent(false);
            GameData.PlayerHealthStatusEvent        = new ManualResetEvent(false);
            GameData.KeyInfoWaitEvent               = new ManualResetEvent(false);
            GameData.PlayerAmmoStatusEvent          = new ManualResetEvent(false);
            GameData.PlayerCurrentWeaponStatusEvent = new ManualResetEvent(false);
            GameData.PlayerScoreStatusEvent         = new ManualResetEvent(false);

            Player.IsReloaded   = true;
            GameData.threadList = new List <Thread>();

            Thread playerScoreStatusThread         = new Thread(() => playerStatusTracker.TrackPlayerScoreStatus());
            Thread playerCurrentWeaponStatusThread = new Thread(() => playerStatusTracker.TrackPlayerCurrentWeaponStatus());
            Thread playerAmmoStatusThread          = new Thread(() => playerStatusTracker.TrackPlayerAmmoStatus());
            Thread playerHealthStatusThread        = new Thread(() => playerStatusTracker.TrackPlayerHealthStatus());
            Thread reloadWeaponThread = new Thread(() => GameMechanics.ReloadWeapon());
            Thread zombieMaker        = new Thread(() => new ZombieMaker(difficulty, GameData.pause).MakeZombies());
            Thread start = new Thread(() => GameData.GameMechanics.StartGame());

            GameData.AddThread(playerScoreStatusThread);
            GameData.AddThread(playerCurrentWeaponStatusThread);
            GameData.AddThread(playerAmmoStatusThread);
            GameData.AddThread(playerHealthStatusThread);
            GameData.AddThread(reloadWeaponThread);
            GameData.AddThread(zombieMaker);

            playerScoreStatusThread.Start();
            playerCurrentWeaponStatusThread.Start();
            playerAmmoStatusThread.Start();
            playerHealthStatusThread.Start();
            reloadWeaponThread.Start();
            zombieMaker.Start();
            start.Start();
        }
예제 #11
0
        public void PushAndStun(Direction direction)
        {
            Position playerPositionCopy = new Position(GameData.Player.Position);
            bool     isDone             = false;

            GameData.Player.Direction = direction;

            int verticalShift = 0, horizontalShift = 0;

            switch (direction)
            {
            case Direction.UP:
                verticalShift   = 0;
                horizontalShift = -1;
                break;

            case Direction.RIGHT:
                verticalShift   = 1;
                horizontalShift = 0;
                break;

            case Direction.DOWN:
                verticalShift   = 0;
                horizontalShift = 1;
                break;

            case Direction.LEFT:
                verticalShift   = -1;
                horizontalShift = 0;
                break;
            }

            try
            {
                while (!isDone)
                {
                    if (IsPaused)
                    {
                        GameData.PauseGameEvent.Reset();
                        GameData.PauseGameEvent.WaitOne();
                    }

                    lock (GameData.ConsoleAccessObject)
                    {
                        switch (GameData.CheckForCollision(new Position(GameData.Player.Position.X + verticalShift, GameData.Player.Position.Y + horizontalShift)))
                        {
                        case Collision.NONE:
                            playerPositionCopy.Y += horizontalShift;
                            playerPositionCopy.X += verticalShift;
                            break;

                        case Collision.WALL:
                            lock (GameData.PlayerHealthAccess)
                            {
                                if (GameData.Player.Health > 0)
                                {
                                    GameData.Player.Health = GameData.Player.Health - 5;
                                    GameData.PlayerHealthStatusEvent.Set();
                                }
                            }
                            isDone = true;
                            break;

                        case Collision.ZOMBIE:
                            lock (GameData.PlayerHealthAccess)
                            {
                                if (GameData.Player.Health > 0)
                                {
                                    GameData.Player.Health = GameData.Player.Health - 5;
                                    GameData.PlayerHealthStatusEvent.Set();
                                }
                            }
                            isDone = true;
                            break;

                        case Collision.DROP:
                            playerPositionCopy.Y += horizontalShift;
                            playerPositionCopy.X += verticalShift;
                            GameData.RemoveDropAtPosition(playerPositionCopy);
                            break;
                        }

                        GameData.DisplayModelAtPosition(playerPositionCopy, GameData.Player.Position, GameData.Player.PlayerModel, GameData.Player.Direction, true);
                    }

                    Thread.Sleep(50);
                }

                Thread stunTrackingThread;
                stunTrackingThread = new Thread(() => new StunTracker(Pause).TrackStun());
                stunTrackingThread.Start();
                GameData.AddThread(stunTrackingThread);
                Pause.Detach(this);
            }
            catch (ThreadInterruptedException) { }
        }
예제 #12
0
        public void Fly()
        {
            int verticalShift = 0, horizontalShift = 0;

            switch (direction)
            {
            case Direction.UP:
                verticalShift   = 0;
                horizontalShift = -1;
                break;

            case Direction.RIGHT:
                verticalShift   = 1;
                horizontalShift = 0;
                break;

            case Direction.DOWN:
                verticalShift   = 0;
                horizontalShift = 1;
                break;

            case Direction.LEFT:
                verticalShift   = -1;
                horizontalShift = 0;
                break;
            }

            while (!isDone && range > 0)
            {
                if (IsPaused)
                {
                    GameData.PauseGameEvent.Reset();
                    GameData.PauseGameEvent.WaitOne();
                }

                lock (GameData.ConsoleAccessObject)
                {
                    Position bulletPositionCopy = new Position(bulletPosition);
                    switch (GameData.CheckForCollision(new Position(bulletPosition.X + verticalShift, bulletPosition.Y + horizontalShift)))
                    {
                    case Collision.NONE:
                        bulletPositionCopy.X += verticalShift;
                        bulletPositionCopy.Y += horizontalShift;
                        GameData.DisplayModelAtPosition(bulletPositionCopy, bulletPosition, bulletModel, direction, clearPrevious);
                        break;

                    case Collision.WALL:
                        if (!GameData.Player.Position.Equals(bulletPosition))
                        {
                            GameData.ClearPosition(bulletPosition);
                        }
                        isDone = true;
                        break;

                    case Collision.ZOMBIE:
                        bulletPositionCopy.X += verticalShift;
                        bulletPositionCopy.Y += horizontalShift;
                        GameData.GameMechanics.HitZombie(bulletPositionCopy, GameData.Player.CurrentWeapon.Damage);
                        if (clearPrevious)
                        {
                            GameData.ClearPosition(bulletPosition);
                        }
                        isDone = true;
                        break;

                    case Collision.DROP:
                        bulletPositionCopy.X += verticalShift;
                        bulletPositionCopy.Y += horizontalShift;
                        GameData.ClearPosition(bulletPosition);
                        GameData.RemoveDropAtPosition(bulletPositionCopy);
                        isDone = true;
                        break;
                    }

                    if (range == 1)
                    {
                        GameData.ClearPosition(bulletPosition);
                    }
                }

                range        -= 1;
                clearPrevious = true;
                Thread.Sleep(GameData.Player.CurrentWeapon.BulletSpeed);
            }
            Pause.Detach(this);
        }
예제 #13
0
        public Bullet(Position playerPosition, Direction direction, Model model, int range, Pause pause)
        {
            isDone         = false;
            clearPrevious  = false;
            bulletPosition = new Position(playerPosition);
            this.direction = direction;
            bulletModel    = model;
            this.range     = range;

            pause.Attach(this);
            this.Pause = pause;
            IsPaused   = pause.GetState();
        }
예제 #14
0
 public PlayerStatusTracker(Pause pause)
 {
     pause.Attach(this);
     this.Pause    = pause;
     this.IsPaused = pause.GetState();
 }