From 53508e2ec64762dda73360fde0ff0e64b122350a Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Wed, 27 Sep 2017 06:19:46 -0700 Subject: [PATCH] added go:make_board --- go/make_board/main.go | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 go/make_board/main.go diff --git a/go/make_board/main.go b/go/make_board/main.go new file mode 100644 index 0000000..da3e7c6 --- /dev/null +++ b/go/make_board/main.go @@ -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() + } +}