Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

setup.gno

2.74 Kb · 83 lines
 1package engine
 2
 3import "gno.land/p/g1th0masp67zfs9lg6d34qhghldhg6kjcqjuv7c2/gnoslinger/hex/v0"
 4
 5// The showdown's SET UP (rules 3.4 and 29.2; [H3]): each character has its
 6// own hexes to set up in, as a showdown's SET UP assigns them (showdown 1,
 7// Gunfight, lines its two sides up inside the corral; this one puts up to
 8// four around its middle). The seats take the characters in order: the creator is
 9// the first, each player joining the next. Nobody is alerted (29.21): all
10// start upright with the Colt holstered, facing any direction.
11
12// CharSetup is where a character of the showdown sets up: the hexes it may
13// stand in, and the way it faces unless its player turns it.
14type CharSetup struct {
15	Char   string
16	Hexes  []string
17	Facing hex.Dir
18}
19
20// Setups is the showdown played, one character per seat in seat order,
21// each a side of its own, around the middle of the corral: the Marshal on
22// the west side in D5-D7, E6 and E7, the Kid on the east side in H5-H7, G6
23// and G7, Reb to the south in E8, F7, F8 and G8, Yankee to the north in
24// E5, F5, F4 and G5. They face
25// the middle: a flat-top grid has no west or east, so the Marshal looks
26// south-east and the Kid north-west; Reb looks north, Yankee south. A
27// character with no entry is not in the showdown; a game of n seats uses
28// the first n.
29var Setups = []CharSetup{
30	{Char: "marshal", Hexes: []string{"A-D5", "A-D6", "A-D7", "A-E6", "A-E7"}, Facing: hex.SE},
31	{Char: "the_kid", Hexes: []string{"A-H5", "A-H6", "A-H7", "A-G6", "A-G7"}, Facing: hex.NW},
32	{Char: "reb", Hexes: []string{"A-E8", "A-F7", "A-F8", "A-G8"}, Facing: hex.N},
33	{Char: "yankee", Hexes: []string{"A-E5", "A-F5", "A-F4", "A-G5"}, Facing: hex.S},
34}
35
36// SeatChar is the character of a seat, "" for a seat the showdown does not have.
37func SeatChar(seat int) string {
38	if seat < 0 || seat >= len(Setups) {
39		return ""
40	}
41	return Setups[seat].Char
42}
43
44// SetupOf returns the set up of a character, nil when it is not in the showdown.
45func SetupOf(charKey string) *CharSetup {
46	for i := range Setups {
47		if Setups[i].Char == charKey {
48			return &Setups[i]
49		}
50	}
51	return nil
52}
53
54// ShowdownChars lists the characters of the showdown, seats in order.
55func ShowdownChars() []string {
56	out := make([]string, len(Setups))
57	for i, s := range Setups {
58		out[i] = s.Char
59	}
60	return out
61}
62
63// CanSetUp reports whether charKey may set up in hex id: one of its hexes.
64func CanSetUp(charKey, id string) bool {
65	s := SetupOf(charKey)
66	if s == nil {
67		return false
68	}
69	for _, h := range s.Hexes {
70		if h == id {
71			return true
72		}
73	}
74	return false
75}
76
77// SetUp stands seat p's character upright in hex id facing f; the rest of
78// its sheet is left as it is.
79func (s *State) SetUp(p int, id string, f hex.Dir) {
80	s.Chars[p].Hex = id
81	s.Chars[p].Facing = f
82	s.Chars[p].Down = false
83}