Create a free account to remove all ad content.

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

0 Members and 1 Guest are viewing this topic.

Craig

  • Developer
  • Extreme Member
  • *
  • Posts: 6655
  • Dig Deep
    • View Profile
    • Twitter
  • 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
    • View Profile
  • 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: 3326
  • ☽♕۞♕☾
    • View Profile
    • Jack Of Shades Youtube Gaming Channel
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
    • View Profile
  • 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
    • View Profile
  • 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: 6655
  • Dig Deep
    • View Profile
    • Twitter
  • 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: 6655
  • Dig Deep
    • View Profile
    • Twitter
  • 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: 6655
  • Dig Deep
    • View Profile
    • Twitter
  • 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: 6655
  • Dig Deep
    • View Profile
    • Twitter
  • 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
    • View Profile
  • 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