示例#1
0
func TestMechFireInRange(t *testing.T) {
	const mechName string = "testMech"
	const mechName2 string = "testMech2"
	const structure int = 2

	mech1 := NewMech(mechName, structure, 0, 0, tl.ColorRed, 'T')
	if mech1 == nil {
		t.Errorf("%s was unable to be created", mechName)
	}

	mech2 := NewMech(mechName2, structure, 0, 0, tl.ColorRed, 'T')
	if mech2 == nil {
		t.Errorf("%s was unable to be created", mechName2)
	}

	weapon1 := weapon.Create(5, 1, "rifle", .75)

	mech1.AddWeapon(weapon1)

	mech1.Fire(3, mech2)
	if mech2.structure != 1 {
		t.Errorf("%s fired at %s at range %d and %s still has %d structure",
			mech1.name,
			mech2.name,
			3,
			mech2.name,
			mech2.structure)
	}
}
示例#2
0
func TestAddWeapon(t *testing.T) {
	const mechName string = "testMech"
	const structure int = 2

	mech1 := NewMech(mechName, structure, 0, 0, tl.ColorRed, 'T')
	if mech1 == nil {
		t.Errorf("%s was unable to be created",
			mechName)
	}
	weapon1 := weapon.Create(5, 1, "rifle", .75)

	mech1.AddWeapon(weapon1)

	if len(mech1.weapons) != 1 {
		t.Errorf("%s has %d weapons instead of 1 weapon",
			mech1.name,
			len(mech1.weapons))
	}
}