[C#] Text-Based RPG

  • (9 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

128 Replies - 29327 Views - Last Post: 20 November 2012 - 08:22 AM

#1 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

[C#] Text-Based RPG

Posted 19 January 2010 - 06:02 PM

Hello.

With all of these RPG posts swimming through my head lately, I seem to have acquired this itch that needs scratching. So, I'm going to bite the bullet and make an RPG.

Now, I'm going to take the path of least resistance here because this is my first RPG game. That's why I'm going to go the text-based route.

At any rate, things will go one of two ways - I'll either finish this thing entirely or I'm going to crash and burn horribly. Either way, we're all going to learn a hell of a lot. I say this because I intend to update this thread with every change. You'll be able to follow along as much as you care to. You can even use my code if you wish.

So, you're probably asking me "Hey Floss, why don't you just put this in your blog?". That's a very good question. There's two reasons actually - I don't want to clutter my blog with the amount of posting I intend to do and I'm sure not as many people will read this if it's just in my blog. This way, a wider audience can gain something from this (Hopefully not a How-Not-To-Make-A-Text-Based-RPG but I digress).

Hope you guys have fun.


EDIT:
In response to this post:

Quote

It would probably be a good idea to explicitly state the language and development tools (e.g., IDE) that you're using.


I'm using C# with VS 2008.

This post has been edited by MentalFloss: 20 January 2010 - 09:25 AM


Is This A Good Question/Topic? 4
  • +

Replies To: [C#] Text-Based RPG

#2 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: [C#] Text-Based RPG

Posted 19 January 2010 - 06:11 PM

First thing's first... what do I need?

Well, I need a world for all the interactions to take place in.
With that requirement, I created a new project called RPG.Environment.

Next, I need creatures to make it interesting. I'd say that everything that can exist in my environment should be an entity.
With that, I created a new project called RPG.Entities.

Moving along... I need some kind of inventory system for all the items in my game.
I created a new project called RPG.Items.

I'd like to have some skills that affect the player's experience as well.
To accommodate that, I created a project called RPG.Skills. This one may not make the cut though.

Finally, I need something that will do my battle calculations for me.
For that, I created a project called RPG.Battle.

For now, I think that's enough to get started.

Attached File(s)

  • Attached File  RPG.zip (38.29K)
    Number of downloads: 1051

This post has been edited by MentalFloss: 19 January 2010 - 06:13 PM

Was This Post Helpful? 0
  • +
  • -

#3 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: [C#] Text-Based RPG

Posted 19 January 2010 - 06:16 PM

Sounds like a good idea so far, and an excellent project to work on. I look forward to seeing the progress you make on this with great interest.
Was This Post Helpful? 0
  • +
  • -

#4 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: [C#] Text-Based RPG

Posted 19 January 2010 - 06:21 PM

So, if you downloaded that attachment, you'll just see the various empty projects added to the solution.

The first thing I am going to work on is the entities. This is where the monsters, NPCs, and player are defined. They all are going to implement IEntity, but as of yet, I'm not fully sure what that means.

Regardless, I added some base entities and the interface.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#5 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: [C#] Text-Based RPG

Posted 19 January 2010 - 06:32 PM

OK. Moving forward here.

(The frequency of these posts will lessen soon when this starts getting hairy)

I realized that I need something of a dumping ground where I can put stuff until I know where I really want it.
I added RPG.Dump to my solution for this.

Currently, the dump just contains some interfaces that items are going to implement.

Here are the following added (currently blank) interfaces:

IConsumable
IDrinkable
IEdible
IWearable
IWieldable

The RPG.Items project now has a directory structure as well.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#6 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: [C#] Text-Based RPG

Posted 19 January 2010 - 06:43 PM

I moved IWieldable to the RPG.Items project. I think it makes the most sense there. In fact, I'm pretty sure all the interfaces in RPG.Dump will end up in the RPG.Items project, but it's nice to have a shuffle project.

Anyway, after I moved IWieldable to RPG.Items, I added a project reference to RPG.Entities so my character can have hands.

using System;

using RPG.Items;

namespace RPG.Entities.Hero
{
	/// <summary>
	/// Represents the character that the player is using
	/// </summary>
	internal class Character : IEntity
	{
		// The equipped item in the character's left hand
		public IWieldable LeftHand
		{ get; private set; }

		// The equipped item in the character's right hand
		public IWieldable RightHand
		{ get; private set; }
	}
}



I'll be back online in a bit. Take care.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#7 dsherohman  Icon User is offline

  • Perl Parson
  • member icon

Reputation: 226
  • View blog
  • Posts: 654
  • Joined: 29-March 09

Re: [C#] Text-Based RPG

Posted 20 January 2010 - 06:56 AM

Two quick suggestions:

1) It would probably be a good idea to explicitly state the language and development tools (e.g., IDE) that you're using.

2) I have a friend building an MMORPG in DarkBASIC and doing a similar record of his efforts at http://sites.google....ames.com/frost/ So far, he's just been doing graphics and network stuff, so I'm not sure how applicable it would be for your project, but it's still probably worth checking out.

Edit: D'oh! Just noticed the "[C#]" in the subject of your post...

This post has been edited by dsherohman: 20 January 2010 - 06:57 AM

Was This Post Helpful? 0
  • +
  • -

#8 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: [C#] Text-Based RPG

Posted 20 January 2010 - 09:27 AM

Quote

I have a friend building an MMORPG in DarkBASIC and doing a similar record of his efforts at http://sites.google....ames.com/frost/ So far, he's just been doing graphics and network stuff, so I'm not sure how applicable it would be for your project, but it's still probably worth checking out.


Thanks for the link. I took a cursory glance at it and it seems like pretty cool stuff. I'll definitely check it out in more detail a bit later.
Was This Post Helpful? 0
  • +
  • -

#9 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: [C#] Text-Based RPG

Posted 20 January 2010 - 09:38 AM

With this update, I have moved the interfaces in my RPG.Dump project to RPG.Items. I also created a new interface that all IEntities will implement called IViewable which I put into yet another project called RPG.Common. I intend for this project to be a location for things in the world that span across multiple projects. For example, items as well as IEntity objects are going to be IViewable. Since I cannot put IViewable into IEntity without creating a circular dependency between RPG.Entities and RPG.Items, I had to create this new project.

Anyway...

using System;

namespace RPG.Common
{
	/// <summary>
	/// Represents anything that may be inspected via the LOOK command.
	/// </summary>
	public interface IViewable
	{
		string GetLookMessage();
	}
}



I toyed around with the idea of calling it IInspectable, but I try to avoid the double-I named interfaces.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#10 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: [C#] Text-Based RPG

Posted 20 January 2010 - 10:20 AM

I realized that my entities should be able to be healed and damaged so I have updated my IEntity interface to include two new methods. Additionally, there needs to be a way to track this information so I created a new class in RPG.Entities called EntityStatus.

Here is the new interface:

using System;

using RPG.Common;

namespace RPG.Entities
{
	/// <summary>
	/// Represents an entity in the game.
	/// </summary>
	// TODO: Design the role of this interface.
	internal interface IEntity : IViewable
	{
		// The overall well-being of this entity
		EntityStatus Status { get; }

		// Cause damage to an entity
		void Damage(int amount);

		// Repair damage to an entity
		void Heal(int amount);
	}
}



Here is the EntityStatus class:

using System;

namespace RPG.Entities
{
	/// <summary>
	/// Represents the overall well-being of an entity
	/// </summary>
	public class EntityStatus
	{
		// Amount of life points an entity has
		public int Health
		{ get; set; }

		// Amount of magical power an entity has
		public int Magic
		{ get; set; }

		// Amount of physical energy an entity has
		public int Stamina
		{ get; set; }
	}
}



So, I'm just about ready to start building pieces of the battle engine.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#11 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: [C#] Text-Based RPG

Posted 20 January 2010 - 10:39 AM

I created a DamageCalculator class in RPG.Battle. Here is the code so far:

using System;

using RPG.Entities;

namespace RPG.Battle
{
	/// <summary>
	/// Handles the game dynamics in regards to damaging entities
	/// </summary>
	public class DamageCalculator
	{
		// Occurs when an entity damages another entity via physical attacks
		public void CausePhysicalDamage(IEntity attacker, IEntity defender)
		{
			throw new NotImplementedException();
		}

		// Occurs when an entity damages another entity via magical attacks
		public void CauseSpellDamage(IEntity attacker, IEntity defender)
		{
			throw new NotImplementedException();
		}
	}
}



This required me to add the following project references to RPG.Battle:
RPG.Entities
RPG.Common

I also realized that RPG.Environment is probably going to have to have its hand in every project file so I am simply including them right now. I'm doing this so I can catch possibilities of circular dependency quickly.

Here are the additional project references to RPG.Environment:
RPG.Battle
RPG.Common
RPG.Entities
RPG.Items
RPG.Skills

Will I truly need them all in the end? Probably not...

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#12 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: [C#] Text-Based RPG

Posted 20 January 2010 - 11:36 AM

I decided that I didn't really like my IEntity interface specification. I have modified it to access individual elements of the Entity's status object.

Here is the updated interface:

using System;

using RPG.Common;

namespace RPG.Entities
{
	/// <summary>
	/// Represents an entity in the game.
	/// </summary>
	public interface IEntity : IViewable
	{
		// The overall well-being of this entity
		EntityStatus Status { get; }

		// Cause damage to an entity
		void DecreaseHealth(int amount);

		// Repair damage to an entity
		void IncreaseHealth(int amount);

		// Decrease available magic power
		void DecreaseMagic(int amount);

		// Increase available magic power
		void IncreaseMagic(int amount);

		// Decrease entity's stamina - simulating fatigue
		void DecreaseStamina(int amount);

		// Increase entity's stamina - simulating additional energy
		void IncreaseStamina(int amount);
	}
}



Considering the similarity between implementations on the Hero and Monsters in regards to these methods, I'm thinking of creating a base class that they will both extend. I haven't done this yet though.

So, with this change, here's the new hero:

using System;

using RPG.Items;

namespace RPG.Entities.Hero
{
	/// <summary>
	/// Represents the character that the player is using
	/// </summary>
	internal class Character : IEntity
	{
		// The equipped item in the character's left hand
		public IWieldable LeftHand
		{ get; private set; }

		// The equipped item in the character's right hand
		public IWieldable RightHand
		{ get; private set; }

		// The overall well-being of this entity
		public EntityStatus Status
		{ get; private set; }

		// The message that is retrieved via a LOOK command
		public string GetLookMessage()
		{
			throw new NotImplementedException();
		}

		// Occurs when this entity is damaged
		public void DecreaseHealth(int amount)
		{
			Status.Health -= amount;
		}

		// Occurs when this entity is healed
		public void IncreaseHealth(int amount)
		{
			Status.Health += amount;
		}

		// Occurs when this entity casts spells
		public void DecreaseMagic(int amount)
		{
			Status.Magic -= amount;
		}

		// TODO: Identify causes of increase in magic power
		public void IncreaseMagic(int amount)
		{
			Status.Magic += amount;
		}

		// TODO: Identify causes of decreased stamina
		public void DecreaseStamina(int amount)
		{
			Status.Stamina -= amount;
		}

		// TODO: Identify causes of increased stamina
		public void IncreaseStamina(int amount)
		{
			Status.Stamina += amount;
		}
	}
}



Monster is essentially the same thing in those interface methods.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#13 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: [C#] Text-Based RPG

Posted 20 January 2010 - 12:26 PM

Under RPG.Entities, I created a new class called Equipment that stores IWearable items on an entity.

From that, I added a new property to my IEntity interface. Here is the updated interface:

using System;

using RPG.Common;

namespace RPG.Entities
{
	/// <summary>
	/// Represents an entity in the game.
	/// </summary>
	public interface IEntity : IViewable
	{
		// The overall well-being of this entity
		EntityStatus Status { get; }

		// The wearable items that an entity has equipped
		Equipment Gear { get; }

		// Cause damage to an entity
		void DecreaseHealth(int amount);

		// Repair damage to an entity
		void IncreaseHealth(int amount);

		// Decrease available magic power
		void DecreaseMagic(int amount);

		// Increase available magic power
		void IncreaseMagic(int amount);

		// Decrease entity's stamina - simulating fatigue
		void DecreaseStamina(int amount);

		// Increase entity's stamina - simulating additional energy
		void IncreaseStamina(int amount);
	}
}



Here is the Equipment class that was added:

using System;

using RPG.Items;

namespace RPG.Entities
{
	/// <summary>
	/// Represents the equipment that an entity is using.
	/// </summary>
	public class Equipment
	{
		// Provides the total amount of defense that an entity has
		public int Defense
		{
			get
			{
				// Sum all of the defense together and return result
				return Head.Defense + Body.Defense + Arms.Defense + Legs.Defense;
			}
		}

		// Helmet type wearables
		public IWearable Head
		{ get; private set; }

		// Wearable that covers the chest
		public IWearable Body
		{ get; private set; }

		// Wearable that covers the arms such as bracers or gloves
		public IWearable Arms
		{ get; private set; }

		// Wearable that covers the legs such as leggings
		public IWearable Legs
		{ get; private set; }
	}
}

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#14 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: [C#] Text-Based RPG

Posted 20 January 2010 - 01:02 PM

To pave the way for implementation of level mechanics, I made a few structural changes. First, I created a new interface called ILevelableEntity inside RPG.Entities project. All levelable entities are indeed still entities, so ILevelableEntity implements IEntity. Because of this new interface, I have changed the hero's class to instead be ILevelableEntity.

In order to store this level information, I created a new class inside RPG.Entities called LevelStatus. This is in keeping with the name of my other status class EntityStatus. All ILevelableEntities must implement this LevelStatus property.

Here's the new interface:

using System;

namespace RPG.Entities
{
	/// <summary>
	/// Represents an entity that may increase in level through experience
	/// </summary>
	public interface ILevelableEntity : IEntity
	{
		// The level information of an entity
		LevelStatus Level { get; }
	}
}



I don't have concrete behavior defined for LevelStatus yet. It's essentially just for structural placement at this time. Soon though...

using System;

namespace RPG.Entities
{
	/// <summary>
	/// Represents an entity's level information
	/// </summary>
	public class LevelStatus
	{
	}
}



Oh, and I also added some more directories to RPG.Items in order to reflect the various areas of IWearable items.

Attached File(s)


This post has been edited by MentalFloss: 20 January 2010 - 01:03 PM

Was This Post Helpful? 0
  • +
  • -

#15 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: [C#] Text-Based RPG

Posted 20 January 2010 - 01:35 PM

I decided that I would like all entities to report their total defense instead of having to get it from their exposed Equipment object:

using System;

using RPG.Common;

namespace RPG.Entities
{
	/// <summary>
	/// Represents an entity in the game.
	/// </summary>
	public interface IEntity : IViewable
	{
		// The overall well-being of this entity
		EntityStatus Status { get; }

		// The wearable items that an entity has equipped
		Equipment Gear { get; }

		// The defense of this entity which may be influenced by armor, status modifiers, etc
		int Defense { get; }

		// Cause damage to an entity
		void DecreaseHealth(int amount);

		// Repair damage to an entity
		void IncreaseHealth(int amount);

		// Decrease available magic power
		void DecreaseMagic(int amount);

		// Increase available magic power
		void IncreaseMagic(int amount);

		// Decrease entity's stamina - simulating fatigue
		void DecreaseStamina(int amount);

		// Increase entity's stamina - simulating additional energy
		void IncreaseStamina(int amount);
	}
}



Now I can create additional defense conditions on the entity itself.

I also added two new interfaces under RPG.Items.Wearable. They are IArmor and IClothing and they are both IWearable.

For good measure, I created an IWearable class called Naked. This will be used to set equipment to essentially unequipped. As for its placement, for now it's just in the main Wearable directory.

I am slightly worried about this decision because I am kind of breaking my association to specific body parts, but it beats having 20 Naked classes that are essentially the same thing so I'm going to go with this for now.

Here's the new naked:

using System;

namespace RPG.Items.Wearable
{
	/// <summary>
	/// Represents an unequipped item
	/// </summary>
	public class Naked : IWearable
	{
		// The defense provided by this wearable item
		public int Defense
		{
			get
			{
				return 0;
			}
		}
	}
}



In order for this to work, I opened up Equipment's properties to be get;set; instead of get;private set;.

I then created a new method on IEntity called UnequipGear() which is supposed to remove the entity's equipped items.

There is currently nothing in place to manage inventory. I'm just creating a new Naked() and assigning it to that item.

Here's UnequipGear() on player:

using System;

using RPG.Items;
using RPG.Items.Wearable;

namespace RPG.Entities.Hero
{
	/// <summary>
	/// Represents the character that the player is using
	/// </summary>
	public class Character : ILevelableEntity
	{

		// Snipped out properties for brevity


		// Removes all equipped items in Equipment
		public void UnequipGear()
		{
			if (Gear != null)
			{
				Gear.Arms = new Naked();
				Gear.Body = new Naked();
				Gear.Head = new Naked();
				Gear.Legs = new Naked();
			}
		}
	}
}



I duplicated this functionality in the Equipment constructor as well.

using System;

using RPG.Items;
using RPG.Items.Wearable;

namespace RPG.Entities
{
	/// <summary>
	/// Represents the equipment that an entity is using.
	/// </summary>
	public class Equipment
	{
		// Provides the total amount of defense that an entity has
		public int Defense
		{
			get
			{
				// Sum all of the defense together and return result
				return Head.Defense + Body.Defense + Arms.Defense + Legs.Defense;
			}
		}

		// Helmet type wearables
		public IWearable Head
		{ get; set; }

		// Wearable that covers the chest
		public IWearable Body
		{ get; set; }

		// Wearable that covers the arms such as bracers or gloves
		public IWearable Arms
		{ get; set; }

		// Wearable that covers the legs such as leggings
		public IWearable Legs
		{ get; set; }

		public Equipment()
		{
			Head = new Naked();
			Body = new Naked();
			Arms = new Naked();
			Legs = new Naked();
		}
	}
}



It's starting to come together I think.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

  • (9 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »