Create a free account to remove all ad content.

Author Topic:  PWR's PRGRSS - Learning C#  (Read 10633 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 #10 on: February 06, 2016, 06:51:13 PM »
What do you mean the parser stopped working?
It works, but it seems like it has to be the next thing in the code for it to work. So if I have the story come before the parser, it'll meed to be at the parsing step. If I have story after the parser, it doesnt seem to work...
/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 #11 on: February 06, 2016, 08:34:39 PM »
Here is a basic structure to start from - this code would go in your program.cs file:

A class called IMPAGame is defined. An object is an instance of a class. The Main method of the program instantiates an IMPAGame object and calls it's Run method. 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.

using System;
using System.Text;

namespace IMPA
{
    class Program
    {
        static void Main(string[] args)
        {
            var game = new IMPAGame();
            game.Run();
        }
    }

    // Class encapsulating everything about the Game (high level).
    class IMPAGame
    {
        Player player;

        public void Run()
        {
            player = new Player();

            // Main game control loop.
            // Get player input, parse/process input, perform appropriate output.
            // Loop for next player input.
            // Break the loop if the player exits the game.
            while (true)
            {
                var input = Console.ReadLine();
                if (!ParseInput(input)) break;
            }
        }

        bool ParseInput(string input)
        {
            switch (input.ToLower())
            {
                case "exit":
                    return false;

                case "help":
                    Console.WriteLine("Help Commands:");
                    Console.WriteLine("Cmd1 - Something1");
                    Console.WriteLine("Cmd2 - Something2");
                    Console.WriteLine("Exit - Exit game.");
                    // etc
                    break;

                case "cmd1":
                    // process cmd1 here
                    break;

                case "cmd2":
                    // process cmd2 here
                    break;
            }

            return true;
        }
    }

    // Class encapsulating everything about a Player.
    class Player
    {
        public Inventory Inventory;

        public Player()
        {
            Inventory = new Inventory();
        }
    }

    // Class encapsulating everything about an Inventory.
    class Inventory
    {
        // bla bla
    }
}

PWRBTTN

  • Legendary Member
  • *
  • Posts: 1172
  • Professional Expert, Comrade
    • View Profile
  • Xbox: PWRBTTN
  • Steam: PWRBTTN
Re: PWR's PRGRSS - Learning C#
« Reply #12 on: February 06, 2016, 08:42:00 PM »
/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 #13 on: February 06, 2016, 08:44:35 PM »
Craig stuff.

Craig, you're like a poet of C# aren't you?

Craig

  • Developer
  • Extreme Member
  • *
  • Posts: 6655
  • Dig Deep
    • View Profile
    • Twitter
  • Steam: tota1miner
Re: PWR's PRGRSS - Learning C#
« Reply #14 on: February 06, 2016, 08:50:09 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.

Jack Of Shades

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