Methodes

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
EdEown
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 30
Joined: Sat Dec 19, 2009 5:00 pm
Favorite Gaming Platforms: PS3
Programming Language of Choice: C#
Location: Bosnia and Herzegovina

Methodes

Post 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:
"There is nothing either good or bad, but our thinking makes it so"
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Methodes

Post 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". :)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Methodes

Post by Ginto8 »

dandymcgee wrote:By the way, the correct spelling in English is "battle" not "bettle". :)
and "methods" not "methodes ;)
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Live-Dimension
Chaos Rift Junior
Chaos Rift Junior
Posts: 345
Joined: Tue Jan 12, 2010 7:23 pm
Favorite Gaming Platforms: PC - Windows 7
Programming Language of Choice: c++;haxe
Contact:

Re: Methodes

Post 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.
Image
Post Reply