Esempio n. 1
0
        public void HeroCatch(Hero hero, int[,] grid)
        {
            if (this.x == hero.x && this.y == hero.y)
            {
                this.RemoveFromGrid(grid);
                type = 5;

            }
        }
Esempio n. 2
0
        public Upgrade Hit_Detect(List<Projectile> j, int[,] grid, Hero pl)
        {
            if (j.Exists(o => o.x == this.x && o.y == this.y && o.direction == -1) && this.lives > 0)
            {
                lives--;
                if (lives == 0)
                {
                    this.RemoveFromGrid(grid);
                    pl.score += 100;
                    return new Upgrade(this.x, this.y, 1, 1, 0);

                }
                int index = j.FindIndex(o => o.x == this.x && o.y == this.y);
                j[index].RemoveFromGrid(grid);
                j.RemoveAt(index);
            }
            return null;
        }
Esempio n. 3
0
        public static int GameTurn(List<Alien> s, List<Projectile> p, List<Upgrade> upgrades, Hero h, int[,] grid, int b)
        {
            string monitor = printGrid(grid);
            PrintMonitorLine(monitor, h, b);

            //Fire
            foreach (Alien ship in s)
            {
                p.Add(ship.Fire());
                ship.ProgressTime();
                p.RemoveAll(o => o == null);
                upgrades.Add(ship.Hit_Detect(p, grid, h));

            }
            p.RemoveAll(o => o == null);
            upgrades.RemoveAll(o => o == null);
            foreach (Upgrade alien in upgrades)
            {
                alien.PlaceInGrid(grid);
                alien.MoveTimeProgress(grid);
                alien.HeroCatch(h, grid);
            }
            upgrades.RemoveAll(o => o.type == 5);
            foreach (Upgrade alien in upgrades)
            {
                if (alien.x == grid.GetLength(0) - 1 || alien.x == 0)
                {
                    alien.direction *= -1;
                    if (alien.y == grid.GetLength(1) - 1 || alien.y == 0)
                    {
                        alien.secondDirection *= -1;
                    }

                }
            }

            foreach (Projectile missle in p)
            {
                missle.PlaceInGrid(grid);
            }
            //

            foreach (Projectile missle in p)
            {
                if (missle.x == grid.GetLength(0) - 1 || missle.x == 0)
                {
                    missle.RemoveFromGrid(grid);
                }
                if (missle.y == grid.GetLength(1) - 1 || missle.y == 0)
                {
                    missle.RemoveFromGrid(grid);
                    missle.direction2 *= -2;
                }

            }
            p.RemoveAll(o => o.x == grid.GetLength(0) - 1);
            p.RemoveAll(o => o.x == 0);
            //
            s.RemoveAll(o => o.lives <= 0);
            monitor = printGrid(grid);

            foreach (Projectile missle in p)
            {
                missle.TimeProgress(grid);
            }

            HeroMove(h, grid, p);
            h.Hit(p, grid);

            Thread.Sleep(100);

            if (h.lives > 0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
Esempio n. 4
0
        public static void RunGame(List<Alien> swarm, List<Projectile> missles, List<Upgrade> upgrades, Random rng, int[,] matrix, int b)
        {
            string[] txtFile = System.IO.File.ReadAllLines("TextFile1.txt");
            for (int i = 0; i < txtFile.Length; i++)
            {
                string[] temp = txtFile[i].Split(',');
                swarm.Add(new Alien(int.Parse(temp[0]), int.Parse(temp[1]), int.Parse(temp[2]), rng.Next(20, 250)));
            }

            foreach (Alien ship in swarm)
            {
                ship.PlaceInGrid(matrix);
            }
            //string monitor = printGrid(matrix);
            // Console.Write(monitor);
            Hero player = new Hero();
            player.PlaceInGrid(matrix);
            while (true)
            {
                int i = GameTurn(swarm, missles, upgrades, player, matrix, b);
                if (i == 0)
                {
                    //=============================================================================================> LOSE SCREEN
                    LoseScreen(29, 80);
                    //=============================================================================================> LOSE SCREEN
                    break;
                }
                if (swarm.Count == 0)
                {
                    break;
                }
            }

            //Console.Clear();
            //Console.WriteLine("Game Over");
            //Console.WriteLine(player.score);

            HighScore(player);
        }
Esempio n. 5
0
        public static void PrintMonitorLine(string s, Hero h, int b)
        {
            string[] lines = s.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

            for (int i = 0; i < lines.Length; i++)
            {
                Console.SetCursorPosition(lines[i].Length / 2, b + i);
                Console.Write(lines[i]);
            }

            Console.SetCursorPosition(lines[1].Length / 2 + lines[0].Length + 2, b + 10);
            Console.Write(h.lives.ToString().PadLeft(5));

            Console.SetCursorPosition(lines[1].Length / 2 + lines[0].Length + 2, b + 12);
            Console.Write(h.score.ToString().PadLeft(5));

            //=============================================================================================> INSTRUCTIONS
            //Print game instructions below the playing field
            Console.SetCursorPosition(lines[1].Length / 2, lines[1].Length / 2 + 6);
            Console.BackgroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("  ← → ↑ ↓ to move    spacebar to fire".ToString().PadRight(40));
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;

            //Set cursor position within the playing field to clear score field bug
            Console.SetCursorPosition(lines[1].Length / 2, lines[0].Length / 2 + 4);
            //=============================================================================================> INSTRUCTIONS
        }
Esempio n. 6
0
        public static void HighScore(Hero player)
        {
            Console.Write("Input your Name:  ");
            string playerName = Console.ReadLine();
            Score current = new Score(playerName, player.score, DateTime.Now);

            string[] scores = System.IO.File.ReadAllLines("HighScore.txt");

            List<Score> tempScore = new List<Score>();

            for (int i = 0; i < scores.Length; i++)
            {
                string[] temp = scores[i].Split('-');
                if (temp != null)
                {
                    tempScore.Add(new Score(temp[0], int.Parse(temp[1]), DateTime.Parse(temp[2])));
                }
            }

            tempScore.Add(current);

            tempScore.Sort((x1, x2) => x1.points.CompareTo(x2.points));

            if (tempScore.Count == 11)
            {
                tempScore.RemoveAt(10);
            }
            Console.Clear();
            List<string> output = new List<string>();

            foreach (var item in tempScore)
            {
                output.Add(item.ToString());
                Console.WriteLine(item.ToString());
            }

            System.IO.File.WriteAllLines("HighScore.txt", output.ToArray());
        }
Esempio n. 7
0
        public static void HeroMove(Hero h, int[,] grid, List<Projectile> p)
        {
            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo userInput = Console.ReadKey();
                if (userInput.Key == ConsoleKey.LeftArrow && h.y >= 1)
                {
                    h.Move(1, grid);
                }
                if (userInput.Key == ConsoleKey.RightArrow && h.y <= grid.GetLength(1) - 2)
                {
                    h.Move(-1, grid);
                }
                if (userInput.Key == ConsoleKey.UpArrow && h.x >= 5)
                {
                    h.Move(2, grid);
                }
                if (userInput.Key == ConsoleKey.DownArrow && h.x < grid.GetLength(0) - 1)
                {
                    h.Move(-2, grid);
                }
                if (userInput.Key == ConsoleKey.Spacebar)
                {

                    switch (h.powerUpLevel)
                    {
                        case 0:
                            p.Add(h.Fire(0));
                            break;
                        case 1:
                            p.Add(h.Fire(0));
                            p.Add(h.Fire(-1));
                            break;
                        case 2:
                            p.Add(h.Fire(0));
                            p.Add(h.Fire(-1));
                            p.Add(h.Fire(1));
                            break;
                        default:
                            break;
                    }

                }
            }

            while (Console.KeyAvailable)
            {
                ConsoleKeyInfo userInput = Console.ReadKey();
            }
        }
Esempio n. 8
0
 public void HitDetect(Hero hero, int[,] grid)
 {
 }