[Golang] Online Snake Game by GopherJS
In GopherJS DOM Example series, we show a lot of examples of DOM manipulation by GopherJS and its DOM binding. Now we will use what we learn to write a simple snake game. I wrote an online snake game in Dart (see [5]) before. This Golang snake game is ported from the Dart version. The DOM APIs provided by GopherJS and its DOM bindings are basically the same as JavaScript DOM APIs, except it is re-written in idiomatic Go. This is a good exercise to make you familiar with DOM manipulation in Go programming language.
Source Code for Demo (HTML):
Source Code for Demo (CSS):
Source Code for Demo (Go):
Tested on: Ubuntu Linux 15.10, Go 1.5.2.
GopherJS DOM Example series
- [Golang] GopherJS DOM Example - getElementById and Set innerHTML
- [Golang] GopherJS DOM Example - Event Binding (addEventListener)
- [Golang] GopherJS DOM Example - Detect Keypress (Keyboard Event)
- [Golang] GopherJS DOM Example - Access Input Element Value
- [Golang] GopherJS DOM Example - Access HTML Data Attribute
- [Golang] Online Input Method (Pāli) by GopherJS
- [Golang] GopherJS DOM Example - Hide Element by display:none
- [Golang] GopherJS DOM Example - Create and Append Element
- [Golang] GopherJS DOM Example - Play Sound on Click Event
- [Golang] GopherJS DOM Example - Toggle (Play/Pause) Sound on Click Event
- [Golang] GopherJS DOM Example - Dropdown Menu
- [Golang] Draggable (Movable) Element by GopherJS
- [Golang] Toggle (Show/Hide) HTML Element by GopherJS
References:
[1] | GopherJS - A compiler from Go to JavaScript (GitHub, GopherJS Playground, ) |
[2] | Bindings · gopherjs/gopherjs Wiki · GitHub |
[3] | dom - GopherJS bindings for the JavaScript DOM APIs (GitHub) |
[4] | Getting Started with GopherJS |
[5] | siongui/dart-snake-game · GitHub (demo) |
[6] | Canvas Particles Using Gopherjs |