Exemple #1
0
//移动一个角色在战场的位置
func (self *BattleField) MoveCharacter(c *Warrior, posTo int) (moved int) {
	moved = 0

	if c.Position != posTo {
		moved = math.AbsInt((posTo - c.Position))
		//从旧的位置删除
		delete(self.field[c.Position], c.Id)
		//移动到新位置
		c.Position = posTo
		self.field[posTo][c.Id] = c
	}

	return moved
}
Exemple #2
0
//获取战场上2个角色之间的距离
func (self *BattleField) GetDistanceBetween(from, to *Warrior) int {
	//由于战场坐标为[0,n],所以可以直接求绝对值
	return math.AbsInt(from.Position - to.Position)
}