Create a free account to remove all ad content.

Author Topic:  PWR's PRGRSS - Learning C#  (Read 9752 times)

0 Members and 1 Guest are viewing this topic.

PWRBTTN

  • Legendary Member
  • *
  • Posts: 1172
  • Professional Expert, Comrade
    • View Profile
  • Xbox: PWRBTTN
  • Steam: PWRBTTN
Re: PWR's PRGRSS - Learning C#
« Reply #30 on: February 07, 2016, 08:21:55 AM »
Yes to run the game outside visual studio you just need to run the .exe file that is produced when you build the solution.
Is there some way to attach music to this somehow? I would like to have some 8-bit music loop until the console window is closed.

I know a great 8-bit sequencer that lets me pretend I am good at music.


EDIT: I posted entry 004 on the original post. This entry is more describing a couple experiences than sharing data or asking a question.
« Last Edit: February 07, 2016, 09:01:33 AM by PWRBTTN »
/snail       /snail    /snail         /snail /snail      /snail   /snail                /snail        

Jack Of Shades

  • Supreme Member
  • *
  • Posts: 3326
  • ☽♕۞♕☾
    • View Profile
    • Jack Of Shades Youtube Gaming Channel
Re: PWR's PRGRSS - Learning C#
« Reply #31 on: February 07, 2016, 01:15:34 PM »
and I've started learning classes, arrays, generics, and enums.
These are perfect for your Inventory.

Create an enum that defines all the items in your game.

    enum Item
    {
        None,
        Knife,
        Flashlight,
        Wrench,
        Water,
        Chitin,
        Map,
        Dogtag,
    }

Your Inventory class uses a generic list to store the items, and a foreach loop to enumerate the items and print.

    struct InventoryItem
    {
        public Item Item;
        public int Count;
    }

    class Inventory
    {
        public List<InventoryItem> Items = new List<InventoryItem>();

        public void Print()
        {
            foreach (var item in Items)
            {
                Console.WriteLine("{0}: {1}", item.Item, item.Count);
            }
        }
    }

Wow! You described this to me and I actually understand it. I DEFINITELY saw this on one exercise I did and was curious as to what it meant/did.

Nefty

  • Supreme Member
  • *
  • Posts: 2452
    • View Profile
  • Xbox: GoatOnTheM00n
Re: PWR's PRGRSS - Learning C#
« Reply #32 on: February 07, 2016, 01:18:00 PM »
This is not really a C# question, but next semester I start of few different classes regarding coding. AP Computer Science, Game Programming, Mobile App Development etc.... The head of the department says these are J.A.V.A. based classes (which I'm not bad at). I'm wondering how that compares to C# if anyone knows? I've heard they are rather similar.

Jack Of Shades

  • Supreme Member
  • *
  • Posts: 3326
  • ☽♕۞♕☾
    • View Profile
    • Jack Of Shades Youtube Gaming Channel
Re: PWR's PRGRSS - Learning C#
« Reply #33 on: February 07, 2016, 02:47:25 PM »
This is not really a C# question, but next semester I start of few different classes regarding coding. AP Computer Science, Game Programming, Mobile App Development etc.... The head of the department says these are J.A.V.A. based classes (which I'm not bad at). I'm wondering how that compares to C# if anyone knows? I've heard they are rather similar.
I know I can't fully answer this, but on an off note this is a C# question ;). Anyway I heard it has similarities but cannot say for sure. I believe Craig could better answer it. Although, now...I am curious as well. lol

PWRBTTN

  • Legendary Member
  • *
  • Posts: 1172
  • Professional Expert, Comrade
    • View Profile
  • Xbox: PWRBTTN
  • Steam: PWRBTTN
Re: PWR's PRGRSS - Learning C#
« Reply #34 on: February 07, 2016, 07:10:49 PM »
Entry:005 added.

This one shows off something really neat, and asks a question.
/snail       /snail    /snail         /snail /snail      /snail   /snail                /snail        

PWRBTTN

  • Legendary Member
  • *
  • Posts: 1172
  • Professional Expert, Comrade
    • View Profile
  • Xbox: PWRBTTN
  • Steam: PWRBTTN
Re: PWR's PRGRSS - Learning C#
« Reply #35 on: February 07, 2016, 08:36:41 PM »
I'd like to mess around some cosmetic commands like CursorSize and ConsoleColor.

Any suggestions anyone? I'm having a hard time finding these.
/snail       /snail    /snail         /snail /snail      /snail   /snail                /snail        

Craig

  • Developer
  • Extreme Member
  • *
  • Posts: 6655
  • Dig Deep
    • View Profile
    • Twitter
  • Steam: tota1miner
Re: PWR's PRGRSS - Learning C#
« Reply #36 on: February 07, 2016, 08:37:14 PM »
Could someone explain what benefits it would have to use enums over classes?
You generally wouldn't use enums over classes, generally you'd use enums in combination with classes. Enums are just a way to conveniently use language to describe numeric ID's - i.e. it's easier to pass the word Knife to some method, rather than some ID number like 8 - it also allows the compiler to detect errors that it wouldn't be able to detect if you just used a basic int number.

With the way your inventory class is currently set up, it doesn't allow the player to carry more than 1 of the same item (except the dog tags), although that's fairly easy to allow by changing the bools to ints.

But most importantly, every time you add a new item into the game or change, rename or remove an existing item, you'll have to add, change or remove code to your inventory class, both for the storage and the methods - like the print method. You definately don't want to be doing that.

The Inventory class I posted means you don't have to change any code in the Inventory class whenever items are added, changed, renamed, removed, because it stores the Item as an enum variable rather than a hard coded field, and it allows carrying more than 1 of the same item.

The benefits will also become more clear as you add more functionality to your Inventory class, like querying if it contains a specific item, or dropping items, etc, you don't want to be changing all that code as well every time a new item is added, changed, renamed or removed. You don't want to be changing any code, anywhere in your game, when items are added, changed or removed, except in the one place they are defined.

PWRBTTN

  • Legendary Member
  • *
  • Posts: 1172
  • Professional Expert, Comrade
    • View Profile
  • Xbox: PWRBTTN
  • Steam: PWRBTTN
Re: PWR's PRGRSS - Learning C#
« Reply #37 on: February 07, 2016, 08:44:21 PM »
Could someone explain what benefits it would have to use enums over classes?
that's incredibly helpful. Thanks.

Where exactly would I stick this?

-----
    enum Item
    {
        None,
        Knife,
        Flashlight,
        Wrench,
        Water,
        Chitin,
        Map,
        Dogtag,
    }

Your Inventory class uses a generic list to store the items, and a foreach loop to enumerate the items and print.

    struct InventoryItem
    {
        public Item Item;
        public int Count;
    }

    class Inventory
    {
        public List<InventoryItem> Items = new List<InventoryItem>();

        public void Print()
        {
            foreach (var item in Items)
            {
                Console.WriteLine("{0}: {1}", item.Item, item.Count);
            }
        }
    }
-----

In the inventory class?

Also, what all of my previous method should I keep and remove?
/snail       /snail    /snail         /snail /snail      /snail   /snail                /snail        

Craig

  • Developer
  • Extreme Member
  • *
  • Posts: 6655
  • Dig Deep
    • View Profile
    • Twitter
  • Steam: tota1miner
Re: PWR's PRGRSS - Learning C#
« Reply #38 on: February 07, 2016, 10:58:26 PM »
Where exactly would I stick this?
In the inventory class?
Also, what all of my previous method should I keep and remove?

It replaces your current Inventory class.

PWRBTTN

  • Legendary Member
  • *
  • Posts: 1172
  • Professional Expert, Comrade
    • View Profile
  • Xbox: PWRBTTN
  • Steam: PWRBTTN
Re: PWR's PRGRSS - Learning C#
« Reply #39 on: February 08, 2016, 01:29:24 AM »
Can anyone tell me how I go about making something like this?

Type 'help' for a list of commands.

I've tried it so many times!! But it won't work!!!
if you're talking about just making it display on screen, use..

Console.WriteLine ("Type Help for list of commands.");

But if you're talking about making a list of things for it to display when typed, you'll find that on the first page of the topic. If I remember correctly, it's the first post by Craig.
/snail       /snail    /snail         /snail /snail      /snail   /snail                /snail