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

0 Members and 1 Guest are viewing this topic.

Jack Of Shades

  • Supreme Member
  • *****
  • Posts: 3303
  • ☽♕۞♕☾
  • Awards 3 years on site Donated a giveaway prize. (Must be a prize of cash value.) 2 years on site Members who have unlocked the robotic avatar 1 year on site Was in the top 10 of the forum stats page as of 4/12/15 Former MotM winners
    • View Profile
    • Jack Of Shades Youtube Gaming Channel
    • Awards
Re: PWR's PRGRSS - Learning C#
« Reply #15 on: February 06, 2016, 08:59:27 PM »
Sometimes its fun revisiting the basics.

PWR if you use any code I post, ensure you fully understand it before moving on, otherwise it's not helping. I'm happy to answer any questions about anything I post here, no matter how simple they might seem. It's easy for me to overlook something or not explain something at a sufficienly simple level, so if that happens, just ask.

I am glad you are taking the time to help PWRBTTN learn C#. I have also had an interest in it, and even did a beginner exercise with it. Making a text box show up when prompted saying a custom sentence or phrase. So much fun doing it and understanding the language of how it's done. I will definitely come to this topic more and learn with PWRBTTN. Very interesting stuff.

PWRBTTN

  • Legendary Member
  • *****
  • Posts: 1172
  • Professional Expert, Comrade
  • Awards Awarded to exemplary forum members 2 years on site Site art contributions/TPs in-game/Contest winners 1 year on site
    • View Profile
    • Awards
  • Xbox: PWRBTTN
  • Steam: PWRBTTN
Re: PWR's PRGRSS - Learning C#
« Reply #16 on: February 06, 2016, 09:00:01 PM »
Sometimes its fun revisiting the basics.

PWR if you use any code I post, ensure you fully understand it before moving on, otherwise it's not helping. I'm happy to answer any questions about anything I post here, no matter how simple they might seem. It's easy for me to overlook something or not explain something at a sufficienly simple level, so if that happens, just ask.
oh, of course.

I wouldn't dare to glance over the code. I want to get skillful at this.

I do have a question.

"  // Class encapsulating everything about the Game (high level)."

What exactly is this.
I understand it's a comment, but what does everything encapsulate? What is high level?
/snail       /snail    /snail         /snail /snail      /snail   /snail                /snail        

PWRBTTN

  • Legendary Member
  • *****
  • Posts: 1172
  • Professional Expert, Comrade
  • Awards Awarded to exemplary forum members 2 years on site Site art contributions/TPs in-game/Contest winners 1 year on site
    • View Profile
    • Awards
  • Xbox: PWRBTTN
  • Steam: PWRBTTN
Re: PWR's PRGRSS - Learning C#
« Reply #17 on: February 06, 2016, 09:03:03 PM »
@Jack of Shades (or anyone interested in C#,  really) You should check out Brackeys C# tutorial on YouTube. There are 15 episodes, and I understood a good portion of the content in the first day of coding.
/snail       /snail    /snail         /snail /snail      /snail   /snail                /snail        

Jack Of Shades

  • Supreme Member
  • *****
  • Posts: 3303
  • ☽♕۞♕☾
  • Awards 3 years on site Donated a giveaway prize. (Must be a prize of cash value.) 2 years on site Members who have unlocked the robotic avatar 1 year on site Was in the top 10 of the forum stats page as of 4/12/15 Former MotM winners
    • View Profile
    • Jack Of Shades Youtube Gaming Channel
    • Awards
Re: PWR's PRGRSS - Learning C#
« Reply #18 on: February 06, 2016, 09:04:34 PM »
The IMPAGame.Run method is the programs main control loop, it receives the user input, parses and processes the input, performs the appropriate output, then loops again to receive the next input.

So this is all basically one big loop of an event/action, or am I way out in left field?

@Jack of Shades (or anyone interested in C#,  really) You should check out Brackeys C# tutorial on YouTube. There are 15 episodes, and I understood a good portion of the content in the first day of coding.
Thanks, PWR! I was checking out websites on C# as well, which is how I did that exercise, and they are WONDERFUL! They explain everything, but some things require a great deal of reading to fully understand. Certain functions and phrases need an EXACT knowledge so it does not mess up a line of code. But thanks, I will DEFINITELY check it out. :)

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6649
  • Dig Deep
  • Awards Developer 5 years on site 4 years on site 3 years on site 2 years on site Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
  • Steam: tota1miner
Re: PWR's PRGRSS - Learning C#
« Reply #19 on: February 06, 2016, 09:08:06 PM »
I do have a question.

"  // Class encapsulating everything about the Game (high level)."

What exactly is this.
I understand it's a comment, but what does everything encapsulate? What is high level?
Don't worry to much about it for now, it will become clearer as your game progresses. The single most important thing to understand is that classes are used to encapsulate concepts. Classes are your primary design tool so the primary design skill you must learn is when to create classes, what the classes should contain, what the class dependencies should be, etc.

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6649
  • Dig Deep
  • Awards Developer 5 years on site 4 years on site 3 years on site 2 years on site Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
  • Steam: tota1miner
Re: PWR's PRGRSS - Learning C#
« Reply #20 on: February 06, 2016, 09:11:37 PM »
The IMPAGame.Run method is the programs main control loop, it receives the user input, parses and processes the input, performs the appropriate output, then loops again to receive the next input.

So this is all basically one big loop of an event/action, or am I way out in left field?
Yea it's just a loop. It waits for the player to enter a command, when a command is entered, processes it and produces any output, then it loops and waits for the next command, until the player exits.

PWRBTTN

  • Legendary Member
  • *****
  • Posts: 1172
  • Professional Expert, Comrade
  • Awards Awarded to exemplary forum members 2 years on site Site art contributions/TPs in-game/Contest winners 1 year on site
    • View Profile
    • Awards
  • Xbox: PWRBTTN
  • Steam: PWRBTTN
Re: PWR's PRGRSS - Learning C#
« Reply #21 on: February 06, 2016, 09:12:37 PM »
Don't worry to much about it for now, it will become clearer as your game progresses, young grasshopper.
Understood, Master Craigfucius.
/snail       /snail    /snail         /snail /snail      /snail   /snail                /snail        

Jack Of Shades

  • Supreme Member
  • *****
  • Posts: 3303
  • ☽♕۞♕☾
  • Awards 3 years on site Donated a giveaway prize. (Must be a prize of cash value.) 2 years on site Members who have unlocked the robotic avatar 1 year on site Was in the top 10 of the forum stats page as of 4/12/15 Former MotM winners
    • View Profile
    • Jack Of Shades Youtube Gaming Channel
    • Awards
Re: PWR's PRGRSS - Learning C#
« Reply #22 on: February 06, 2016, 09:16:06 PM »
Yea it's just a loop. It waits for the player to enter a command, when a command is entered, processes it and produces any output, then it loops and waits for the next command, until the player exits.

Oh okay, well good I need to remember this then because I did see something like it before. I didn't know if it was a single moment loop or it looped the same command whenever it was executed by a player/user.

PWRBTTN

  • Legendary Member
  • *****
  • Posts: 1172
  • Professional Expert, Comrade
  • Awards Awarded to exemplary forum members 2 years on site Site art contributions/TPs in-game/Contest winners 1 year on site
    • View Profile
    • Awards
  • Xbox: PWRBTTN
  • Steam: PWRBTTN
Re: PWR's PRGRSS - Learning C#
« Reply #23 on: February 06, 2016, 10:51:21 PM »
The best place for commands like buffer width and window width would be in the Main, right? They only need to be ran once, but will stay active the entire time.
/snail       /snail    /snail         /snail /snail      /snail   /snail                /snail        

PWRBTTN

  • Legendary Member
  • *****
  • Posts: 1172
  • Professional Expert, Comrade
  • Awards Awarded to exemplary forum members 2 years on site Site art contributions/TPs in-game/Contest winners 1 year on site
    • View Profile
    • Awards
  • Xbox: PWRBTTN
  • Steam: PWRBTTN
Re: PWR's PRGRSS - Learning C#
« Reply #24 on: February 07, 2016, 12:11:17 AM »
Another question for you, Craig.

In order for a player to check inventory, they type "Check bag"

Here's the snippet of code.

case "check bag";
          Console.WriteLine(); //for visual space
          inventory.print();
          Console.WriteLine(); //for visual space
          break;

I highlighted the problem.
I'm trying to call for the inventory to be printed in the console. Here is the snippet it's trying to print.

    // Class encapsulating everything about an Inventory.
    class Inventory
    {
        public bool knife = true;
        public bool flashlight = true;
        public bool wrench = true;
        public bool water = true;
        public bool chitin = true;
        public bool map = true;
        public bool dogtags = true;
        public int dogtagsqty = 2;
        public string action = "";

        public void print()
        {
            if (knife == true)
            {
                Console.WriteLine(" - knife");
                Console.WriteLine();
            }
            if (flashlight == true)
            {
                Console.WriteLine(" - flashlight");
                Console.WriteLine();
            }
            if (wrench == true)
            {
                Console.WriteLine(" - wrench");
                Console.WriteLine();
            }
            if (water == true)
            {
                Console.WriteLine(" - water");
                Console.WriteLine();
            }
            if (chitin == true)
            {
                Console.WriteLine(" - chitin");
                Console.WriteLine();
            }
            if (map == true)
            {
                Console.WriteLine(" - map");
                Console.WriteLine();
            }
            if (dogtags == true)
            {
                Console.WriteLine(" - " + dogtagsqty + " dogtags");
                Console.WriteLine();
            }
        }
    }
« Last Edit: February 07, 2016, 12:15:58 AM by PWRBTTN »
/snail       /snail    /snail         /snail /snail      /snail   /snail                /snail        

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6649
  • Dig Deep
  • Awards Developer 5 years on site 4 years on site 3 years on site 2 years on site Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
  • Steam: tota1miner
Re: PWR's PRGRSS - Learning C#
« Reply #25 on: February 07, 2016, 02:46:52 AM »
The best place for commands like buffer width and window width would be in the Main, right? They only need to be ran once, but will stay active the entire time.
Either Main or the game class.

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6649
  • Dig Deep
  • Awards Developer 5 years on site 4 years on site 3 years on site 2 years on site Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
  • Steam: tota1miner
Re: PWR's PRGRSS - Learning C#
« Reply #26 on: February 07, 2016, 02:49:34 AM »
          inventory.print();
The game class has a member variable called player which is a reference to a Player object. The Player object has a member variable called Inventory which is a reference to an Inventory object. So you can access the Player object via the player reference on the game class and the Inventory object via the Inventory reference on the Player object.

TLDR;
player.Inventory.print();

The Microsoft.Net standards specify:
Method names should use Pascal case, so the print method should be called Print(), not print().
Public member fields should use Pascal case (Inventory member on Player class).
Protected and Private member fields should use Camel case (player member on IMPAGame class).
« Last Edit: February 07, 2016, 05:02:44 AM by Craig »

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6649
  • Dig Deep
  • Awards Developer 5 years on site 4 years on site 3 years on site 2 years on site Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
  • Steam: tota1miner
Re: PWR's PRGRSS - Learning C#
« Reply #27 on: February 07, 2016, 05:53:56 AM »
It may be possible to run without a studio so long as you click open the right folder... I don't entirely know.
Yes to run the game outside visual studio you just need to run the .exe file that is produced when you build the solution.

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6649
  • Dig Deep
  • Awards Developer 5 years on site 4 years on site 3 years on site 2 years on site Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
  • Steam: tota1miner
Re: PWR's PRGRSS - Learning C#
« Reply #28 on: February 07, 2016, 06:02:32 AM »
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);
            }
        }
    }

PWRBTTN

  • Legendary Member
  • *****
  • Posts: 1172
  • Professional Expert, Comrade
  • Awards Awarded to exemplary forum members 2 years on site Site art contributions/TPs in-game/Contest winners 1 year on site
    • View Profile
    • Awards
  • Xbox: PWRBTTN
  • Steam: PWRBTTN
Re: PWR's PRGRSS - Learning C#
« Reply #29 on: February 07, 2016, 08:14:23 AM »
PWRBTTN has really inspired me, so do any of you know a good website for learning c#?
I don't know any site in particular, but search "Brackeys" on YouTube, and I learnt a good portion of what I'm alreadu using in the first day.
/snail       /snail    /snail         /snail /snail      /snail   /snail                /snail