syntax issues, objects, get, set,classes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amber892
    New Member
    • Dec 2016
    • 1

    #1

    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.Collecti ons.Generic;
    using System.Linq;
    using System.Text;
    using System.Threadin g.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("Gr eat 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("Dra wing 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("Ki tchen");// it states that my objects e.g kit is not valid in this current context-this is for all
    kit.setS(pan);

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

    lib.setName("Li brary ");
    lib.setE(din);

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

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

    gal.setName("Tr easure 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.WriteL ine("You are in room " + current.getRoom name() + "and you can move ");
    if( current.getN() != null)
    Console.WriteLi ne("North (N) ");
    if( current.getE() != null)
    Console.WriteLi ne("East (E) ");

    Console.WriteLi ne("Please enter the direction you wish to go in ");
    string choice = Console.ReadLin e();
    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.Writeli ne ("Well done you have found the treasure room");


    }
    }
Working...