Exemplo n.º 1
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            Console.OutputEncoding = System.Text.Encoding.Unicode;

            KeyListener     keyboard = new KeyListener();
            ConsoleRenderer renderer = new ConsoleRenderer(ConsoleSettings.ConsoleHeight, ConsoleSettings.ConsoleWidth);
            GameEngine      engine   = new GameEngine(keyboard, renderer);

            engine.InitAllGameObjects();

            Console.BufferHeight = Console.WindowHeight; // Remove the scrollbar

            keyboard.OnDownPressed  += (sender, eventInfo) => { engine.Team.Move(Direction.Down); };
            keyboard.OnUpPressed    += (sender, eventInfo) => { engine.Team.Move(Direction.Up); };
            keyboard.OnLeftPressed  += (sender, eventInfo) => { engine.Team.Move(Direction.Left); };
            keyboard.OnRightPressed += (sender, eventInfo) => { engine.Team.Move(Direction.Right); };

            engine.Run();
        }
Exemplo n.º 2
0
        private void CheckAllCollisions()
        {
            BattleHandler battles = CollisionDispatcher.SeeForCollisionsWithEnemies(this.team, this.allEnemies);

            if (battles)
            {
                if (this.team.CanFly)
                {
                    Console.WriteLine("You met {0}, do you want to fly away? Y/N", battles.Enemy.Name);
                    string command = Console.ReadLine().ToLower();
                    if (command == "y")
                    {
                        Console.Clear();
                        Location locationArrival = GetFreeLocationAtDistance(this.team.Position, this.Team.FlyAway());
                        this.Team.Position = locationArrival;
                        this.team.CanFly   = false;
                        return;
                    }
                }
                if (this.team.CanRide)
                {
                    Console.WriteLine("You met {0}, do you want to ride away? Y/N", battles.Enemy.Name);
                    string command = Console.ReadLine().ToLower();
                    if (command == "y")
                    {
                        Console.Clear();
                        Location locationArrival = GetFreeLocationAtDistance(this.team.Position, this.Team.RideAway());
                        this.Team.Position = locationArrival;
                        this.team.CanRide  = false;
                        return;
                    }
                }

                Console.WriteLine("You met {0}", battles.Enemy.Name);

                ConsoleRenderer newBattleField = new ConsoleRenderer(this.battleField.Rows, this.battleField.Cols);
                BattleEngine    battleEngine   = new BattleEngine(newBattleField, battles.Friend, battles.Enemy);
                this.joinInTeamMessage = null;
                battleEngine.Run();
            }

            if (CollisionDispatcher.SeeForCollisionsWithWalls(this.team, this.allWalls))
            {
                this.team.MoveBack();
            }

            Friend friendToJoin = CollisionDispatcher.SeeForCollisionsWithFriends(team, this.allFriends);

            if (friendToJoin != null)
            {
                this.team.AddCompanion(friendToJoin);
                //this.joinInTeamMessage = string.Format("{0} just joined the team. The team's strength is now {1:0.00}.",
                //friendToJoin.Name, team.Strength);

                friendToJoin.IsAlive = false;
            }

            Item itemToJoin = CollisionDispatcher.SeeForCollisionWithItems(this.team, this.allItems);

            if (itemToJoin != null)
            {
                this.team.AddItem(itemToJoin);
                if (itemToJoin is Horses)
                {
                    this.joinInTeamMessage = "Riding ability was added to the team.";
                }
                else if (itemToJoin is Eagles)
                {
                    this.joinInTeamMessage = "Flying ability was added to the team.";
                }
                else if (itemToJoin is Food)
                {
                    this.joinInTeamMessage = string.Format("The team found some food. After having a nice lunch, its strength is now {0:0.00}.",
                                                           team.Strength);
                }
                else
                {
                    this.joinInTeamMessage = string.Format("The team found some weapons. After filling the arsenal, its strength is now {0:0.00}.",
                                                           team.Strength);
                }

                itemToJoin.IsAlive = false;
            }

            if (CollisionDispatcher.SeeForCollisionWithTreasure(this.team, this.treasure))
            {
                Console.Clear();
                Console.WriteLine("Contragulations, you win the game, you got the treasure, do you want to start again y/n");
                string command = Console.ReadLine().ToLower();

                if (command == "y")
                {
                    Console.Clear();
                    this.allObjects  = new List <GameObject>();
                    this.allEnemies  = new List <Enemy>();
                    this.allWalls    = new List <Wall>();
                    this.allFriends  = new List <Friend>();
                    this.allItems    = new List <Item>();
                    this.battleField = new ConsoleRenderer(ConsoleSettings.ConsoleHeight, ConsoleSettings.ConsoleWidth);

                    this.InitAllGameObjects();
                }
                else
                {
                    Environment.Exit(1);
                }
            }
            if (this.team.IsAlive == false)
            {
                Console.Clear();
                Console.WriteLine("Game Over, do you want to start again y/n");
                string command = Console.ReadLine().ToLower();

                if (command == "y")
                {
                    Console.Clear();
                    this.allObjects  = new List <GameObject>();
                    this.allEnemies  = new List <Enemy>();
                    this.allWalls    = new List <Wall>();
                    this.allFriends  = new List <Friend>();
                    this.allItems    = new List <Item>();
                    this.battleField = new ConsoleRenderer(ConsoleSettings.ConsoleHeight, ConsoleSettings.ConsoleWidth);

                    this.InitAllGameObjects();
                }
                else
                {
                    Environment.Exit(1);
                }
            }
        }