473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

syntax issues, objects, get, set,classes

I am new to C# and have been working on a project for a maze game in a haunted house context.After researching different approaches I have decided to go with using objects and a linked list. However, despite weeks of trying I am struggling with the code and have gotten to the point after hours of reading articles and watching online tutorials that I am now more confused that ever before. I want to go with this approach rather than an array as I feel like this is more efficient and more OOP. I was thinking of going with a simple if/else structure but for this level of coding I feel it would be too messy. Any help, constructive criticism or ideas would be highly appreciated as I don't want to give up after so many hours spent on it but I feel its getting to that point. This is my code so far. Thanks in advance :)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace maze_3
{//open namespace
class Room
{//open class room

private string RoomName;
private Room N = null; // so that when i set the links they are automatically null unless i specify in main
private Room E = null;
private Room S = null;
private Room W = null;

public Room X { get; private set; } // the software implemented this

public void setName(string N) // so that i am able to set the name of the room
{
RoomName = N;
}

public void setN(Room X) // sets the north direction between the objects of the rooms
{
N = X;
}

public void setE(Room X)
{
E = X;
}

public void setW(Room X)
{
W = X;
}

public void setS(Room x)
{
S = X;
}


public Room getN() // want to get a direction from the user, in this case they would input a north direction
{
return N;
}

public Room getE()
{
return E;
}

public Room getS()
{
return S;
}

public Room getW()
{
return W;
}


static void Main(string[] args)// it is asking for a ; here but also says that I should declare it as extern, partial etc

class chamber// its telling me that a ; is expected ???



chamber gh = new chamber();// my objects that are the rooms in the haunted house.
chamber kit = new chamber();
chamber Pan = new chamber();
chamber Dun = new chamber();
chamber dr = new chamber();
chamber lib = new chamber();
chamber din = new chamber();
chamber sr = new chamber();
chamber weap = new chamber();
chamber tow = new chamber();
chamber gal = new chamber();
chamber tr = new chamber();

gh.RoomName("Great Hall"); //to set the object name as the Great Hall, all get and set links were available in class
gh.setW(dr); ///I want to set a west direction between my object gh to dr
gh.SetS(kit);// to set a south link between my two objects

dr.setName("Drawing Room");//states that all my setlinks are not valid in the current context- this is for all
dr.setS(lib); //it states the ; is not a valid token in class, struct or interface

kit.setName("Kitchen");// it states that my objects e.g kit is not valid in this current context-this is for all
kit.setS(pan);

pan.setName("Pantry");
pan.SetE(dun); /// this is a dead end in the game

lib.setName("Library ");
lib.setE(din);

din.setName("Dining Room");
din.setN(sr);
din.setE(gal);
din.setS(weap); //dead end in the game

sr.setName("Smoking Room");
sr.setE(tow);//dead end

gal.setName("Treasure Room");
gal.setS(tr)


/// </summary> so i wanted to have the actual game play to follow a linked list with a if else structure.
int finish = 0;
string choice;

Room current;

current=gh;
while (finish !=1) (finish ==0) //im confused as to which condition is best to use.
{Console.WriteLine("You are in room " + current.getRoomname() + "and you can move ");
if( current.getN() != null)
Console.WriteLine("North (N) ");
if( current.getE() != null)
Console.WriteLine("East (E) ");

Console.WriteLine("Please enter the direction you wish to go in ");
string choice = Console.ReadLine();
if (choice[0] == 'E') // or alternative means of getting in a choice from a string
current = current.getE();// to be able to move to next 'current'room

// i was going to do this for all the options.

if(current == tr // ie last room
exit = 1;
Console.Writeline ("Well done you have found the treasure room");


}
}
Dec 10 '16 #1
0 1283

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: shank | last post by:
I have the following. I've tried swapping the " and ' in and around and can't get the right syntax. <% varA = "<a href=" & "article.asp?id=" & (rsHead.Fields.Item("ID").Value) & ">Article</a>"...
2
by: Scott Townsend | last post by:
I'm trying to create a class library of a bunch of objects and I'm looking for a way to diagram and document the objects. Is there a tool that people use to do this? I've seen many Database...
12
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded...
0
by: hazz | last post by:
I would really appreciate syntax -double quote - single quote - help with the line # 2 below that uses DataBinder.Eval. Line #1 works fine. It's from MSDN sample...
10
by: Mark Rae | last post by:
Hi, This relates to the previous thread "Disappearing Sessions", but is a bit more generic so I thought I'd start a new thread. This one relates to the storing of objects in Session once only to...
5
by: Jon Clements | last post by:
Hi All, I've reached the point in using Python where projects, instead of being like 'batch scripts', are becoming more like 'proper' programs. Therefore, I'm re-designing most of these and...
4
by: Todd R. Jacobs | last post by:
Hi group, I had this with VS2003 Managed C++ pro-to-types: =================================== TimeHandler.h class TimeHandler
13
by: canam | last post by:
Hi Everyone. I hope someone can point me in the right direction. I have an input form where I have set one Combo Box to fill in a Text Box when a selection is made from the drop down. I would...
4
by: turnitup | last post by:
I am in the process of transforming a procedural code base into an OO code base. The code lends itself to this refactoring and it is proving an effective exercise. However, I am running into a...
6
by: BOMEz | last post by:
So i've recently been starting to program PHP in an object oriented way, but I'm running into some difficulties in from a design stand point and from an object oriented stand point: Issue 1: In my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.