示例#1
0
 public RoboFighter(Fighter thePlayer, string theName) : base(theName)
 {
     player = thePlayer;
 }         // end constructor
示例#2
0
        public MainMenu()
        {
            int    choice;
            string name;

            //set up the contestants
            Console.Write("What is your name? ");
            name   = Console.ReadLine();
            player = new Fighter(name);
            Console.Write("What's your opponent's name? ");
            name     = Console.ReadLine();
            opponent = new RoboFighter(player, name);

            range = 10;
            while (keepGoing)
            {
                choice = displayMenu();
                switch (choice)
                {
                case 0:
                    //quit
                    Console.WriteLine("quitting");
                    keepGoing = false;
                    break;

                case 1:
                    //make a snowball
                    player.snowballs++;
                    break;

                case 2:
                    range--;
                    if (range < 0)
                    {
                        range = 0;
                    }     // end if
                    break;

                case 3:
                    range++;
                    break;

                case 4:
                    if (player.throwSnow(range))
                    {
                        Console.WriteLine("You hit {0}", opponent.name);
                        opponent.strength--;
                    }
                    else
                    {
                        Console.WriteLine("You missed {0}", opponent.name);
                    }     // end if
                    break;

                default:
                    Console.WriteLine("you said {0}", choice);
                    break;
                }     // end switch
                range = opponent.choosePlay(range);
                checkWinner();
            }     // end while loop
        }         // end constructor