added go:make_board
This commit is contained in:
parent
c57f8e4a86
commit
53508e2ec6
47
go/make_board/main.go
Normal file
47
go/make_board/main.go
Normal file
@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
const board_y int = 7
|
||||
const board_x int = 12
|
||||
|
||||
board := make_board(board_y, board_x)
|
||||
|
||||
// Pretend that the player did something in the middle
|
||||
player_move_y := board_y / 2
|
||||
player_move_x := board_x / 2
|
||||
|
||||
board[player_move_y][player_move_x] = "@ "
|
||||
|
||||
print_board(board)
|
||||
|
||||
}
|
||||
|
||||
func make_board(size_y, size_x int) [][]string {
|
||||
//Make an array of empty strings
|
||||
// Rows
|
||||
board := make([][]string, size_y)
|
||||
|
||||
for y := 0; y < size_y; y++ {
|
||||
//Make each array an array of empty strings
|
||||
//cols
|
||||
board[y] = make([]string, size_x)
|
||||
// and populate em
|
||||
for x := 0; x < size_x; x++ {
|
||||
board[y][x] = "_ "
|
||||
}
|
||||
}
|
||||
return board
|
||||
}
|
||||
|
||||
func print_board(board [][]string) {
|
||||
for y := 0; y < len(board); y++ {
|
||||
for x := 0; x < len(board[y]); x++ {
|
||||
fmt.Print(board[y][x])
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user