/
position_info.go
35 lines (24 loc) · 1.19 KB
/
position_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
// This program merely displays constantly-updated position info.
import (
"fmt"
"time"
"github.com/fohristiwhirl/gofighter" // go get -u github.com/fohristiwhirl/gofighter
)
func main() {
// The following assumes game_start.exe has already been called, and thus that
// there exists a file in the /gm/ directory which contains info about the level.
info := gofighter.GetUserSelection("known_levels.json")
position_queries := make(chan chan gofighter.Position)
go gofighter.PositionWatch(info, position_queries)
// How this works: the goroutine PositionWatch uses a WebSocket to keep track of
// the position, and when we send a channel to it via its input channel, it sends
// a copy of the position back to us along the channel we provided.
for {
position := gofighter.GetPosition(position_queries) // Behind the scenes, this sends a
// one-time channel to the goroutine
fmt.Printf(time.Now().Format("2006-01-02 15:04:05 ... "))
fmt.Printf("Shares: %d, Dollars: $%d\n", position.Shares, position.Cents / 100)
time.Sleep(2 * time.Second)
}
}