#12 It sucks, doesn't work.
This commit is contained in:
		
							
								
								
									
										2
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								main.go
									
									
									
									
									
								
							@@ -1,9 +1,11 @@
 | 
				
			|||||||
 | 
					// An amateurs approach to the game of Snake
 | 
				
			||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// main function
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create channles to manage keypresses and the gamestate
 | 
						// Create channles to manage keypresses and the gamestate
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@ import (
 | 
				
			|||||||
	"github.com/gdamore/tcell/v2"
 | 
						"github.com/gdamore/tcell/v2"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// drawScore Print the score
 | 
				
			||||||
func drawScore(screen tcell.Screen, style tcell.Style, score int) {
 | 
					func drawScore(screen tcell.Screen, style tcell.Style, score int) {
 | 
				
			||||||
	var x, y int = 5, 24
 | 
						var x, y int = 5, 24
 | 
				
			||||||
	for _, r := range []rune("[ Score: " + strconv.FormatInt(int64(score), 10) + " ]") {
 | 
						for _, r := range []rune("[ Score: " + strconv.FormatInt(int64(score), 10) + " ]") {
 | 
				
			||||||
@@ -14,6 +15,7 @@ func drawScore(screen tcell.Screen, style tcell.Style, score int) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// drawCoords Print the coordinates of the head of the snake
 | 
				
			||||||
func drawCoords(screen tcell.Screen, style tcell.Style, snake *Snake) {
 | 
					func drawCoords(screen tcell.Screen, style tcell.Style, snake *Snake) {
 | 
				
			||||||
	var x, y int = 25, 24
 | 
						var x, y int = 25, 24
 | 
				
			||||||
	for _, r := range []rune("[ x:" + strconv.FormatInt(int64(*&snake.head.x), 10) + " y: " + strconv.FormatInt(int64(*&snake.head.y), 10) + " ]") {
 | 
						for _, r := range []rune("[ x:" + strconv.FormatInt(int64(*&snake.head.x), 10) + " y: " + strconv.FormatInt(int64(*&snake.head.y), 10) + " ]") {
 | 
				
			||||||
@@ -22,6 +24,7 @@ func drawCoords(screen tcell.Screen, style tcell.Style, snake *Snake) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// drawBox Draw the outline of the box the snake can move in
 | 
				
			||||||
func drawBox(s tcell.Screen, style tcell.Style, x1, y1, x2, y2 int) {
 | 
					func drawBox(s tcell.Screen, style tcell.Style, x1, y1, x2, y2 int) {
 | 
				
			||||||
	if y2 < y1 {
 | 
						if y2 < y1 {
 | 
				
			||||||
		y1, y2 = y2, y1
 | 
							y1, y2 = y2, y1
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								snake.go
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								snake.go
									
									
									
									
									
								
							@@ -4,6 +4,7 @@ import (
 | 
				
			|||||||
	"github.com/gdamore/tcell/v2"
 | 
						"github.com/gdamore/tcell/v2"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// initSnake Initialize the snake
 | 
				
			||||||
func initSnake(snakex *int, snakey *int) Snake {
 | 
					func initSnake(snakex *int, snakey *int) Snake {
 | 
				
			||||||
	var x, y int = *snakex, *snakey
 | 
						var x, y int = *snakex, *snakey
 | 
				
			||||||
	snake := Snake{
 | 
						snake := Snake{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user