Ok so for my C# programming class I am making an adventure game. I think I understand how to do most of it expect I'm having trouble setting up the "world".
I have a class for the world (World.cs) where I started creating a list for each room. However I'm confused of to add a name and description for each room.
For example if the List (room) is type String I would do room.Add("Prison", "This is a prison).
What is the best way to do this?
That's when you create a class
public class Room {
public string Name { get; set; }
public string Description { get; set; }
}
And hold a list of rooms:
List<Room> rooms = new List<Room>();
In order to add anything to the list, simply do this:
rooms.Add(new Room { Name = "Prison", Description = "This is a prison" });
Objects are used to group data together, this will allow for much cleaner code. It is one of the keystones of Object-Oriented Programming.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With