Learn C# by Building a Simple RPG – Index

Giant Spider!
Mandatory Giant Spider!

If you want to write a Role Playing Game, but don’t know how to program, or just want to learn how to program in C#, then you’re at right the place.

These lessons will take you from a complete beginner, to being an author of a Role Playing Game, for free.

Now, this isn’t the world’s greatest game. In fact, it’s very short and kind of ugly.

However, as you create it, you’ll learn the most common C# programming practices and techniques. Then, if you want, you can improve the game, adding more features and your own special touch to it.

 

NOTE: One of the awesome students here created a PDF document of the lessons. You can get a copy of it here. You can also download the source code files for the lessons here. Thank you, Mark!

 

SECTIONS

Lesson 00.1 – What is in these lessons?

Lesson 00.2 – General information about programming in C#

Lesson 00.3 – The parts of Visual Studio

Lesson 01.1 – Defining classes and objects for the game

Lesson 02.1 – Installing Visual Studio Express 2013 for Desktop

Lesson 02.2 – Building the solution for the game

Lesson 03.1 – Building the first screen

Lesson 04.1 – Creating the Player class and its properties

Lesson 05.1 – Creating objects from classes

Lesson 06.1 – Creating the remaining classes

Lesson 07.1 – Inheritance and base classes

Lesson 08.1 – Setting properties with a class constructor

Lesson 08.2 – Using class constructors with derived classes

Lesson 09.1 – Using your classes as datatypes

Lesson 10.1 – Creating collections of objects

Lesson 11.1 – Using a static class

Lesson 12.1 – Add the remaining UI controls

Lesson 13.1 – Functions, procedures, and methods

Lesson 13.2 – Creating functions to handle user input

Lesson 14.1 – Variables

Lesson 14.2 – If statements

Lesson 14.3 – Foreach loops

Lesson 15.1 – Getting random numbers for the game

Lesson 16.1 – Writing the function to move the player

Lesson 16.2 – Refactoring the player movement function

Lesson 16.3 – Functions to use weapons and potions

Lesson 17.1 – Running the game on another computer

Lesson 18.1 – Future enhancements for the game

Bonus lessons (enhancements to the game)

Lesson 19.1 – Scroll to the bottom of a rich text box

Lesson 19.2 – Use a calculated value for a property

Lesson 19.3 – Clean up the source code by converting foreach to LINQ

Lesson 19.4 – Saving and loading the player information

Lesson 19.5 – Changing dropdown default values

Lesson 19.6 – Increase maximum hit points when the player gains a level

Improving SuperAdventure’s code quality by refactoring

Lesson 20.1 – Refactoring the SuperAdventure program

Lesson 20.2 – Binding a custom object’s properties to UI controls

Lesson 20.3 – Binding list properties to datagridviews

Lesson 20.4 – Binding child list properties to a combobox

Lesson 20.5 – Moving the game logic functions from the UI project to the Engine project

Adding a vendor to locations (with buying and selling items)

Lesson 21.0 – Plans for adding a vendor to locations

Lesson 21.1 – Adding a price to game items

Lesson 21.2 – Create the vendor class and add it to locations

Lesson 21.3 – Add a button and create its eventhandler in code, without the UI design screen

Lesson 21.4 – Completing the trading screen

Use SQL to save and restore player’s game data

Lesson 22.1 – Installing MS SQL Server on your computer

Lesson 22.2 – Creating database tables from classes

Lesson 22.3 – Creating the SQL to save and load the saved game data

Creating a console UI for SuperAdventure

Lesson 23.1 – Creating a console front-end for the game

Final refactoring (cleanup) of the SuperAdventure source code

Lesson 24.1 – Make the SuperAdventure source code easier to understand and modify

New game features

Lesson 25.1 – Select a random monster at a location

Lesson 26.1 Displaying a World Map

Lesson 26.2 – Hiding Unvisited Locations on the World Map

 

Bug Fixes

Lesson 99.1 – Preventing duplicate quests

Lesson 99.2 – Setting CurrentWeapon when the player has multiple weapons

 

Share your personal, expanded versions of SuperAdventure here!

305 thoughts on “Learn C# by Building a Simple RPG – Index

  1. Loved the tutorial, right up to the point where I had to start pulling code from GitHub… I peruse tutorials like this to kill downtime at work, and GitHub is blocked on our firewall.

    Plus, I take tutorials to learn how to write code, not download code someone else already wrote…

    Other than that, great showing all around!

  2. I’ve been self-learning C# and doing simple games using MonoGame for almost half a year and it was full of struggles trying to understand C# to create games. Just happened to find your tutorials and it looks promising. Hopefully, i’d be able to improve my C# and game programming after going through all your tutorials. Thank you.

  3. I’ve just completed all the tutorials within the pdf and I have to say that you are absolutely phenomenal in helping those with little understanding of programming really get a grasp at what it is you are talking about and how to use it. Thank you so much, bookmarked and following!

  4. If I may, will you be writing a tutorial about making the game multiplayer? I believe it is beyond the scope of the provided material but it is my ambition to write mine to be multiplayer. I have (currently) a rather limited understanding of coding (enhanced now thanks to your excellent teaching) and I cant think of a better teacher than yourself. I have seen the tutorials for sql database and making player/world objects save but I do not believe the current scope supports unique characters. Any insight you could provide on the subject will have every byte of wisdom consumed!

    Also, making buttons to pull up another window in the UI, after following these tutorials, I have the knowledge base to get this accomplished? Anything in particular I am lacking that would stop me from accomplishing this?

    Thanks again for all the time and effort,

    Michael

    1. When you say “multi-player”, do you mean the ability for more than one person to play the game at the same time – so they could fight enemies together, trade with each other, etc.? Or, do you only want to have the ability to load and save different versions of XML/SQL saved game data?

      The first would be very complex. There is a lot of communication and timing code that would need to be written.

      The second method would be fairly simple to do. In the game’s startup, and closing code, popup a new form to let the user select a file to load or save. You could use the OpenFileDialog class to let them select the saved game file to load from. Then use the SaveFileDialog class to let them save their game data.

      If you want to do this with SQL, there is a little more worked involved. My first thoughts are that you’d want to add a Name and ID property to the Player class. Then, save the Player information to a new Player table. The SavedGame table would need to store the Player.ID, so you know which player the SavedGame row belongs to.

      I’d probably also add the ability for the players to save multiple games. To do this, I would add a new column to SavedGame that would store the saved game datetime. In the Inventory and Quest tables, you would need to add the Player.ID and the unique datetime of the SavedGame, to store the player’s inventory and quests at the time of the save. You would also need to change the DELETEs in the Inventory and Quest update SQL statements to include a WHERE clause, so you only delete the items and quests for the SavedGame they belong to.

      Let me know if you want to try those and if you have any questions.

      I don’t have any immediate plans to make the game multi-player. I might try that with the WPF version of the course I’m creating, as an additional set of intermediate lessons.

  5. Hey, probably a really simple question here, but i’ve finished the tutorials, up until the bonuses and stuff (excluding lessons 19.1 and 19.4-6) but I’ve gone off and added a lot of new areas, loot, monsters, etc. Anyways the issue i’m having is with the inventory grid. there are more items than can fit in the grid (around 20 or so), once i get enough loot for the list to go off the grid, i can’t seem to scroll down to look at what’s off the screen. i looked through to properties of the grid and couldn’t find anything that looked right, but who knows maybe i’m just blind, haha.

    Anyways thank you for the incredible tutorials, I’ve really enjoyed them and have learned quite a bit from them!

    1. You should be able to set the datagrid’s “Scrollbar” property to “ScrollBars.Vertical”. You can do that through the design view of SuperAdventure.cs, by looking for the property in the “Layout” section:

      Or, you should be able to set it in the constructor for SuperAdventure.cs, after you define the columns for the datagrid. Add this line:

      dgvInventory.ScrollBars = ScrollBars.Vertical;

      You may also need to make the Width value for your datagrid columns a little smaller, to ensure there is space for the scrollbar.

      Let me know if that doesn’t work.

  6. I must say: This is a very good tutorial. I loved the creation of a game like this and I’m improving it day for day.

    But I want to ask something: Could you maybe describe, how to add stats like Strengh to improve the game feeling?

    Would be very awesome.

    1. Thank you, Dennis.

      I have different program where the combat is a little more difficult – you can pick a class and have a “to hit” bonus, or an additional damage bonus. I’ll try to show some similar modifications for this game, but I probably won’t be able to work on that for a couple of weeks.

      1. No need to hurry. At the moment I’m working on a spawnrate modification for several monsters in the same location. And creating my own world of course. Would just be nice to know how that system would work in this game (I’m a learning by seeing person).

  7. This is an incredible tutorial.  This gave me the idea to make an rpg for a project for one of my classes. My partner and I used your tutorial to help us with traveling and saving and loading a game.

    We finally got the project to a point where it is playable and presentable. We wanted to thank you for the tutorial and provide a link to our project on Github.

    https://github.com/lpbearden/reswobs_revenge

     

  8. Hey Scott!

    Just wanted to say thanks for all your help and your amazing tutorial. I’ve been working on building this game for about 8 months now. The first 4 months I spent learning the architecture and adding new features and locations. After that I realized the game was a giant mess so I scrapped it and started a rewrite. I’m now 4 months into it and I thought it would be cool to share my progress with you. Currently there is only 3 dungeons out of the planned 8 but there is enough content to keep you busy for an hour or two. Let me know what you think! You’ll probably recognize some of it (like the main town) but I’ve expanded it quite a bit and added alot of neat little features. Let me know what you think! Use the link below to go the a small website I’ve built for releasing it.

    homepages.uc.edu/~ronekm

    Thanks again,

    Kyle

     

     

    1. Awesome! You’ve really added a lot to the game. The graphics give it a great feel.

      I need to create a page with links to all the versions of the program that everyone has created.

  9. Hi. I love your tutorials!
    I have finished all of them, and added a few things like a background picture for all the locations and some onscreen buttons with images of NPC’s and chests to interact with. But after adding the chests I had to add the chests to the locations to check whether I am in the same location as the chest. When I finished adding the chest and wanted to test the game, the game doesn’t seem to set my location. Whenever I check the debugger to see what my currentLocation variable is set to it shows null. I don’t know why my code for locations look exactly like yours except I just added chests to the constructor. Debugger is not much helpful except it only shows me that my currentLocation value is null. I use this to set my location:

    player.CurrentLocation = World.LocationByID(World.LOCATION_ID_VILLAGE_OF_THE_NORTH);

    I am out of ideas on how to fix the problem. Any tips would be appreciated.

      1. I think I sorted the location issue out. But now that I’ve completed that step, when looting the chest I can’t add the item to my inventory because the item = null. I tried putting the Item.Details.ID/Name into a messageBox and it does return an ID and Name value. But the line where it adds the item gives me a null reference exception. Not sure if my syntax to add the item is quite right. I simulate my chests as if they where a monster, so I used the same code from the monster, only the chest is of type Chest and not of type Monster. I also tried adding the actual item directly to my inventory and I also get null reference exception but this time at the property in the InventoryItem class :
        public Item Details { get return _details; } // nullReferenceException

        I uploaded my whole solution. Hope it’s not too messy >.< haha. I basically took your engine and incorporated it into my own RPG. Still working through it converting bit by bit of the engine into my RPG so far I completed the player creation. Working on my first area.

        Thanks in advance.

        LINK REMOVED – FOR PRIVACY

          1. Opps my bad. Didn’t build the engine.

            Here you go:
            LINK REMOVED – FOR PRIVACY

            It starts in MainForm.cs at the bottom there is an event Btn_NPC_Click and the last “if” statement in that event calls the Player.OpenChest() method. If you start a new game and go to Village of the North Tab, at the bottom of map there is a red chest, click on it and open. Then you will get a NullReferenceException error. The error is in the Player.cs class at the AddItemToInventory() method line 263:

            InventoryItem item = Inventory.SingleOrDefault(ii => ii.Details.ID == itemToAdd.ID);

            If I click on view error details I get: {“Object reference not set to an instance of an object.”} But my items are created in the World.cs class. I used the items that you made. Didn’t create my own yet.

            I hope this information will help you to locate my problem. If not, just tell me what details you need and I will see what I can do.

            Sorry about that.
            And thanks again.

          2. I think I found the problem. I’ll give you a clue, so you can get some practice debugging. If you need a little more help, let me know.

            In the “constructor” for the World class, the first line is PopulateChests(). The next line is PopulateItems(). Inside the PopulateChests() function, it tries to add items to the ChestLootTable. What values are in the Items list, at that point in time?

  10. hahaha, something so simple can give you such a headache. XD

    It didn’t even cross my mind. No wonder it didn’t make sense.

    Thank you so much! 🙂

    Now I will pay more attention to the order of how I call my methods. The order plays a big part in your applications.

    If I would to make Spells or skills in my game, I’m thinking of making them similarly to how a weapon is made, instead with different parameters . And then instead of “Use Weapon” I will make 2 buttons, one “Attack” for normal attacks, and then “Use Skill/Spell” with a ComboBox for skill selection. I also want to make weaknesses and resistances like fire, ice and lightning. I will make them a percentage value that will ether decrease or increase the type of incoming damage by a percentage value.

    Shouldn’t be too hard, I must just play around with different formulas. But I will test it out.

    But anyway, thanks again for your advice. I really appreciate it. 😀

      1. Thanks.
        By the way, I seem to have some troubles with the xml save and load. They don’t seem to save any of my player properties even the new properties I added to the save and load method. And also my player stats labels that where databinded to the player properties aren’t doing what the should do. When I create character the labels show all the default stats. But when I change those stats in-game the labels don’t update. However, when I try to print the changed stats (like Gold) in a message Box, it appears the players Gold is being increased. It’s just not showing on labels.(After I load the game the players Gold is back to default value.) Although it does save my players inventory for some reason. I made a button to MoveWest for testing, it didn’t update the label straight away, after I exited and loaded game from save then only the currentLocation label showed my new location.
        It feels like the game has 2 players, and the labels show one player and when I change stats in-game I am changing the other players stats. And the databinders are attached to the first players stat properties. But I can’t find anywhere where it might be that I create a new object of player. Or maybe it’s totally something different.

        Here is updated dropbox if you want to take a look.

        LINK REMOVED – FOR PRIVACY

        Oh, I don’t use the SQL database save because it takes like 15 seconds for game to start and exit. So I am just using xml for now.

        1. I’ll look at the code, but I probably won’t be able to until this weekend. Meanwhile, if you go your code to the lesson that uses NotifyPropertyChanged, make sure you use that for your new properties, to notify the UI there is a new value.

          1. No problem.

            I went through the code again, and I got the labels to update every time I change stats. But the load from xml data is still giving me troubles. I went back to the lesson where you made the xml save. Everything seems the same still. I read some of the comments and one comment was to put a break point in the start of CreatePlayerFromXmlString(), so I did and checked how the game reads in the data.

            Here is the 2 classes:
            LINK REMOVED FOR PRIVACY

            I put the BreakPoint on line 125 and it ran perfectly through up until line 138
            and then the next line says “Player player = new Player();”, from there onwards up until line 173 where it says “return player;” the debugger show player as null. And then the CreatePlayerFromXmlString() method returns a null player witch then saves it into the “_player” object in the MainForm.cs class. And then my game loads up with all the default stats and an empty name. I then tried to messageBox the players name to see if there weren’t perhaps 2 player objects like last time. And the name returned null. So I fixed the first problem I had but now I’m stuck with the game loading up a whole new player.
            I opened the xml document to have a look inside if it maybe didn’t save correctly, but it does indeed save all my player data as it should. So it’s not the save method that’s the problem. I’m guessing somewhere in the CreatePlayerFromXmlString(). Then again it could be my MainForm.cs. I don’t know haha. Not so clued up on xml.

          2. Before the “player” object is created on line 140, the function reads some values from the XML (name, currentHitPoints, etc.). Where are those values assigned to the “player” object’s properties?

            I believe the “player” variable is not null after line 140. If it was null, the program would throw a null exception on the lines where it tries too assign values to the player’s current weapon, inventory, and quests – and never get to line 173.

  11. Ok, I added the player parameters to my parameterless player constructor. And added the rest of the player stats to the CreatePlayerFromXmlString() and ToXmlString(). However, the game still loads up a default character. I placed a breakpoint on line 37 in MainForm.cs to see what the CreatePlayerFromXmlString() loads up. And all the player parameters are default. I’m guessing the game doesn’t save? I do have a FormClosing event and that event is attached to the MainForm when closing. And this is what is inside that event:

    File.WriteAllText(PLAYER_DATA_FILE_NAME, _player.ToXmlString(_player));

    Application.Exit();

    Although I did check the xml data and it did save the player stats. I don’t know what else could be the problem. After I added the rest of the player properties to the CreatPlayerFromXmlString(), I again put a breakpoint at line 117 in Player.cs and watched the debug run, it ran fine up until line 131(MaxHitPoints) and the the debugger skipped the rest of the code and went to the end of the CreatPlayerFromXmlString(). Don’t know why it skipped the rest of the lines…

    Here is updated Player.cs and MainForm.cs and I included a copy of the XmlDocument.

    LINK REMOVED FOR PRIVACY

    Actually now that I think about it, when the debugger skipped the rest of the lines it went to the “catch” part of the “Try-catch” block. and in there is:

    return CreateDefaultPlayer();

    So there must be something wrong with the xml data or something. It found an error and then returns a default player instead. I checked from where the debugger skipped those lines and it appears that I have 2 maxHitpoints entries. I removed the extra one and ran the debugger again and it ran everything nicely. The debugger got to MainForm.cs line 37 and the debugger showed the “_player” created from the CreatePlayerFromXmlString() with all the default stats. So after I fixed the xml error the game still loads up a default character. I’m out of ideas, I will check it again, but in the meantime I posted this comment.

    1. I sent you an e-mail. In case you didn’t get it, I moved my projects to my new computer and I don’t have your previous solution. Can you re-upload it to Dropbox, so I can run the latest version and test that?

      1. Ok, sure.

        LINK REMOVED FOR PRIVACY

        Are you still using this website though?
        The save works on your SuperAdventure game. Well atleast the SuperAdventure game that I have from your tutorials. Unless there’s something missing that will make it work with other projects?

        1. Yes, I’m still using this website. I just built a new computer at home, for all my programming work (my other computer will be for games, music, etc.) When I copied over my projects, yours was in a different set of directories, and I didn’t have it any more.

          For the problem in your game, look at the Player constructor, on line 106. CreatePlayerFromXmlString gets all the values from the XML file, and passes them to the constructor. However, the only properties that are set in the constructor are the Inventory, Quests, ExperiencePoints, and Specialization. The constructor calls SetSpecialization(), which sets more property values (based on the player’s specialization). But the Name, Gold, ExperiencePoints, etc. properties do not get set with the parameter values.

          1. Cool, it’s working now! Thanks.
            I will use this save method for my other project too. I used to use another save method for that game but it was a very simple one. It just serializes a class and then saves all the variables.
            I finished that game and gave it to my friends to test to give me feedback on bugs and glitches and stuff. Most of them came back and said they wanted a feature added where you can capture a planet(it’s a text based space game btw) and then get bonuses off of the planet and be able to upgrade the planets base attribute. So now Im going through all the code doing cleanups and refactoring adding and removing features. But I’m having difficulties with the planet capture. It’s basically going to be like “equipment” and then upgrading that equipment. Want to use equipments for my rpg aswel. I can get the planet in my “inventory” but how to add the planets bonuses to the player I do not know. Do you have any ideas for “equipment” for games?

          2. If you pass the equipment values to the Player constructor (similar to the inventory list), could you go through the items in that list and apply pass it to a new function that works similarly to SetSpecialization (expect, to handle the equipment)?

  12. Hi, I was planning to make a simple mini map for the game using picture boxes that would change colour dependant on where you are on the map, but I can’t seem to figure out a good way to do so. Do you know any possible way to make this?

    1. This is how I would do it:

      1. Create the images for the locations, using whatever graphics program you like.
      2. Embed those image files into the project, this way: https://msdn.microsoft.com/en-us/library/aa984367%28v=vs.71%29.aspx
      3. Add a new string property to the Location class. I’ll use “ImageFileName” for this example. Add this as a parameters to Location’s constructor.
      4. In the World class, when you populate the Locations, pass the value for the ImageFileName parameter.
      5. Create a new “Map” Windows Form, in the SuperAdventure project. This would have five picture box controls: center (for current location) and one for each direction.
      6. Create a new “Show Map” button on the SuperAdventure screen.
      7. Create the function to handle clicking on the “Show Map” button. This will create an instance of the Map form and passes the _player object to that form.
      8. In the Map form, get the ImageFileName for the player’s current location, and the locations in each direction (if they aren’t null).
      9. Populate the picture boxes with the location’s image.

      If you made the SuperAdventure form larger, you could eliminate the new Map form, put the picture boxes directly on the SuperAdventure form, and populate them in the MoveTo function.

      You could build a larger map, that showed more than the neighboring locations. But that is a little more difficult. Onec you get the small map working, you can experiment with making a larger one – if you want.

  13. I would first like to say thank you for the wonderful tutorial.  I am in the process of learning C#, and I’m past all the ‘basic’ stuff and needed something with a little more substance.  This tutorial was what I needed/wanted.

    After going through the tutorial and playing the game a few times I decided to make a quick little mapping system in the MOVETO function that changes the Text on the “Map buttons” to let you know where you head to if you click the button.

    btnNorth.Visible = (newLocation.LocationToNorth != null);
    if (btnNorth.Visible == true)
    btnNorth.Text = newLocation.LocationToNorth.Name;

    btnEast.Visible = (newLocation.LocationToEast != null);
    if (btnEast.Visible == true)
    btnEast.Text = newLocation.LocationToEast.Name;

    btnSouth.Visible = (newLocation.LocationToSouth != null);
    if (btnSouth.Visible == true)
    btnSouth.Text = newLocation.LocationToSouth.Name;

    btnWest.Visible = (newLocation.LocationToWest != null);
    if (btnWest.Visible == true)
    btnWest.Text = newLocation.LocationToWest.Name;

     

    I would like to learn how to do a Map system, sorta like Kuro was trying to do.  However I need to learn a little bit more before I tackle that project.

     

    Good Job on the Tutorial and Thanks for publishing it for us newbies  😉

    1. You’re welcome.

      That’s a great idea – changing the button text to display the location name. Several people have been interested in a map for the game. I might add that in the future, but it will be a while (my “to do” list only gets longer, never shorter 🙁 ).

  14. Hi! So i’m currently taking a c# course in school and we we’re tasked to make a simple game. And I stumbled upon your tutorial and thought I could use this as a backbone for my project. Problem is, we need to implement direct x features to the game. Do you think it will be possible to implement direct x to your project? thank you

    1. If you want to add DirectX graphics to this game, I’d suggest getting all the way to the final lessons (or, at least through all the 20.X lessons), without adding any graphics. Then, when the game is working, add the graphics. Otherwise, as you constantly change the program in the lessons, you would also need to keep changing the graphics. Keeping the game code changes synchronized with the graphics changes might be difficult.

  15. I just started using the tutorial with Visual Studio 2013, and I’ve already hit a snag – on the step where I’m supposed to create a reference to “Engine” in “SuperAdventure,” it tells me “Unable to add a reference to project ‘Engine’.”  Any idea why this might be happening and what to do about it?  Thanks!

    1. Can you take a screenshot of your Solution Explorer (the upper-right section of Visual Studio, with the files in the project), upload it someplace, and send me the link to it?

  16. Good Morning from Germany,

    i receive the error “The type or Namespace Name ‘MessageEventArgs’ could not be found(are you missing a using directive or an assembly reference?)

    The error occurs twice in the Program.cs, twice in the Player.cs, and once in the SuperAdventure.cs.

    Additionally i receive the error “No overload for ‘Player_OnMessage’ matches delegate ‘EventHandler<MessageEventArgs>’

    I hope you can help me with this, im Close to finish this lessons and i already learned soooo much!

    Thanks and best regards,
    Gerrit

  17. Nevermind, im sorry,
    just overread an class and didnt add it at the time.. just found it now..

    Now i got no Errors and im finished, but if i try to debug nothing happens, no window or something else..

    Regards,

    Gerrit

      1. Here it is:

        LINK REMOVED, FOR PRIVACY

        But i got another Problem now.. i can debug it, but it wont work because of some exceptions =/

        1. I noticed a problem in the Program.cs class (in the UI project). It looks like it has some code pasted into it from SuperAdventure.cs. Try replacing all the code in that class with this:

          using System;
          using System.Windows.Forms;

          namespace SuperAdventure
          {
          static class Program
          {
          ///

          /// The main entry point for the application.
          ///

          [STAThread]
          static void Main()
          {
          Application.EnableVisualStyles();
          Application.SetCompatibleTextRenderingDefault(false);
          Application.Run(new SuperAdventure());
          }
          }
          }

          Also, because you are using a different type of database, you will need to change the connection string in the PlayerDataMapper class to this:

          private static readonly string _connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\SuperAdventure.mdf;Integrated Security=True;Connect Timeout=30";

          Let me know if that does not fix the program for you.

  18. Hi, I’ve just started using this tutorial, and I have reached the point in Lesson 5 where I must enter

    using Engine;

    Below the rest of the using lines. But it is telling me that the “using directive is unnecessary”.

    And that ‘The type or namespace ‘Engine’ could not be found (are you missing a using directive or an assembly reference?)”

    but I have created an Engine reference in the Super Adventure project and can see it in the references section.

    This is stopping the datatype Player removing the red squiggly line.

    Any help would be greatly appreciated!

    1. Can you check if the Player class has these lines near the top of the class:

      namespace Engine

      and

      public class Player (especially the “public”)

      If it has those lines, did you create the Engine project with a different name, then rename it later? If so, check the solution here: Lesson 02.2B – Fixing the namespace

      If that doesn’t help you solve the error, can you upload your solution (all the files) to Dropbox or GitHub, so I can examine it?

  19. Hi, I’ve been following your tutorial in my free time to refresh my memory of C# before I go back to university and I’d just like to say thank you!

    Ever since I completed the tutorial it’s been so much fun & headache learning to change/add all the new things I’ve been adding to the game. (some days I’d spend hours trying to figure out a problem that I’d end up solving in minutes the next day)  Right now, I’m working on a special attack button for special weapons and then I’d like to have the default selected weapon in the combo box be your most powerful weapon.

    Once again, thanks!

    1. You’re welcome! I’m glad you enjoyed the tutorial.

      It’s amazing how much a night of sleep will help with finding a solution to a programming problem. I hope you have a good year in university.

  20. Hi and greetings from Germany 🙂

    I have a problem with adding a Spawnrate for Monsters. I managed to add a Lootrate for Items, but if I try to do the same with the Monsters, I always fail. I loot different things from the Monsters, but there is always the same Monster spawning, even if I put the Spawnrate for other Monsters up to 100%. Hope you can help me with it.

    Also I would like to add Player Classes (Warrior, Mage, etc.) to the game. Would it be possible that you could write a tutorial for that?

    With best regards
    Dennis

    1. Hello from Texas 🙂

      Can you upload your solution (all the files, including the sub-folders, and their files) to GitHub or Dropbox, so I can examine them?

      For the different player classes, have you seen my demonstration of “Composition over Inheritance“? That might give you an idea how to create the different classes. The new WPF guide will use this technique to make different character classes (Warriors, Mager, etc.). If that article does not help. please tell me.

Leave a Reply

Your email address will not be published. Required fields are marked *