@@ -12,7 +12,6 @@ import (
1212 gc "github.com/rthornton128/goncurses"
1313)
1414
15- // Trackers
1615var (
1716 globalScore int
1817 startTime time.Time
@@ -54,7 +53,6 @@ type Screen struct {
5453 rows , cols int
5554}
5655
57- // Logo
5856func drawBorder (stdscr * gc.Window ) {
5957 stdscr .ColorOn (3 )
6058 stdscr .Box (gc .ACS_VLINE , gc .ACS_HLINE )
@@ -71,46 +69,29 @@ func drawLogo(stdscr *gc.Window, rows, cols int) {
7169
7270func initColors () {
7371 // Set up colors.
74- if err := gc .InitPair (1 , gc .C_GREEN , gc .C_BLACK ); err != nil {
75- log .Fatal ("InitPair failed: " , err )
76- }
77-
78- if err := gc .InitPair (2 , gc .C_RED , gc .C_BLACK ); err != nil {
79- log .Fatal ("InitPair failed: " , err )
80- }
81-
82- if err := gc .InitPair (3 , gc .C_YELLOW , gc .C_BLACK ); err != nil {
83- log .Fatal ("InitPair failed: " , err )
84- }
85-
86- if err := gc .InitPair (4 , gc .C_MAGENTA , gc .C_BLACK ); err != nil {
87- log .Fatal ("InitPair failed: " , err )
88- }
89-
90- if err := gc .InitPair (5 , gc .C_BLACK , gc .C_BLACK ); err != nil {
91- log .Fatal ("InitPair failed: " , err )
92- }
93-
94- if err := gc .InitPair (6 , gc .C_WHITE , gc .C_BLACK ); err != nil {
95- log .Fatal ("InitPair failed: " , err )
96- }
72+ tools .Check (gc .InitPair (1 , gc .C_GREEN , gc .C_BLACK ))
73+ tools .Check (gc .InitPair (2 , gc .C_RED , gc .C_BLACK ))
74+ tools .Check (gc .InitPair (3 , gc .C_YELLOW , gc .C_BLACK ))
75+ tools .Check (gc .InitPair (4 , gc .C_MAGENTA , gc .C_BLACK ))
76+ tools .Check (gc .InitPair (5 , gc .C_BLACK , gc .C_BLACK ))
77+ tools .Check (gc .InitPair (6 , gc .C_WHITE , gc .C_BLACK ))
9778}
9879
99- // InitFood initializes the foods position.
80+ // printFood prints the symbol for food at a given position.
10081func printFood (stdscr * gc.Window , newFood * Food , rows , cols int ) {
10182 stdscr .ColorOn (2 )
10283 stdscr .MoveAddChar (newFood .y , newFood .x , foodChar )
10384 stdscr .ColorOff (2 )
10485}
10586
106- // InitFood initializes the foods position
87+ // InitFood initializes the foods position.
10788func initFood (stdscr * gc.Window , myFood * Food , rows , cols int ) {
10889 if myFood .y == 0 && myFood .x == 0 {
10990 for ! testFoodCollision (stdscr , myFood , rows , cols ) {
11091 myFood .y = rand .Intn (rows )
11192 myFood .x = rand .Intn (cols )
11293 }
113- // Start timer for score
94+ // Start the timer for the score calculation.
11495 startTime = time .Now ()
11596 }
11697}
@@ -268,7 +249,7 @@ func calcBoardSize(stdscr *gc.Window) {
268249}
269250
270251func SetupGameBoard () * gc.Window {
271- // Setup stdscr buffer
252+ // Setup stdscr buffer.
272253 stdscr , err := gc .Init ()
273254 calcBoardSize (stdscr )
274255 if err != nil {
@@ -283,10 +264,8 @@ func SetupGameBoard() *gc.Window {
283264 log .Fatal ("Require a color capable terminal" )
284265 }
285266
286- // Initalize use of color
287- if err := gc .StartColor (); err != nil {
288- log .Fatal (err )
289- }
267+ // Initalize the use of color.
268+ tools .Check (gc .StartColor ())
290269
291270 gc .Echo (false )
292271 gc .Cursor (0 ) // Hide cursor
0 commit comments