public static bool HeroNearby(Map mymap, Hero myHero, Creeper creeper)
 {
     for (int i = creeper.Position.X - 1; i <= creeper.Position.X + 1; i++)
     {
         for (int j = creeper.Position.Y - 1; j <= creeper.Position.Y + 1; j++)
         {
             if (myHero.Position.X == i && myHero.Position.Y == j)
             {
                 return true;
             }
         }
     }
     return false;
 }
 public void Walk(Map mymap, Hero myHero, Creeper creeper)
 {
     if (!HeroInRange(myHero, creeper))
     {
         if (this.Orientation == 0)
         {
             if (mymap.CanBeStepped(this.Position.X - 1, this.Position.Y))
             {
                 this.MoveUp();
             }
         }
         else if (this.Orientation == 1)
         {
             if (mymap.CanBeStepped(this.Position.X, this.Position.Y + 1))
             {
                 this.MoveRight();
             }
         }
         else if (this.Orientation == 2)
         {
             if (mymap.CanBeStepped(this.Position.X + 1, this.Position.Y))
             {
                 this.MoveDown();
             }
         }
         else if (this.Orientation == 3)
         {
             if (mymap.CanBeStepped(this.Position.X, this.Position.Y - 1))
             {
                 this.MoveLeft();
             }
         }
     }
     else
     {
         this.MoveTowardsHero(mymap, myHero, creeper);
     }
 }
        public static void AllCreepersWalk(Map map, Hero myHero, List<Creeper> creepers)
        {
            foreach (var creeper in creepers)
            {
                Console.SetCursorPosition(creeper.Position.Y, creeper.Position.X);
                Console.Write(" ");
                map.WriteToMap(creeper.Position.X, creeper.Position.Y, "0");
                creeper.Walk(map, myHero, creeper);

                string creeperNumber = "0";

                if (creeper.GetType().Name == "Goblin")
                {
                    creeperNumber = "5";
                }
                else if (creeper.GetType().Name == "Orc")
                {
                    creeperNumber = "6";
                }

                map.WriteToMap(creeper.Position.X, creeper.Position.Y, creeperNumber);
            }
        }
 private static void RemoveDeadCreepers(Map mymap, Hero myHero, List<Creeper> creepers)
 {
     for (int i = 0; i < creepers.Count; i++)
     {
         if (creepers[i].Health < 1)
         {
             mymap.WriteToMap(creepers[i].Position.X, creepers[i].Position.Y, "0");
             Console.SetCursorPosition(creepers[i].Position.Y, creepers[i].Position.X);
             Console.Write(" ");
             Console.SetCursorPosition(creepers[i].Position.Y, creepers[i].Position.X);
             if (creepers[i].GetType().Name == "Orc")
             {
                 creepers[i] = new Orc("Orc" + (i + 1), mymap.RandomFreePosition());
                 myHero.Health += 3;
                 myHero.Money += 20;
                 InfoBox.PrintMoney(myHero);
             }
             else if (creepers[i].GetType().Name == "Goblin")
             {
                 creepers[i] = new Goblin("Goblin" + (i + 1), mymap.RandomFreePosition());
                 myHero.Health += 2;
                 myHero.Money += 10;
                 InfoBox.PrintMoney(myHero);
             }
         }
     }
 }
        public static void Main()
        {
            ConsoleClass.SetConsoleSize();

            // printing intro page
            Intro.PrintYellowBird();

            string heroName = Hero.EnterName();
            Hero myHero = new Hero(heroName);
            Map mymap = new Map(MapPath);
            ConsoleClass.PrintBorders();
            DateTime now = new DateTime();
            now = DateTime.Now;

            List<NPC> NPCs = new List<NPC>();
            AddNPCs(NPCs,mymap);

            List<Creeper> creepers = new List<Creeper>();
            for (int i = 0; i < 10; i++)
            {
                creepers.Add(new Orc("Orc" + (i + 1), mymap.RandomFreePosition()));
            }
            for (int i = 0; i < 15; i++)
            {
                creepers.Add(new Goblin("Goblin" + (i + 1), mymap.RandomFreePosition()));
            }

            mymap.InputCreaturesInMap(creepers);
            InfoBox.PrintInfo(myHero);
            mymap.PrintAroundPoint(myHero.Position.X, myHero.Position.Y);
            mymap.MarkAsVisited(myHero.Position.X, myHero.Position.Y);
            myHero.PrintHero();
            MessageBox.Print("Hello "+myHero.Name+"!");
            MessageBox.Print("This is Team Yellow Bird's RPG game, hope you enjoy it :)");
            Console.ReadKey();
            MessageBox.Clear();
            while (true)
            {

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();

                    if (key.Key == ConsoleKey.UpArrow)
                    {
                        if (mymap.CanBeStepped(myHero.Position.X - 1, myHero.Position.Y))
                        {
                            mymap.WriteToMap(myHero.Position.X, myHero.Position.Y, "0");
                            myHero.MoveUp();
                            mymap.WriteToMap(myHero.Position.X, myHero.Position.Y, "7");
                        }
                    }
                    else if (key.Key == ConsoleKey.DownArrow)
                    {
                        if (mymap.CanBeStepped(myHero.Position.X + 1, myHero.Position.Y))
                        {
                            mymap.WriteToMap(myHero.Position.X, myHero.Position.Y, "0");
                            myHero.MoveDown();
                            mymap.WriteToMap(myHero.Position.X, myHero.Position.Y, "7");
                        }
                    }
                    else if (key.Key == ConsoleKey.LeftArrow)
                    {
                        if (mymap.CanBeStepped(myHero.Position.X, myHero.Position.Y - 1))
                        {
                            mymap.WriteToMap(myHero.Position.X, myHero.Position.Y, "0");
                            myHero.MoveLeft();
                            mymap.WriteToMap(myHero.Position.X, myHero.Position.Y, "7");
                        }
                    }
                    else if (key.Key == ConsoleKey.RightArrow)
                    {
                        if (mymap.CanBeStepped(myHero.Position.X, myHero.Position.Y + 1))
                        {
                            mymap.WriteToMap(myHero.Position.X, myHero.Position.Y, "0");
                            myHero.MoveRight();
                            mymap.WriteToMap(myHero.Position.X, myHero.Position.Y, "7");
                        }
                    }
                    else if (key.Key == ConsoleKey.Spacebar)
                    {
                        Hero.HitNearby(myHero, creepers);
                    }

                    if (mymap.WasVisited(myHero.Position.X, myHero.Position.Y) == false)
                    {
                        mymap.PrintAroundPoint(myHero.Position.X, myHero.Position.Y);
                        mymap.MarkAsVisited(myHero.Position.X, myHero.Position.Y);
                    }
                    if (key.Key != ConsoleKey.Spacebar)
                    {
                        mymap.PrintAroundPoint(myHero.Position.X, myHero.Position.Y);
                        myHero.PrintHero();
                    }
                    RemoveDeadCreepers(mymap, myHero, creepers);
                }

                NPC.GiveQuestIfNeccessary(NPCs, myHero);
                NPC.OpenDoorIfQuestIsFinished(myHero, mymap);
                if(NPC.IsTheGameFinished(myHero))
                {
                    break;
                }
                MessageBox.Clear();
                now = DateTime.Now;

                if (now.Millisecond % 200 == 0)
                {
                    myHero.PrintHero();

                    Creeper.TurnIfNeccessary(mymap, creepers);
                    Creeper.AllCreepersWalk(mymap, myHero, creepers);
                    Creeper.PrintCreepers(mymap, creepers);
                    Creeper.HitIfNearby(mymap, myHero, creepers);
                }

                if (myHero.Health < 1)
                {
                    GameOver.EndGame();
                    break;
                }
            }

            if (NPC.IsTheGameFinished(myHero))
            {
                GameOver.GameWon();
            }
            ConsoleKeyInfo endKey = Console.ReadKey();
            while (endKey.Key != ConsoleKey.Enter)
            {
                endKey = Console.ReadKey();
            }
            MessageBox.Clear();
            Console.ReadLine();
        }
        private static void AddNPCs(List<NPC> NPCs, Map mymap)
        {
            NPCs.Add(new NPC("Kenov", new Coordinates(33,39), new Quest("First Quest", new List<string>{"Hello, boy!" , "You are new here, aren't you?", "You look very weak.", "With only this much health, you won't be able to survive!" , "Bring me 200 coins, and I'll double your health!"})));

            NPCs.Add(new NPC("Kostov", new Coordinates(5, 49), new Quest("Second Quest", new List<string>{"Hey, there!" , "I see you are a tough guy.", "If you can beat all these orcs and goblins", "and bring me 400 coins" , "I'll give you the key for the bridge!"})));

            foreach(var NPC in NPCs)
            {
                mymap.WriteToMap(NPC.Position.X, NPC.Position.Y, "8");
            }
        }
Exemple #7
0
 internal static void OpenDoorIfQuestIsFinished(Hero myHero,Map mymap)
 {
     if (myHero.keyFound)
     {
         mymap.WriteToMap(18, 53, "0");
         mymap.WriteToMap(19, 53, "0");
     }
 }
 internal static void HitIfNearby(Map mymap, Hero myHero, List<Creeper> creepers)
 {
     foreach (var creeper in creepers)
     {
         if (Creeper.HeroNearby(mymap, myHero, creeper))
         {
             myHero.Health -= creeper.Damage;
             InfoBox.PrintHealth(myHero);
             Console.Beep();
         }
     }
 }
        private void MoveTowardsHero(Map mymap, Hero myHero, Creeper creeper)
        {
            for (int i = creeper.Position.X - RangeAroundCreeper; i < creeper.Position.X + RangeAroundCreeper; i++)
            {
                for (int j = creeper.Position.Y - RangeAroundCreeper; j < creeper.Position.Y + RangeAroundCreeper; j++)
                {
                    if (myHero.Position.X == i && myHero.Position.Y == j)
                    {
                        if (i < creeper.Position.X)
                        {
                            if (mymap.CanBeStepped(this.Position.X - 1, this.Position.Y))
                            {
                                creeper.Orientation = 0;
                                if (mymap.CanBeStepped(this.Position.X - 1, this.Position.Y))
                                {
                                    this.MoveUp();
                                }
                            }
                            else if (j < creeper.Position.Y)
                            {
                                if (mymap.CanBeStepped(this.Position.X, this.Position.Y - 1))
                                {
                                    creeper.MoveLeft();
                                }
                            }
                            else if (j > creeper.Position.Y)
                            {
                                if (mymap.CanBeStepped(this.Position.X, this.Position.Y + 1))
                                {
                                    creeper.MoveRight();
                                }
                            }
                        }
                        else if (i > creeper.Position.X)
                        {
                            if (mymap.CanBeStepped(this.Position.X + 1, this.Position.Y))
                            {
                                creeper.Orientation = 2;
                                if (mymap.CanBeStepped(this.Position.X + 1, this.Position.Y))
                                {
                                    this.MoveDown();
                                }
                            }
                            else if (j < creeper.Position.Y)
                            {
                                if (mymap.CanBeStepped(this.Position.X, this.Position.Y - 1))
                                {
                                    creeper.MoveLeft();
                                }
                            }
                            else if (j > creeper.Position.Y)
                            {
                                if (mymap.CanBeStepped(this.Position.X, this.Position.Y + 1))
                                {
                                    creeper.MoveRight();
                                }
                            }
                        }
                        else if (j < creeper.Position.Y)
                        {
                            if (mymap.CanBeStepped(this.Position.X, this.Position.Y - 1))
                            {
                                creeper.Orientation = 3;
                                if (mymap.CanBeStepped(this.Position.X, this.Position.Y - 1))
                                {
                                    this.MoveLeft();
                                }
                            }
                            else if (mymap.CanBeStepped(this.Position.X - 1, this.Position.Y))
                            {
                                creeper.MoveUp();
                            }
                            else if (mymap.CanBeStepped(this.Position.X + 1, this.Position.Y))
                            {
                                creeper.MoveDown();
                            }
                        }
                        else if (j > creeper.Position.Y)
                        {
                            if (mymap.CanBeStepped(this.Position.X, this.Position.Y + 1))
                            {
                                creeper.Orientation = 1;
                                if (mymap.CanBeStepped(this.Position.X, this.Position.Y + 1))
                                {
                                    this.MoveRight();
                                }
                            }
                            else if (mymap.CanBeStepped(this.Position.X - 1, this.Position.Y))
                            {
                                creeper.MoveUp();
                            }
                            else if (mymap.CanBeStepped(this.Position.X + 1, this.Position.Y))
                            {
                                creeper.MoveDown();
                            }
                        }
                    }

                }
            }
        }
Exemple #10
0
        private static void CreeperTurnIfNeccessary(Map mymap, Creeper creeper)
        {
            Random randomGenerator = new Random();

            if (creeper.Orientation == 0 && !mymap.CanBeStepped(creeper.Position.X - 1, creeper.Position.Y))
            {
                creeper.Orientation = randomGenerator.Next(4);
            }
            else if (creeper.Orientation == 1 && !mymap.CanBeStepped(creeper.Position.X, creeper.Position.Y + 1))
            {
                creeper.Orientation = randomGenerator.Next(4);
            }
            else if (creeper.Orientation == 2 && !mymap.CanBeStepped(creeper.Position.X + 1, creeper.Position.Y))
            {
                creeper.Orientation = randomGenerator.Next(4);
            }
            else if (creeper.Orientation == 3 && !mymap.CanBeStepped(creeper.Position.X, creeper.Position.Y - 1))
            {
                creeper.Orientation = randomGenerator.Next(4);
            }
        }
Exemple #11
0
 internal static void TurnIfNeccessary(Map mymap, List<Creeper> creepers)
 {
     foreach (var creeper in creepers)
     {
         CreeperTurnIfNeccessary(mymap, creeper);
     }
 }
Exemple #12
0
 internal static void PrintCreepers(Map mymap, List<Creeper> creepers)
 {
     foreach (var creeper in creepers)
     {
         if (mymap.IsShown(creeper.Position.X, creeper.Position.Y))
         {
             Console.SetCursorPosition(creeper.Position.Y, creeper.Position.X);
             mymap.PrintColor(creeper.Position.X, creeper.Position.Y);
             Console.SetCursorPosition(creeper.Position.Y, creeper.Position.X);
         }
     }
 }
        public static void Main()
        {
            ConsoleClass.SetConsoleSize(); // old name Justify

            // printing intro page
            Intro.PrintYellowBird();

            string heroName = Hero.EnterName();  // moved from class Intro to Hero + renamed
            Hero myHero = new Hero(heroName);

            Map mymap = new Map(MapPath);
            ConsoleClass.PrintBorders();

            List<Creeper> creepers = new List<Creeper>();
            for (int i = 0; i < 5; i++)
            {
                creepers.Add(new Orc("Orc"+(i+1), mymap.RandomFreePosition()));
                //Console.WriteLine(creepers[i].Name);
            }
            for (int i = 0; i < 10; i++)
            {
                creepers.Add(new Goblin("Goblin" + (i + 1), mymap.RandomFreePosition()));
            }

            mymap.PrintAroundPoint(myHero.Position.X, myHero.Position.Y);
            myHero.PrintHero();
            //MessageBox.Print("Hello, " + myHero.Name);
            //MessageBox.Print("This is  Team Yellow Bird's RPG Game");
            //MessageBox.Print("Enjoy !");

            mymap.InputCreaturesInMap(creepers);
            //mymap.PrintMatrix();
            while (true)
            {

                //TODO:Make methods MoveUp,MoveDown,MoveLeft,MoveRight in the Alive class (abstract in the Alive class, also in the IAlive and in Hero class)!!!!!!!
                //Methods should use mymap.CanBeStepped() method !!!!

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();

                    if (key.Key == ConsoleKey.UpArrow)
                    {
                        if (mymap.CanBeStepped(myHero.Position.X - 1, myHero.Position.Y))
                        {
                            myHero.MoveUp();
                        }
                    }
                    else if (key.Key == ConsoleKey.DownArrow)           //TODO: MOVE ALL THIS METHODS IN THE HERO CLASS and check if the position is avaliable to step by using
                    {                                                   //mymap.CanBeStepped();
                        if (mymap.CanBeStepped(myHero.Position.X + 1, myHero.Position.Y))
                        {
                            myHero.MoveDown();
                        }
                    }
                    else if (key.Key == ConsoleKey.LeftArrow)
                    {
                        if (mymap.CanBeStepped(myHero.Position.X, myHero.Position.Y - 1))
                        {
                            myHero.MoveLeft();
                        }
                    }
                    else if (key.Key == ConsoleKey.RightArrow)
                    {
                        if (mymap.CanBeStepped(myHero.Position.X, myHero.Position.Y + 1))
                        {
                            myHero.MoveRight();
                        }
                    }

                    if (mymap.WasVisited[myHero.Position.X, myHero.Position.Y] == false)
                    {
                        mymap.PrintAroundPoint(myHero.Position.X, myHero.Position.Y);
                        mymap.WasVisited[myHero.Position.X, myHero.Position.Y] = true;
                    }
                    myHero.PrintHero();
                }
            }

            //TOVA E TESTOV KOMENTAR S CEL PROVERKA NA RABOTATA S GITHUB.......==
            // test OK ... - lenchev

            //mymap.PrintWholeMap();

            Console.ReadLine();
            MessageBox.Clear();
            Console.ReadLine();
        }