コード例 #1
0
ファイル: Engine.cs プロジェクト: nina75/PoliticianGame
        public static void Action()
        {
            DrawScreen.DrawConsoleBottom();
            var baba = new GrandMom(48, 23);
            var parliament = new Parliament(40, 2);
            var garden1 = new Garden(5, 2);
            var garden2 = new Garden(73, 2);
            var policeman1 = new Policeman(76, 4);
            var policeman2 = new Policeman(8, 4);
            var politician1 = new Politician(0, 12);
            var politician2 = new Politician(97, 15);
            var politician3 = new Politician(0, 18);
            var mom = new BGMom(30, 4);
            var walker = new Walker(64, 4);

            Console.SetCursorPosition(0, 33);
            Console.WriteLine("Money:        $  Use Arrows: ");
            Console.WriteLine("Cane:         %  UP");
            Console.WriteLine("Bag:          %  DOWN  ");
            Console.WriteLine("Umbrella:     %  LEFT ");
            Console.WriteLine("Gun:          %  RIGHT");
            Console.WriteLine("Health:       %");

            var objects =
                new List<GameObject>()
                {
                    baba, parliament, garden1, garden2, policeman1, policeman2, politician1,
                    politician2, politician3, mom, walker, baba.Money, baba.Cane, baba.Bag, baba.Umbrella, baba.Gun
                };

            baba.AddEnemies(objects);

            //Using polumorphism
            foreach (var obj in objects)
            {
                obj.RenderImg();
            }

            var allWeapons = baba.AllWeapons();

            while (true)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                baba.Move();
                Console.ForegroundColor = ConsoleColor.Yellow;
                policeman1.Move(76, 4);
                policeman2.Move(8, 4);
                politician1.Move(0, 12);
                politician2.MoveBack(97, 15);
                politician3.Move(0, 18);

                UpdateResource(allWeapons, baba);

                //Baba meets the BGMama
                if (baba.CoordX == 31 && baba.CoordY == 6)
                {
                    MeetTheBGMom(baba, mom);
                }

                //Baba meets the walker
                if (baba.CoordX == 64 && baba.CoordY == 6)
                {
                    MeetTheWalker(baba, walker);
                }

                //Handling crashes with politicians and policemen
                HandleCrashes(baba);

                if (!UpdateGrannyStatus(baba))
                {
                    break;
                }

                Thread.Sleep(100);
            }

            Console.SetCursorPosition(47, 20);
            Console.ForegroundColor = ConsoleColor.Red;
            DialogResult res = MessageBox.Show("GAME OVER!\nDo you want to start a new game?", "PoliticianCrusade", MessageBoxButtons.YesNo);

            if (res == DialogResult.Yes)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Gray;
                Action();

            }
            else
            {
                Environment.Exit(0);
            }
        }
コード例 #2
0
ファイル: Engine.cs プロジェクト: nina75/PoliticianGame
        public static void Action()
        {
            DrawScreen.DrawConsoleBottom();
            var baba        = new GrandMom(48, 23);
            var parliament  = new Parliament(40, 2);
            var garden1     = new Garden(5, 2);
            var garden2     = new Garden(73, 2);
            var policeman1  = new Policeman(76, 4);
            var policeman2  = new Policeman(8, 4);
            var politician1 = new Politician(0, 12);
            var politician2 = new Politician(97, 15);
            var politician3 = new Politician(0, 18);
            var mom         = new BGMom(30, 4);
            var walker      = new Walker(64, 4);

            Console.SetCursorPosition(0, 33);
            Console.WriteLine("Money:        $  Use Arrows: ");
            Console.WriteLine("Cane:         %  UP");
            Console.WriteLine("Bag:          %  DOWN  ");
            Console.WriteLine("Umbrella:     %  LEFT ");
            Console.WriteLine("Gun:          %  RIGHT");
            Console.WriteLine("Health:       %");


            var objects =
                new List <GameObject>()
            {
                baba, parliament, garden1, garden2, policeman1, policeman2, politician1,
                politician2, politician3, mom, walker, baba.Money, baba.Cane, baba.Bag, baba.Umbrella, baba.Gun
            };

            baba.AddEnemies(objects);

            //Using polumorphism
            foreach (var obj in objects)
            {
                obj.RenderImg();
            }

            var allWeapons = baba.AllWeapons();

            while (true)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                baba.Move();
                Console.ForegroundColor = ConsoleColor.Yellow;
                policeman1.Move(76, 4);
                policeman2.Move(8, 4);
                politician1.Move(0, 12);
                politician2.MoveBack(97, 15);
                politician3.Move(0, 18);

                UpdateResource(allWeapons, baba);

                //Baba meets the BGMama
                if (baba.CoordX == 31 && baba.CoordY == 6)
                {
                    MeetTheBGMom(baba, mom);
                }

                //Baba meets the walker
                if (baba.CoordX == 64 && baba.CoordY == 6)
                {
                    MeetTheWalker(baba, walker);
                }

                //Handling crashes with politicians and policemen
                HandleCrashes(baba);

                if (!UpdateGrannyStatus(baba))
                {
                    break;
                }

                Thread.Sleep(100);
            }

            Console.SetCursorPosition(47, 20);
            Console.ForegroundColor = ConsoleColor.Red;
            DialogResult res = MessageBox.Show("GAME OVER!\nDo you want to start a new game?", "PoliticianCrusade", MessageBoxButtons.YesNo);

            if (res == DialogResult.Yes)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Gray;
                Action();
            }
            else
            {
                Environment.Exit(0);
            }
        }