48 lines
875 B
Go
48 lines
875 B
Go
package main
|
|
|
|
import (
|
|
"math/rand"
|
|
|
|
"github.com/gdamore/tcell/v2"
|
|
)
|
|
|
|
// getFoodItem returns an emoji from a string used to represent food
|
|
// Takes no arguments, but returns an emoji/rune from a predefined string
|
|
// func getFoodItem() rune {
|
|
// var foods string = "🐵🐱🐷🐁🐇🐿🦇🐓🐣🐸🦎🍎🍏"
|
|
// foodsRune := []rune(foods)
|
|
// randomIndex := rand.Intn(len(foodsRune))
|
|
// return foodsRune[randomIndex]
|
|
// }
|
|
|
|
func placeApple(snakex *int, snakey *int) Apple {
|
|
var x, y int
|
|
var found bool
|
|
|
|
for !found {
|
|
|
|
x = rand.Intn(80)
|
|
y = rand.Intn(24)
|
|
|
|
if x != *snakex && y != *snakey {
|
|
found = true
|
|
}
|
|
if x == 0 || x == 79 || y == 0 || y == 23 {
|
|
found = false
|
|
}
|
|
|
|
}
|
|
|
|
apple := Apple{
|
|
x: x,
|
|
y: y,
|
|
}
|
|
|
|
return apple
|
|
|
|
}
|
|
|
|
func drawApple(screen tcell.Screen, style tcell.Style, x int, y int) {
|
|
screen.SetContent(x, y, '🍎', nil, style)
|
|
}
|