Browse Source

Add log in form

register
Trevor Slocum 3 months ago
parent
commit
dc1881064c
  1. 13
      README.md
  2. 58
      app.go
  3. 1
      board.go
  4. 2
      go.mod
  5. BIN
      screenshot.png

13
README.md

@ -3,17 +3,24 @@
Terminal-based online backgammon client ([FIBS](http://fibs.com))
**Note:** Incomplete. Stay tuned.
[![Screenshot](https://code.rocketnine.space/tslocum/bgammon/raw/branch/master/screenshot.png)](https://code.rocketnine.space/tslocum/bgammon/raw/branch/master/screenshot.png)
When this is playable, a demo will be available at:
## Play via SSH
To play via SSH, execute the following command:
`ssh rocketnine.space -p 5000`
See [this page](https://bkgm.com/rules.html) for information on how to play backgammon.
A FIBS account is required to play. See [this page](http://www.fibs.com/help.html#register) for information on how to register.
## Missing features
- Doubling
- User info display
- Display pre-moves before submitting
- Chat system (tab through chat types)
- Displaying pre-moves before they are submitted
## Installation

58
app.go

@ -26,6 +26,15 @@ func (w *appWriter) Write(p []byte) (int, error) {
return n, err
}
func (c *Client) connect() {
l("Connecting...")
err := telnet.DialToAndCall("fibs.com:4321", c)
if err != nil {
lf("disconnected: %s", err)
}
}
func RunApp(c *Client) error {
app = cview.NewApplication()
app.EnableMouse(true)
@ -47,16 +56,49 @@ func RunApp(c *Client) error {
f.AddItem(statusBuffer, 0, 1, false)
f.AddItem(inputField, 1, 1, true)
app.SetRoot(f, true)
form := cview.NewForm()
usernameField := cview.NewInputField()
usernameField.SetLabel("Username")
usernameField.SetFieldWidth(16)
passwordField := cview.NewInputField()
passwordField.SetLabel("Password")
passwordField.SetFieldWidth(16)
passwordField.SetMaskCharacter('*')
form.AddFormItem(usernameField)
form.AddFormItem(passwordField)
form.AddButton("Connect", func() {
c.username = usernameField.GetText()
c.password = passwordField.GetText()
app.SetRoot(f, true)
app.SetFocus(inputField)
go c.connect()
})
form.SetPadding(1, 0, 2, 0)
logInHeader := cview.NewTextView()
logInHeader.SetDynamicColors(true)
logInHeader.SetText("\n [" + cview.ColorHex(cview.Styles.SecondaryTextColor) + "] Connect to FIBS[-]")
logInFooter := cview.NewTextView()
logInFooter.SetText(" For information on how to play backgammon, visit\n https://bkgm.com/rules.html\n\n For information on how to register, visit\n http://www.fibs.com/help.html#register\n\n For information on bgammon (this FIBS client), visit\n https://code.rocketnine.space/tslocum/bgammon")
f2 := cview.NewFlex() // Login flex
f2.SetDirection(cview.FlexRow)
f2.AddItem(logInHeader, 2, 1, true)
f2.AddItem(form, 8, 1, true)
f2.AddItem(logInFooter, 0, 1, true)
app.SetFocus(inputField)
if c.username == "" || c.password == "" {
app.SetRoot(f2, true)
app.SetFocus(form)
} else {
app.SetRoot(f, true)
app.SetFocus(inputField)
go func() {
err := telnet.DialToAndCall("fibs.com:4321", c)
if err != nil {
lf("disconnected: %s", err)
}
}()
go c.connect()
}
return app.Run()
}

1
board.go

@ -223,7 +223,6 @@ func (b *Board) Update() {
if b.selected[0] == 0 && spaceValue <= b.selected[1] {
r = []byte("*")
} else {
lf("%+v %d", b.selected, i-5)
r = []byte(playerColor)
}
}

2
go.mod

@ -1,4 +1,4 @@
module code.rocketnine.spacetslocum/bgammon
module code.rocketnine.space/tslocum/bgammon
go 1.16

BIN
screenshot.png

After

Width: 735  |  Height: 483  |  Size: 51 KiB

Loading…
Cancel
Save