コード例 #1
0
        // This program simulates a simple game. The game is as follows:
        // There is a player who fires a weapon. There can be different types of weapons.
        // The player is represented by a Player class.
        static void Main(string[] args)
        {
            while (true)
            {
                Console.Write("Enter 1 for Gun, 2 for Bow and Arrow, any other key to exit: ");

                string option = Console.ReadLine();

                IWeapon weapon;

                if (option == "1")
                {
                    weapon = new Gun();
                }
                else if (option == "2")
                {
                    weapon = new BowAndArrow();
                }
                else
                {
                    return;
                }

                Player player = new Player();
                player.UseWeapon(weapon);
            }
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: girish-a/bms-college
        public void UseBowAndArrow()
        {
            BowAndArrow bowAndArrow = new BowAndArrow();

            bowAndArrow.Fire();
        }