Total Miner Forums

General => General Discussion => Topic started by: PWRBTTN on February 05, 2016, 09:16:00 PM

Title: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 05, 2016, 09:16:00 PM
I'm learning C#.

On this topic, I will talk about my experience. I may also ask for solutions to problems.

Entry: 001
I've learnt a good portion of the basic material, and I've started learning classes, arrays, generics, and enums.

I wanted to start on a simple project, so I asked the first developer I could think of... Fabian Vikingnamedrop. He's got a bunch of games on the Xbox market place, and tonnes of experience with different styles of games.

He suggested I try a Console Application with a text parser. I was actually quite excited about this because I like old text adventure games. However, I can't figure out how to parse text.

For example, old text based games usually had a "help" command. When you type in "help", all of the possible commands would come up on screen. How do I do this?


Entry: 002
I learnt a really neat program while trolling around the web.
Code: [Select]
using System;
using System.Text;

class CodePage437
{
     public static void Main(string[] args)
     {
          // Set the window size and title
          Console.Title = "Code Page 437: MS-DOS ASCII Characters";
     
          for (byte b = 0; b < byte.MaxValue; b++)
          {
               char c = Encoding.GetEncoding(437).GetChars(new byte[] {b})[0];
               switch (b)
               {
                    case 8: // Backspace
                    case 9: // Tab
                    case 10: // Line feed
                    case 13: // Carriage return
                        c = '.';
                        break;
                }
       
               Console.Write("{0:000} {1}   ", b, c);
       
               // 7 is a beep -- Console.Beep() also works
               if (b == 7) Console.Write(" ");
       
               if ((b + 1) % 8 == 0)
                   Console.WriteLine();
           }
          Console.WriteLine();
      }
}
What this does is open up a console application that lets me access the ASCII characters. I'll show a picture below of both what it makes, and what you can do with it.

(http://i.imgur.com/eCUZiac.jpg)
You may need to enlarge by clicking on the image, or just zoom in.

(http://i.imgur.com/p6Sicrs.jpg)
Fantastic, right? This will be the title of my first project. If it turns out nicely, I may even make it into a trilogy.

-"Intelligent Martian Parasites Attack"

-"Intelligent Martian Parasites Attack II: Intelligent Martian Parasites Strike Back"

-"Intelligent Martian Parasites Attack III: Intelligent Martian Parasites Last Stand"

Well, I'll be writing some more code for the rest of the strange hours of the morning, and probably into midday. I'm having too much fun with this coding stuff.


Entry: 003
Well, I've written a class that is the player's inventory. I hope that's a common practice, I'd be disappointed if I did something wrong or... like... not as good as I could have. In any case, upon doing this, and testing if it works, I found out that my parsing solution stopped working. I'm pretty sure it's because it only works if it's next in code, and I really don't want to have to paste them in every possible useable location. If I'm not clear, I need a way to always be able to access my words wherever I am in the program.

So that's my question this time. How do I make it so that my parser can detect anywhere? I hope that's understandable.

Until I figure this out, I can't really test if my inventory system works.


Entry: 004
Well, I did something really neat when I screwed up a bit of code. I meant to cut and paste it into notepad, but I forgot to save the document.

It made words change colours and letters. I was trying to do an important text thing, but I think I put my goto in the wrong place near my random number generator and I... I'm not sure. It was cool, though. If I can figure it out, it'd be neat to turn it into a "garbled speech" encounter in a future project.

I'm also doing another really neat thing with ASCII that I will show you all later. It's directly got to do with my game, but I need to finish it.

I can't finish it right now, though. I need sleep. Since I started learning C# on... Thursday, I think, I've gotten maybe 6-8 hours of sleep altogether. I personally don't notice it, but gravity is wearing out my beautiful face, and I keep seeing that stupid cat that I know darn well I got rid of a week or two ago. Clarification, I'm not actually seeing a cat. I'm seeing black blurs due to sleep deprivation, but my brain is telling me that they look like that darn cat.

At least it's obvious I'm enjoying this newfound hobby.

Toodles!


Entry:005
First off, I finished the ASCII project I mentioned to you all earlier. It's the map of the space ship you'll be playing on. Now, there aren't technically any spoilers, but if you do plan on playing this when I finish, I would recommend not looking at it. I've played my fair share of text adventures to know that going in blind is so satisfying. However, that decision will be up to you.
(http://i.imgur.com/EWUEwwP.png)

Key:
CRDR = Corridor
MNTC = Maintenance
QTRS = Quarters


Also on my list of things to say, I'm going to try and take Craig's advice about enums (on page 2), but I'm still sort of confused. Could someone explain what benefits it would have to use enums over classes? I'll show an example of my current inventory code.

    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 = "";

Then when someone types in "check bag" this runs...

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();
            }
        }

This way they can see all of what they have in their inventory shows up, and what they don't have doesn't show up.


Entry: 006
I'm having a lot of fun. Learning a lot. However despite what I've been learning, it still hasn't seemed to be enough. I know I've only been doing this for a few days, but new errors keep coming up that I'm completely lost about. Like one I'm currently having problems with...

Type or namespace definition, or end-of-file expected.

This is at the very bottom on the last closed curly bracket. I haven't even touched down there.

I don't know. I mean, I am truly having fun. It just seems so strange that I'm still lost on trying to translate what errors mean. I find myself taking a couple breaks over 2 or 3 hours of trying to understand the error. Eventually (normally) i give up trying to figure it out myself, then go ask google. Which returns very little... I rectract... A LOT of stuff... however, so little of it has meaning to my beginner brain that I'm still lost. So I come ask you guys (mainly Craig). Which is helpful, but then I feel like it's cheating.

In any case, I'm not even anywhere close to quitting, even if it seems like it. I also encourage anyone reading this who wants to start learning coding to not give up when this stuff happens. It's tough, but it's worth it, I feel.

Well, that's it for this entry. I hope you all are enjoying reading so far.


Entry: 007
Frustrated... taking a break of a couple days.


Entry: 008
Not exactly sure what all to say, but I feel as though I need to say something.

My studying has gone further in the last two days than my entire experience combined. I've been trolling around the web and I found some sotes that nicely document different C# commands. I've been reading them. Some of them feel out of order, like... badly. For example, they start talking about how to manipulate some things before telling you what the things wot you're manipulating. Which is mostly fine. Skip forward a few pages to read about the thing, and then go back to learn. However, my main problem is that the one site wot has the best documentation has no order whatsoever. Some things can't even be found from I. Annoying, very, to say the least.

That aside, I've been practicing some other console-based code. I managed to figure out how to slow down the visual portion of the program. I'll use this for "cinematic" effect. A better word is actually stylistic... but whatever. Basically I just need to use the Console.Beep command, but give it my desired length and a kHz level of 0. It's really neat.

I've also looked into graphics engines for a future secret project. Sort of secret. Technically, you all know about it, but you don't know how it's going to work. Eh... you'll understand eventually.

Turns out, though, most graphics engines don't actually support 2D. It's all 3D, but made to look 2D. Which... isn't a huge problem, but actually kind of throws a gear in my sticks.

That's about it, I'm pretty sure... In any case, I've got to get ready for school soon.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 05, 2016, 10:47:29 PM
Maybe something like this, I'm not 100% sure, haven't done a console app for a while.

var run = true;

while (run)
{
   var input = Console.ReadLine();

   switch (input.ToLower())
   {
      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;

      case "exit":
         run = false;
         break;
   }
}
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 05, 2016, 11:57:41 PM
Craig, you glorious man! That's exactly what I needed! Thank you a thousand times, thank you!

I tried so many solutions!

Now that this is working, I can start other things like... I don't know... an enemy randomiser.

EDIT: Didn't feel like making another post, but wanted to let you all know that I posted another entry in the original post.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 06, 2016, 05:15:10 AM
// 7 is a beep -- Console.Beep() also works
if (b == 7) Console.Write(" ");

Seems to me the code above is a bug, it rather should be part of the switch statement like so:

case 7: // Beep
Title: Re: PWR's PRGRSS - Learning C#
Post by: Dryym on February 06, 2016, 11:17:11 AM
I love Text based adventure games.
Mind filling us in on a bit of the story, Maybe some mechanics you have planned?


Will it be a puzzle adventure akin to Zork?
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 06, 2016, 11:30:18 AM
I believe, but don't hold me to this... just started this stuff... but I believe that because the ASCII characters; space, tab, linefeed, and carriage return aren't visible characters, they kept them out...? However, since beep is technically one of the ASCII signals, it still gets played when it's hexcode comes up... I think. I'm honestly not sure.

If what I said doesn't explain what you were talking about, then... um... I don't know. I just know that it beeps at the end of the printing where it's hexcode would be.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 06, 2016, 11:54:42 AM
It's closest entity would be Zork, yes. I love Zork, as I have probably stated somewhere else in another postI know I have. Probably talking about an about more arcade games in Total Miner. I may make a dungeon crawler if I can figure out the solution for doing that. I'm pretty sure I'll need to use ConsoleKey or something, as well as figure out how to keep the map generated as you move around.

As for the storyline for Intelligent Martian Parasites Attack, it's not entirely flushed out, but here's what I've got...

Years into the future, it's 2023!
You are Captain (name here) of the I.S.S. (name here). Your mission was simple; collect water samples from Mars and return to Earth so it could be studied. There's only one catch! Mars has parasites that are intelligent, and they boarded your ship. Your entire crew has already been eaten, and you can't let the intelligent martian parasites get to Earth! Point the ship away from Earth and take an escape pod to save humanity!

Coming soon, to a RadioShack near you!



EDIT: For the time being, you'll need to have some sort of programmeing studio to play it. I mean... I think. I'm using Visual Studio and Xamarin when Visual Studio decides to act up. It may be possible to run without a studio so long as you click open the right folder... I don't entirely know.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Stoneart on February 06, 2016, 01:15:13 PM
Sounds cool! Can't wait to be able to try it sometime.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 06, 2016, 05:20:18 PM
Entry: 003 updated to the original post.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 06, 2016, 06:20:03 PM
I believe, but don't hold me to this... just started this stuff... but I believe that because the ASCII characters; space, tab, linefeed, and carriage return aren't visible characters, they kept them out...? However, since beep is technically one of the ASCII signals, it still gets played when it's hexcode comes up... I think. I'm honestly not sure.

If what I said doesn't explain what you were talking about, then... um... I don't know. I just know that it beeps at the end of the printing where it's hexcode would be.
Backspace, Tab, LF and CR are all printable characters, but printing them adversely affects the format of the printed table, which is why they're replaced with a '.'. I think Beep falls into the same category, it shouldn't be printed, it has no visual output.

What do you mean the parser stopped working?
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN 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...
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig 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
    }
}
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 06, 2016, 08:42:00 PM
Wow, this is fantastic. Thanks.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Jack Of Shades on February 06, 2016, 08:44:35 PM
Craig stuff.

Craig, you're like a poet of C# aren't you?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Jack Of Shades 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN 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?
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Jack Of Shades 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. :)
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Jack Of Shades 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN 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();
            }
        }
    }
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig 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).
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig 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);
            }
        }
    }
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Jack Of Shades 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Nefty 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Jack Of Shades 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
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 07, 2016, 07:10:49 PM
Entry:005 added.

This one shows off something really neat, and asks a question.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN 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?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN 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.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 08, 2016, 02:06:43 AM
I've spent the last hour and a half messing with this stuff. Craig, please clear this up. I read through it, I still don't understand enums very well. I was going to read through it when it was working, but it's not working. So I can't read through it. So I don't understand enums. It's simply how I learn. There are three issues presented, and they're all on the same screen. So to save time, I took a picture.

[Removed picture]
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 08, 2016, 03:07:54 AM
I've spent the last hour and a half messing with this stuff...
The compiler is just telling you it doesn't know which .Net assembly to find the List<T> class (type) in.

Add the following line to the top of your .cs file.

using System.Collections.Generic;


Under the hood, Enums are just an integer number. But they allow us to use an english name when telling the compiler we want to use them.

So the Item enum is just an enumeration of numbers, ID numbers if you like, at the same time allowing the programmer to refer to them using their english name equivalent.

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

With the enum above, Item is an Int32 (32 bit integer) and the names have an ascending integer assigned to them:

i.e.

    enum Item
    {
        None = 0,
        Knife = 1,
        Flashlight = 2,
        Wrench = 3,
        Water = 4,
        Chitin = 5,
        Map = 6,
        Dogtag =7,
    }

Say you have a method like so:

void AddItem(Item item) { .. }

calling it using: AddItem(Item.Flashlight);

is essentially the same under the hood as:

void AddItem(int item) { .. }
calling: Additem(2);

So AddItem(Item.Flashlight) is easier to read/understand than AddItem(2), but to the compiler and the executable they're essentially the same thing.


Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 08, 2016, 03:58:19 AM
I've spent the last hour and a half messing with this stuff...
Wow. I didn't now that. See, I wish the tutorial would have said that. I mean, I'm not sure knowing that would solve my problem of the program not working. You solved that, too, though.

You are a wizard! A technomancer!

I'm excited about this. My text adventure is going to be the best text-based game released in February of this year!

Well... I hope it'll be in February. I mean... it's just a text-based game.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 08, 2016, 06:21:31 AM
Here's a flashier version of the Inventory.Print() method. You should be able to see what's different.

Code: [Select]
        public void Print()
        {
            Console.WriteLine();

            if (Items.Count < 1)
            {
                Console.WriteLine("Inventory: Empty");
            }
            else
            {
                Console.WriteLine("Inventory:");
                foreach (var item in Items)
                {
                    Console.WriteLine("{0}: {1}", item.Item, item.Count);
                }
            }

            Console.WriteLine();
        }
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 08, 2016, 06:28:45 AM
Here's a method to allow you to add items to the inventory:

Code: [Select]
        // this method is public so that code outside the Inventory class can call it
        public void AddItem(Item item)
        {
            // see if we already have the item in inventory
            var i = GetIndex(item);

            // if i >= 0 then we already have the item in inventory
            if (i >= 0)
            {
                // we already have item, so just increase the count
                var ii = Items[i];
                ii.Count++;
                Items[i] = ii;
            }
            else
            {
                // we don't have the item, so add a new one with a count of 1.
                var ii = new InventoryItem() { Item = item, Count = 1 };
                Items.Add(ii);
            }
        }

        // this method is private, it's only used internally by the Inventory class
        int GetIndex(Item item)
        {
            // enumerate each item in the item list and return its index if found, otherwise return -1
            for (int i = 0; i < Items.Count; i++)
            {
                if (Items[i].Item == item) return i;
            }
            return -1;
        }
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 08, 2016, 06:33:01 AM
And here is how you can use the AddItem command to add some random items into the inventory (mainly for testing).

Put this into your parser switch statement.

Code: [Select]
                case "add":
                    var r = new Random();
                    var i = (Item)r.Next(1, (int)Item.Dogtag);
                    player.Inventory.AddItem(i);
                    break;

So if you enter the command "add" into the game, it will add a new random item to the inventory. use "check bag" to test.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 08, 2016, 06:36:29 AM
And now young grasshopper your task is to add a new method to the Inventory class that returns the count (quantity) of a specified item in inventory.

Code: [Select]
int GetCount(Item item)
{
   // your task. hint use GetIndex to find the item.
}
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 08, 2016, 06:43:35 AM
I will do stuff with this during lunch, today. I seriously appreciate the help I've received from, if my memory serves, what's been exclusively you.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 08, 2016, 06:11:26 PM
I haven't gotten to touch my laptop at all today. I'm also really tired.

I will be doing stuff tonight when I wake up.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 09, 2016, 08:04:55 AM
I'm having a problem in the parser... but it's less of the parser, and more of just this command...

case "check bag":
          Console.WriteLine();
          Inventory.Print();
          Console.WriteLine();

Is not working because...

An object reference is required for the non-static field, method, or property 'Inventory.Print()'

I don't understand. I looked through it all. Am I missing something obvious?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 09, 2016, 08:10:17 AM
I'm having a problem in the parser... but it's less of the parser, and more of just this command...

case "check bag":
          Console.WriteLine();
          Inventory.Print();
          Console.WriteLine();

Is not working because...

An object reference is required for the non-static field, method, or property 'Inventory.Print()'

I don't understand. I looked through it all. Am I missing something obvious?

          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();
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 09, 2016, 01:16:34 PM
That makes sense. That makes so much sense. I know I'm learning still... and that it probably was a common beginner mistake... but I feel so silly...
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 09, 2016, 09:00:24 PM
Get used to feeling silly, trying to program computers does that to everyone.

An Object is an instance of a Class. You should write this on the blackboard 700 times. Tattoo it on your forehead. It is the absolute fundamental of OO programming (C# is an OO programming language). OO programming is about defining objects to be consumed by the program when it executes.

But this particular concept is about Membership and Scope. Scope defines the visibility of objects.

In C# are several scopes:

Local scope: The object is visible witinh the current block, which is defined by opening/closing braces, and can be nested. The object is created somewhere within the block, and automatically destroyed once the program leaves the block.

Method scope: The object is visible within the current method. The object is created somewhere within the method, and destroyed when the program leaves the method.

Class scope: The object is visible by any code in the class it's defined in. The object is created when the class is instantiated (also an object, the parent object), and destroyed when the parent object is destroyed.

Global scope: The object can be seen anywhere within the program. It is created when the program is launched, and destroyed when the program exits.


The IMPAGame class contains a Player object and anything on the Player object must be accessed via the player reference member variable on the IMPAGame class. So the player reference has class scope. Any code inside the IMPAGame class can access the Player object via this reference. The Player object is a member of the IMPAGame class. (Actually the Player object is stored on the Heap and the player reference (which is also an object itself) is the actual member of IMPAGame, but that's not important right now. What's important is understanding membership, and how to access objects that are members on other objects).

Similarily the Player class contains an Inventory object and anything on the Inventory object must be accessed via the Inventory reference member variable on the Player class. The Inventory object is a member of the Player class.

So if any code in the IMPAGame class wants to access the Inventory, it must do it via it's player reference -> Inventory reference, hence player.Inventory.Print()
Title: Re: PWR's PRGRSS - Learning C#
Post by: Nefty on February 09, 2016, 09:17:27 PM
I dont mean to butt in here, but why learn C#? I dont know much about the language but from what research ive done and from talking to various developers, C# seems to be falling by the wayside. C++ is becoming the main language for developers, Paul Blart: Mall CopScript usage is also on the rise. Paul Blart: Mall Cop is becoming used more as well for mobile app development, along with Python.

Obviously Im not as in depth with my knowledge as I would like to be, but it seems the other C languages are much more useful for game development specifically.. If anyone could shed some light i'd appreciate it, but from what i can find not many tools are used with c# (Unity is the main one i have found, but its such a horrid engine to use in my opinion I dont know if that's a great instance).
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 09, 2016, 11:23:35 PM
@Nefty

C++ is not becoming the main language for game developers, it has been the main language for the past 15-20 years, taking over from C in the 90s, which took over from Assembly in the 70s, which took over from machine code in the 60s.

A good reason to learn C# as a beginner is not necessarily because it might get you a job or get you into the game development industry, but mainly because it is much much easier to learn and use than C++. If you try to learn C++ first, it's going to be A LOT more difficult, cause A LOT more frustration, and increase the chance of giving up.

With C#, you can get simple programs working (or any program for that matter), much quicker and easier than you could if using C++, and when learning, getting things working easily is extremely valuable.

If someone wants to be a professional game developer, they're going to have to learn several languages anyway, you're not much use to anyone in a serious game studio if you only know one language.

By all means learn C++ when you want to or need to, but I'd recommend doing that after getting good at C# first, which is a much better introduction. And the basic syntax is enough like C++ that you won't have to start again when learning C++.

Also I don't think C# is falling by the wayside, at least on the tools side. C# is now used a lot in the game industry for tool development, a lot more than most realize.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 09, 2016, 11:28:05 PM
Get used to feeling silly, trying to program computers does that to everyone...
This was an amazing explanation. It's become a lot clearer, I believe.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 09, 2016, 11:44:32 PM
Regarding post #47, I think I found where it goes. I couldn't figure it out...

(http://i.imgur.com/okRBdjd.jpg) is this right?

P.S. I made sure this picture didn't visibly include my other internet activities. Sorry about that to those who saw it and pointed it out last time.
Title: Re: PWR's PRGRSS - Learning C#
Post by: MrMarooca on February 09, 2016, 11:53:20 PM
Regarding post #47, I think I found where it goes. I couldn't figure it out...

Just a guess based on flipping through the pages of this thread - I think it should go in your inventory class so you can call Inventory.AddItem() from anywhere else in the program.

I don't really know the structure of your program entirely though, so I'm just going off what I can see.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 09, 2016, 11:56:17 PM
Regarding post #47, I think I found where it goes. I couldn't figure it out...

Just a guess based on flipping through the pages of this thread - I think it should go in your inventory class so you can call Inventory.AddItem() from anywhere else in the program.

Yep you're both right.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 10, 2016, 12:32:40 AM
Entry: 006 posted to the original post.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 10, 2016, 03:51:02 AM
Entry: 006..
It usually means a closing curly brace is missing somewhere in the file. Every opening curly brace must have a corresponding closing one.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 10, 2016, 08:53:33 AM
Entry: 006..
It usually means a closing curly brace is missing somewhere in the file. Every opening curly brace must have a corresponding closing one.
I must have deleted one on accident at some point.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 10, 2016, 08:25:52 PM
I must have deleted one on accident at some point.
So you've fixed it?
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 11, 2016, 06:04:40 PM
I fixed it finally. That was so frustrating. Gah! I got so angry I took the batteries out of my mouse and threw them on the ground.

I was missing a curly bracket in a spot where the rest of the program was happy with it being gone.

Anyway... I'm going try and get back into the motion of progressive coding. I'd like to start working on getting the nouns parser worked out. Like...

Use
  What would you like to use?

Wrench
  You twist the bolts tighter into place.

Use button
  You press the button on the console, and suddenly the engine starts whirring away.

... so basically, it should be able to detect what you want to use even if it's on the same line or the next line. Also, I need to figure out how to make rooms... I guess. I'm kind of lost on what I need to start with on these.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Jack Of Shades on February 11, 2016, 07:20:59 PM
Finally got off my lazy butt and started learning this again. I am going to try my best to keep up with PWR and any tips/help Craig posts as well. Great start by the way, PWR.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 11, 2016, 09:07:05 PM
Before moving on with more code, now might be a good time to test your understanding of the code.

Split the solution up into 5 source files.

Program.cs - Contains the Main method.
IMPAGame.cs - Contains the IMPAGame class (or whatever you've decided to name it).
Player.cs - Contains the Player class.
Inventory.cs - Contains the Inventory class.
Item.cs - Contains the Item enum.

In general, each class should reside in it's own file.
Remember to back up the solution before starting this exercise in case you run into too many problems and need to rollback.

Also you didn't do this task below, which you're going to need to do before you can properly do the Use command, because you're going to need to be able to query inventory to see if the player has the item they're trying to use.

And now young grasshopper your task is to add a new method to the Inventory class that returns the count (quantity) of a specified item in inventory.

Code: [Select]
int GetCount(Item item)
{
   // your task. hint use GetIndex to find the item.
}

e.g.

// Processing Use command
Code: [Select]
if (player.Inventory.GetCount(item) > 0)
{
   // Use item
}
else
{
   Console.WriteLine("You don't have that item");
}
Title: Re: PWR's PRGRSS - Learning C#
Post by: Jack Of Shades on February 11, 2016, 11:24:41 PM
Okay, a lot has changed since I last attempted this...ironically not TOO long ago. I cannot recall what programs I need to begin. :/ And my last attempt this evening ended up getting me a virus (or two), and having to restore my computer.  >:(
Title: Re: PWR's PRGRSS - Learning C#
Post by: MrMarooca on February 12, 2016, 12:24:32 AM
Okay, a lot has changed since I last attempted this...ironically not TOO long ago. I cannot recall what programs I need to begin. :/ And my last attempt this evening ended up getting me a virus (or two), and having to restore my computer.  >:(

All you need is Visual Studio (https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx).
Title: Re: PWR's PRGRSS - Learning C#
Post by: Jack Of Shades on February 12, 2016, 01:16:32 AM

All you need is Visual Studio (https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx).

Anything to work for a computer that ISN'T updated with Windows 10?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 12, 2016, 02:12:44 AM
Anything to work for a computer that ISN'T updated with Windows 10?
Visual Studio 2015 Community should run on previous versions of Windows, afaik.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 12, 2016, 03:38:33 AM
Visual Studio does work on previous versions. I have a really, REALLY old laptop barely running Windows 7 professional. Visual Studio is what I use.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Jack Of Shades on February 12, 2016, 10:43:02 AM
Bizarre...this one won't allow some features, or say it's not compatible. Ah well, I'll grab it anyway and try to do what I can. Thanks!

EDIT:
 (http://i68.tinypic.com/28iqq9f.png)
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 12, 2016, 03:39:03 PM
Bizarre...this one won't allow some features, or say it's not compatible. Ah well, I'll grab it anyway and try to do what I can. Thanks!
It's odd. I installed VS 2015 on Windows 7 no problem. But that was a year ago. Not sure if MS have changed anything. You could try installing VS 2012.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Jack Of Shades on February 12, 2016, 04:01:32 PM
It's odd. I installed VS 2015 on Windows 7 no problem. But that was a year ago. Not sure if MS have changed anything. You could try installing VS 2012.
That's what I was thinking as well, maybe grab an older version I know worked. But hey, at least I gave it a shot. Thanks, Craig.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 12, 2016, 07:07:18 PM
Weird. VS15 is what I'm using.

Well if that doesn't work, Xamarin Studio is sort of nice. A bit plain, doesn't autocomplete some things, command documentation is a little lacking, but otherwise works.

For Xamarin, go to monodevelop.com, download the two things below the windows section, then download monodevelop. It'll become Xamarin Studio.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 12, 2016, 07:13:48 PM
Personally I wouldn't bother with Xamarin. Visual Studio is far superior, and free, why use an inferior product. Programming is hard enough as it is, might as well use the best tools available.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Jack Of Shades on February 12, 2016, 07:42:30 PM
Alright, so! Finding this download is damn near impossible without running into "2015." Now, I figure someone will link it to me with: "I found it with no problem." Well, you're a damn WIZARD! This crap is not easy. D: <
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 12, 2016, 07:57:33 PM
Direct Link (https://app.vssps.visualstudio.com/profile/create?download=true&family=VisualStudioCSharpExpress&release=VisualStudio2010&type=web&slcid=0x409&context=eyJwZSI6MCwicGMiOjAsImljIjowLCJhbyI6MCwiYW0iOjAsIm9wIjoxLCJhZCI6MSwiZmEiOjAsImF1IjpudWxsLCJjdiI6MTY4MTA2OTEzLCJmcyI6MCwic3UiOjAsImVyIjoxfQ2)

That should link you to the VS 2010 Express download. 2010 has everything you need for now.
Title: Re: PWR's PRGRSS - Learning C#
Post by: FatbFFA on February 12, 2016, 07:59:37 PM
Alright, so! Finding this download is damn near impossible without running into "2015." Now, I figure someone will link it to me with: "I found it with no problem." Well, you're a damn WIZARD! This crap is not easy. D: <
Im a wizard.
https://www.visualstudio.com/en-us/news/vs2013-community-vs.aspx
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 12, 2016, 08:00:37 PM
Yea use the one ETTP linked.
Title: Re: PWR's PRGRSS - Learning C#
Post by: FatbFFA on February 12, 2016, 08:02:26 PM
Yea use the one ETTP linked.
Kinda surprised i found it tbh cause usually it brings you to 2015.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 12, 2016, 08:52:25 PM
Entry:007 posted to original OP.

I screwed something up. I got rid of something, then I went to undo, but I saved instead.

I thought I got everything back in place, but now the code from post #47 is giving me trouble again. I know that the rest of the program is alright, but... I don't know. I've been having nothing but problems for days, now. I need to take a break.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 12, 2016, 09:05:42 PM
Program.cs:
Code: [Select]
namespace IMPA
{
    class Program
    {
        static void Main(string[] args)
        {
            var game = new IMPAGame();
            game.Run();
        }
    }
}

Item.cs:
Code: [Select]
namespace IMPA
{
    enum Item
    {
        None,
        Knife,
        Flashlight,
        Wrench,
        Water,
        Chitin,
        Map,
        Dogtag,
    }
}

Game.cs:
Code: [Select]
using System;
using System.Text;

namespace IMPA
{
    class IMPAGame
    {
        Actor player;

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

            // 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)
            {
                Console.Write("> ");
                var input = Console.ReadLine();
                if (!ParseInput(input)) break;
            }
        }

        bool ParseInput(string input)
        {
            switch (input.ToLower())
            {
                case "":
                    break;

                case "exit":
                    return false;

                case "help":
                    Console.WriteLine();
                    Console.WriteLine("Help Commands:");
                    Console.WriteLine("inv - show inventory");
                    Console.WriteLine("add - add random item");
                    Console.WriteLine("Exit - Exit game.");
                    Console.WriteLine();
                    // etc
                    break;

                case "inv":
                    player.Inventory.Print();
                    break;

                case "add":
                    var r = new Random();
                    var i = (Item)r.Next(1, (int)Item.Dogtag);
                    player.Inventory.AddItem(i);
                    break;

                default:
                    Console.WriteLine("Unknown command");
                    Console.WriteLine();
                    break;
            }

            return true;
        }
    }
}

Actor.cs:
Code: [Select]
namespace IMPA
{
    class Actor
    {
        public Inventory Inventory;

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

Inventory.cs:
Code: [Select]
using System;
using System.Collections.Generic;

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

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

        // this method is public so that code outside the Inventory class can call it
        public void AddItem(Item item)
        {
            // See if we already have an item in inventory
            var i = GetIndex(item);

            // if i >= 0 then we already have item in the inventory
            if (i >= 0)
            {
                // we already have item, so just increase the count
                var ii = Items[i];
                ii.Count++;
                Items[i] = ii;
            }
            else
            {
                // we don't have item, so add a new one with a count of 1.
                var ii = new InventoryItem() { Item = item, Count = 1 };
                Items.Add(ii);
            }
        }

        public void Print()
        {
            Console.WriteLine();

            if (Items.Count < 1)
            {
                Console.WriteLine("Inventory: Empty");
            }
            else
            {
                Console.WriteLine("Inventory:");
                foreach (var item in Items)
                {
                    Console.WriteLine("{0}: {1}", item.Item, item.Count);
                }
            }

            Console.WriteLine();
        }

        // this method is private, it's only used internally by the Inventory class
        int GetIndex(Item item)
        {
            // enumerate each item in the item list and return its index if found, otherwise return -1
            for (int i = 0; i < Items.Count; i++)
            {
                if (Items[i].Item == item) return i;
            }
            return -1;
        }
    }
}
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 12, 2016, 09:31:00 PM
I don't even recognise actor.cs.

I recognise the code in it, but why does that need to be seperate?

And why did you call it actor?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 12, 2016, 09:38:36 PM
I renamed the Player class to Actor. Actor is a better name, it's more general, and is the standard name used in games for characters. Later a Player class can inherit from Actor if need be, but for now, Actor is a better name. So it has replaced Player.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 13, 2016, 03:13:14 AM
I said I'd be taking a break for a couple days. I was going to, but after a couple hours of playing Aardwolf I got the itch for this...

So I'll just keep going till I hit another brick wall...
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 15, 2016, 07:13:27 AM
I'm still working on C#, of course, but I had a question regarding other coding languages.

I've been checking out some MUDs and single-player text adventures. They seem to, more frequently than not, use Python.

Could someone tell me advantages of some common languages over others? Here are the few I'm most interested in learning, if not at least learning about...

•Python
•C#
•C
•C++
•lua
•Javа
•Javаscript (I'm not even sure of the difference between this and Javа)
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 15, 2016, 07:33:07 AM
A MUD is basically a database so it makes sense to use a language that makes it easy(ier) to work with databases.

So SQL is the obvious choice for the database.

I've never used Python, but I've been told it's great for small apps that do database queries and reports. I don't know how well it scales once the application starts getting big though.

C# Lambda is quite good for SQL queries directly in the language. I'd personally go with this, but I'm biased to C# having used it so much.

C/C++ wouldn't go near it for making a MUD.

Haven't used Lua.

Haven't used J.ava so I'm not sure if it has C# Lambda type queries.

J.avascript is a completely different language to J.ava and is mainly used for website coding, and is also sometimes used for scripting in games. Personally I wouldn't bother with it.


Title: Re: PWR's PRGRSS - Learning C#
Post by: Dryym on February 15, 2016, 07:49:00 AM
•Javа
•Jаvаscript (I'm not even sure of the difference between this and Javа)

Quote from: Wikipedia
JаvaScript and Jаva
A common misconception is that JаvaScript is similar or closely related to Jаva. It is true that both have a C-like syntax (the C language being their most immediate common ancestor language). They also are both typically sandboxed (when used inside a browser), and JаvaScript was designed with Jаva's syntax and standard library in mind. In particular, all Jаva keywords were reserved in original JаvaScript, JаvaScript's standard library follows Jаva's naming conventions, and JаvaScript's Math and Date objects are based on classes from Jаva 1.0,[122] but the similarities end there.

The differences between the two languages are more prominent than their similarities. Jаva has static typing, while JаvaScript's typing is dynamic. Jаva is loaded from compiled bytecode, while JаvaScript is loaded as human-readable source code. Jаva's objects are class-based, while JаvaScript's are prototype-based. Finally, Jаva did not support functional programming until Jаva 8, while JаvaScript has done so from the beginning, being influenced by Scheme.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 15, 2016, 08:09:13 AM
A MUD is basically a database so it makes sense to use a language that makes it easy(ier) to work with databases.

So SQL is the obvious choice for the database.

I've never used Python, but I've been told it's great for small apps that do database queries and reports. I don't know how well it scales once the application starts getting big though.

C# Lambda is quite good for SQL queries directly in the language. I'd personally go with this, but I'm biased to C# having used it so much.

C/C++ wouldn't go near it for making a MUD.

Haven't used Lua.

Haven't used J.ava so I'm not sure if it has C# Lambda type queries.

J.avascript is a completely different language to J.ava and is mainly used for website coding, and is also sometimes used for scripting in games. Personally I wouldn't bother with it.
I don't mean for just MUDs. I mean in general. Like... in most cases, what is one language more useful for than another?

Also, to what extent can you mix and match languages with each other in programs? Why would one do this?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 15, 2016, 08:48:56 AM
Imho C# is the best general programming language, and the best language for learning general programming skills.

But the application matters. The language you choose to make a MUD with, may well be different to the language you choose to make a SHMUP with, that is one of the main benefits of knowing several languages, you are better able to choose the right tools for the job.

I don't know if there are any general answers regarding multi-language solutions, it depends on the programming language, compilers, linkers, the platform, the O/S and the runtime. I know in Windows, in the .Net world, any language supported by .Net can be used together. I'm not sure if .Net supports Python.

Why? Using the best tool for the job. It may be the case that different languages are better suited for different parts of the application. I think generally only in business, and in large enterprise applications. But also in games, e.g. some studio's use C++ for their main game engine, and J.avascript or Lua for a script language for designers.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 16, 2016, 07:04:20 AM
Finally relieved myself of my frustrations with learning code.

New problem with the program.

In Program.cs, I'm having problems with...
var game = new IMPAGame();

... Where it's telling me...

The type or namespace name 'IMPAGame' could not be found (are you missing a using directive or an assembly reference?)

... and I checked Game.cs, it's all correct. So I checked my using directives and I don't know if I'm missing one, because I don't know which one I'd need. However, I'm thinking it's likely the using directive I'm missing.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 16, 2016, 07:17:25 AM
When exactly should I use different using directives? How will I know which ones? Why do some of these files have some, but others none?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 16, 2016, 08:53:26 AM
The type or namespace name 'IMPAGame' could not be found (are you missing a using directive or an assembly reference?)
When the compiler is talking about types, it's talking about either Classes, Structs or Enums. So the error message is the compiler saying it can't find the class IMPAGame. You shouldn't need a using directive because the IMPAGame class should be in the same namespace as the code in Program.cs. So if the IMPAGame class name is the same, check the namespace in both Game.cs and check the namespace in the Program.cs file, they should both match, I think they're IMPA. If that doesn't fix it, you'll need to post the code from both Program.cs and Game.cs for me to find the problem.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 16, 2016, 08:58:07 AM
When exactly should I use different using directives? How will I know which ones? Why do some of these files have some, but others none?
Using directives tell the compiler which namespaces to search when searching for type names that aren't fully qualified. If you fully qualify all your type names, you'll never need using directives, but that's cumbersome because typing out fully qualified type names is long winded. How will you know which namespaces the types are in? That's just something you have to learn as you go.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 17, 2016, 05:04:56 AM
I checked them. They're both the same.

Game.cs
(http://i.imgur.com/x6qtKGI.jpg)

Program.cs
(http://i.imgur.com/aQjxeCb.jpg)
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 17, 2016, 05:59:26 AM
You posted Game.cs twice. But anyhow it doesn't matter. You see how the code is not properly indented? That means you're missing a curly brace somewhere, probably a closing one.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 17, 2016, 06:03:48 AM
You posted Game.cs twice. But anyhow it doesn't matter. You see how the code is not properly indented? That means you're missing a curly brace somewhere, probably a closing one.
oops. I didn't mean to post the same image twice. I'll fix that in a minute.

As for the indentation, I know for fact that there isn't a curly brace missing. I accidentally put a curly brace, and it autoindented all of that. However, when I got rid of it, it didn't put it back.

EDIT: Fixed the image.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 17, 2016, 06:32:30 AM
Entry: 008 posted to the original post.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 17, 2016, 06:45:38 AM
If there are no curly braces missing then the indentation should be correct. The best way to check is to go to the end of the file, delete the last curly brace (closing one), and replace it. Immediately after you replace it, VS will automatically fix all the indentation in that file. If it doesn't, then there is either a curly brace missing in that file, or another syntax error. But based on the 'type not found' error you posted above, it's likely a curly brace missing.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 17, 2016, 06:51:28 AM
Indentation fixed, problems still persists.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 17, 2016, 06:52:41 AM
If you know how to use pastebin, send me the file so I can fix, or just post the code in Game.cs directly here, there's not much of it.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 17, 2016, 06:56:53 AM
Pastebin?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 17, 2016, 06:58:03 AM
Pastebin?
.com
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 17, 2016, 07:06:12 AM
Turns out, though, most graphics engines don't actually support 2D. It's all 3D, but made to look 2D. Which... isn't a huge problem, but actually kind of throws a gear in my sticks.
Use Win2D?
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 17, 2016, 07:08:42 AM
Sent via PM.

Use Win2D?

Okay. I'll look into it. Any reason for the question mark?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 17, 2016, 07:09:37 AM
Any reason for the question mark?
No..
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 17, 2016, 07:12:46 AM
No..
Are you sure? That half-elipses after your "no" leads me to believe otherwise. Is this a trap? Are you trapping me?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 17, 2016, 07:16:45 AM
Are you trapping me?
No?..
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 17, 2016, 07:26:29 AM
No?..
hmmm...

(http://i.imgur.com/0vqmkYo.jpg)
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 26, 2016, 09:50:55 AM
I've not been working as much on learning C#. I've had problems to deal with regarding other people. I'll pick up on learning some tonight if at all possible. I have not given up.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 27, 2016, 07:45:12 PM
I found a C# compiler that sort of works with IMPA on my phone using the Google Play store.

It's called C#Shell.

It doesn't like long lines, but otherwise, it's pretty swish. This means I theoretically should have more time to work on IMPA and my C# learning.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 04, 2016, 01:26:52 AM
I've finally ended my... sort of hiatus.

I was really just dabbling here and there in story stuff. As well as looking at functions in finished games, and guessing how they could be done. There was a decent amount of help in this from Fabian.

I'm ready to look into making my commands work.

So my first question... uh... how do I make my commands work? I imagine all the same, just different words.

I'm really not sure where to start beyond adding a line in the series of conditionals in Game.cs.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 04, 2016, 07:39:08 PM
Today, I got Windows 10 downloaded on my laptop. It was recommended by Quanrian. A game developer I met the other day. Hoping it's... uh... I don't know... better than Windows 7 professional.

I'm about to start looking into how to make my commands work as soon as I finish this post. I think I'll be using... um... maybe goto... it'll take it to a series of conditionals asking... what item? do you have the item? How many?

I'm not sure about this... :(
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 05, 2016, 09:47:04 AM
This is my first attempt at working out how to make my commands work.

First (I think), I need to be able to parse two seperate things in one line; an item and a command (i.e. Use lighter). I didn't even know what command to use or in what order. So just as a test, I went to Game.cs and put in...

case "command":
case "item":
     Console.WriteLine("used item");
     break;

Not quite sure where I would go after this, but it didn't matter. It didn't work, and I should have guessed. Instead of expecting both commands in the same line, it expected one or the other. So... that was a let down. That said, I'm not sure it's the right decision to put that part of the code where I tried it. I'll be messing around some more today.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 05, 2016, 02:36:07 PM
Sensei Craig, please offer your wisdom.

I am very lost. It appears my break has made me lose understanding of a few things. I shall not break from now on. I cannot figure out how to make my commands work.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 09, 2016, 06:04:15 PM
After looking around, I found a few commands that might work for what I need. Well... one, really. It seems right. At first I was thinking string comparison... but... I read more stuff, and I think Console.GetKey makes sense. I just need to decide how to apply it... Oh no...
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 10, 2016, 09:18:01 PM
The Split method on the string class might be a good place to start. It would allow you to split the whole line the player input, into separate strings or tokens. With the first token being the command, and the following tokens being the arguments/parameters/items etc.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 11, 2016, 05:56:20 PM
I don't actually know how I would do string comparison. I read what it does on a C# documentation app. I remember I have to do something along the lines of...

String (command == item)

... or something.

I'm not sure how to do it, really. Also, would this go in a different class?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 13, 2016, 08:33:41 AM
I don't actually know how I would do string comparison.
The same as any other variable

var strA = "Hello";
var strB = "World";
if (strA == strB)
   // they are the same
else
   // they are different

Also, would this go in a different class?
What is a class?
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 13, 2016, 08:50:25 AM
What is a class?
Isn't that what they're called? Have I been calling them the wrong thing the whole time? Classes... like... Inventory.cs, Game.cs, etcetera. That's what you have to type in when you make a new one is class... I think... I'm really confused.

EDIT: Like here...

namespace IMPA
{
    class Actor
    {
        public Inventory Inventory;

        public Actor()
        {
            Inventory = new Inventory();
        }
    }
}
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 13, 2016, 09:34:21 AM
In any case, I imagine it would go something like this. All items and commands would need to be a variable. Then I'll need to write out each event. How do I do multiple queries for one event? Is it just "if" followed by each query in its own set of parantheses like so?...

if (query1) (query2)
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 13, 2016, 09:34:30 AM
No, I'm asking you, What is class?

Because you can't answer this:

Also, would this go in a different class?

Unless you know what a class is.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 13, 2016, 09:36:22 AM
In any case, I imagine it would go something like this. All items and commands would need to be a variable. Then I'll need to write out each event. How do I do multiple queries for one event? Is it just "if" followed by each query in its own set of parantheses like so?...

if (query1) (query2)
What is an event?
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 13, 2016, 09:38:58 AM
No, I'm asking you, What is class?

Because you can't answer this:

Also, would this go in a different class?

Unless you know what a class is.
Oh. A class is something that defines the behaviour of a type. Right? So... since I'm using variables in this portion, and types are variables... I would create a new class for this.

Yes?
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 13, 2016, 09:40:46 AM
In any case, I imagine it would go something like this. All items and commands would need to be a variable. Then I'll need to write out each event. How do I do multiple queries for one event? Is it just "if" followed by each query in its own set of parantheses like so?...

if (query1) (query2)
What is an event?
The the thing that happens after the conditions are met?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 13, 2016, 03:24:52 PM
Oh. A class is something that defines the behaviour of a type. Right?
No. Classes are a type of user defined type. (structs and enums are some others). Classes are a design mechanism, used to express encapsulated concepts in your program.

and types are variables... I would create a new class for this.
Types are not variables. Variables are instances of types.

Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 13, 2016, 06:19:27 PM
What sort of concepts? Could you give me a machine example so I know better when to use them?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 14, 2016, 05:36:50 PM
What sort of concepts?
If you describe your game in words, what it is, what it does, what players can do, then any nouns are potential classes.

You already have IMPAGame which encapsulates an instance of the game.
Actor/Player, Inventory/InventoryItem.

Others may be:

Map: Encapsulates the game world and it's locations.
Parser: Parses player text input into commands.
Quest: A list of requirements, tasks to perform, a reward etc.

The above classes may also need smaller helper classes. e.g. the Map class may need a Location or Cell class. The Quest class may need a Task class. The Parser may use a Command class.

This is probably not helping much. The best thing to do is just program, then program some more, until things start to make sense, which really only happens by programming some more.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 14, 2016, 09:26:51 PM
Right. Well, I think I understood that. I'm not entirely sure. If you could give me a machine example, that's how I learn best. For example, when I was learning how to script on Total Miner, this machine example helped a lot...

If
    You don't understand
Then
     Ask questions
Else
     You won't understand
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 14, 2016, 11:46:18 PM
If
    You don't understand
Then
     Ask questions
Else
     You won't understand

Else If
    You don't understand
Then
     Take a step back
Else
     Take a step forward
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 14, 2016, 11:48:32 PM
If
    You don't understand
Then
     Ask questions
Else
     You won't understand

Else If
    You don't understand
Then
     Take a step back
Else
     Take a step forward
Right, right. That's helpful for scripting in Total Miner... but what about C#?...
Title: Re: PWR's PRGRSS - Learning C#
Post by: FatbFFA on March 15, 2016, 12:36:23 AM
If
    You don't understand
Then
     Ask questions
Else
     You won't understand

Else If
    You don't understand
Then
     Take a step back
Else
     Take a step forward
Right, right. That's helpful for scripting in Total Miner... but what about C#?...

No this is how its written in c# almost, and many other languages.

Code: [Select]
int Ex = 3;


if(Ex = 1){
      Console.WriteLine("Ex is equal to 1");
} else if(Ex = 2) {
      Console.WriteLine("Ex is equal to 2");
} else if(Ex = 3) {
      Console.WriteLine("Ex is equal to 3");
} else {
      Console.WriteLine("You are screwed, your over the limit.");
}



Also have you learned about arrays and for loops for storing data as it may come in handy also if you know about arrays learn about for loops to read the data more effectively.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 15, 2016, 12:38:39 AM
I believe you misunderstood. That's not the problem I'm having.
Title: Re: PWR's PRGRSS - Learning C#
Post by: FatbFFA on March 15, 2016, 12:41:37 AM
Right, right. That's helpful for scripting in Total Miner... but what about C#?...

Ah i though you were asking how to do if and else/ else if statements.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 15, 2016, 04:10:03 AM
Code: [Select]
if(Ex = 1){
      Console.WriteLine("Ex is equal to 1");
} else if(Ex = 2) {
      Console.WriteLine("Ex is equal to 2");
} else if(Ex = 3) {
      Console.WriteLine("Ex is equal to 3");
} else {
      Console.WriteLine("You are screwed, your over the limit.");
}

Your code would cause a compiler error because you're using assignment where the compiler expects comparison, but in any case the .Net Standard suggests it should be written like this:

Code: [Select]
int ex = 3;

if (ex == 1)
{
   Console.WriteLine("ex is equal to 1");
}
else if (ex == 2)
{
   Console.WriteLine("ex is equal to 2");
}
else if (ex == 3)
{
   Console.WriteLine("ex is equal to 3");
}
else
{
   Console.WriteLine("You are screwed, your over the limit.");
}
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 15, 2016, 04:32:26 AM
The code below requires knowledge of arrays.

It splits the one input string the gamer entered into an array of strings delimited by either a space or comma. The first element of the array is the command, and any following elements are arguments/items etc (note there may not be any).

It also now declares a separate method for each command. So the main parse method now just splits the input into the array, checks the first element (the command) and passes the array to the appropriate command method.

Each command method will process it's respective command, dealing with the user input appropriately for it's command.

It's worth noting this may not be the best way to do things, and I suspect it isn't, but I've never written a text adventure before, so this is at least, at this beginning, from my point of view, the simplest logical progression or direction to move forward.

Code: [Select]
using System;
using System.Text;

namespace IMPA
{
    class IMPAGame
    {
        Actor player;

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

            // 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)
        {
            var args = input.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (args == null || args.Length < 1) return true;

            switch (args[0].ToLower())
            {
                case " ":
                    break;

                case "add":
                    CommandAdd(args);
                    break;

                case "help":
                    CommandHelp(args);
                    break;

                case "check bag":
                    CommandCheckBag(args);
                    break;

                case "examine":
                    CommandExamine(args);
                    break;

                case "use":
                    CommandUse(args);
                    break;

                case "pickup":
                    CommandPickup(args);
                    break;

                case "drop":
                    CommandDrop(args);
                    break;

                case "open":
                    CommandOpen(args);
                    break;

                case "close":
                    CommandClose(args);
                    break;

                case "clear":
                    CommandClear(args);
                    break;

                case "exit":
                    return false;

                default:
                    Console.WriteLine();
                    Console.WriteLine("  Command not recognised");
                    Console.WriteLine();
                    break;
            }

            return true;
        }

        void CommandAdd(string[] args)
        {
            var r = new Random();
            var i = (Item)r.Next(1, (int)Item.Dogtag);
            player.Inventory.AddItem(i);
        }

        void CommandHelp(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("  - Help --------------------------------------- Lists usable commands");
            Console.WriteLine();
            Console.WriteLine("  - Check bag ---------------------------------- Displays your inventory");
            Console.WriteLine();
            Console.WriteLine("  - Examine ------------------------------------ Examine an object");
            Console.WriteLine();
            Console.WriteLine("  - Use ---------------------------------------- Use an object");
            Console.WriteLine();
            Console.WriteLine("  - Pickup ------------------------------------- Pick up an object");
            Console.WriteLine();
            Console.WriteLine("  - Drop --------------------------------------- Drop an object");
            Console.WriteLine();
            Console.WriteLine("  - Open --------------------------------------- Open an object");
            Console.WriteLine();
            Console.WriteLine("  - Close -------------------------------------- Close an object");
            Console.WriteLine();
            Console.WriteLine("  - Clear -------------------------------------- Clear the console of text");
            Console.WriteLine();
            Console.WriteLine("  - Exit --------------------------------------- Exit game");
            Console.WriteLine();
            Console.WriteLine();
        }

        void CommandCheckBag(string[] args)
        {
            Console.WriteLine();
            player.Inventory.Print();
            Console.WriteLine();
        }

        void CommandExamine(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("  What do you want to examine?");
            Console.WriteLine();
        }

        void CommandUse(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("  What do you want to use?");
            Console.WriteLine();
        }

        void CommandPickup(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("  What do you want to pick up?");
            Console.WriteLine();
        }

        void CommandDrop(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("  What do you want to drop?");
            Console.WriteLine();
        }

        void CommandOpen(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("  What do you want to open?");
            Console.WriteLine();
        }

        void CommandClose(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("  What do you want to close?");
            Console.WriteLine();
        }

        void CommandClear(string[] args)
        {
            Console.Clear();
        }
    }
}
Title: Re: PWR's PRGRSS - Learning C#
Post by: FatbFFA on March 15, 2016, 09:47:23 AM
Code: [Select]
if(Ex = 1){
      Console.WriteLine("Ex is equal to 1");
} else if(Ex = 2) {
      Console.WriteLine("Ex is equal to 2");
} else if(Ex = 3) {
      Console.WriteLine("Ex is equal to 3");
} else {
      Console.WriteLine("You are screwed, your over the limit.");
}

Your code would cause a compiler error because you're using assignment where the compiler expects comparison, but in any case the .Net Standard suggests it should be written like this:

Code: [Select]
int ex = 3;

if (ex == 1)
{
   Console.WriteLine("ex is equal to 1");
}
else if (ex == 2)
{
   Console.WriteLine("ex is equal to 2");
}
else if (ex == 3)
{
   Console.WriteLine("ex is equal to 3");
}
else
{
   Console.WriteLine("You are screwed, your over the limit.");
}
Ah yes, was working in some GML before I posted this and its not as strict with how it handles stuff like that, it just knows thats what I want it to do in GML.

Say in GML I do variables it don't have to be specified.

Ex.

A = 1;
B = true;
C = "I like this way of handling vars"

Anyways sorry PWR i got off so abrupt last night my internet died.

I explained very quickly about arrays, just the uses and stuff. I didn't go over 2D and 3D arrays.
(Note to PWR 3D arrays aren't 3D)
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 15, 2016, 09:31:33 PM
The command "check bag" isn't working. Is it because there's a space in the command?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 15, 2016, 10:00:34 PM
Correct. The input string is split using spaces as one of the delimeters (comma being the other), so the first element of the input array will be "check" and the second will be "bag" so the case statement won't find "check bag".

The way to fix that is either remove the space so the command becomes "checkbag", or have a more general "check" command, which will then look at the 2nd element to determine what to check.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 15, 2016, 10:15:57 PM
So, I suppose "check" and "examine" could be synonymous. So, if I set it up so that "bag", "i" and/or "inventory" were... uh... items, then that would fix it? I don't want "bag" to show up in my inventory if "bag" is an item. Also, "pick up" is another two word command. How would I fix that?

What about Items with two words? Like Fuel Tank.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 16, 2016, 12:05:56 AM
Yep, check/examine can be merged into one command. Most MUD's use 'Look' I think.

I changed Pick up to Pickup. Most MUD's would use 'Take'.

If you want to handle item names with spaces, you're probably going to have abandon the provided Split method and roll your own, to handle surrounding names in quotes like "Fuel Tank"

No don't make bag or inventory as items, just handle them separately in the check or examine command/method.

e.g.

if (args[1] == "bag" || args[1] == "i" || args[1] == "inventory")
{
   // check bag
}
else
{
// check item (args[1])
}
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 16, 2016, 01:38:35 AM
Yep, check/examine can be merged into one command. Most MUD's use 'Look' I think.
No. Look and Examine are generally different. Look describes what you see in a room. Examine describes the specified item. Some do combine them, but as far as I'm aware, MUD players prefer them seperate.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 18, 2016, 06:55:52 AM
I've decided I'll just go the more traditional route and use "Inventory" instead of examine bag, check bag, or what have you.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 18, 2016, 07:49:41 AM
So for Examine to work, I imagine it'll need to be something along the lines of...

void CommandExamine (string[] args)
{
     Console.WriteLine
     {
           /* Check to see what the player wants to examine, if anything. Otherwise, describe the room.

           Then see if the player has or is in the same room with the item. If not, then say "You cannot see that"

           If the previous conditions have been met, describe the item.
           */
     {
     Console.WriteLine
}

... I realise the actual important part isn't code, but I'm trying to clarify whether or not I have the idea down, or if I should do it different. I hope that makes sense
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 19, 2016, 10:19:38 AM
My laptop is acting nuts, and I didn't do anything... Well... I did download Windows 10, but... I don't know if that's the cause. Until I get it back in decent order, I'm going to try and work an old, old, old, old, old, old, old PC with Windows 95. Visual Studio should work on it, right? I mean... Microsoft is crazy about their software having backwards compatibility, right? Guess I can only try...
Title: Re: PWR's PRGRSS - Learning C#
Post by: Dryym on March 19, 2016, 10:53:02 AM
Are you planning on having an advanced system with the commands like Zork did?

For example "Hit Troll with Sword" And "Hit the Troll with the Elven Sword" are both valid options.

And some funny things such as "Eat the Troll" returning "I don't think the troll would agree with you."
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 19, 2016, 10:57:04 AM
Are you planning on having an advanced system with the commands like Zork did?

For example "Hit Troll with Sword" And "Hit the Troll with the Elven Sword" are both valid options.

And some funny things such as "Eat the Troll" returning "I don't think the troll would agree with you."
The humour is definitely a goal. In fact, in the wise words of my favourite YouTuber,"The greatest adventures always have buckets."... so that's another goal.

As for complex word parsing, no. If you've been following along, you'll see I can't use but one space in a single string of text. So, maybe eventually... but not at this stage...
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 21, 2016, 08:03:29 AM
So for Examine to work, I imagine it'll need to be something along the lines of...

void CommandExamine (string[] args)
{
     Console.WriteLine
     {
           /* Check to see what the player wants to examine, if anything. Otherwise, describe the room.

           Then see if the player has or is in the same room with the item. If not, then say "You cannot see that"

           If the previous conditions have been met, describe the item.
           */
     {
     Console.WriteLine
}

... I realise the actual important part isn't code, but I'm trying to clarify whether or not I have the idea down, or if I should do it different. I hope that makes sense
Yes I guess you could do something like that:

Code: [Select]
void CommandExamine(string[] args)
{
     Console.WriteLine
     {
         item = GetItem(args)
         if (item)
         {
            if (IsItemInRoom(item))
            {
               Console.WriteLine("Details about item.")
            }
            else
            {
               Console.WriteLine("This item is not in the room.")
            }
         }
         else
         {
            Console.WriteLine("Item not found.")
            Console.WriteLine("Details about room.")
         }
     }
     Console.WriteLine
}

My honest opinion is that a MUD is too advanced for you at this time in your learning, and you'd be better off working on simpler programs, until you get a better feel for how to do things. A MUD requires complex text parsing, which is not easy, even for advanced programmers. It requires advanced database management, again not easy. Writing a good MUD would test the skills of most advanced programmers.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 21, 2016, 12:35:00 PM
Well, I'm not really planning on working on a MUD yet. Multiplayer seems just way too hard for a beginner. For now, the simple text based game like IMPA here should be the kind of project that is fitting for a first good learning project. It seems to use a good portion of the tools I have been learning and have yet to learn in C#. After it's finished, I will keep it as what would mostly be a reference field guide as to what different commands and tools are used for and how. I hope that made sense.

In any case, is there anything you think I may be missing as far as how items should work? Like... I was thinking alternate descriptions would make sense to have, for in case you do something to the item, but I don't know. I'm not sure if that'll be necessary.

On that note, though, I should say that I have been having problems with my desktop. So, since my laptop is weirding out, too, I can't do much in the ways of anything with it. On top of that, a huge predicament I have found myself in will in less than a month keep me from having internet access (among other things) for... who knows how long. It may be a long time, or it may be a week. I do have to say, though, in the low, low, low chance I don't get to come back to the community, I have to say I enjoyed my run. I don't want to go into detail publicly. If anyone is curious, I don't mind sharing over PM. I will give a good bye on the first day of my leave, though. So don't worry about me just disappearing.

Sorry for the rambling. Just had a lot to get out.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 21, 2016, 09:15:39 PM
Sorry, I meant like text adventures in general, not just MUDs, they're both hard to program, too hard for beginners I think. With programming I think it's better to work and practice within your knowledge, only pushing out beyond that conservatively at first. Get the fundamentals down, then it becomes a lot easier to start pushing out into new ground. Without the fundamentals, you'll get stuck in a bog pretty quick. Programming text adventures requires some pretty sophisticated programming knowledge, far beyond fundamentals.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 21, 2016, 09:40:53 PM
Ah, well if that's the case, I suppose I should put IMPA on hold for a bit. In case I can manage to mess around with C# a bit more before I have to deal with my dilemma, what do you recommend I try doing?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 21, 2016, 10:20:54 PM
Programming can be a bit of a slog at first, hard to make sense out of everything, too many details obscuring the basics. But once you start to get the basics down, things start to make a lot more sense, progress becomes more rapid, and it becomes a lot more fun (less frustrating).

I think you'd enjoy making IMPA a lot more once you get to that point where things start to make sense.

Maybe you could work on some subsets. Like the inventory class. Make a console app that allows you to add items to an inventory object, to list the items, to remove an item, to move an item to another position. To handle finite sized stacks of items etc.

I'm not really sure. Whatever you can think of that you think you might be able to do, with some aspects that will also require you to learn some new stuff.

For me it was all about graphics, when I started, I just wanted to make as many things appear on the screen as I could, making them move as fast as I could. In those days, that goal was relevant because the hardware was so limited. These days it's not so relevant, the hardware now allows us to draw tens of thousands of almost screen sized sprites in a singe frame, so I guess goals will be different now. I started off just getting a single sprite to move on the screen, then several, then made games like river rapids that just basically rained rocks and you had to avoid them, then moved onto games like basic space invaders (like total invaders), and derivatives, galaxians, galaga, millipede, phoenix, etc, simple 2d vertical car racing games, karate type games, dig-dug, tutankhamun, maze games, etc. all very simple versions of their arcade equivalents. Keeping it simple is really important at first.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 22, 2016, 06:18:20 AM
Do you have any old projects I could look at to study the code? Also, preferably, anything that doesn't require me to download anything extra?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 22, 2016, 08:58:30 AM
Do you have any old projects I could look at to study the code? Also, preferably, anything that doesn't require me to download anything extra?
Hmm now where did I put those cassette tapes and 3.5' floppies...

Here is the Total Invaders source code:

Object.cs
Code: [Select]
using Microsoft.Xna.Framework;

namespace Craig.TotalMiner.Arcade.TotalInvaders
{
    struct Invader
    {
        public bool IsAlive;
        public Vector2 Position;
    }

    enum PickupType
    {
        None,
        PlayerShip
    }

    struct UFO
    {
        public bool IsAlive;
        public PickupType Pickup;
        public Vector2 Position;
        public Vector2 Velocity;
    }

    struct Pickup
    {
        public bool IsAlive;
        public PickupType PickupType;
        public Vector2 Position;
        public Vector2 Velocity;
    }

    struct Bullet
    {
        public Vector2 Position;
        public Vector2 Velocity;
    }

    struct Player
    {
        public bool IsAlive;
        public Vector2 Position;
        public Vector2 Velocity;
        public float Speed;
        public float ShotDelay;
        public float ShotDelayTimer;
        public Vector2 BulletVelocity;

        public Player(bool isAlive)
        {
            IsAlive = isAlive;
            Position = new Vector2(10, 220);
            Velocity = Vector2.Zero;
            Speed = 0.8f;
            ShotDelay = 0.5f;
            ShotDelayTimer = 0;
            BulletVelocity = new Vector2(0f, -7);
        }
    }

    struct Particle
    {
        public float Age;
        public Vector2 Position;
        public Vector2 Velocity;
        public Color Color;
    }
}

InvaderWave.cs
Code: [Select]
using System;
using Microsoft.Xna.Framework;
using Craig.Engine;

namespace Craig.TotalMiner.Arcade.TotalInvaders
{
    class InvaderWave
    {
        #region Fields

        public Vector2 Position;
        public Vector2 Velocity;
        public Rectangle Box;
        public Invader[] Invaders;

        TotalInvaders instance;
        bool dropDown;
        float dropStartY;
        int invaderCount;
        float newWavePauseTimer;
        Vector2 invaderBulletVelocity;

        #endregion

        #region Initialization

        public InvaderWave(TotalInvaders instance)
        {
            this.instance = instance;
            Invaders = new Invader[55];
        }

        #endregion

        #region Reset Wave

        public void ResetWave()
        {
            newWavePauseTimer = 2f;

            for (int i = 0; i < Invaders.Length; i++)
                Invaders[i].IsAlive = false;
        }

        void NewWave()
        {
            newWavePauseTimer = 0f;
            dropDown = false;
            Position = new Vector2(0f, Math.Min(instance.Wave, 30));
            Velocity = new Vector2(-MathHelper.Lerp(0.05f, 1f, instance.Wave / 30f), 0.1f);
            invaderBulletVelocity = new Vector2(0f, 1f);

            int i = 0;
            for (int y = 0; y < 97; y += 24)
            {
                for (int x = 0; x < 264; x += 24)
                {
                    Invaders[i].IsAlive = true;
                    Invaders[i++].Position = new Vector2(x + 50, y + 30);
                }
            }

            invaderCount = i;
            RecalcBoxSize();

            instance.FrameCounter = (int)(10 / System.Math.Abs(Velocity.X));
            instance.AnimFrame = 0;
        }

        #endregion

        #region Box

        void RecalcBoxSize()
        {
            Vector2 min = new Vector2(float.MaxValue, float.MaxValue);
            Vector2 max = new Vector2(float.MinValue, float.MinValue);

            foreach (var invader in Invaders)
            {
                if (invader.IsAlive)
                {
                    if (invader.Position.X < min.X) min.X = invader.Position.X;
                    if (invader.Position.Y < min.Y) min.Y = invader.Position.Y;
                    if (invader.Position.X + TotalInvaders.InvaderWidth > max.X) max.X = invader.Position.X + TotalInvaders.InvaderWidth;
                    if (invader.Position.Y + TotalInvaders.InvaderHeight > max.Y) max.Y = invader.Position.Y + TotalInvaders.InvaderHeight;
                }
            }

            float oldx = Position.X;
            float oldy = Position.Y;

            Position.X += min.X;
            Position.Y += min.Y;

            Box.Width = (int)(max.X - min.X);
            Box.Height = (int)(max.Y - min.Y);

            float diffx = Position.X - oldx;
            float diffy = Position.Y - oldy;

            for (int i = 0; i < Invaders.Length; i++)
            {
                if (Invaders[i].IsAlive)
                {
                    Invaders[i].Position.X -= diffx;
                    Invaders[i].Position.Y -= diffy;
                }
            }
        }

        #endregion

        #region Check Hit

        public bool CheckHit(Bullet b)
        {
            for (int k = 0; k < Invaders.Length; k++)
            {
                var i = Invaders[k];
                if (i.IsAlive)
                {
                    if (b.Position.X <= i.Position.X + TotalInvaders.InvaderWidth - 2 + Position.X &&
                        b.Position.X + TotalInvaders.BulletWidth > i.Position.X + Position.X &&
                        b.Position.Y < i.Position.Y + TotalInvaders.InvaderHeight + Position.Y &&
                        b.Position.Y + TotalInvaders.BulletHeight > i.Position.Y + Position.Y)
                    {
                        instance.AddExplosionParticles(Position + i.Position + new Vector2(TotalInvaders.InvaderWidth / 2, TotalInvaders.InvaderHeight / 2), Velocity * 0.5f, new Color(39, 216, 17), 10);
                        Invaders[k].IsAlive = false;
                        RecalcBoxSize();
                        Velocity.X *= 1.05f;
                        Velocity.Y *= 1.05f;
                        if (--invaderCount == 0)
                        {
                            newWavePauseTimer = 2f;
                        }
                        return true;
                    }
                }
            }

            return false;
        }

        #endregion

        #region Update

        public void Update()
        {
            if (newWavePauseTimer > 0)
            {
                newWavePauseTimer -= Services.ElapsedTime;
                if (newWavePauseTimer <= 0)
                {
                    instance.Wave++;
                    instance.WaveText = "Wave: " + instance.Wave.ToString();
                    NewWave();
                }
            }
            else
            {
                CheckForBoundaryBounce();
                BombPlayers();
            }
        }

        void BombPlayers()
        {
            if (instance.State == TotalInvaders.GameState.Play)
            {
                if (instance.Random.Next(2) == 0)
                {
                    int i = instance.Random.Next(Invaders.Length);
                    var invader = Invaders[i];

                    if (invader.IsAlive && invader.Position.Y == Box.Height - TotalInvaders.InvaderHeight)
                    {
                        instance.InvaderBullets.Add(new Bullet());
                        ActivateBullet(invader, instance.InvaderBullets.Count - 1);
                    }
                }
            }
        }

        void ActivateBullet(Invader invader, int i)
        {
            var b = instance.InvaderBullets[i];
            b.Position.X = Position.X + invader.Position.X + TotalInvaders.InvaderWidth / 2 - TotalInvaders.InvaderWidth / 2;
            b.Position.Y = Position.Y + invader.Position.Y + TotalInvaders.InvaderHeight / 2;
            b.Velocity = invaderBulletVelocity;
            instance.InvaderBullets[i] = b;
        }

        void CheckForBoundaryBounce()
        {
            if (dropDown)
            {
                Position.Y += Velocity.Y;

                if (Position.Y > dropStartY + 6)
                {
                    dropDown = false;
                }
            }
            else
            {
                Position.X += Velocity.X;
            }

            Box.X = (int)Position.X;
            Box.Y = (int)Position.Y;

            if (Box.Y + Box.Height >= 230)
            {
                instance.GameOver(true);
            }
            else if (!dropDown)
            {
                if (Velocity.X < 0)
                {
                    if (Box.X < 5)
                    {
                        Velocity.X = -Velocity.X;
                        dropDown = true;
                        dropStartY = Position.Y;
                    }
                }
                else if (Velocity.X > 0)
                {
                    if (Box.X + Box.Width > instance.ScreenSize.X - 5)
                    {
                        Velocity.X = -Velocity.X;
                        dropDown = true;
                        dropStartY = Position.Y;
                    }
                }
            }
        }


        #endregion
    }
}

TotalInvaders.cs
Code: [Select]
using System;
using System.Collections.Generic;
using Craig.BlockWorld;
using Craig.Engine;
using Craig.Engine.Integration;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Craig.TotalMiner.Arcade.TotalInvaders
{
    class TotalInvaders : ArcadeMachine
    {
        #region Enum

        public enum GameState
        {
            Play,
            GameOverTransition,
            GameOver
        }

        #endregion

        #region Fields

        public const int InvaderWidth = 16;
        public const int InvaderHeight = 14;
        public const int PlayerWidth = 18;
        public const int PlayerHeight = 12;
        public const int UFOWidth = 22;
        public const int UFOHeight = 8;
        public const int BulletWidth = 2;
        public const int BulletHeight = 10;
        public const int PickupWidth = 8;
        public const int PickupHeight = 6;
        public const int ParticleWidth = 1;
        public const int ParticleHeight = 1;
        public static int HighScore = 0;
        public static string HighScoreText;
        public static string HighScoreGamer = "";
        public static string HighScoreVersion = "";
        public GameState State;
        public InvaderWave InvaderWave;
        public Point ScreenSize;
        public int Score;
        public int Lives;
        public int Wave;
        public List<Player> Players;
        public List<Bullet> PlayerBullets;
        public List<Bullet> InvaderBullets;
        public List<Pickup> Pickups;
        public List<Particle> Particles;
        public UFO UFO;
        public Random Random;
        public int FrameCounter;
        public int AnimFrame;

        public string ScoreText;
        public string WaveText;

        float ufoSpeed;
        float pickupSpeed;
        float gameOverTransitionTimer;
        bool highscoreGamerUpdated;
        Color[] explosionColors = new Color[] { Color.Red, Color.Yellow, Color.Orange };

        #endregion

        #region Properties

        public override bool CanDeactivate { get { return State == GameState.GameOver; } }

        #endregion

        #region Initialization

        public TotalInvaders(GameInstance instance, Map map, Craig.TotalMiner.Player player, GlobalPoint3D point, BlockFace face)
            : base(instance, map, player, point, face)
        {
            GpPerCredit = 1;
        }

        public override void LoadContent(InitState state)
        {
            base.LoadContent(state);

            ScreenSize = new Point(renderTarget.Width, renderTarget.Height);
            InvaderWave = new InvaderWave(this);

            State = GameState.GameOver;
            Random = new Random();

            ufoSpeed = 1.4f;
            pickupSpeed = 0.8f;

            PlayerBullets = new List<Bullet>(10);
            InvaderBullets = new List<Bullet>(10);
            Players = new List<Player>();
            Particles = new List<Particle>();
            Pickups = new List<Pickup>();

            ResetHud();
        }

        void ResetHud()
        {
            Score = 0;
            Lives = 3;
            Wave = 1;

            WaveText = "Wave: 1";
            ScoreText = "Score: 0";

            HighScoreText = "High Score: " + HighScore.ToString();
            highscoreGamerUpdated = false;
        }

        public override void StartGame()
        {
            if (State != GameState.Play)
            {
                if (Credits > 0)
                {
                    ChangeCredits(-1);

                    ResetHud();

                    State = GameState.Play;

                    Players.Clear();
                    var p = new Player(true);
                    Players.Add(p);

                    Wave = 0;
                    InvaderWave.ResetWave();
                    UFO.IsAlive = false;
                }
            }
            else
            {
                GameOver(false);
            }
        }

        public void GameOver(bool transition)
        {
            if (transition)
            {
                State = GameState.GameOverTransition;
                gameOverTransitionTimer = 3;
            }
            else
            {
                State = GameState.GameOver;
                PlayerBullets.Clear();
                InvaderBullets.Clear();
                Particles.Clear();
                Pickups.Clear();
            }

            if (highscoreGamerUpdated)
            {
                instance.NetworkManager.SendArcadeState();
                highscoreGamerUpdated = false;
            }
        }

        #endregion

        #region Input

        public override bool HandleInput(GamePadState pad, GamePadState lastpad)
        {
            var result = OnLeftStick(pad.ThumbSticks.Left);
            result |= OnAButton(pad.Buttons.A == ButtonState.Pressed && lastpad.Buttons.A == ButtonState.Released); ;
            if (pad.Buttons.B == ButtonState.Pressed && lastpad.Buttons.B == ButtonState.Released) { GameOver(false); result = true; }
            if (pad.Buttons.Start == ButtonState.Pressed) return false; // let game process them
            return result;
        }

        bool OnLeftStick(Vector2 stick)
        {
            if (State == GameState.Play)
            {
                var p = Players[0];
                if (stick.X < 0) p.Velocity.X = -p.Speed;
                else if (stick.X > 0) p.Velocity.X = p.Speed;
                else p.Velocity.X = 0;
                Players[0] = p;
                return true;
            }
            else if (State == GameState.GameOverTransition)
            {
                return true;
            }

            return false;
        }

        bool OnAButton(bool newPress)
        {
            if (State == GameState.Play)
            {
                var p = Players[0];
                p.ShotDelayTimer += Services.ElapsedTime;

                if (newPress)
                {
                    p.ShotDelayTimer = p.ShotDelay;
                }

                if (p.ShotDelayTimer >= p.ShotDelay)
                {
                    FirePlayerBullet();
                    p.ShotDelayTimer = 0;
                }

                return true;
            }
            else if (State == GameState.GameOverTransition)
            {
                return true;
            }

            return false;
        }

        void FirePlayerBullet()
        {
            for (int i = 0; i < Players.Count; i++)
            {
                PlayerBullets.Add(new Bullet());
                ActivateBullet(Players[i], PlayerBullets.Count - 1);
            }
            CoreGlobals.AudioManager.PlaySound("InvadersFire");
        }

        void ActivateBullet(Player player, int i)
        {
            var b = PlayerBullets[i];
            b.Position.X = player.Position.X + TotalInvaders.PlayerWidth / 2 - TotalInvaders.BulletWidth / 2;
            b.Position.Y = player.Position.Y;
            b.Velocity = Players[0].BulletVelocity;
            PlayerBullets[i] = b;
        }

        #endregion

        #region Update

        protected override void UpdateCore()
        {
            if (!tmPlayer.IsInputEnabled) return;

            try
            {
                switch (State)
                {
                    case GameState.Play:
                        UpdatePlayState();
                        break;

                    case GameState.GameOverTransition:
                        UpdateGameOverTransitionState();
                        break;
                }

                if (tmPlayer.IsGod && Players.Count > 0)
                {
                    var pad = GamePad.GetState(tmPlayer.PlayerIndex);
                    if (pad.Buttons.Y == ButtonState.Pressed && lastpad.Buttons.Y == ButtonState.Released)
                    {
                        AddPlayerShip();
                    }
                    lastpad = pad;
                }
            }
            catch (Exception e)
            {
                Services.ExceptionReporter.ReportExceptionCaught(1, e);
                GameOver(false);
            }
        }

        GamePadState lastpad;

        void UpdatePlayState()
        {
            if (--FrameCounter < 0)
            {
                FrameCounter = (int)Math.Max(10f / Math.Abs(InvaderWave.Velocity.X), 10);
                ++AnimFrame;
            }


            UpdatePlayers();
            InvaderWave.Update();
            UpdateUFO();
            UpdatePlayerBullets();
            UpdateInvaderBullets();
            UpdatePickups();
            UpdateParticles();
        }

        void UpdateGameOverTransitionState()
        {
            gameOverTransitionTimer -= Services.ElapsedTime;
            if (gameOverTransitionTimer > 0)
            {
                UpdateUFO();
                UpdatePlayerBullets();
                UpdateInvaderBullets();
                UpdatePickups();
                UpdateParticles();
            }
            else
            {
                GameOver(false);
            }
        }

        void UpdateUFO()
        {
            if (UFO.IsAlive)
            {
                UFO.Position += UFO.Velocity;
                if (UFO.Position.X + TotalInvaders.UFOWidth < 0 || UFO.Position.X > ScreenSize.X)
                {
                    UFO.IsAlive = false;
                }
            }
            else if (State == GameState.Play)
            {
                if (Random.Next(800) == 0)
                {
                    UFO.IsAlive = true;
                    if (Random.Next(2) == 0)
                    {
                        UFO.Position.X = -TotalInvaders.UFOWidth;
                        UFO.Velocity.X = ufoSpeed;
                    }
                    else
                    {
                        UFO.Position.X = ScreenSize.X;
                        UFO.Velocity.X = -ufoSpeed;
                    }
                    UFO.Position.Y = 14;
                    UFO.Pickup = (PickupType)Random.Next(2);
                    CoreGlobals.AudioManager.PlaySound("InvadersUfo");
                }
            }
        }

        void UpdatePlayers()
        {
            bool move = false;

            if (Players[0].Velocity.X < 0)
            {
                move = Players[0].Position.X > 4;
            }
            else if (Players[0].Velocity.X > 0)
            {
                move = Players[Players.Count - 1].Position.X + PlayerWidth < ScreenSize.X - 4;
            }

            if (move)
            {
                for (int i = 0; i < Players.Count; i++)
                {
                    var p = Players[i];
                    p.Position += Players[0].Velocity;
                    Players[i] = p;
                }
            }
        }

        void UpdatePlayerBullets()
        {
            for (int i = PlayerBullets.Count - 1; i >= 0; i--)
            {
                var b = PlayerBullets[i];
                b.Position += b.Velocity;

                if (InvaderWave.CheckHit(b))
                {
                    PlayerBullets.RemoveAt(i);
                    UpdateScore(10);
                    CoreGlobals.AudioManager.PlaySound("InvadersExplosion");
                }
                else
                {
                    if (UFO.IsAlive)
                    {
                        if (b.Position.X <= UFO.Position.X + TotalInvaders.UFOWidth - 2 &&
                            b.Position.X + TotalInvaders.BulletWidth > UFO.Position.X &&
                            b.Position.Y < UFO.Position.Y + TotalInvaders.UFOHeight &&
                            b.Position.Y + TotalInvaders.BulletHeight > UFO.Position.Y)
                        {
                            UFODestroyed(i);
                            PlayerBullets.RemoveAt(i);
                            continue;
                        }
                    }

                    if (b.Position.Y < -TotalInvaders.BulletHeight)
                    {
                        PlayerBullets.RemoveAt(i);
                    }
                    else
                    {
                        PlayerBullets[i] = b;
                    }
                }
            }
        }

        void UFODestroyed(int i)
        {
            AddExplosionParticles(UFO.Position + new Vector2(TotalInvaders.InvaderWidth / 2, TotalInvaders.InvaderHeight / 2), UFO.Velocity, new Color(181, 0, 208), 30);
            CoreGlobals.AudioManager.PlaySound("InvadersPlayerExplosion");
            UFO.IsAlive = false;
            UpdateScore(50);

            if (Random.Next(3) == 0)
            {
                int pk = Random.Next(2);
                if (pk > 0)
                {
                    Vector2 pos = UFO.Position;
                    pos.X += TotalInvaders.UFOWidth / 2 - TotalInvaders.PickupWidth / 2;

                    var pickup = new Pickup()
                    {
                        IsAlive = true,
                        PickupType = (PickupType)pk,
                        Position = pos,
                        Velocity = new Vector2(0f, pickupSpeed)
                    };
                    Pickups.Add(pickup);
                }
            }
        }

        void UpdateInvaderBullets()
        {
            for (int i = InvaderBullets.Count - 1; i >= 0; i--)
            {
                var b = InvaderBullets[i];
                b.Position += b.Velocity;

                if (CheckHitOnPlayer(b))
                {
                    InvaderBullets.RemoveAt(i);
                }
                else
                {
                    if (b.Position.Y > ScreenSize.Y)
                    {
                        InvaderBullets.RemoveAt(i);
                    }
                    else
                    {
                        InvaderBullets[i] = b;
                    }
                }
            }
        }

        void UpdatePickups()
        {
            for (int i = Pickups.Count - 1; i >= 0; i--)
            {
                var p = Pickups[i];
                p.Position += p.Velocity;

                if (CheckHitOnPlayer(p))
                {
                    PlayerGotPickup(p.PickupType);
                    Pickups.RemoveAt(i);
                }
                else
                {
                    if (p.Position.Y > ScreenSize.Y)
                    {
                        Pickups.RemoveAt(i);
                    }
                    else
                    {
                        Pickups[i] = p;
                    }
                }
            }
        }

        void PlayerGotPickup(PickupType type)
        {
            switch (type)
            {
                case PickupType.PlayerShip:
                    AddPlayerShip();
                    break;
            }
        }

        bool CheckHitOnPlayer(Bullet b)
        {
            for (int i = Players.Count - 1; i >= 0; i--)
            {
                var p = Players[i];
                if (b.Position.X <= p.Position.X + TotalInvaders.PlayerWidth - 2 &&
                    b.Position.X + TotalInvaders.BulletWidth > p.Position.X &&
                    b.Position.Y < p.Position.Y + TotalInvaders.PlayerHeight - 1 &&
                    b.Position.Y + TotalInvaders.BulletHeight > p.Position.Y + 4)
                {
                    AddExplosionParticles(p.Position + new Vector2(TotalInvaders.PlayerWidth / 2, TotalInvaders.PlayerHeight / 2), p.Velocity, new Color(192, 192, 192), 120);
                    Players.RemoveAt(i);
                    CoreGlobals.AudioManager.PlaySound("InvadersPlayerExplosion");
                    if (Players.Count == 0) GameOver(true);
                    return true;
                }
            }

            return false;
        }

        bool CheckHitOnPlayer(Pickup p)
        {
            for (int i = 0; i < Players.Count; i++)
            {
                var pl = Players[i];
                if (p.Position.X <= pl.Position.X + TotalInvaders.PlayerWidth - 2 &&
                    p.Position.X + TotalInvaders.PickupWidth > pl.Position.X &&
                    p.Position.Y < pl.Position.Y + TotalInvaders.PlayerHeight &&
                    p.Position.Y + TotalInvaders.PickupHeight > pl.Position.Y)
                {
                    return true;
                }
            }

            return false;
        }

        void UpdateParticles()
        {
            for (int i = Particles.Count - 1; i >= 0; i--)
            {
                var p = Particles[i];
                p.Position += p.Velocity;

                if (p.Position.Y < 0 || p.Position.X < 0 || p.Position.Y > ScreenSize.Y || p.Position.X > ScreenSize.X)
                {
                    Particles.RemoveAt(i);
                }
                else
                {
                    p.Age -= Services.ElapsedTime;
                    if (p.Age < 0)
                    {
                        Particles.RemoveAt(i);
                    }
                    else
                    {
                        p.Velocity.X *= 0.99f;
                        p.Velocity.Y *= 0.99f;
                        Particles[i] = p;
                    }
                }
            }
        }

        void UpdateCollisions()
        {
            //for (int i = 0; i < playerBullets.Array.Length; i++)
            //{
            //    if (playerBullets.Array[i].IsAlive)
            //    {
            //    }
            //}
        }

        void UpdateScore(int inc)
        {
            if (inc != 0)
            {
                Score += inc;
                ScoreText = "Score: " + Score.ToString();

                if (Score > TotalInvaders.HighScore)
                {
                    TotalInvaders.HighScore = Score;
                    TotalInvaders.HighScoreText = "High Score: " + TotalInvaders.HighScore.ToString();

                    if (!highscoreGamerUpdated)
                    {
                        TotalInvaders.HighScoreGamer = tmPlayer.Gamertag;
                        highscoreGamerUpdated = true;
                    }
                }

                tmPlayer.Raise_TotalInvadersScore(Score);
            }
        }

        void AddPlayerShip()
        {
            if (Players.Count < 14)
            {
                var player = new Player(true);
                player.Position = Players[Players.Count - 1].Position;
                Players.Add(player);

                float x = (Players.Count == 1 ? TotalInvaders.PlayerWidth + 4 : Players[0].Position.X - (TotalInvaders.PlayerWidth + 4) / 2);

                for (int i = 0; i < Players.Count; i++)
                {
                    var p = Players[i];
                    p.Position.X = x;
                    Players[i] = p;
                    x += TotalInvaders.PlayerWidth + 4;
                }
            }
        }

        public void AddExplosionParticles(Vector2 position, Vector2 velocity, Color color, int count)
        {
            int ecl = explosionColors.Length;

            while (count-- > 0)
            {
                var p = new Particle();
                p.Position = position;
                p.Age = (float)(Random.NextDouble() * 0.5 + 1.0);
                p.Velocity = velocity * 0.5f;
                p.Velocity.X += (float)(Random.NextDouble() * 2.5 - 1.25);
                p.Velocity.Y += (float)(Random.NextDouble() * 2.5 - 1.25);
                int r = Random.Next(ecl * 2);
                p.Color = r < ecl ? explosionColors[r] : color;
                Particles.Add(p);
            }
        }

        #endregion
    }
}

cont next post...
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on March 22, 2016, 09:15:31 AM
TotalInvadersRenderer.cs
Code: [Select]
using Craig.Engine;
using Craig.Engine.Integration;
using Craig.Engine.Core;
using Craig.TotalMiner.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Craig.TotalMiner.Arcade.TotalInvaders
{
    class TotalInvadersRenderer : IHasContent
    {
        #region Fields

        SpriteBatchSafe spriteBatch;
        TotalInvaders game;
        Texture2D texture;

        #endregion

        #region Initialization

        public void LoadContent(InitState state)
        {
            spriteBatch = CoreGlobals.SpriteBatch;
            texture = CoreGlobals.Content.Load<Texture2D>(@"Textures\TotalInvaders");
        }

        public void UnloadContent()
        {
        }

        #endregion

        #region Draw

        public void Draw(TotalInvaders game)
        {
            this.game = game;
            CoreGlobals.GraphicsDevice.SetRenderTarget(game.RenderTarget);
            CoreGlobals.GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, DepthStencilState.None, null);

            if (game.State == TotalInvaders.GameState.GameOver)
            {
                DrawGameOver();
                DrawHud();
            }
            else
            {
                DrawWave();
                DrawPlayer();
                DrawBullets();
                DrawPickups();
                DrawParticles();
                DrawHud();
            }

            spriteBatch.End();
        }

        void DrawWave()
        {
            int y = (game.AnimFrame % 2) == 0 ? 0 : 15;
            var rect = new Rectangle() { Width = TotalInvaders.InvaderWidth, Height = TotalInvaders.InvaderHeight };
            var srcrect = new Rectangle() { X = 0, Y = y, Width = TotalInvaders.InvaderWidth, Height = TotalInvaders.InvaderHeight };
            var wave = game.InvaderWave;

            foreach (var invader in wave.Invaders)
            {
                if (invader.IsAlive)
                {
                    rect.X = (int)(invader.Position.X + wave.Position.X);
                    rect.Y = (int)(invader.Position.Y + wave.Position.Y);
                    spriteBatch.Draw(texture, rect, srcrect, Color.White);
                }
            }

            if (game.UFO.IsAlive)
            {
                rect.X = (int)game.UFO.Position.X;
                rect.Y = (int)game.UFO.Position.Y;
                rect.Width = TotalInvaders.UFOWidth;
                rect.Height = TotalInvaders.UFOHeight;
                srcrect.X = 17;
                srcrect.Y = 13;
                srcrect.Width = TotalInvaders.UFOWidth;
                srcrect.Height = TotalInvaders.UFOHeight;
                spriteBatch.Draw(texture, rect, srcrect, Color.White);
            }
        }

        void DrawPlayer()
        {
            var rect = new Rectangle() { Width = TotalInvaders.PlayerWidth, Height = TotalInvaders.PlayerHeight };
            var srcrect = new Rectangle() { X = 17, Y = 0, Width = TotalInvaders.PlayerWidth, Height = TotalInvaders.PlayerHeight };

            for (int i = 0; i < game.Players.Count; i++)
            {
                rect.X = (int)game.Players[i].Position.X;
                rect.Y = (int)game.Players[i].Position.Y;
                spriteBatch.Draw(texture, rect, srcrect, Color.White);
            }
        }

        void DrawBullets()
        {
            Rectangle rect = new Rectangle();
            rect.Width = TotalInvaders.BulletWidth;
            rect.Height = TotalInvaders.BulletHeight;

            foreach (var bullet in game.PlayerBullets)
            {
                rect.X = (int)bullet.Position.X;
                rect.Y = (int)bullet.Position.Y;
                spriteBatch.Draw(CoreGlobals.BlankTexture, rect, Color.White);
            }

            foreach (var bullet in game.InvaderBullets)
            {
                rect.X = (int)bullet.Position.X;
                rect.Y = (int)bullet.Position.Y;
                spriteBatch.Draw(CoreGlobals.BlankTexture, rect, Color.White);
            }
        }


        void DrawPickups()
        {
            Rectangle rect = new Rectangle();
            rect.Width = TotalInvaders.PickupWidth;
            rect.Height = TotalInvaders.PickupHeight;
            var srcrect = new Rectangle() { X = 17, Y = 22, Width = TotalInvaders.PickupWidth, Height = TotalInvaders.PickupHeight };

            foreach (var pickup in game.Pickups)
            {
                rect.X = (int)pickup.Position.X;
                rect.Y = (int)pickup.Position.Y;
                spriteBatch.Draw(texture, rect, srcrect, Color.White);
            }
        }

        void DrawParticles()
        {
            Rectangle rect = new Rectangle();
            rect.Width = 2;
            rect.Height = 2;
            float alpha = 1f;

            foreach (var p in game.Particles)
            {
                rect.X = (int)p.Position.X;
                rect.Y = (int)p.Position.Y;
                alpha = p.Age < 0.5f ? p.Age * 2f : 1f;
                spriteBatch.Draw(CoreGlobals.BlankTexture, rect, p.Color * alpha);
            }
        }

        void DrawHud()
        {
            spriteBatch.DrawString(GraphicStatics.InvadersFont, game.ScoreText, new Vector2(4f, 0f), Color.White, 0f, Vector2.Zero, 0.7f, SpriteEffects.None, 0f);
            spriteBatch.DrawString(GraphicStatics.InvadersFont, TotalInvaders.HighScoreText, new Vector2(110f, 0f), Color.White, 0f, Vector2.Zero, 0.7f, SpriteEffects.None, 0f);
            spriteBatch.DrawString(GraphicStatics.InvadersFont, game.WaveText, new Vector2(250f, 0f), Color.White, 0f, Vector2.Zero, 0.7f, SpriteEffects.None, 0f);
        }

        void DrawGameOver()
        {
            int v = TotalMinerGame.ExeVersion;
            string vtext = string.Format("V{0}.{1}.{2:D3}", v / 10000, (v % 10000) / 1000, v % 1000);
            spriteBatch.DrawString(GraphicStatics.InvadersFont, vtext, new Vector2(4f, 10f), Color.White, 0f, Vector2.Zero, 0.7f, SpriteEffects.None, 1f);
            spriteBatch.DrawString(GraphicStatics.InvadersFont, TotalInvaders.HighScoreGamer, new Vector2(110f, 10f), Color.White, 0f, Vector2.Zero, 0.7f, SpriteEffects.None, 1f);
            spriteBatch.DrawStringCentered(GraphicStatics.InvadersFont, "Total", 35, Color.White, 2.2f);
            spriteBatch.DrawStringCentered(GraphicStatics.InvadersFont, "Invaders", 65, Color.White, 2.2f);
            spriteBatch.DrawStringCentered(GraphicStatics.InvadersFont, "Game Over", 130, Color.White, 1.6f);
            spriteBatch.DrawStringCentered(GraphicStatics.InvadersFont, game.CreditText, 170, Color.White, 1f);
        }

        #endregion
    }
}
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on March 22, 2016, 05:48:56 PM
Mind if I ask... uh... why do you use your name in the code?
Title: Re: PWR's PRGRSS - Learning C#
Post by: Dryym on March 22, 2016, 06:25:33 PM
Mind if I ask... uh... why do you use your name in the code?

Why not? It seems to serve as both a watermark, And a way to determine what code is his, And what code is MS resources, Or something like that.

I'd say it's most likely for identification if there is a reason to it. Otherwise I'd think he just does it because he can.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on April 03, 2016, 11:10:03 PM
You might find this interesting.

https://handmadehero.org/

He writes a game from scratch on Windows without the use of libraries, engines or frameworks, and explains everything in reasonable detail.

He programs using C rather than C++ so you won't get bogged down in OOP details.

He uses just a text editor to edit the source code, rather than an IDE, so again you won't get bogged down in IDE details.

Pretty much as basic as it gets when it comes to writing a game without an engine. A very good resource. You learn how to do real programming for yourself, rather than how to use other peoples libraries/engines/frameworks.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on April 04, 2016, 09:06:02 AM
Sweet, I'll check it out here in a bit. I guess I'll use that to learn C.
Title: Re: PWR's PRGRSS - Learning Spreadsheet Formulae
Post by: PWRBTTN on November 05, 2016, 04:58:45 AM
Figured I'd respond to this, and slightly alter the title instead of creating a brand new topic. Besides, this will probably only be a few posts.

I decided to check out google spreadsheet after Trub suggested it for organising a thing for a script. Turns out, spreadsheets are kinda cool. So I got into the guides for it and read how to do some of the formulae. long story short, I was trying to see if I could do something. Spent an hour and a half learning how to do it. Turns out, I didn't even need a formula to do what I wanted to do, because there was a button for it. However, if there wasn't a button, I found out how to do it anyway.

Moral of the story is: know your tools, but if you don't, know how to make your tools.

That's an okay moral. Right? Anyway, I might dive into this some more. Maybe.
Title: Re: PWR's PRGRSS - Learning Spreadsheet Formulae
Post by: Dryym on November 05, 2016, 09:03:59 AM
Figured I'd respond to this, and slightly alter the title instead of creating a brand new topic. Besides, this will probably only be a few posts.

I decided to check out google spreadsheet after Trub suggested it for organising a thing for a script. Turns out, spreadsheets are kinda cool. So I got into the guides for it and read how to do some of the formulae. long story short, I was trying to see if I could do something. Spent an hour and a half learning how to do it. Turns out, I didn't even need a formula to do what I wanted to do, because there was a button for it. However, if there wasn't a button, I found out how to do it anyway.

Moral of the story is: know your tools, but if you don't, know how to make your tools.

That's an okay moral. Right? Anyway, I might dive into this some more. Maybe.


That's how I script. XD I can work out how to make just about any tool as long as I know the math involved (So, Don't ask me to generate Mandelbrot fractals.)

It's mostly a matter of whether or not I want to.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 25, 2018, 04:36:37 AM
It's been a while, but I wanna gdt back at it. I've no longer got my crappy laptop. I now have a decent PC. I also now have loads more time, being I'm out of school and all. Besides, now that PC total miner is out now, learning C# is more relevant. So let's do this.

Where should I start? I asked myself this earlier yesterday as I was preparing visual studio on my PC. I had a few ideas, but mostly I kept finding my way back to one thing. Character generators. Nothing complex, I believe. Character generators for tabletop RPGs, like Dungeons and Dragons or Pathfinder. I have progress on a homebrew ruleset, so I know all the traits and formulae I need. I just need the code.

So here's where I start. A windows form application seems like my best bet. Just an open window, most of the stuff I can drag and drop. I just need to work out how to... err... plug them all into each other. Hopefully @Craig can lend some advice or code snippets like he did before, because I've retained very, very little memory on C#.

If anyone is interested in periodically learning C# along with me, or is just interested in my second expedition into the wild jungle of C#, feel free to post with your own thoughts and opinions.

At the moment, I'm trying to understan what the purpose of all the different text boxes are, and how to make the main start generating numbers to run through math problems to put in the textboxes. Any advice from anyone would be great.

Anyway, thanks for reading.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 25, 2018, 05:05:37 AM
Mod for Total Miner Arcade Block FTW!
Title: Re: PWR's PRGRSS - Learning C#
Post by: Dryym on February 25, 2018, 08:07:16 AM
Mod for Total Miner Arcade Block FTW!

2 things. 1: Is that a good thing for a beginner to try? 2: Total Dungeons & Dragons ftw.
Title: Re: PWR's PRGRSS - Learning C#
Post by: PWRBTTN on February 25, 2018, 08:26:34 AM
Mod for Total Miner Arcade Block FTW!
Mod for Total Miner Arcade Block FTW!

2 things. 1: Is that a good thing for a beginner to try? 2: Total Dungeons & Dragons ftw.
Both of you have lost me already.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Craig on February 25, 2018, 07:19:59 PM
Mod for Total Miner Arcade Block FTW!

1: Is that a good thing for a beginner to try?
Yes of course because you can start a simple as you like.
Title: Re: PWR's PRGRSS - Learning C#
Post by: Rev Elevenclaw on April 28, 2018, 04:13:50 PM
This topic really makes me want to get into programming!