-
October 13th, 2011, 09:43 PM
#1
What is WRONG with this code?
I've been working on the source code for an RPG game. This class I have here is the MainWorld class, a class designated to control movement in the game. So far, I've gone from about 70 to 13 compile errors. A few of them are syntax errors. The main ones are telling me that my type or namespace names are not found, even though I imported them into my code.
I'm also getting a message telling me I can't convert from int to string with my random functions. What's the fix for this?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RpgTutorial
{
class MainWorld
{
List<Character> Monster;
DataHandler data = new DataHandler();
Hero myhero;
public void Mainworld(Hero hero, List<Character> monsters)
{
Console.Write(@"
You are in a valley, not far from the town of Zalgalax.
Where do you wish to travel?
_____________________________
(NW) (N) (NE)
(w) (E)
(SW) (S) (SE)
(Exit)
_____________________________
");
Console.ReadLine();
choice = Console.ReadLine();
switch (answer)
{
case "NW":
case "nw":
case "Nw":
Northwest northwest = new Northwest(myhero);
case "N":
case "n":
North north = new North(myhero);
case "NE":
case "ne":
case "Ne":
Northeast northeast = new northeast(myhero);
//NE class will be added later
default:
Console.WriteLine("I'm sorry, I didn't understand that.");
return;
}
int battlechance;
int setnumber;
setnumber = 1;
rand = new Random();
battlechance = Random.Next(1, 100);
if (battlechance >= setnumber)
{
int randtwo;
gibblychance = 10;
string monsterchance;
Console.WriteLine("Suddenly, a wild monster appears!");
monsterchance = randtwo.Next(1, 60);
if (monsterchance = 1);
{
Monster.Add(new Zombie());
Monster.Add(new Zombie());
Monster.Add(new Zombie());
}
if (monsterchance = 2);
{
Monster.Add(new Borg());
}
if (monsterchance = 3);
{
Monster.Add(new Garryxx());
}
if (monsterchance = 4);
{
Console.WriteLine("You've been attacked by a tribal raiding party!");
Monster.Add(new Barbarian());
Monster.Add(new Barbarian());
Monster.Add(new Mage());
}
if (monsterchance = 5);
{
Monster.Add(new Slime());
}
if (monsterchance = 6);
{
Console.WriteLine("A vicious warrior of Gorox appears, a Gorox Paladin!");
Monster.Add(new GoroxPaladin());
}
Battle battle = new Battle(myhero, Monster);
}
}
}
}
I also have the full source code if you want to see the other classes.
-
October 13th, 2011, 11:38 PM
#2
Re: What is WRONG with this code?
This should be defined as an int not a string
Always use [code][/code] tags when posting code.
-
October 14th, 2011, 02:01 AM
#3
Re: What is WRONG with this code?
Originally Posted by Krunchyman
I've been working on the source code for an RPG game. This class I have here is the MainWorld class, a class designated to control movement in the game. So far, I've gone from about 70 to 13 compile errors. A few of them are syntax errors. The main ones are telling me that my type or namespace names are not found, even though I imported them into my code.
I'm also getting a message telling me I can't convert from int to string with my random functions. What's the fix for this?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RpgTutorial
{
class MainWorld
{
List<Character> Monster;
DataHandler data = new DataHandler();
Hero myhero;
public void Mainworld(Hero hero, List<Character> monsters)
{
Console.Write(@"
You are in a valley, not far from the town of Zalgalax.
Where do you wish to travel?
_____________________________
(NW) (N) (NE)
(w) (E)
(SW) (S) (SE)
(Exit)
_____________________________
");
Console.ReadLine();
choice = Console.ReadLine();
switch (answer)
{
case "NW":
case "nw":
case "Nw":
Northwest northwest = new Northwest(myhero);
case "N":
case "n":
North north = new North(myhero);
case "NE":
case "ne":
case "Ne":
Northeast northeast = new northeast(myhero);
//NE class will be added later
default:
Console.WriteLine("I'm sorry, I didn't understand that.");
return;
}
int battlechance;
int setnumber;
setnumber = 1;
rand = new Random();
battlechance = Random.Next(1, 100);
if (battlechance >= setnumber)
{
int randtwo;
gibblychance = 10;
string monsterchance;
Console.WriteLine("Suddenly, a wild monster appears!");
monsterchance = randtwo.Next(1, 60);
if (monsterchance = 1);
{
Monster.Add(new Zombie());
Monster.Add(new Zombie());
Monster.Add(new Zombie());
}
if (monsterchance = 2);
{
Monster.Add(new Borg());
}
if (monsterchance = 3);
{
Monster.Add(new Garryxx());
}
if (monsterchance = 4);
{
Console.WriteLine("You've been attacked by a tribal raiding party!");
Monster.Add(new Barbarian());
Monster.Add(new Barbarian());
Monster.Add(new Mage());
}
if (monsterchance = 5);
{
Monster.Add(new Slime());
}
if (monsterchance = 6);
{
Console.WriteLine("A vicious warrior of Gorox appears, a Gorox Paladin!");
Monster.Add(new GoroxPaladin());
}
Battle battle = new Battle(myhero, Monster);
}
}
}
}
I also have the full source code if you want to see the other classes.
Shouldn't your comparisons also be "==" ?
-
October 14th, 2011, 02:46 AM
#4
Re: What is WRONG with this code?
few things I found
rand = new Random(); // I guiess rand instance you crated properly
battlechance = Random.Next(1, 100); this should be rand not Random
randtwo should of type Random not int
Monster is list of "Character" you are trying to add Zombie, Brog, Garryxxx - If these classes are not derived from Character do that also.
If(...) will not be ended with ";"
if - equla condition is ==
etc..
Regards
Ravi
Ravi.Battula
-
October 14th, 2011, 02:50 AM
#5
Re: What is WRONG with this code?
One more thing
If you use more than one case statement, these case statements should end with break or continue or goto etc.
ex:
case "NW":
case "nw":
case "Nw":
Northwest northwest = new Northwest(myhero);
break;
Regards
Ravi
Ravi.Battula
-
October 14th, 2011, 03:27 AM
#6
Re: What is WRONG with this code?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RpgTutorial
{
class MainWorld
{
List<Character> Monster; // Zombie? Hmm. What's this type?
DataHandler data = new DataHandler();
Hero myhero;
string choice;
public void Mainworld(Hero hero, List<Character> monsters)
{
Console.Write(@"You are in a valley, not far from the town of Zalgalax.
Where do you wish to travel?
_____________________________
(NW) (N) (NE)
(W) (E)
(SW) (S) (SE)
(Exit)
_____________________________
");
Console.ReadLine();
choice = Console.ReadLine();
choice = choice.ToUpper();
switch (choice)
{
case "NW":
Northwest northwest = new Northwest(myhero);
break;
case "N":
North north = new North(myhero);
break;
case "NE":
Northeast northeast = new Northeast(myhero);
break;
default:
Console.WriteLine("I'm sorry, I didn't understand that.");
return;
}
int setnumber = 1;
Random rand = new Random();
int battlechance = rand.Next(1, 100);
if (battlechance >= setnumber)
{
Random randtwo = new Random();
int gibblychance = 10;
int monsterchance = randtwo.Next(1, 60);
Console.WriteLine("Suddenly, a wild monster appears!");
if (monsterchance == 1)
{
Monster.Add(new Zombie());
Monster.Add(new Zombie());
Monster.Add(new Zombie());
}
if (monsterchance == 2)
{
Monster.Add(new Borg());
}
if (monsterchance == 3)
{
Monster.Add(new Garryxx());
}
if (monsterchance == 4)
{
Console.WriteLine("You've been attacked by a tribal raiding party!");
Monster.Add(new Barbarian());
Monster.Add(new Barbarian());
Monster.Add(new Mage());
}
if (monsterchance == 5)
{
Monster.Add(new Slime());
}
if (monsterchance == 6)
{
Console.WriteLine("A vicious warrior of Gorox appears, a Gorox Paladin!");
Monster.Add(new GoroxPaladin());
}
Battle battle = new Battle(myhero, Monster);
}
}
}
}
I think most are fixed.
Hope it helps!
Regards,
Quinn
If this post helps, please rate this post!
Last edited by QuinnJohns; October 14th, 2011 at 01:41 PM.
Reason: Wow, good save TGC.
-
October 14th, 2011, 05:49 AM
#7
Re: What is WRONG with this code?
Except for the ';' at the if-statements - it should be removed. For example:
Code:
if (monsterchance == 3); // <---- (here)
{
Monster.Add(new Garryxx());
}
Anyway, Krunchyman, go throughout all the post and correct the errors they found. There's a whole bunch of mistakes here that clearly show you really need to read up on C# basics - and honestly, that's the best advice I can give you; there's simply no other way to start coding.
-
October 14th, 2011, 07:43 AM
#8
Re: What is WRONG with this code?
Ok, thanks guys. I should have all the help I need now.
-
October 14th, 2011, 01:41 PM
#9
Re: What is WRONG with this code?
Originally Posted by TheGreatCthulhu
Except for the ';' at the if-statements - it should be removed. For example:
Code:
if (monsterchance == 3); // <---- (here)
{
Monster.Add(new Garryxx());
}
Anyway, Krunchyman, go throughout all the post and correct the errors they found. There's a whole bunch of mistakes here that clearly show you really need to read up on C# basics - and honestly, that's the best advice I can give you; there's simply no other way to start coding.
wow, good save. I can't believe I missed that.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|