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


Golang Monster.Hp方法代碼示例

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


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

示例1: CheckReadBuffer

// CheckReadBuffer checks that the given buffer is evaluated correctly
// as the example Monster.
func CheckReadBuffer(buf []byte, offset flatbuffers.UOffsetT, fail func(string, ...interface{})) {
	monster := example.GetRootAsMonster(buf, offset)

	if got := monster.Hp(); 80 != got {
		fail(FailString("hp", 80, got))
	}

	// default
	if got := monster.Mana(); 150 != got {
		fail(FailString("mana", 150, got))
	}

	if got := monster.Name(); "MyMonster" != got {
		fail(FailString("name", "MyMonster", got))
	}

	// initialize a Vec3 from Pos()
	vec := new(example.Vec3)
	vec = monster.Pos(vec)
	if vec == nil {
		fail("vec3 initialization failed")
	}

	// check that new allocs equal given ones:
	vec2 := monster.Pos(nil)
	if !reflect.DeepEqual(vec, vec2) {
		fail("fresh allocation failed")
	}

	// verify the properties of the Vec3
	if got := vec.X(); float32(1.0) != got {
		fail(FailString("Pos.X", float32(1.0), got))
	}

	if got := vec.Y(); float32(2.0) != got {
		fail(FailString("Pos.Y", float32(2.0), got))
	}

	if got := vec.Z(); float32(3.0) != got {
		fail(FailString("Pos.Z", float32(3.0), got))
	}

	if got := vec.Test1(); float64(3.0) != got {
		fail(FailString("Pos.Test1", float64(3.0), got))
	}

	if got := vec.Test2(); int8(4) != got {
		fail(FailString("Pos.Test2", int8(4), got))
	}

	// initialize a Test from Test3(...)
	t := new(example.Test)
	t = vec.Test3(t)
	if t == nil {
		fail("vec.Test3(&t) failed")
	}

	// check that new allocs equal given ones:
	t2 := vec.Test3(nil)
	if !reflect.DeepEqual(t, t2) {
		fail("fresh allocation failed")
	}

	// verify the properties of the Test
	if got := t.A(); int16(5) != got {
		fail(FailString("t.A()", int16(5), got))
	}

	if got := t.B(); int8(6) != got {
		fail(FailString("t.B()", int8(6), got))
	}

	if got := monster.TestType(); example.AnyMonster != got {
		fail(FailString("monster.TestType()", example.AnyMonster, got))
	}

	if unionType := monster.TestType(); unionType != example.AnyMonster {
		fail("monster.TestType()")
	}

	// initialize a Table from a union field Test(...)
	var table2 flatbuffers.Table
	if ok := monster.Test(&table2); !ok {
		fail("monster.Test(&monster2) failed")
	}

	// initialize a Monster from the Table from the union
	var monster2 example.Monster
	monster2.Init(table2.Bytes, table2.Pos)

	if got := monster2.Hp(); int16(20) != got {
		fail(FailString("monster2.Hp()", int16(20), got))
	}

	if got := monster.InventoryLength(); 5 != got {
		fail(FailString("monster.InventoryLength", 5, got))
	}

//.........這裏部分代碼省略.........
開發者ID:lbensaad,項目名稱:flatbuffers,代碼行數:101,代碼來源:go_test.go


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