Page 1 of 1

Methodes

Posted: Thu Jan 07, 2010 4:30 am
by EdEown
Ah I know I am pain in the ass, but blain Gryo, he gave me this idea ;)

Ok, I have understand the methodes, learn how to write them but when I come to the part where I have to use the I get all confused. Here are methodes for text
game that I created. I need to use them, but i have problem. I dont know I to put them to interact between each other. It is easy with "Switch" or "if" statment where you easyle guide user, but I just dont how to do it with methodes. I think I didnt explain my problem well, sorry for english :(

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static string ChoiceA()
        {
            string Attack;
            Console.WriteLine("Enter 'Attack' to attack with your Hero");
            Attack = Console.ReadLine();
            Console.WriteLine();
            return Attack;
        }

        static string ChoiceD()
        {
            string Defend;
            Console.WriteLine("Enter 'Defend' to defend your self from monster");
            Defend = Console.ReadLine();
            Console.WriteLine();
            return Defend;
        }

        static int HeroBettle(int monsterHitpoints, int heroBattleDemage)
        {
            monsterHitpoints = 25;
                Random rand;
                rand = new Random();
                heroBattleDemage = rand.Next(4, 8);
                monsterHitpoints = monsterHitpoints - heroBattleDemage;
            Console.WriteLine("Your Hero attacks with {0} demage", heroBattleDemage);
            Console.WriteLine("");
            Console.WriteLine("The monster has {0} hp", monsterHitpoints);
            return monsterHitpoints;
        }
       
        
        static int HeroDefends(int HeroHitPoints, int MonsterDefendedBettleDemage)
        {
            HeroHitPoints = 30;
                Random rand;
                rand = new Random();
                MonsterDefendedBettleDemage = rand.Next(2, 5);
                HeroHitPoints = HeroHitPoints - MonsterDefendedBettleDemage;
            Console.WriteLine(@"The monster attacks with {0} demage and the hero defends him self, receiving minimal    
            demage", MonsterDefendedBettleDemage);
            Console.WriteLine("The Hero has {0} hp", HeroHitPoints);
            return HeroHitPoints;
         }



        static int MonsterBettle(int heroHitPoints, int monsterBettleDemage)
        {
            heroHitPoints  = 25;
                Random rand;
                rand = new Random ();
                monsterBettleDemage = rand.Next(5, 10);
                heroHitPoints = heroHitPoints - monsterBettleDemage;
            Console.WriteLine("The monster attacks with {0} demage", monsterBettleDemage);
            Console.WriteLine("");
            Console.WriteLine("The hero has {0} hp", heroHitPoints);
            return heroHitPoints ;
        }

        static void Main(string[] args)
        {    

        }
    }
}
I need to make methodes in Main (where my program start) work together. Dono how..xD
I easyly done it with digitron because that is a bit easy, but this one is hard (for me )--

thanks :worship:

Re: Methodes

Posted: Thu Jan 07, 2010 7:45 pm
by dandymcgee
Just call them from main like this:

Code: Select all

        static void Main(string[] args)
        {
                ChoiceA();
                ChoiceD();
                HeroBettle( 35, 15 );
                HeroDefends( 14, 32 );
                MonsterBettle( 10, 10 );
        }
By the way, the correct spelling in English is "battle" not "bettle". :)

Re: Methodes

Posted: Thu Jan 14, 2010 7:03 am
by Ginto8
dandymcgee wrote:By the way, the correct spelling in English is "battle" not "bettle". :)
and "methods" not "methodes ;)

Re: Methodes

Posted: Thu Jan 14, 2010 8:25 am
by Live-Dimension
Not exactly relevant, work on getting some more skills up and understanding of c#. Then, since your new to programming, i suggest you start with XNA which is c# based if you want to try out game programming - it handles almost all of the hard yards for you and the tutorials are easy to work with. It's also pretty powerful - you can't go wrong with it as a starter.