1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Basic Battle Game

Discussion in 'C++' started by Whitfox, Apr 21, 2008.

  1. Whitfox

    Whitfox New Member

    Joined:
    Apr 21, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hey i have this so far as a little Dos text game
    Code:
    namespace AutoBattle
    {   
            public class Start
            {
                static void Main()
                {
                    Fighting.battlemethod();
                }
            }
    }
    
    and another class
    
    namespace AutoBattle
    {
        class Fighting
        {
            public static void battlemethod(string hero, string Monster, int Damage)
            {
                Console.WriteLine("What is the hero's name");
                hero = Console.ReadLine();
                Console.WriteLine("What is the Monsters name?");
                Monster = Console.ReadLine();
                Console.Write("{0} is facing a {1}",
                    hero, Monster);
            }
        }
    }
    In main the Fighting.Battlemethod is highlighted and the error reads No overload for method "battlemethod" takes '0' arguments.
    how do i fix this? :confused:
     
  2. imported_xpi0t0s

    imported_xpi0t0s New Member

    Joined:
    Jul 18, 2008
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Give Fighting.battlemethod() some arguments, e.g.
    Code:
    Fighting.battlemethod("xpi0t0s","whitfox",MAXINT);
    
    C# uses function overloading, which means you can have multiple functions named battlemethod(), but they must have different argument lists, for example you could have the battlemethod defined above for a player, a monster and damage points; you could also have one for traps where a player just gets hit with a number of points, you can have one with no agruments at all that does whatever seems appropriate etc. So the other possibility is to define Fighting::battlemethod(/*no arguments*/).
     

Share This Page