Reputation: 3
using System;
namespace VSCode
{
class Program
{
static void Main()
{
//Terminal Settings
Console.Title = "Dungeon Crawler";
Console.WindowHeight = 40;
Console.WindowWidth = 150;
//vars
int playerHP = 10;
string armorType = "Leather Tunic";
int armorValue = 1;
string weaponType = "Wooden sword";
int weaponDMG = 2;
int gold = 100;
string enemyType;
int enemyHP;
int enemyArmor;
int enemyDMG;
Console.WriteLine("Type 'start' to start the game");
if(Console.ReadLine() == "start")
{
DungeonCrawlersIntro();
}
void DungeonCrawlersIntro()
{
//intro
Console.WriteLine("---Welcome To Dungeon Crawler!");
Console.WriteLine("---Press Any Key to get the next line---");
Console.ReadKey(true);
Console.WriteLine("---Dungeon Crawler is a game made by YaLocalJesterBoi AKA Addi-O---");
Console.ReadKey(true);
Console.WriteLine("---It is a simple pure text RPG that I am working on alone with minimal yt help and the like. its just me making this thing for fun---");
Console.ReadKey(true);
Console.WriteLine("---Anyways, enjoy!");
Console.ReadKey(true);
Console.WriteLine("---You are an adventurer who has come from far away in order defeat the dungeon of the gods, 'Malakeith'---");
Console.ReadKey(true);
Console.WriteLine("--Like most other adventurers, all you want is money and loot. To be the strongest of them all---");
Console.ReadKey(true);
Console.WriteLine("---Currently you have " + playerHP + " HP " + armorType + " armor type that gives " + armorValue + " armor and " + gold + " Gold along with a " + weaponType + " that deals " + weaponDMG + " Attack damage---");
Console.ReadKey(true);
Console.WriteLine("---The dungeon Malakeith is quite famous and has a dfficulty all the from 'F' rank adventurers adventuring, to S class adventurers comeing to beat the dungeon entirely---");
Console.ReadKey(true);
Console.WriteLine("---You, just like many other ambitious adventurers just want some money and loot to live your life lavishly---");
Console.ReadKey(true);
Console.WriteLine("---The Dungeon itself is extremely popular, garnering people from all pver the world to explore it, but the selling point isn't just the dungeon itself, but the city that has been created around it. Malakeith city is well known as the best place to buy and sell anything obtained, or used in adventuring, all the way from a godly sword, to a simple health potion sold by every peddler---");
Console.ReadKey(true);
Console.WriteLine("---Type '/dungeon' to go to the dungeon---");
Console.WriteLine("---If you dont comply the game will simply shut down---");
if(Console.ReadLine() == "/dungeon")
{
Dungeon();
}
else
{
Console.WriteLine("---Since you were messing around, you got mugged and killed---");
Console.ReadKey();
playerHP = playerHP - 10;
if(playerHP < 1)
{
return;
}
}
}
void Dungeon()
{
Console.WriteLine("---You have entered the very first floor of the Malakeith dungeon!---");
Console.ReadKey(true);
Console.WriteLine("As you enter, you get transported into an iteration of the dungeon, totally randomized each time for every adventurer or party---");
Console.ReadKey(true);
Console.WriteLine("---The inside seem to be meadows, stretching on beyond the horizon---");
Console.ReadKey(true);
Console.WriteLine("---The only residents of this area are slimes and some other petty creatures such as goblins and the occasional goblin leader---");
Console.ReadKey(true);
Console.WriteLine("---One such resident of this area has decided to have a shit at killing you---");
Console.ReadKey(true);
enemyRoll();
}
void enemyRoll()
{
Random enemyRollValue = new Random();
int roll = 0;
roll = enemyRollValue.Next(1,7);
while(roll > 3)
{
goblinFight();
}
else
{
slimeFight();
}
}
void goblinFight()
{
enemyType = "goblin";
enemyHP = 5;
enemyArmor = 0;
enemyDMG = 4;
Console.WriteLine("---This resident that has come to fight is a " + enemyType + "---");
Console.ReadKey(true);
Console.WriteLine("It has " + enemyHP + " HP");
Console.ReadKey(true);
Attack();
}
void slimeFight()
{
enemyType = "slime";
enemyHP = 3;
enemyArmor = 0;
enemyDMG = 2;
Console.WriteLine("---This resident that has come to fight is a " + enemyType + "---");
Console.ReadKey(true);
Console.WriteLine("It has " + enemyHP + " HP");
Console.ReadKey(true);
}
void Attack()
{
enemyHP = (enemyHP + armorValue) - (weaponDMG + extraATK);
}
void AddAttack()
{
Random addAttack = new Random();
int extraATKRoll = 0;
extraATKRoll = addAttack.Next(1,10);
while(extraATKRoll >= 5)
{
public static int extraATK = 1;
}
}
}
}
}
it's a hundred something line of code that i've written for my pet project, dungeon crawlers. It's just a simple pure text RPG game made in VSCode alone that i've been making to brush up my skills and typing speed and to make me just more comfortable with VSCode. there's a couple errors that i'm having that i cant seem to find the answers to. I have tried the stuff i found online, but to no avail. the error messages are as follows:
} expected [VSCode]
} expected [VSCode, VSCode, VSCode]
Type or namespace definition, or end-of-file expected [VSCode]
Type or namespace definition, or end-of-file expected [VSCode]
Type or namespace definition, or end-of-file expected [VSCode]
The variable 'enemyArmor' is assigned but its value is never used [VSCode]
The variable 'enemyDMG' is assigned but its value is never used [VSCode]
The local function 'AddAttack' is declared but never used [VSCode]
The strange thing with enemy armor is that there are other ints and and strings that are declared and used in the exact same place with no difference(that i see) in use or writing. the main issue is with the '}' because previously the only problem was that there was 1 where it required 1 extra '}' because i messed up, but after that as i wrote more and more code, there were more of these popping up. i tried whatever i could find and havent been able to get further ahead. i have copy pasted some of my code from a previous iteration of the game that i scrapped for too much sphaghetti.
Do keep in mind that i'm pretty new to coding and not very good at it, so please put your answers in terms a new coder would understand
Upvotes: 0
Views: 52
Reputation: 81493
Firstly, you have the following; you can't else
a while
statement
while(roll > 3)
{
goblinFight();
}
//Comment out this mess, or do something else with it
//else
//{
// slimeFight();
//}
Secondly, you are trying to declare a static member inside a while
statement.. Once again it doesn't make sense:
while(extraATKRoll >= 5)
{
// this doesn't make sense, comment it out
//public static int extraATK = 1;
}
You need to put it directly in the class (at least):
class Program
{
public static int extraATK = 1;
Upvotes: 0
Reputation: 2988
Let's go through this one at a time:
void enemyRoll()
{
Random enemyRollValue = new Random();
int roll = 0;
roll = enemyRollValue.Next(1,7);
while(roll > 3)
{
goblinFight();
}
else
{
slimeFight();
}
}
There's an else
that isn't prefixed with an if
block. Change the while to an if
block to resolve the issue
void enemyRoll()
{
Random enemyRollValue = new Random();
int roll = 0;
roll = enemyRollValue.Next(1,7);
if(roll > 3)
{
goblinFight();
}
else
{
slimeFight();
}
}
Next error:
void AddAttack()
{
Random addAttack = new Random();
int extraATKRoll = 0;
extraATKRoll = addAttack.Next(1,10);
while(extraATKRoll >= 5)
{
public static int extraATK = 1;
}
}
You cannot create a global variable (i.e. extraATK
) inside a method. Define extraATK
below int enemyDMG
like int extraATK = 0;
After converting the while
to if
, the function should look like:
New function should look like:
void AddAttack()
{
Random addAttack = new Random();
int extraATKRoll = 0;
extraATKRoll = addAttack.Next(1,10);
if(extraATKRoll >= 5)
{
extraATK = 1;
}
}
This should resolve the issues.
Upvotes: 1
Reputation: 54417
Things go pear-shaped at that enemyRoll
method. You have a while
statement followed by an else
statement. You seem to be missing an if
somewhere but it's impossible to know for sure what you intended there.
Changing the while
to an if
fixed that issue but you still have another problem. In the AddAttack
method you have another while
loop and inside that you try to declare a static
field, which makes no sense at all.
Upvotes: 0