Пример #1
0
func displayPickUpChoice() []entity.ID {
	var str *C.char
	C.clear()
	C.move(0, 0)
	str = C.CString("Pick up what?\n")
	C.addstr(str)
	C.free(unsafe.Pointer(str))

	px, py := currentLevel.EntityLocation(player.EntityID())
	itemsAvailable := currentLevel.ItemsAt(px, py)
	for i, eid := range itemsAvailable {
		C.addch(C.chtype(inventoryChar(byte(i))))
		str = C.CString(" - ")
		C.addstr(str)
		C.free(unsafe.Pointer(str))
		str = C.CString(currentLevel.EntityByID(eid).EntityName())
		C.addstr(str)
		C.free(unsafe.Pointer(str))
	}

	itemsChosen := make([]bool, len(itemsAvailable))
	for {
		ch := C.getch()
		if ch == C.KEY_ENTER || ch == ' ' || ch == '\n' {
			break
		}
		if ch > C.int(255) {
			continue
		}
		if i := inventoryIndex(byte(ch)); (int(i) < len(itemsChosen)) &&
			(i != 255) {
			if itemsChosen[i] {
				itemsChosen[i] = false
				C.mvaddch(C.int(i+1), 2, C.chtype('-'))
			} else {
				itemsChosen[i] = true
				C.mvaddch(C.int(i+1), 2, C.chtype('+'))
			}
		}
	}

	result := make([]entity.ID, 0, len(itemsAvailable))
	for i, v := range itemsChosen {
		if v {
			result = append(result, itemsAvailable[i])
		}
	}
	return result
}
Пример #2
0
func drawSymbol(x, y int, s symbol.Symbol) {
	cx, cy := C.int(x), C.int(y)
	switch s {
	case symbol.Blank:
		C.mvaddch(cy, cx, ' ')
	case symbol.Floor:
		C.mvaddch(cy, cx, '.')
	case symbol.HWall:
		C.mvaddch(cy, cx, '-')
	case symbol.VWall:
		C.mvaddch(cy, cx, '|')
	case symbol.Rock:
		C.mvaddch(cy, cx, '#')
	case symbol.Player:
		C.mvaddch(cy, cx, '@')
	case symbol.Stone:
		C.mvaddch(cy, cx, '*')
	default:
		C.mvaddch(cy, cx, '\000')
	}
}
Пример #3
0
func Mvaddch(y, x int, ch rune) {
	C.mvaddch(C.int(y), C.int(x), C.chtype(ch))
}