Jump to content

opinions on my text based adventure game(WIP and first game)

themaniac
6 hours ago, themaniac said:

I'm having a bit of a hard time understanding, could you give an example of it using part of my code, if you don't mind?

Sure of course.

 

Magic numbers and literals:

const string SomeNumberChoice = "2";

if(BushSound == SomeNumberChoice)

Implicit Types:

var SEXanswer = Console.ReadLine();

String interpolation:

Console.WriteLine($"???: I am {SEXanswer}.");

 

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, Nuluvius said:

Sure of course.

 

Magic numbers and literals:


const string SomeNumberChoice = "2";

if(BushSound == SomeNumberChoice)

Implicit Types:


var SEXanswer = Console.ReadLine();

String interpolation:


Console.WriteLine($"???: I am {SEXanswer}.");

 

that makes since now, thanks also is there any other way to make comments other then // ?

 

EDIT: I tried to do the magic numbers and literals one but it just skips the if statement and closes, heres the code if it helps

EDIT 2: nevermind figured it out, just needed to add bushSound = Console.ReadLine(); above the const(under the writeline asking about the bush)

//Adventure Start
//Part 1 The Forest

var Narrator = "Narrator: ";
var partnerName = "nothing";
var PartnerCompliment = "nothing";
var Partner = "nothing";
var bushSound = "";



if (SEXanswer == "male")
{
  partnerName = "Jessica";
  Partner = "Jessica: ";
  PartnerCompliment = "beautiful young lady";
}
else if(SEXanswer == "female")
{
  partnerName = "Rapheal";
  Partner = "Rapheal: ";
  PartnerCompliment = "handsome young man";
}

Console.WriteLine(Narrator + "You open your eyes and see you are on a cliff surrounded by a beautiful, lush, and green forest.");
Console.WriteLine(MC + "Wow! This is amazing!");
Console.WriteLine(Narrator + "You here a sound in the bush's behind you. Do you");
Console.WriteLine("Investigate the sound = 1 or Explore the forest elsewhere = 2");

const string bushSoundInvest = "1";
const string bushSoundExplore = "2";

if (bushSound == bushSoundInvest)
{
  Console.WriteLine(Narrator + "You investigate the sound only to find a pack of wolves eating a deer.");
  Console.WriteLine(MC + "Holy ****!");
  Console.WriteLine(Narrator + "The wolves notice you. You try to run away but to no avail, they catch you.");
  Console.WriteLine(Narrator + "As you are screaming and fighting for your life the wolves are shot by arrows");
  Console.WriteLine(Narrator + "Before your eyes go black, you see a " + PartnerCompliment + "." + " You have died of blood loss.");
  Console.ReadLine();
  return;
}
if(bushSound == bushSoundExplore)
{
  Console.WriteLine(Narrator + "You explore the forest elsewhere.");
  Console.WriteLine(Narrator + "As you are exploring the forest, you see a group of deers in front of you, they are surrounding something.");
  Console.WriteLine(Narrator + "You move in slowly and quietly to see what they are surrounding and see a doe giving birth");
  Console.WriteLine(MC + "Well thats a first for me, guess I should leave before I'm noticed and get in the way.");

  //Part 1 The Forest: The Sasquatch
  Console.WriteLine(Narrator + "As you turn around you see a " + PartnerCompliment + ", she asks you");
  Console.WriteLine("???: What are you doing this deep in the forest?");
  Console.WriteLine(Narrator + "You pause unable to think of answer.");
  Console.WriteLine("???: Well? Not gonna answer me?");
  Console.WriteLine(Narrator + "All of a sudden you here a stampeding sound, you turn around only to see the group of deers behind you run off in a hurry.");
  Console.WriteLine(Narrator + "You turn back to the " + PartnerCompliment + " and see a sasquatch behind her.");
  Console.WriteLine(Narrator + "You struggle to warn her.");
  Console.WriteLine(MC + "B-b-b-behind you!");
  Console.WriteLine(Narrator + "She turns around, only to be hit by the sasquatch, she flies off into the forest.");
  Console.WriteLine(Narrator + "You watch her get flung off into the forest and notice a knife fall out of her sheath.");
  Console.WriteLine(Narrator + "You unconsiously run towards the knife, you pick up the knife, turn around, and prepare to fight.");
  Console.WriteLine(Narrator + "The sasquatch is about to punch you. Do you try to dodge the punch = 1 or do you rush in to stab the sasquatch = 2?");

  string Sasquatch = Console.ReadLine();

  if (Sasquatch == "1")
  {
    Console.WriteLine(Narrator + "You quickly back up to dodge the punch.");
    Console.WriteLine(Narrator + "The sasquatch misses.");
    Console.WriteLine(Narrator + "The sasquatch quickly swings its arm back at you, you get hit before you can even respond.");
    Console.WriteLine(Narrator + "You get flung into a tree and your right leg breaks.");
    Console.WriteLine(MC + "ARGH!!!");
    Console.WriteLine(Narrator + "You struggle to pull yourself back on your feet. Once you get up on your feet you taunt the sasquatch");
    Console.WriteLine(MC + "HEY! *cough* You piece of **** come and get me.");
    Console.WriteLine(Narrator + "The sasquatch charges at you. You dodge the sasquatch, the sasquatch runs into the tree behind you.");
    Console.WriteLine(Narrator + "You quickly get behind the sasquatch, jump on it, and slice its neck.");
    Console.WriteLine(Narrator + "The adrenaline rush go's away and you fall to your knees in pain.");
    Console.WriteLine(Narrator + "The " + PartnerCompliment + " comes back and see's you laying on the ground in pain.");
    Console.ReadLine();
    Console.WriteLine("???: Did you kill the sasquatch?");
    Console.WriteLine(MC + "Y-y-yeah.");
    Console.WriteLine("???: How?! How did you kill it?");
    Console.WriteLine(MC + "I *cough* used your knife and sliced its neck.");
    Console.WriteLine("???: What are you!?");
    Console.WriteLine(MC + "What do you mean.");
    Console.WriteLine("???: The sasquatch has been terrorizing my town for six months.");
    Console.WriteLine("???: Our best fighters went out one by one to kill it, they either were found dead or made it back half dead.");
    Console.WriteLine(MC + "Guess *cough* I got lucky.");
    Console.WriteLine(MC + "Can you take me to your town.");
    Console.WriteLine("???: Why?");
    Console.WriteLine(MC + "Well I'm guessing there was a reward for whoever killed the sasquatch and I'm in a lot of pain so it would be helpful if i could see a doctor.");
    Console.WriteLine("???: Oh right, I'll take you to my town, but you'll have to talk to the mayor about a reward, he never official announced a reward ");
    Console.WriteLine(Partner + "I'm " + partnerName + " what's your name.");
    Console.WriteLine(MC + "I'm " + MCName + ".");
    Console.WriteLine(Narrator + "She helps you up, you and her start heading towards the town.");
  }
  if (Sasquatch == "2")
  {
    Console.WriteLine(Narrator + "You rush in and stab the sasquatch.");
    Console.WriteLine(Narrator + "You quickly get behind the sasquatch, jump on it, and try to choke it out.");
    Console.WriteLine(Narrator + "While the sasquatch is struglling to get you off, it slams you into a tree.");
    Console.WriteLine(MC + "ARGH!!!");
    Console.WriteLine(Narrator + "You fall off of the sasquatch, before you can get up the sasquatch picks you up and throws you.");
    Console.WriteLine(Narrator + "You fly into a rock an break your left leg.");
    Console.WriteLine(Narrator + "While you are stuggling to get up the sasquatch picks you up and breaks each and everyone of your limbs before killing you");
    Console.ReadLine();
    return;
  }
}

Console.ReadLine();

 

Spoiler

My system is the Dell Inspiron 15 5559 Microsoft Signature Edition

                         The Austrailian king of LTT said that I'm awesome and a funny guy. the greatest psu list known to man DDR3 ram guide

                                                                                                               i got 477 posts in my first 30 days on LinusTechTips.com

 

Link to comment
Share on other sites

Link to post
Share on other sites

16 hours ago, themaniac said:

that makes since now, thanks also is there any other way to make comments other then // ?

Yes, this is a multi line comment:

/* Some content */

You can also make XML Documentation Comments.

 

Be mindful that you don't overuse comments. The code should be descriptive enough that it can tell it's story without them for the most part. The presence of lots and lots of comments is a code smell and is indicative of a violation of good practices and principals or simply a bad design.

 

As you can see:

if(bushSound == bushSoundExplore)

Now tells us a story that actually means something.

16 hours ago, themaniac said:

EDIT: I tried to do the magic numbers and literals one but it just skips the if statement and closes, heres the code if it helps

EDIT 2: nevermind figured it out, just needed to add bushSound = Console.ReadLine(); above the const(under the writeline asking about the bush)

While promoting things to constants certainly makes things simpler, easier to read and understand; in your case it's ultimately not going help a massive amount, especially as you begin to build up more complexity. As you have seen, it's easy to get tripped up and lost in the growing nest of conditionals. This is why I suggested having a think about introducing the Command Pattern. Another consideration could be to get all of that text out of the code and into some kind of resource such as a text file for instance.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

@themaniac if you're up for a small task.

 

Could you port your Console app to a .NET core Console App?

 

.NET core apps can run on Mac, Linux and Windows.

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, Nuluvius said:

Yes, this is a multi line comment:


/* Some content */

You can also make XML Documentation Comments.

 

Be mindful that you don't overuse comments. The code should be descriptive enough that it can tell it's story without them for the most part. The presence of lots and lots of comments is a code smell and is indicative of a violation of good practices and principals or simply a bad design.

 

As you can see:


if(bushSound == bushSoundExplore)

Now tells us a story that actually means something.

While promoting things to constants certainly makes things simpler, easier to read and understand; in your case it's ultimately not going help a massive amount, especially as you begin to build up more complexity. As you have seen, it's easy to get tripped up and lost in the growing nest of conditionals. This is why I suggested having a think about introducing the Command Pattern. Another consideration could be to get all of that text out of the code and into some kind of resource such as a text file for instance.

I've been delaying when i'd read the stuff you gave until the semester ended(yesterday), would I be fine putting all the text in one text file or would I have to separate it, and how would I take some of the text out of the text file

1 hour ago, AluminiumTech said:

@themaniac if you're up for a small task.

 

Could you port your Console app to a .NET core Console App?

 

.NET core apps can run on Mac, Linux and Windows.

I don't see it in the new project selection, I'm guessing i'll have to download it right?

 

EDIT: ok I believe I have ported it(no errors and everything does what its supposed to do) but cant figure out how I would publish it

Spoiler

My system is the Dell Inspiron 15 5559 Microsoft Signature Edition

                         The Austrailian king of LTT said that I'm awesome and a funny guy. the greatest psu list known to man DDR3 ram guide

                                                                                                               i got 477 posts in my first 30 days on LinusTechTips.com

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, themaniac said:

I've been delaying when i'd read the stuff you gave until the semester ended(yesterday), would I be fine putting all the text in one text file or would I have to separate it

Placing it all into a single file should be fine.

4 hours ago, themaniac said:

how would I take some of the text out of the text file

In what sense? If you are asking from a technical perspective then have a look at the File class.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

7 hours ago, Nuluvius said:

In what sense? If you are asking from a technical perspective then have a look at the File class.

basically just take line X to line Y and write them, with each line going under the other and not everything on one line

Spoiler

My system is the Dell Inspiron 15 5559 Microsoft Signature Edition

                         The Austrailian king of LTT said that I'm awesome and a funny guy. the greatest psu list known to man DDR3 ram guide

                                                                                                               i got 477 posts in my first 30 days on LinusTechTips.com

 

Link to comment
Share on other sites

Link to post
Share on other sites

9 hours ago, themaniac said:

I've been delaying when i'd read the stuff you gave until the semester ended(yesterday), would I be fine putting all the text in one text file or would I have to separate it, and how would I take some of the text out of the text file

I don't see it in the new project selection, I'm guessing i'll have to download it right?

If you want to do that then you need to download the .NET core SDK

 

It's really tiny.

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, AluminiumTech said:

If you want to do that then you need to download the .NET core SDK

 

It's really tiny.

yeah, I've done that, just cant find the way to publish any programs with it

Spoiler

My system is the Dell Inspiron 15 5559 Microsoft Signature Edition

                         The Austrailian king of LTT said that I'm awesome and a funny guy. the greatest psu list known to man DDR3 ram guide

                                                                                                               i got 477 posts in my first 30 days on LinusTechTips.com

 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, themaniac said:

yeah, I've done that, just cant find the way to publish any programs with it

Read this. It might be helpful.

 

https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, AluminiumTech said:

thanks

Spoiler

My system is the Dell Inspiron 15 5559 Microsoft Signature Edition

                         The Austrailian king of LTT said that I'm awesome and a funny guy. the greatest psu list known to man DDR3 ram guide

                                                                                                               i got 477 posts in my first 30 days on LinusTechTips.com

 

Link to comment
Share on other sites

Link to post
Share on other sites

On ‎1‎/‎21‎/‎2017 at 6:12 AM, Nuluvius said:

This is why I suggested having a think about introducing the Command Pattern.

ok, I've looked at it but I'm really confused, could give an example on how to do it?

Spoiler

My system is the Dell Inspiron 15 5559 Microsoft Signature Edition

                         The Austrailian king of LTT said that I'm awesome and a funny guy. the greatest psu list known to man DDR3 ram guide

                                                                                                               i got 477 posts in my first 30 days on LinusTechTips.com

 

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, themaniac said:

ok, I've looked at it but I'm really confused, could give an example on how to do it?

Sure. The very basic principle I was thinking of was something a bit like this:

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var commands = new Dictionary<string, Action>
            {
                { "some choice 1", () => Console.WriteLine("I made some choice") },
                { "some choice 2", () => Console.WriteLine("I made some other choice") }
            };

            commands["some choice 1"]();
            commands["some choice 2"]();
            Console.ReadKey();
        }
    }
}

An important rule to remember about design patterns is that they should serve as base guidelines or templates even, doing otherwise can in fact be detrimental to good software design. Thus we are free to build this premise out a lot further and tailor it, it's really quite flexible. Have a look here and especially here for some more examples; have a think about how some of those may apply to your game.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×