• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang types.Room类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/Cristofori/kmud/types.Room的典型用法代码示例。如果您正苦于以下问题:Golang Room类的具体用法?Golang Room怎么用?Golang Room使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Room类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: DeleteRoom

func DeleteRoom(room types.Room) {
	db.DeleteObject(room.GetId())

	// Disconnect all exits leading to this room
	loc := room.GetLocation()

	updateRoom := func(dir types.Direction) {
		next := loc.Next(dir)
		room := GetRoomByLocation(next, room.GetZoneId())

		if room != nil {
			room.SetExitEnabled(dir.Opposite(), false)
		}
	}

	updateRoom(types.DirectionNorth)
	updateRoom(types.DirectionNorthEast)
	updateRoom(types.DirectionEast)
	updateRoom(types.DirectionSouthEast)
	updateRoom(types.DirectionSouth)
	updateRoom(types.DirectionSouthWest)
	updateRoom(types.DirectionWest)
	updateRoom(types.DirectionNorthWest)
	updateRoom(types.DirectionUp)
	updateRoom(types.DirectionDown)
}
开发者ID:Cristofori,项目名称:kmud,代码行数:26,代码来源:model.go


示例2: MoveCharacterToRoom

func MoveCharacterToRoom(character types.Character, newRoom types.Room) {
	oldRoomId := character.GetRoomId()
	character.SetRoomId(newRoom.GetId())

	oldRoom := GetRoom(oldRoomId)

	// Leave
	dir := DirectionBetween(oldRoom, newRoom)
	events.Broadcast(events.LeaveEvent{Character: character, RoomId: oldRoomId, Direction: dir})

	// Enter
	dir = DirectionBetween(newRoom, oldRoom)
	events.Broadcast(events.EnterEvent{Character: character, RoomId: newRoom.GetId(), Direction: dir})
}
开发者ID:Cristofori,项目名称:kmud,代码行数:14,代码来源:model.go


示例3: DirectionBetween

func DirectionBetween(from, to types.Room) types.Direction {
	for _, exit := range from.GetExits() {
		nextLocation := from.NextLocation(exit)
		nextRoom := GetRoomByLocation(nextLocation, from.GetZoneId())

		if nextRoom == to {
			return exit
		}
	}

	return types.DirectionNone
}
开发者ID:Cristofori,项目名称:kmud,代码行数:12,代码来源:model.go


示例4: GetNeighbors

func GetNeighbors(room types.Room) []types.Room {
	neighbors := []types.Room{}

	for _, dir := range room.GetExits() {
		coords := room.NextLocation(dir)
		neighbor := GetRoomByLocation(coords, room.GetZoneId())
		if neighbor != nil {
			neighbors = append(neighbors, neighbor)
		}
	}

	for _, id := range room.GetLinks() {
		neighbor := GetRoom(id)
		if neighbor != nil {
			neighbors = append(neighbors, neighbor)
		}
	}

	return neighbors
}
开发者ID:Cristofori,项目名称:kmud,代码行数:20,代码来源:model.go


示例5: CreatePlayerCharacter

func CreatePlayerCharacter(name string, userId types.Id, startingRoom types.Room) types.PC {
	pc := db.NewPc(name, userId, startingRoom.GetId())
	events.Broadcast(events.EnterEvent{Character: pc, RoomId: startingRoom.GetId(), Direction: types.DirectionNone})
	return pc
}
开发者ID:Cristofori,项目名称:kmud,代码行数:5,代码来源:model.go


示例6: printRoom

func (self *Session) printRoom(room types.Room) {
	pcs := model.PlayerCharactersIn(self.pc.GetRoomId(), self.pc.GetId())
	npcs := model.NpcsIn(room.GetId())
	items := model.ItemsIn(room.GetId())
	store := model.StoreIn(room.GetId())

	var area types.Area
	if room.GetAreaId() != nil {
		area = model.GetArea(room.GetAreaId())
	}

	var str string

	areaStr := ""
	if area != nil {
		areaStr = fmt.Sprintf("%s - ", area.GetName())
	}

	str = fmt.Sprintf("\r\n %v>>> %v%s%s %v<<< %v(%v %v %v)\r\n\r\n %v%s\r\n\r\n",
		types.ColorWhite, types.ColorBlue,
		areaStr, room.GetTitle(),
		types.ColorWhite, types.ColorBlue,
		room.GetLocation().X, room.GetLocation().Y, room.GetLocation().Z,
		types.ColorWhite,
		room.GetDescription())

	if store != nil {
		str = fmt.Sprintf("%s Store: %s\r\n\r\n", str, types.Colorize(types.ColorBlue, store.GetName()))
	}

	extraNewLine := ""

	if len(pcs) > 0 {
		str = fmt.Sprintf("%s %sAlso here:", str, types.ColorBlue)

		names := make([]string, len(pcs))
		for i, char := range pcs {
			names[i] = types.Colorize(types.ColorWhite, char.GetName())
		}
		str = fmt.Sprintf("%s %s \r\n", str, strings.Join(names, types.Colorize(types.ColorBlue, ", ")))

		extraNewLine = "\r\n"
	}

	if len(npcs) > 0 {
		str = fmt.Sprintf("%s %s", str, types.Colorize(types.ColorBlue, "NPCs: "))

		names := make([]string, len(npcs))
		for i, npc := range npcs {
			names[i] = types.Colorize(types.ColorWhite, npc.GetName())
		}
		str = fmt.Sprintf("%s %s \r\n", str, strings.Join(names, types.Colorize(types.ColorBlue, ", ")))

		extraNewLine = "\r\n"
	}

	if len(items) > 0 {
		itemMap := make(map[string]int)
		var nameList []string

		for _, item := range items {
			if item == nil {
				continue
			}

			_, found := itemMap[item.GetName()]
			if !found {
				nameList = append(nameList, item.GetName())
			}
			itemMap[item.GetName()]++
		}

		sort.Strings(nameList)

		str = str + " " + types.Colorize(types.ColorBlue, "Items: ")

		var names []string
		for _, name := range nameList {
			if itemMap[name] > 1 {
				name = fmt.Sprintf("%s x%v", name, itemMap[name])
			}
			names = append(names, types.Colorize(types.ColorWhite, name))
		}
		str = str + strings.Join(names, types.Colorize(types.ColorBlue, ", ")) + "\r\n"

		extraNewLine = "\r\n"
	}

	str = str + extraNewLine + " " + types.Colorize(types.ColorBlue, "Exits: ")

	var exitList []string
	for _, direction := range room.GetExits() {
		exitList = append(exitList, utils.DirectionToExitString(direction))
	}

	if len(exitList) == 0 {
		str = str + types.Colorize(types.ColorWhite, "None")
	} else {
		str = str + strings.Join(exitList, " ")
	}
//.........这里部分代码省略.........
开发者ID:Cristofori,项目名称:kmud,代码行数:101,代码来源:session.go


示例7: addRoom

func (self *mapBuilder) addRoom(room types.Room, x int, y int, z int) {
	x = x * 2
	y = y * 2

	addIfExists := func(dir types.Direction, x int, y int) {
		if x < 0 || y < 0 {
			return
		}

		if room.HasExit(dir) {
			self.data[z][y][x].addExit(dir)
		}
	}

	if self.userRoom.GetId() == room.GetId() {
		self.data[z][y][x].char = '*'
		self.data[z][y][x].color = types.ColorRed
	} else {
		self.data[z][y][x].color = types.ColorMagenta
		if room.HasExit(types.DirectionUp) && room.HasExit(types.DirectionDown) {
			self.data[z][y][x].char = '+'
		} else if room.HasExit(types.DirectionUp) {
			self.data[z][y][x].char = '^'
		} else if room.HasExit(types.DirectionDown) {
			self.data[z][y][x].char = 'v'
		} else {
			char := '#'

			/*
				count := len(model.CharactersIn(room.GetId()))
				if count < 10 {
					char = rune(strconv.Itoa(count)[0])
				}
			*/

			self.data[z][y][x].char = char
			self.data[z][y][x].color = types.ColorWhite
		}
	}

	addIfExists(types.DirectionNorth, x, y-1)
	addIfExists(types.DirectionNorthEast, x+1, y-1)
	addIfExists(types.DirectionEast, x+1, y)
	addIfExists(types.DirectionSouthEast, x+1, y+1)
	addIfExists(types.DirectionSouth, x, y+1)
	addIfExists(types.DirectionSouthWest, x-1, y+1)
	addIfExists(types.DirectionWest, x-1, y)
	addIfExists(types.DirectionNorthWest, x-1, y-1)
}
开发者ID:Cristofori,项目名称:kmud,代码行数:49,代码来源:mapbuilder.go


示例8: costEstimate

func costEstimate(start, goal types.Room) int {
	c1 := start.GetLocation()
	c2 := goal.GetLocation()

	return utils.Abs(c1.X-c2.X) + utils.Abs(c1.Y-c2.Y) + utils.Abs(c1.Z-c2.Z)
}
开发者ID:Cristofori,项目名称:kmud,代码行数:6,代码来源:pathing.go



注:本文中的github.com/Cristofori/kmud/types.Room类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang encoding.Cbor函数代码示例发布时间:2022-05-23
下一篇:
Golang adapter.WisplyError类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap