|
-
June 7th, 2012, 04:20 PM
#1
Game problem
Hey im a new C# learner and im currently following a guide on a website. In the guide we are currently making a rpg (role playing game) and i just cant seem to get it to work. Now this may see a little wall of textish but im going to post my code for all the classes and stuff. The error i get a lot is The name *____* does not exist in the current context. Also the error member names can not be the same as their enclosing type( this one seems to have gone away with some tweaking). So heres my code thanks in advance to anyone who can help.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RpgTutorial
{
class Damage
{
int DealDamage(Hero hero, Monster monster)
{
int max;
int min;
rand = new Random();
max = hero.AttackDamage - monster.Defense;
if (max <= 0)
{
max = 1;//right now this isn't a concern, but this is a bit
//of future proofing our damage mechanism
}
min = (int)(hero.AttackDamage * .8) - monster.Defense;//**I'll explain this one**
if (min <= 0)
{
min = 1;
}
damage = rand.Next(min, max);//calculate the damage
return damage;//send it on back
}
bool CheckHealth(int health)
{
bool alive;
if (health > 0)
{
alive = true;
}
else
{
alive = false;
}
return alive;
}
}
}
__________________________________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RpgTutorial
{
class PrintChoices
{
string PrintChoice()
{
string choice;
Console.WriteLine();
Console.Write(@"
_____________________
Please choose an action:
(A)ttack:
(D)efend:
_____________________");
Console.WriteLine();
choice = Console.ReadLine();
return choice;
}
}
}
_______________________________________________________________________using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RpgTutorial
{
class ProcessChoices
{
void ProcessChoice(string choice, Hero hero, Monster monster)
{
switch (choice)
{
case "A":
case "a":
Console.WriteLine();
Console.WriteLine("{0} attacks!", hero.Identifier);//print what it is
DealDamage(hero, monster);//send it to our damage method
monster.CurrentHealth -= damage;//take it from the monster
Console.WriteLine("{0} hits the {1} for {2}hp of damage"
, hero.Identifier, monster.Identifier, damage);//show result
break;
case "D":
case "d":
Console.WriteLine();
Console.WriteLine("{0} defends!", hero.Identifier);
//we will make defending more beneficial later
//Many times you will see this shown like below:
//To Do: Add logic to make defending beneficial
break;
default:
Console.WriteLine("I'm sorry, I didn't recognize that.");
Console.WriteLine();//if the choice isn't valid
choice = PrintChoice();//the we'll keep asking till
Console.WriteLine();//they get it right
ProcessChoice(choice, hero, monster);
break;
}
}
}
}
_________________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RpgTutorial
{
class Monster
{
public int CurrentHealth, MaxHealth, CurrentMagic;
public int M*****ic, Strength, Defense, Agility;
public int Experience, Gold, AttackDamage;
public string Identifier;
public bool isAlive;
public Monster()
{
CurrentHealth = 8;
MaxHealth = 8;
CurrentMagic = 0;
M*****ic = 0;
Strength = 5;
Defense = 3;
Agility = 4;
Experience = 5;
Gold = 2;
Identifier = "Monster";
isAlive = true;
AttackDamage = Strength;
}
}
}
__________________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RpgTutorial
{
class Hero
{
public int CurrentHealth, MaxHealth, CurrentMagic;
public int M*****ic, Strength, Defense, Agility;
public int Experience, Gold, AttackDamage;
public string Identifier;
public bool isAlive;
public Hero()
{
}
public static void Initialize(Hero hero)
{
hero.CurrentHealth = 18;
hero.MaxHealth = 18;
hero.CurrentMagic = 8;
hero.M*****ic = 8;
hero.Strength = 10;
hero.Defense = 3;
hero.Agility = 6;
hero.Experience = 0;
hero.Gold = 0;
Console.WriteLine("What is your Hero's name?");
hero.Identifier = Console.ReadLine();
hero.isAlive = true;
hero.AttackDamage = hero.Strength;
}
}
}
_____________________________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RpgTutorial
{
class Battle
{
string userchoice;
int damage;
Random rand;
public Battle(Hero hero, Monster monster)
{
Console.WriteLine("{0} is facing a {1}.", hero.Identifier, monster.Identifier);
BattleLoop(hero, monster);
}
public void BattleLoop(Hero hero, Monster monster)
{
do
{
PrintStatus(hero, monster);
userchoice = PrintChoice();
Console.WriteLine();
ProcessChoice(userchoice, hero, monster);
Console.ReadLine();
Console.Clear();//This clears our screen so the next turn is a fresh screen
}
while (hero.isAlive == true && monster.isAlive == true);
}
void PrintStatus(Hero hero, Monster monster)
{
Console.Write(@"
********************************
HP/MaxHP MP/MaxMP
{0}: {1}/{2}hp {3}/{4}mp
{5}: {6}/{7}hp {8}/{9}mp
********************************
", hero.Identifier, hero.CurrentHealth, hero.MaxHealth, hero.CurrentMagic, hero.M*****ic,
monster.Identifier, monster.CurrentHealth, monster.MaxHealth, monster.CurrentMagic, monster.M*****ic);
}
}
}
______________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RpgTutorial
{
class Program
{
static void Main(string[] args)
{
MainGame maingame = new MainGame();
}
}
}
___________________________________________________
and lastly these are all the errors i am currently recieving
Error 2 The name 'damage' does not exist in the current context
C:\Users\Randomized\Documents\Visual Studio 2010\Projects\Restarted\ProcessChoice.cs
19 46 Restarted
Error 3 The name 'damage' does not exist in the current context
C:\Users\Randomized\Documents\Visual Studio 2010\Projects\Restarted\ProcessChoice.cs
21 64 Restarted
Error 8 The name 'damage' does not exist in the current context
C:\Users\Randomized\Documents\Visual Studio 2010\Projects\Restarted\Damage.cs
26 13 Restarted
Error 10 The name 'damage' does not exist in the current context
C:\Users\Randomized\Documents\Visual Studio 2010\Projects\Restarted\Damage.cs
27 20 Restarted
Error 1 The name 'DealDamage' does not exist in the current context
C:\Users\Randomized\Documents\Visual Studio 2010\Projects\Restarted\ProcessChoice.cs
18 21 Restarted
Error 4 The name 'PrintChoice' does not exist in the current context
C:\Users\Randomized\Documents\Visual Studio 2010\Projects\Restarted\Battle.cs
26 30 Restarted
Error 6 The name 'PrintChoice' does not exist in the current context
C:\Users\Randomized\Documents\Visual Studio 2010\Projects\Restarted\ProcessChoice.cs
34 30 Restarted
Error 5 The name 'ProcessChoice' does not exist in the current context
C:\Users\Randomized\Documents\Visual Studio 2010\Projects\Restarted\Battle.cs
28 17 Restarted
Error 7 The name 'rand' does not exist in the current context
C:\Users\Randomized\Documents\Visual Studio 2010\Projects\Restarted\Damage.cs
14 13 Restarted
Error 9 The name 'rand' does not exist in the current context
C:\Users\Randomized\Documents\Visual Studio 2010\Projects\Restarted\Damage.cs
26 22 Restarted
____________________________________________________
Thats it if anyone notices anything else that needs fixing tell me and i will fix it right away 
Reply
Last edited by Marc G; June 8th, 2012 at 06:53 AM.
Reason: added code tags
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
|