I'm porting the server from my previous snake-python project from Python 3 to Go, and the frontend to Javascript using HTML5 bindings.
Run the command 'go get github.com/gorilla/websocket' to grab the only dependency. Run 'go install' inside of the source directory to install 'snake-mmo' into '$GOPATH/bin'. Then, start the server with 'snake-mmo' (or '$GOPATH/bin/snake-mmo'), and open snake.html in a web browser.
We need to modify the server to compute and pass the high/current scores, and we need to modify the frontend to parse the high/current scores and attach them to the DOM. Changes that need to be made:
- The message format needs to be changed from "(\(\d+ \d+ \w+\))*" (the escaped parentheses, like "(", mean literal parentheses in the string) to the following in BNF:
message ::== "(" <message-part> ")"
message-part ::== <location-message>
| <score-message>
| <direction-message>
location-message ::== "loc " <number> " " <number> " " <color>
score-message ::== "score " <string> " " <number>
direction-message ::== "dir " <direction>
direction ::== "left" | "right" | "up" | "down"
color ::== a string defined as a constant in color.go
-
func createSendData's internals should be refactored into two functions, createLocationData and createScoreData, which are then concatenated together and returned by createSendData.
-
func decodeMessage needs to be created, which parses the message passed througrh the websocket connection and calls either func decodeDir or func decodeName. It should be called in the "case c := <-h.update" block in func (h *hub) run.
-
func decodeName needs to be created, to parse and return a name.
- Update drawScreen to parse incoming messages. Think about refactoring the parsing part into multiple functions.