From 07a3313362ed262e0e853d7959e6b77e4601f4f7 Mon Sep 17 00:00:00 2001 From: MichaelS11 Date: Fri, 11 Sep 2020 03:33:02 -0700 Subject: [PATCH] logger: Llongfile -> Lshortfile --- board.go | 2 +- colorTest/main.go | 130 +++++++-------- edit.go | 416 +++++++++++++++++++++++----------------------- tetris.go | 2 +- tetris_test.go | 2 +- 5 files changed, 276 insertions(+), 276 deletions(-) diff --git a/board.go b/board.go index 7e7998b..3166ec2 100644 --- a/board.go +++ b/board.go @@ -49,7 +49,7 @@ func ChangeBoardSize(width int, height int) { board.currentMino = NewMino() } -// Clear clears the board to orginal state +// Clear clears the board to original state func (board *Board) Clear() { board.width = len(boards[board.boardsIndex].colors) board.height = len(boards[board.boardsIndex].colors[0]) diff --git a/colorTest/main.go b/colorTest/main.go index 8a1473d..ccef17f 100644 --- a/colorTest/main.go +++ b/colorTest/main.go @@ -1,65 +1,65 @@ -package main - -import ( - "fmt" - "strconv" - - "github.com/gdamore/tcell" -) - -var ( - screen tcell.Screen - x = 0 - y = 1 -) - -func main() { - var err error - screen, err = tcell.NewScreen() - if err != nil { - fmt.Println("NewScreen error:", err) - } - err = screen.Init() - if err != nil { - fmt.Println("screen Init error:", err) - } - - screen.Clear() - - for i := 0; i < 379; i++ { - printNum(i) - style := tcell.StyleDefault.Foreground(tcell.Color(i)).Background(tcell.Color(i)).Dim(true) - screen.SetContent(x, y, '▄', nil, style) - x++ - screen.SetContent(x, y, '▄', nil, style) - x += 2 - if x > 80 { - x = 0 - y += 2 - } - if i == 15 { - i = 255 - } - } - - screen.Show() -} - -func printNum(num int) { - word := strconv.FormatInt(int64(num), 10) + ":" - if num < 10 { - word = " " + word - } else if num < 100 { - word = " " + word - } - if len(word)+x+2 > 80 { - x = 0 - y += 2 - } - style := tcell.StyleDefault.Foreground(tcell.ColorLightGray).Background(tcell.ColorBlack) - for _, char := range word { - screen.SetContent(x, y, char, nil, style) - x++ - } - -} +package main + +import ( + "fmt" + "strconv" + + "github.com/gdamore/tcell" +) + +var ( + screen tcell.Screen + x = 0 + y = 1 +) + +func main() { + var err error + screen, err = tcell.NewScreen() + if err != nil { + fmt.Println("NewScreen error:", err) + } + err = screen.Init() + if err != nil { + fmt.Println("screen Init error:", err) + } + + screen.Clear() + + for i := 0; i < 379; i++ { + printNum(i) + style := tcell.StyleDefault.Foreground(tcell.Color(i)).Background(tcell.Color(i)).Dim(true) + screen.SetContent(x, y, '▄', nil, style) + x++ + screen.SetContent(x, y, '▄', nil, style) + x += 2 + if x > 80 { + x = 0 + y += 2 + } + if i == 15 { + i = 255 + } + } + + screen.Show() +} + +func printNum(num int) { + word := strconv.FormatInt(int64(num), 10) + ":" + if num < 10 { + word = " " + word + } else if num < 100 { + word = " " + word + } + if len(word)+x+2 > 80 { + x = 0 + y += 2 + } + style := tcell.StyleDefault.Foreground(tcell.ColorLightGray).Background(tcell.ColorBlack) + for _, char := range word { + screen.SetContent(x, y, char, nil, style) + x++ + } + +} diff --git a/edit.go b/edit.go index a1f6c94..5997dd2 100644 --- a/edit.go +++ b/edit.go @@ -1,208 +1,208 @@ -package main - -import ( - "time" - - "github.com/gdamore/tcell" -) - -// NewEdit creates a new edit mode -func NewEdit() { - edit = &Edit{moved: true} -} - -// EnabledEditMode enable edit mode -func (edit *Edit) EnabledEditMode() { - if edit.y > board.height-1 { - edit.y = board.height - 1 - } - if edit.x > board.width-1 { - edit.x = board.width - 1 - } - edit.moved = true -} - -// DisableEditMode disable edit mode -func (edit *Edit) DisableEditMode() { - err := saveUserBoards() - if err != nil { - logger.Fatal("error saving user boards:", err) - } -} - -// BoardSizeMode changed to board size edit mode -func (edit *Edit) BoardSizeMode() { - edit.width = board.width - edit.height = board.height - edit.boardSize = true -} - -// BoardWidthIncrement board width increment -func (edit *Edit) BoardWidthIncrement() { - if edit.width > 39 { - return - } - edit.width++ -} - -// BoardWidthDecrement board width decrement -func (edit *Edit) BoardWidthDecrement() { - if edit.width < 9 { - return - } - edit.width-- -} - -// BoardHeightIncrement board height increment -func (edit *Edit) BoardHeightIncrement() { - if edit.height > 39 { - return - } - edit.height++ -} - -// BoardHeightDecrement board height decrement -func (edit *Edit) BoardHeightDecrement() { - if edit.height < 9 { - return - } - edit.height-- -} - -// ChangeBoardSize create new board -func (edit *Edit) ChangeBoardSize() { - ChangeBoardSize(edit.width, edit.height) - edit.saved = false - edit.boardSize = false -} - -// EmptyBoard removes all blocks/colors from the board -func (edit *Edit) EmptyBoard() { - board.EmptyBoard() -} - -// CursorUp move cursor up -func (edit *Edit) CursorUp() { - if !edit.moved { - edit.moved = true - } - if edit.y < 1 { - return - } - edit.y-- -} - -// CursorDown move cursor down -func (edit *Edit) CursorDown() { - if !edit.moved { - edit.moved = true - } - if edit.y == board.height-1 { - return - } - edit.y++ -} - -// CursorRight move cursor right -func (edit *Edit) CursorRight() { - if !edit.moved { - edit.moved = true - } - if edit.x == board.width-1 { - return - } - edit.x++ -} - -// CursorLeft move cursor left -func (edit *Edit) CursorLeft() { - if !edit.moved { - edit.moved = true - } - if edit.x < 1 { - return - } - edit.x-- -} - -// SetColor sets the board color -func (edit *Edit) SetColor(color tcell.Color) { - if edit.moved { - edit.moved = false - } - if edit.saved { - edit.saved = false - } - board.SetColor(edit.x, edit.y, color, -1) -} - -// RotateLeft rotates cell left -func (edit *Edit) RotateLeft() { - if edit.moved { - edit.moved = false - } - if edit.saved { - edit.saved = false - } - board.RotateLeft(edit.x, edit.y) -} - -// RotateRight rotates cell right -func (edit *Edit) RotateRight() { - if edit.moved { - edit.moved = false - } - if edit.saved { - edit.saved = false - } - board.RotateRight(edit.x, edit.y) -} - -// DrawCursor draws the cursor location when cursor moves -func (edit *Edit) DrawCursor() { - if !edit.moved { - return - } - board.DrawCursor(edit.x, edit.y) -} - -// SaveBoard save board -func (edit *Edit) SaveBoard() { - if board.boardsIndex < numInternalBoards { - edit.SaveBoardNew() - return - } - boards[board.boardsIndex].colors = board.colors - boards[board.boardsIndex].rotation = board.rotation - if !edit.saved { - edit.saved = true - } -} - -// SaveBoardNew save board as new board -func (edit *Edit) SaveBoardNew() { - aBoards := Boards{name: time.Now().Format("Jan 2 3:4:5")} - aBoards.colors = make([][]tcell.Color, len(board.colors)) - for i := 0; i < len(board.colors); i++ { - aBoards.colors[i] = append(aBoards.colors[i], board.colors[i]...) - } - aBoards.rotation = make([][]int, len(board.rotation)) - for i := 0; i < len(board.rotation); i++ { - aBoards.rotation[i] = append(aBoards.rotation[i], board.rotation[i]...) - } - boards = append(boards, aBoards) - board.boardsIndex = len(boards) - 1 - if !edit.saved { - edit.saved = true - } -} - -// DeleteBoard deletes a board -func (edit *Edit) DeleteBoard() { - if board.boardsIndex < numInternalBoards { - return - } - boards = append(boards[:board.boardsIndex], boards[board.boardsIndex+1:]...) - board.boardsIndex-- - board.Clear() -} +package main + +import ( + "time" + + "github.com/gdamore/tcell" +) + +// NewEdit creates a new edit mode +func NewEdit() { + edit = &Edit{moved: true} +} + +// EnabledEditMode enable edit mode +func (edit *Edit) EnabledEditMode() { + if edit.y > board.height-1 { + edit.y = board.height - 1 + } + if edit.x > board.width-1 { + edit.x = board.width - 1 + } + edit.moved = true +} + +// DisableEditMode disable edit mode +func (edit *Edit) DisableEditMode() { + err := saveUserBoards() + if err != nil { + logger.Fatal("error saving user boards:", err) + } +} + +// BoardSizeMode changed to board size edit mode +func (edit *Edit) BoardSizeMode() { + edit.width = board.width + edit.height = board.height + edit.boardSize = true +} + +// BoardWidthIncrement board width increment +func (edit *Edit) BoardWidthIncrement() { + if edit.width > 39 { + return + } + edit.width++ +} + +// BoardWidthDecrement board width decrement +func (edit *Edit) BoardWidthDecrement() { + if edit.width < 9 { + return + } + edit.width-- +} + +// BoardHeightIncrement board height increment +func (edit *Edit) BoardHeightIncrement() { + if edit.height > 39 { + return + } + edit.height++ +} + +// BoardHeightDecrement board height decrement +func (edit *Edit) BoardHeightDecrement() { + if edit.height < 9 { + return + } + edit.height-- +} + +// ChangeBoardSize create new board +func (edit *Edit) ChangeBoardSize() { + ChangeBoardSize(edit.width, edit.height) + edit.saved = false + edit.boardSize = false +} + +// EmptyBoard removes all blocks/colors from the board +func (edit *Edit) EmptyBoard() { + board.EmptyBoard() +} + +// CursorUp move cursor up +func (edit *Edit) CursorUp() { + if !edit.moved { + edit.moved = true + } + if edit.y < 1 { + return + } + edit.y-- +} + +// CursorDown move cursor down +func (edit *Edit) CursorDown() { + if !edit.moved { + edit.moved = true + } + if edit.y == board.height-1 { + return + } + edit.y++ +} + +// CursorRight move cursor right +func (edit *Edit) CursorRight() { + if !edit.moved { + edit.moved = true + } + if edit.x == board.width-1 { + return + } + edit.x++ +} + +// CursorLeft move cursor left +func (edit *Edit) CursorLeft() { + if !edit.moved { + edit.moved = true + } + if edit.x < 1 { + return + } + edit.x-- +} + +// SetColor sets the board color +func (edit *Edit) SetColor(color tcell.Color) { + if edit.moved { + edit.moved = false + } + if edit.saved { + edit.saved = false + } + board.SetColor(edit.x, edit.y, color, -1) +} + +// RotateLeft rotates cell left +func (edit *Edit) RotateLeft() { + if edit.moved { + edit.moved = false + } + if edit.saved { + edit.saved = false + } + board.RotateLeft(edit.x, edit.y) +} + +// RotateRight rotates cell right +func (edit *Edit) RotateRight() { + if edit.moved { + edit.moved = false + } + if edit.saved { + edit.saved = false + } + board.RotateRight(edit.x, edit.y) +} + +// DrawCursor draws the cursor location when cursor moves +func (edit *Edit) DrawCursor() { + if !edit.moved { + return + } + board.DrawCursor(edit.x, edit.y) +} + +// SaveBoard save board +func (edit *Edit) SaveBoard() { + if board.boardsIndex < numInternalBoards { + edit.SaveBoardNew() + return + } + boards[board.boardsIndex].colors = board.colors + boards[board.boardsIndex].rotation = board.rotation + if !edit.saved { + edit.saved = true + } +} + +// SaveBoardNew save board as new board +func (edit *Edit) SaveBoardNew() { + aBoards := Boards{name: time.Now().Format("Jan 2 3:4:5")} + aBoards.colors = make([][]tcell.Color, len(board.colors)) + for i := 0; i < len(board.colors); i++ { + aBoards.colors[i] = append(aBoards.colors[i], board.colors[i]...) + } + aBoards.rotation = make([][]int, len(board.rotation)) + for i := 0; i < len(board.rotation); i++ { + aBoards.rotation[i] = append(aBoards.rotation[i], board.rotation[i]...) + } + boards = append(boards, aBoards) + board.boardsIndex = len(boards) - 1 + if !edit.saved { + edit.saved = true + } +} + +// DeleteBoard deletes a board +func (edit *Edit) DeleteBoard() { + if board.boardsIndex < numInternalBoards { + return + } + boards = append(boards[:board.boardsIndex], boards[board.boardsIndex+1:]...) + board.boardsIndex-- + board.Clear() +} diff --git a/tetris.go b/tetris.go index 6f47128..8a07785 100644 --- a/tetris.go +++ b/tetris.go @@ -10,7 +10,7 @@ import ( func main() { baseDir, _ = filepath.Abs(filepath.Dir(os.Args[0])) - logger = log.New(os.Stderr, "", log.Ldate|log.Ltime|log.LUTC|log.Llongfile) + logger = log.New(os.Stderr, "", log.Ldate|log.Ltime|log.LUTC|log.Lshortfile) logFile, err := os.OpenFile(baseDir+"/go-tetris.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) if err != nil { logger.Fatal("opening log file error:", err) diff --git a/tetris_test.go b/tetris_test.go index 7888534..050812d 100644 --- a/tetris_test.go +++ b/tetris_test.go @@ -22,7 +22,7 @@ func TestMain(m *testing.M) { } func setupForTesting() { - logger = log.New(os.Stdout, "", log.Ldate|log.Ltime|log.LUTC|log.Llongfile) + logger = log.New(os.Stdout, "", log.Ldate|log.Ltime|log.LUTC|log.Lshortfile) rand.Seed(1)