ftbt

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

README

ftbt

介绍

一款战棋游戏引擎及基于 ncurses 的 UI, 采用 go 语言开发. 支持调整规则, 设计关卡, 和对接不同类型的 UI.
目前的包中包含一种简单的 AI 和基于 ncurses 的用户界面.

软件文档

详见 doc/ftbt.pdf

游戏基本流程:

双方控制人物(棋子)在地图(棋盘)上移动并使用技术对对方人物造成伤害. 如果某人物的生命值 (HP) 被减少至零, 则从战斗地图中
退场 (移出棋盘). 首先将对方全部人物消灭的一方取得胜利. 双方轮流按回合进行游戏.

安装教程

安装引擎

git clone https://gitee.com/tfcolin/ftbt
cd ftbt
go build .

安装基于 ncurses 的终端 UI 实现的可执行程序.

cd ftbt_nc
go build .
cd ../ftbt_ai_nc
go build .
cd ..

如果想不依赖 ncurses, 可以使用如下 engine 分支. 该分支去掉了 UI.
git clone https://gitee.com/tfcolin/ftbt -b engine

试验运行

ftbt_ai_nc/ftbt_ai_nc star.tech m2.map m2.intro

在 go 代码中 import 该库.

import (
    "gitee.com/tfcolin/ftbt"
)

使用 Archlinux 发行版的用户可直接通过 AUR 安装:

软件包名称: ftbt
文档安装到位置: /usr/share/doc/ftbt/ftbt.pdf
可执行文件位置: /usr/bin/

Documentation

Index

Constants

View Source
const (
	TST_NORMAL = -1
	TST_WIN    = 0
	TST_LOSS   = 1
	TST_QUIT   = 2
)
View Source
const (
	TC_PEOPLE = 0
	/* 时间, 范围均不可变 */
	TC_ABI_BUF = 1
	TC_DEF_BUF = 2
	/* 时间固定, 范围可变 */
	TC_FLY = 3
	/* 时间, 范围均可变 */
	TC_DISABLE_LONG = 4
)
View Source
const (
	NEIGHBOUR_WEIGHT_SCALE = 2
)
View Source
const (
	NUM_WTECH int = 10
)

Variables

View Source
var (
	AI_MAX_MOVE_DIST    int
	AI_MAX_MOVE_SCORE   int
	AI_MAX_BUF_VALUE    int
	AI_MAX_BUF_SCORE    int
	AI_MAX_DEF_DIST     int
	AI_MAX_DEF_SCORE    int
	AI_MAX_TECH_DIST    int
	AI_MAX_TECH_SCORE   int
	AI_MAX_TECH_BUF_VMD int
	AI_MAX_TECH_FLY_VMD int
	AI_MAX_TECH_DL_VMD  int
)
View Source
var (
	MAX_FLY_WEIGHT int
	MAX_ABI        int
)
View Source
var (
	MAP_SIZE [2]int
)

Functions

func AICalAllDist

func AICalAllDist()

called for all people

func AICalTechObjs

func AICalTechObjs(ip int, move_loc []int)

func AIMakeDecision

func AIMakeDecision(ip int, move_loc []int)

called for only AI People

func AISetArg

func AISetArg(ip int, goal int, fact_att, fact_def, fact_move int)

func CalDist

func CalDist(center int, weight []int, dist []int)

func Do

func Do() (st int)

func DoOneTurn

func DoOneTurn() (status int)

func DoPeople

func DoPeople(ip int, ui UI) bool

func DoTech

func DoTech(ip int, itech int, obj_loc int, ui UINote) (is_err bool)

如果目标类型错误, 返回 true

func GetAoeRange

func GetAoeRange(cloc int, d int) (aloc []int)

func IAbs

func IAbs(a int) int

func Init

func Init(ui_note UINote, ui_select [2]UISelect, ftech, fmap io.Reader, fintro_name string) bool

func InitAI

func InitAI()

func InitMiniPath

func InitMiniPath()

func LoadAI

func LoadAI(ftech, fmap io.Reader) bool

func LoadAIBase

func LoadAIBase(fin io.Reader) bool

func LoadAIPeople

func LoadAIPeople(fin io.Reader) bool

func LoadDX

func LoadDX(fin io.Reader) bool

func LoadIntro

func LoadIntro(fin_name string)

func LoadMap

func LoadMap(fin io.Reader, ui UINote) bool

func LoadPeople

func LoadPeople(fin io.Reader, ui UINote) bool

func LoadTech

func LoadTech(fin io.Reader) bool

func Loc2XY

func Loc2XY(loc int) (x, y int)

func LocDist

func LocDist(l1, l2 int) int

func MapClearPath

func MapClearPath(is_valid bool)

func MapUpdataAux

func MapUpdataAux()

func MapUpdateWeight

func MapUpdateWeight(opt int)

func MovePeople

func MovePeople(ip int, iloc int, ui UINote)

func RemovePeople

func RemovePeople(ip int, ui UINote)

func SetMovingRange

func SetMovingRange(ip int) (valid_loc []int)

func SetPeople

func SetPeople(ip int, iloc int, ui UINote)

func SetTechRange

func SetTechRange(ip int, itech int)

func StartTurnPeople

func StartTurnPeople()

func XY2Loc

func XY2Loc(x, y int) (loc int)

Types

type AIPeople

type AIPeople struct {
	// contains filtered or unexported fields
}

type Location

type Location struct {
	// contains filtered or unexported fields
}

type MPEdge

type MPEdge struct {
	// contains filtered or unexported fields
}

type NCursesUI

type NCursesUI struct {
	// contains filtered or unexported fields
}

func InitNCursesUI

func InitNCursesUI() *NCursesUI

func (*NCursesUI) CenterCursor

func (nui *NCursesUI) CenterCursor()

func (*NCursesUI) DoTech

func (nui *NCursesUI) DoTech(itech, p_src, p_obj, l_obj int)

func (*NCursesUI) DrawGrid

func (nui *NCursesUI) DrawGrid(x, y int, hp_down int)

func (*NCursesUI) DrawInfo

func (nui *NCursesUI) DrawInfo()

func (*NCursesUI) DrawMapStatic

func (nui *NCursesUI) DrawMapStatic()

func (*NCursesUI) End

func (nui *NCursesUI) End()

func (*NCursesUI) GameOver

func (nui *NCursesUI) GameOver(win_opt int)

func (*NCursesUI) GameStart

func (nui *NCursesUI) GameStart()

func (*NCursesUI) HPDown

func (nui *NCursesUI) HPDown(ip, loc, hp, dhp int)

func (*NCursesUI) LoadMapDone

func (nui *NCursesUI) LoadMapDone()

func (*NCursesUI) LocBuf

func (nui *NCursesUI) LocBuf(loc, att_def, val, dur int)

func (*NCursesUI) LocDisableLong

func (nui *NCursesUI) LocDisableLong(loc, dur int)

func (*NCursesUI) LocFly

func (nui *NCursesUI) LocFly(loc, weight, dur int)

func (*NCursesUI) PeopleIn

func (nui *NCursesUI) PeopleIn(ip, loc int)

func (*NCursesUI) PeopleMove

func (nui *NCursesUI) PeopleMove(ip, loc_start, loc_end int)

func (*NCursesUI) PeopleOut

func (nui *NCursesUI) PeopleOut(ip, loc int)

func (*NCursesUI) PeopleStep

func (nui *NCursesUI) PeopleStep(ip, loc, dir int)

func (*NCursesUI) ShowGrid

func (nui *NCursesUI) ShowGrid(x, y int)

func (*NCursesUI) ShowMsg

func (nui *NCursesUI) ShowMsg(msg string)

func (*NCursesUI) TurnStart

func (nui *NCursesUI) TurnStart(opt int)

func (*NCursesUI) Update

func (nui *NCursesUI) Update()

func (*NCursesUI) UpdateCursor

func (nui *NCursesUI) UpdateCursor(cx, cy int, hp_down int)

func (*NCursesUI) UpdateScroll

func (nui *NCursesUI) UpdateScroll()

type NCursesUIAISelect

type NCursesUIAISelect struct {
	*NCursesUISelect
	// contains filtered or unexported fields
}

func InitNCursesUIAISelect

func InitNCursesUIAISelect(opt int, nui *NCursesUI) *NCursesUIAISelect

func (*NCursesUIAISelect) Confirm

func (nuis *NCursesUIAISelect) Confirm(msg string) bool

return true to confirm quit

func (*NCursesUIAISelect) SelObj

func (nuis *NCursesUIAISelect) SelObj(status SelObjStatus, itech int, valid_loc []int) int

return -1 to quit, -2 to end turn (only for SOS_PEOPLE)

func (*NCursesUIAISelect) SelTech

func (nuis *NCursesUIAISelect) SelTech(ip int) int

return -1 to give up tech use

func (*NCursesUIAISelect) TurnStart

func (nuis *NCursesUIAISelect) TurnStart(opt int)

type NCursesUISelect

type NCursesUISelect struct {
	*NCursesUI
	// contains filtered or unexported fields
}

func InitNCursesUISelect

func InitNCursesUISelect(opt int, nui *NCursesUI) *NCursesUISelect

func (*NCursesUISelect) BrowseOperation

func (nuis *NCursesUISelect) BrowseOperation(c goncurses.Key, cur_p *int)

func (*NCursesUISelect) Confirm

func (nuis *NCursesUISelect) Confirm(msg string) bool

func (*NCursesUISelect) SelObj

func (nuis *NCursesUISelect) SelObj(status SelObjStatus, itech int, valid_loc []int) int

func (*NCursesUISelect) SelTech

func (nuis *NCursesUISelect) SelTech(ip int) int

func (*NCursesUISelect) TurnStart

func (nuis *NCursesUISelect) TurnStart(opt int)

type People

type People struct {
	// contains filtered or unexported fields
}

type SelObjStatus

type SelObjStatus int
const (
	SOS_PEOPLE   SelObjStatus = 0
	SOS_MOVE_OBJ SelObjStatus = 1
	SOS_TECH_OBJ SelObjStatus = 2
)

type Tech

type Tech struct {
	// contains filtered or unexported fields
}

type UI

type UI struct {
	// contains filtered or unexported fields
}

type UINote

type UINote interface {
	/* DoTech triger before HPDown, Loc.. */
	DoTech(itech, p_src, p_obj, l_obj int)
	HPDown(ip, loc, hp, dhp int)
	PeopleIn(ip, loc int)
	PeopleOut(ip, loc int)
	/* PeopleMove trigger after PeopleStep */
	PeopleMove(ip, loc_start, loc_end int)
	PeopleStep(ip, loc, dir int)
	/* att_def: 0: att; 1: def */
	LocBuf(loc, att_def, val, dur int)
	LocFly(loc, weight, dur int)
	LocDisableLong(loc, dur int)

	LoadMapDone()
	GameStart()
	/* win_opt == -1: 退出*/
	GameOver(win_opt int)
}

all UI event is driven before data update

type UISelect

type UISelect interface {
	TurnStart(opt int)
	/* return -1 to quit, -2 to end turn (only for SOS_PEOPLE)
	* valid_loc is only valid in SOS_MOVE_OBJ status
	* */
	SelObj(status SelObjStatus, itech int, valid_loc []int) int
	/* return -1 to give up tech use */
	SelTech(ip int) int
	/* return true to confirm */
	Confirm(msg string) bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL