当前位置: 首页>>代码示例>>Golang>>正文


Golang interfaces.Entity类代码示例

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


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

示例1: GetPlayerByEntity

func (g *Game) GetPlayerByEntity(entity interfaces.Entity) interfaces.Player {
	for player, ent := range g.PlayersToEntities {
		if ent.GetEntityId() == entity.GetEntityId() {
			return player
		}
	}

	return nil
}
开发者ID:Garoth,项目名称:StAbbey,代码行数:9,代码来源:game.go

示例2: SwapPositionWith

func (e *Entity) SwapPositionWith(other interfaces.Entity) {
	if !e.IsTangible() || !other.IsTangible() {
		log.Fatalf("Swap only makes sense for tangible entities. Got %v & %v",
			e.GetName(), other.GetName())
	}

	/* It's crucial that two tagnible entities don't end up on same tile */
	boardId, x, y := e.GetPosition()
	boardId2, x2, y2 := other.GetPosition()
	e.BoardId, e.X, e.Y = boardId2, x2, y2
	/* Can work since both entities are technically in the same place */
	other.SetPosition(boardId, x, y)

	/* Manually trigger trodden functions since we didn't SetPosition */
	for _, entity := range e.Game.GetEntitiesAtSpace(e.GetPosition()) {
		entity.Trodden(e)
	}

	/* other's reposition function will be called by SetPosition */
	e.RepositionFunction(boardId, x, y, boardId2, x2, y2)
}
开发者ID:Garoth,项目名称:StAbbey,代码行数:21,代码来源:entity.go

示例3: AddEntity

func (g *Game) AddEntity(entity interfaces.Entity) {
	g.Entities[entity.GetEntityId()] = entity
}
开发者ID:Garoth,项目名称:StAbbey,代码行数:3,代码来源:game.go

示例4: placeEntityRandomly

func (g *Game) placeEntityRandomly(entity interfaces.Entity, boardId int) {
	x, y := g.GetRandomEmptySpace()
	entity.SetPosition(boardId, x, y)
	g.AddEntity(entity)
}
开发者ID:Garoth,项目名称:StAbbey,代码行数:5,代码来源:game.go

示例5: PlaceAtNearestTile

func (g *Game) PlaceAtNearestTile(ent interfaces.Entity, boardId, x, y int) {
	tryX, tryY := -1, -1

	/* assuming BOARD_WIDTH is the higher of the two */
	for radius := 0; radius < interfaces.BOARD_WIDTH+5; radius++ {

		/* Testing horizontally an vertically closest tiles */
		/* Right */
		tryX, tryY = x+radius, y
		if g.CanMoveToSpace(boardId, tryX, tryY) {
			ent.SetPosition(boardId, tryX, tryY)
			return
		}

		/* Bottom */
		tryX, tryY = x, y+radius
		if g.CanMoveToSpace(boardId, tryX, tryY) {
			ent.SetPosition(boardId, tryX, tryY)
			return
		}

		/* Left */
		tryX, tryY = x-radius, y
		if g.CanMoveToSpace(boardId, tryX, tryY) {
			ent.SetPosition(boardId, tryX, tryY)
			return
		}

		/* Top */
		tryX, tryY = x, y-radius
		if g.CanMoveToSpace(boardId, tryX, tryY) {
			ent.SetPosition(boardId, tryX, tryY)
			return
		}

		/* Testing all tiles at increasing distances away */
		for wallLen := 0; wallLen < (radius*2)+1; wallLen++ {
			/* Testing top wall of new circle */
			tryX, tryY = x-radius+wallLen, y-radius
			if g.CanMoveToSpace(boardId, tryX, tryY) {
				ent.SetPosition(boardId, tryX, tryY)
				return
			}

			/* Testing right wall of new circle */
			tryX, tryY = x+radius, y-radius+wallLen
			if g.CanMoveToSpace(boardId, tryX, tryY) {
				ent.SetPosition(boardId, tryX, tryY)
				return
			}

			/* Testing left wall of new circle */
			tryX, tryY = x-radius, y-radius+wallLen
			if g.CanMoveToSpace(boardId, tryX, tryY) {
				ent.SetPosition(boardId, tryX, tryY)
				return
			}

			/* Testing bottom wall of new circle */
			tryX, tryY = x-radius+wallLen, y+radius
			if g.CanMoveToSpace(boardId, tryX, tryY) {
				ent.SetPosition(boardId, tryX, tryY)
				return
			}
		}
	}
}
开发者ID:Garoth,项目名称:StAbbey,代码行数:67,代码来源:game.go

示例6: setEntity

func setEntity(game interfaces.Game, entity interfaces.Entity,
	boardId, x, y int) {
	entity.SetPosition(boardId, x, y)
	game.AddEntity(entity)
}
开发者ID:Garoth,项目名称:StAbbey,代码行数:5,代码来源:generator-util.go

示例7: NewEntity

func NewEntity(e interfaces.Entity) *Entity {
	se := &Entity{}
	se.EntityId = e.GetEntityId()
	se.Name = e.GetName()
	se.Type = e.GetType()
	se.Subtype = e.GetSubtype()
	se.MaxArdour = e.GetMaxArdour()
	se.Ardour = e.GetArdour()
	se.BoardId, se.X, se.Y = e.GetPosition()
	se.ActionQueue = e.GetStringActionQueue()
	return se
}
开发者ID:Garoth,项目名称:StAbbey,代码行数:12,代码来源:entity.go

示例8: act

/* Generic action handler for any entity */
func act(entity interfaces.Entity, action interfaces.Action) {
	if err := action.Act(entity, GAME); err != nil {
		log.Printf("%v: %v", entity.GetName(), err)
	}
}
开发者ID:Garoth,项目名称:StAbbey,代码行数:6,代码来源:runtime.go

示例9: setEntity

func (me *entranceGen) setEntity(game interfaces.Game,
	entity interfaces.Entity, x, y int) {

	entity.SetPosition(me.GetId(), x, y)
	game.AddEntity(entity)
}
开发者ID:Garoth,项目名称:StAbbey,代码行数:6,代码来源:entrance.go


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