예제 #1
0
파일: defs.go 프로젝트: vhochmann/hex
func PlayState(g *game.Game) (State, *game.Game) {
	mc := g.Spawn()
loop:
	for {
		ui.Clear()
		for i := range g.Players.Players {
			if plyr := &g.Players.Players[i]; plyr.Alive {
				plyr.Update()
				ui.DrawRune(int(plyr.Pos.X), int(plyr.Pos.Y), '#')
				//ui.SetCell(int(plyr.Pos.X), int(plyr.Pos.Y), '#')
			}
		}
		ui.PrintSliceAtBottom(g.Read(8))
		ui.Update()
		switch ev := ui.GetEvent(); ev.Key {
		case ui.ESC:
			break loop
		case ui.UP:
			mc.SetVel(engine.Vec(0.0, -1.0))
		case ui.DOWN:
			mc.SetVel(engine.Vec(0.0, 1.0))
		case ui.LEFT:
			mc.SetVel(engine.Vec(-1.0, 0))
		case ui.RIGHT:
			mc.SetVel(engine.Vec(1.0, 0))
		}
	}
	return MenuState, g
}
예제 #2
0
파일: defs.go 프로젝트: vhochmann/hex
func Run(g *game.Game) {
	g = game.NewGame()
	defer g.DumpLog()
	defer ui.Uninit()
	for s := InitialState; s != nil; {
		s, g = s(g)
	}
}
예제 #3
0
파일: defs.go 프로젝트: vhochmann/hex
func LoadState(g *game.Game) (State, *game.Game) {
	ui.Clear()
	ui.Print(0, 0, "Loading...")
	// do actual loading here
	ui.PrintSliceAtBottom(g.Read(8))
	ui.Update()
	time.Sleep(time.Millisecond * 200)
	return PlayState, g
}
예제 #4
0
파일: defs.go 프로젝트: vhochmann/hex
func MenuState(g *game.Game) (State, *game.Game) {
	var offSet = 4
	var current = 0
	var printFormat string
	var ev ui.Event
	var options = []struct {
		name string
		val  State
	}{
		{"Play", PlayState},
		{"Save", SaveState},
		{"Load", LoadState},
		{"Exit", ExitState},
	}
menu:
	for {
		ui.Clear()
		for i := range options {
			if i == current {
				printFormat = SelectPrint
			} else {
				printFormat = NormalPrint
			}
			ui.Print(offSet*2, offSet+i, fmt.Sprintf(printFormat, options[i].name))
		}
		ui.PrintSliceAtBottom(g.Read(8))
		ui.Update()
		switch ev = ui.GetEvent(); ev.Key {
		case ui.DOWN:
			if current+1 < len(options) {
				current++
			}
		case ui.UP:
			if current-1 > -1 {
				current--
			}
		case ui.ENTER:
			break menu
		}
	}
	return options[current].val, g
}