cgseif323's Profile
Reputation: 0
Apprentice
- Group:
- Members
- Active Posts:
- 27 (0.02 per day)
- Joined:
- 01-April 09
- Profile Views:
- 981
- Last Active:
Jul 13 2012 06:40 PM- Currently:
- Offline
Previous Fields
- Country:
- US
- OS Preference:
- Linux
- Favorite Browser:
- Chrome
- Favorite Processor:
- Intel
- Favorite Gaming Platform:
- XBox
- Your Car:
- Who Cares
- Dream Kudos:
- 0
Latest Visitors
-
Mobuis1995 
06 Jul 2012 - 22:39
Posts I've Made
-
In Topic: NullReferenceException (And yes, I've searched this forum)
Posted 7 Jul 2012
Alright, I finally got something. I kept stepping through the code, and I stopped on what GetCurrentLocation() returns. It now says in the Autos window that Level.Locations[1,2] is null, Level.Locations[0,0] is null, and Level.Locations[0,1] is null. I stepped through everything a dozen times, and I didn't see this before. Anyways, here's the Level class...
Level.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using TextRPGv2; namespace TextRPGv2 { static class Level { private static Location[,] locations; #region Properties public static Location[,] Locations { get { return locations; } } #endregion public static void Initialize() { BuildLevel(); } private static void BuildLevel() { locations = new Location[1, 2]; LocationDB locationDB = new LocationDB(); Player.PosX = 0; Player.PosY = 0; } } }
Location.cs
using System; using System.IO; using System.Collections.Generic; using System.Linq; using TextRPGv2; namespace TextRPGv2 { /// <summary> /// This is the base class for every location /// in the game. Add more fields if necessary. /// </summary> class Location { private string title; private string description; private List<string> exits; private List<Item> items; #region Properties // not relevant #endregion public Location() { exits = new List<string>(); items = new List<Item>(); } // Public Methods #region Public Methods public void Describe() { TextBuffer.Add(this.description); TextBuffer.Add(this.GetItemList()); TextBuffer.Add(this.GetExitList()); } public void ShowTitle() { TextBuffer.Add(this.title); } public Item GetItem(string itemName) { foreach (Item item in this.items) { if (item.Name.ToLower() == itemName.ToLower()) return item; } return null; } public void AddExit(string direction) { if (this.exits.IndexOf(direction) == -1) this.exits.Add(direction); } public void RemoveExit(string direction) { if (this.exits.IndexOf(direction) != -1) this.exits.Remove(direction); } public bool CanExit(string direction) { foreach (string validExit in this.exits) { if (direction == validExit) return true; } return false; } #endregion // Private Methods #region Private Methods private string GetItemList() { string itemString = ""; string message = "Items in Room:"; string underline = ""; underline.PadLeft(message.Length, '-'); if (this.items.Count > 0) { foreach (Item item in this.items) { itemString += "\n[" + item.Name + "]"; } } else { itemString = "\n<none>"; } return "\n" + message + "\n" + underline + itemString; } private string GetExitList() { string exitString = ""; string message = "Possible Directions:"; string underline = ""; underline.PadLeft(message.Length, '-'); if (this.exits.Count > 0) { foreach (string exitDirection in this.exits) { exitString += "\n[" + exitDirection + "]"; } } else { exitString = "\n<none>"; } return "\n" + message + "\n" + underline + exitString; } private string GetCoordinates() { for (int y = 0; y < Level.Locations.GetLength(1); y++) { for (int x = 0; x < Level.Locations.GetLength(0); x++) { if (this == Level.Locations[x, y]) return "[" + x.ToString() + "," + y.ToString() + "]"; } } return "This location is not within the Locations grid."; } #endregion } }
LocationDB.cs - Sets the properties of each town/other location in the game
using System; using TextRPGv2; using System.IO; namespace TextRPGv2 { class LocationDB { public Location Glenshaw() { Location location; Item item; ////////////////////////////////////////////////////////// // Glenshaw location = new Location(); // Assign it to a location 0, 0 Level.Locations[0, 0] = location; location.Title = "Glenshaw"; location.Description = "You are in your home town."; location.AddExit(Direction.South); return Glenshaw(); } public Location Etna() { Location location; Item item; ////////////////////////////////////////////////////////// // Etna location = new Location(); // Assign it to a location 0, 1 Level.Locations[0, 1] = location; location.Title = "Etna"; location.Description = "You have entered Etna - A congested, rundown town that is very close to Glenshaw."; location.AddExit(Direction.North); return Etna(); } } }
I've looked over every resource that was linked to by others, and they were helpful. At least we narrowed down the issue
Thanks! -
In Topic: NullReferenceException (And yes, I've searched this forum)
Posted 7 Jul 2012
modi123_1, on 06 July 2012 - 10:59 PM, said:Try putting a break point on line 29 and seeing what the object "Player" is. I don't see it declared so my guess that is your problem... but you should verify.
Debugging
I declared the Player class in a separate file, because it's pretty large. Should I post it?
Mobuis1995, on 06 July 2012 - 11:20 PM, said:In start game, where you sayPlayer.GetCurrentLocation().Describe();
aren't GetCurrentLocation() and Describe() their own methods? Also, it's always helpful to step through the code.
Yes, GetCurrentLocation() is a method in the Player class, and Describe() is in the Location class.
I tried stepping through it, and the code went through the GetCurrentLocation() method, so this must be a problem with how Describe() is called/is set up. But I don't understand how that could throw a NullReferenceException?
Also, thanks for replying! -
In Topic: .NET 4.0 Full/Client profiles; Does anyone care?
Posted 6 Jul 2012
I believe you'd usually want the Client Profile, unless you are trying to go cross-platform. Linux has Mono and MonoDevelop (Visual Studio-like IDE), and I don't think Mono supports developing using the Client Profile.
Also, use the Client Profile if you are developing anything other than server apps. Server apps like in Asp.NET do need the full framework. -
In Topic: C# For Beginners Tutorial I
Posted 19 May 2012
phasex, on 15 April 2012 - 05:02 PM, said:
Fungle, on 05 July 2011 - 01:53 PM, said:Sorry I've been sleeping so long, I've changed a hell of alot of things, Mainly the OS, therefore I shall start a new series, Of Monodevelop and C#! Why limit to .NET when you can use C# on more platforms!
Thanks for your tutorial Fungle. I've used several languages before and have always been curious about c#. You mentioned that it can be used on many platforms. Can you please elaborate what these platforms are and how c# may be used in each?
He's talking about Monodevelop for Linux. The Mono Project is basically like .NET for Linux, with C# support. Monodevelop is very similar to Visual Studio, except you can use it on Linux to make .NET (Mono)/ C# projects. -
In Topic: Simple Temperature Conversion Program - Logical Error
Posted 13 May 2012
Ahh, thank you very much. I know exactly what you mean, but how would I change that in the code? I changed the variable types to float, but that didn't work. Sorry haha I'm very new to this!
EDIT: Nevermind - I changed the variables to float and changed the numbers to 5f and 9f. Thanks for your help!
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
- Location:
- Pittsburgh, PA
- Interests:
- Windows Programming, CLR Programming
- Years Programming:
- 3
- Programming Languages:
- C#, Python, C++
Contact Information
- E-mail:
- Private
- AIM:
-
bbking5554
- Website URL:
-
http://cgseif.yourliveblog.com/
Friends
cgseif323 hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
cgseif323 has no profile comments yet. Why not say hello?