jeudi 7 avril 2016

If statement always true with enum in comparison

I'm having a problem. I'm making a utility to do procedural generated maps. I have a room pool and each rooms are disposed in a table of room. I have a method to connect all the room together witch walk in the table and connect adjacent rooms.

I have an enum which contain the type of rooms :

public enum RoomType
{
    Default = 0,
    Building,
    Boss,
    Item,
    Standard,
    Start,
}

In the connection method I check the neighborhood to see what kind of room it is :

if (neighbourhood[2, 1] != null)
{
    if (firstLevel.isOn)
    {                     
        if (neighbourhood[2,1].TypeOfRoom == RoomType.Start)
        {
            roomGrid[x, y].AddConnection(neighbourhood[2, 1], Location.RIGHT)
        }
    }
    else if (neighbourhood[2,1].TypeOfRoom != RoomType.Boss)
        roomGrid[x, y].AddConnection(neighbourhood[2, 1], Location.RIGHT);
}

But when the i check if the type of room is Start, it's always true and the connection is added.

img img2

I don't know why this happen..

where i set the TypeOfRoom : img3

Aucun commentaire:

Enregistrer un commentaire