Exemple #1
0
func CreateRoom(zone types.Zone, location types.Coordinate) (types.Room, error) {
	existingRoom := GetRoomByLocation(location, zone.GetId())
	if existingRoom != nil {
		return nil, errors.New("A room already exists at that location")
	}

	return db.NewRoom(zone.GetId(), location), nil
}
Exemple #2
0
func Test_Room(t *testing.T) {
	fakeZoneId := bson.ObjectId("!2345")
	room := database.NewRoom(fakeZoneId, types.Coordinate{X: 0, Y: 0, Z: 0})

	testutils.Assert(room.GetZoneId() == fakeZoneId, t, "Room didn't have correct zone ID upon creation", fakeZoneId, room.GetZoneId())

	fakeZoneId2 := bson.ObjectId("11111")
	room.SetZoneId(fakeZoneId2)
	testutils.Assert(room.GetZoneId() == fakeZoneId2, t, "Call to room.SetZoneId() failed")

	directionList := make([]types.Direction, 10)
	directionCount := 10

	for i := 0; i < directionCount; i++ {
		directionList[i] = types.Direction(i)
	}

	for _, dir := range directionList {
		testutils.Assert(!room.HasExit(dir), t, "Room shouldn't have any exits enabled by default", dir)
		room.SetExitEnabled(dir, true)
		testutils.Assert(room.HasExit(dir), t, "Call to room.SetExitEnabled(true) failed")
		room.SetExitEnabled(dir, false)
		testutils.Assert(!room.HasExit(dir), t, "Call to room.SetExitEnabled(false) failed")
	}

	title := "Test Title"
	room.SetTitle(title)
	testutils.Assert(title == room.GetTitle(), t, "Call to room.SetTitle() failed", title, room.GetTitle())

	description := "This is a fake description"
	room.SetDescription(description)
	testutils.Assert(description == room.GetDescription(), t, "Call to room.SetDescription() failed", description, room.GetDescription())

	coord := types.Coordinate{X: 1, Y: 2, Z: 3}
	room.SetLocation(coord)
	testutils.Assert(coord == room.GetLocation(), t, "Call to room.SetLocation() failed", coord, room.GetLocation())
}