當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Command.CanLock方法代碼示例

本文整理匯總了Golang中code/wolfmud/org/WolfMUD/git/utils/command.Command.CanLock方法的典型用法代碼示例。如果您正苦於以下問題:Golang Command.CanLock方法的具體用法?Golang Command.CanLock怎麽用?Golang Command.CanLock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在code/wolfmud/org/WolfMUD/git/utils/command.Command的用法示例。


在下文中一共展示了Command.CanLock方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: move

// move implements the directional movement commands. This allows movement from
// location to location by typing a direction such as N or North.
//
// TODO: Modify command so that it can handle buffering of multiple location
// broadcasts.
func (b *Basic) move(cmd *command.Command, d direction) (handled bool) {
	if to := b.directionalExits[d]; to != nil {
		if !cmd.CanLock(to) {
			cmd.AddLock(to)
			return true
		}

		b.Remove(cmd.Issuer)

		// If the location is crowded you are not going to notice someone leaving
		if !b.Crowded() {
			b.Broadcast([]thing.Interface{cmd.Issuer}, "[YELLOW]You see %s go %s.", cmd.Issuer.Name(), directionLongNames[d])
		}

		to.Add(cmd.Issuer)

		// If the location is crowded you are not going to notice someone entering
		if !to.Crowded() {
			to.Broadcast([]thing.Interface{cmd.Issuer}, "[YELLOW]You see %s walk in.", cmd.Issuer.Name())
		}

		to.look(cmd)
	} else {
		cmd.Respond("[RED]You can't go %s from here!", directionLongNames[d])
	}
	return true
}
開發者ID:iaingmackay,項目名稱:simplemud,代碼行數:32,代碼來源:basic.go

示例2: parseStage2

// parseStage2 is called by Parse to take advantage of defer unwinding. By
// splitting the parsing we can easily obtain the locks we want and defer the
// unlocking. This makes both Parse and parseStage2 very simple.
func (p *Player) parseStage2(cmd *command.Command) (retry bool) {
	for _, l := range cmd.Locks {
		l.Lock()
		defer l.Unlock()
	}

	// If player moved before we locked we need to retry
	if !cmd.CanLock(p.Locate()) {
		return true
	}

	handled := p.Process(cmd)
	retry = cmd.LocksModified()

	if !handled && !retry {
		cmd.Respond("[RED]Eh?")
	}

	if !retry {
		cmd.Flush()
	}

	return
}
開發者ID:iaingmackay,項目名稱:simplemud,代碼行數:27,代碼來源:player.go


注:本文中的code/wolfmud/org/WolfMUD/git/utils/command.Command.CanLock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。