logger: Llongfile -> Lshortfile
This commit is contained in:
parent
ab91e02f03
commit
07a3313362
2
board.go
2
board.go
|
@ -49,7 +49,7 @@ func ChangeBoardSize(width int, height int) {
|
||||||
board.currentMino = NewMino()
|
board.currentMino = NewMino()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear clears the board to orginal state
|
// Clear clears the board to original state
|
||||||
func (board *Board) Clear() {
|
func (board *Board) Clear() {
|
||||||
board.width = len(boards[board.boardsIndex].colors)
|
board.width = len(boards[board.boardsIndex].colors)
|
||||||
board.height = len(boards[board.boardsIndex].colors[0])
|
board.height = len(boards[board.boardsIndex].colors[0])
|
||||||
|
|
|
@ -1,65 +1,65 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
screen tcell.Screen
|
screen tcell.Screen
|
||||||
x = 0
|
x = 0
|
||||||
y = 1
|
y = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
screen, err = tcell.NewScreen()
|
screen, err = tcell.NewScreen()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("NewScreen error:", err)
|
fmt.Println("NewScreen error:", err)
|
||||||
}
|
}
|
||||||
err = screen.Init()
|
err = screen.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("screen Init error:", err)
|
fmt.Println("screen Init error:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
screen.Clear()
|
screen.Clear()
|
||||||
|
|
||||||
for i := 0; i < 379; i++ {
|
for i := 0; i < 379; i++ {
|
||||||
printNum(i)
|
printNum(i)
|
||||||
style := tcell.StyleDefault.Foreground(tcell.Color(i)).Background(tcell.Color(i)).Dim(true)
|
style := tcell.StyleDefault.Foreground(tcell.Color(i)).Background(tcell.Color(i)).Dim(true)
|
||||||
screen.SetContent(x, y, '▄', nil, style)
|
screen.SetContent(x, y, '▄', nil, style)
|
||||||
x++
|
x++
|
||||||
screen.SetContent(x, y, '▄', nil, style)
|
screen.SetContent(x, y, '▄', nil, style)
|
||||||
x += 2
|
x += 2
|
||||||
if x > 80 {
|
if x > 80 {
|
||||||
x = 0
|
x = 0
|
||||||
y += 2
|
y += 2
|
||||||
}
|
}
|
||||||
if i == 15 {
|
if i == 15 {
|
||||||
i = 255
|
i = 255
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
screen.Show()
|
screen.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
func printNum(num int) {
|
func printNum(num int) {
|
||||||
word := strconv.FormatInt(int64(num), 10) + ":"
|
word := strconv.FormatInt(int64(num), 10) + ":"
|
||||||
if num < 10 {
|
if num < 10 {
|
||||||
word = " " + word
|
word = " " + word
|
||||||
} else if num < 100 {
|
} else if num < 100 {
|
||||||
word = " " + word
|
word = " " + word
|
||||||
}
|
}
|
||||||
if len(word)+x+2 > 80 {
|
if len(word)+x+2 > 80 {
|
||||||
x = 0
|
x = 0
|
||||||
y += 2
|
y += 2
|
||||||
}
|
}
|
||||||
style := tcell.StyleDefault.Foreground(tcell.ColorLightGray).Background(tcell.ColorBlack)
|
style := tcell.StyleDefault.Foreground(tcell.ColorLightGray).Background(tcell.ColorBlack)
|
||||||
for _, char := range word {
|
for _, char := range word {
|
||||||
screen.SetContent(x, y, char, nil, style)
|
screen.SetContent(x, y, char, nil, style)
|
||||||
x++
|
x++
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
416
edit.go
416
edit.go
|
@ -1,208 +1,208 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewEdit creates a new edit mode
|
// NewEdit creates a new edit mode
|
||||||
func NewEdit() {
|
func NewEdit() {
|
||||||
edit = &Edit{moved: true}
|
edit = &Edit{moved: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnabledEditMode enable edit mode
|
// EnabledEditMode enable edit mode
|
||||||
func (edit *Edit) EnabledEditMode() {
|
func (edit *Edit) EnabledEditMode() {
|
||||||
if edit.y > board.height-1 {
|
if edit.y > board.height-1 {
|
||||||
edit.y = board.height - 1
|
edit.y = board.height - 1
|
||||||
}
|
}
|
||||||
if edit.x > board.width-1 {
|
if edit.x > board.width-1 {
|
||||||
edit.x = board.width - 1
|
edit.x = board.width - 1
|
||||||
}
|
}
|
||||||
edit.moved = true
|
edit.moved = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisableEditMode disable edit mode
|
// DisableEditMode disable edit mode
|
||||||
func (edit *Edit) DisableEditMode() {
|
func (edit *Edit) DisableEditMode() {
|
||||||
err := saveUserBoards()
|
err := saveUserBoards()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatal("error saving user boards:", err)
|
logger.Fatal("error saving user boards:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BoardSizeMode changed to board size edit mode
|
// BoardSizeMode changed to board size edit mode
|
||||||
func (edit *Edit) BoardSizeMode() {
|
func (edit *Edit) BoardSizeMode() {
|
||||||
edit.width = board.width
|
edit.width = board.width
|
||||||
edit.height = board.height
|
edit.height = board.height
|
||||||
edit.boardSize = true
|
edit.boardSize = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// BoardWidthIncrement board width increment
|
// BoardWidthIncrement board width increment
|
||||||
func (edit *Edit) BoardWidthIncrement() {
|
func (edit *Edit) BoardWidthIncrement() {
|
||||||
if edit.width > 39 {
|
if edit.width > 39 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
edit.width++
|
edit.width++
|
||||||
}
|
}
|
||||||
|
|
||||||
// BoardWidthDecrement board width decrement
|
// BoardWidthDecrement board width decrement
|
||||||
func (edit *Edit) BoardWidthDecrement() {
|
func (edit *Edit) BoardWidthDecrement() {
|
||||||
if edit.width < 9 {
|
if edit.width < 9 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
edit.width--
|
edit.width--
|
||||||
}
|
}
|
||||||
|
|
||||||
// BoardHeightIncrement board height increment
|
// BoardHeightIncrement board height increment
|
||||||
func (edit *Edit) BoardHeightIncrement() {
|
func (edit *Edit) BoardHeightIncrement() {
|
||||||
if edit.height > 39 {
|
if edit.height > 39 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
edit.height++
|
edit.height++
|
||||||
}
|
}
|
||||||
|
|
||||||
// BoardHeightDecrement board height decrement
|
// BoardHeightDecrement board height decrement
|
||||||
func (edit *Edit) BoardHeightDecrement() {
|
func (edit *Edit) BoardHeightDecrement() {
|
||||||
if edit.height < 9 {
|
if edit.height < 9 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
edit.height--
|
edit.height--
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChangeBoardSize create new board
|
// ChangeBoardSize create new board
|
||||||
func (edit *Edit) ChangeBoardSize() {
|
func (edit *Edit) ChangeBoardSize() {
|
||||||
ChangeBoardSize(edit.width, edit.height)
|
ChangeBoardSize(edit.width, edit.height)
|
||||||
edit.saved = false
|
edit.saved = false
|
||||||
edit.boardSize = false
|
edit.boardSize = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmptyBoard removes all blocks/colors from the board
|
// EmptyBoard removes all blocks/colors from the board
|
||||||
func (edit *Edit) EmptyBoard() {
|
func (edit *Edit) EmptyBoard() {
|
||||||
board.EmptyBoard()
|
board.EmptyBoard()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorUp move cursor up
|
// CursorUp move cursor up
|
||||||
func (edit *Edit) CursorUp() {
|
func (edit *Edit) CursorUp() {
|
||||||
if !edit.moved {
|
if !edit.moved {
|
||||||
edit.moved = true
|
edit.moved = true
|
||||||
}
|
}
|
||||||
if edit.y < 1 {
|
if edit.y < 1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
edit.y--
|
edit.y--
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorDown move cursor down
|
// CursorDown move cursor down
|
||||||
func (edit *Edit) CursorDown() {
|
func (edit *Edit) CursorDown() {
|
||||||
if !edit.moved {
|
if !edit.moved {
|
||||||
edit.moved = true
|
edit.moved = true
|
||||||
}
|
}
|
||||||
if edit.y == board.height-1 {
|
if edit.y == board.height-1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
edit.y++
|
edit.y++
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorRight move cursor right
|
// CursorRight move cursor right
|
||||||
func (edit *Edit) CursorRight() {
|
func (edit *Edit) CursorRight() {
|
||||||
if !edit.moved {
|
if !edit.moved {
|
||||||
edit.moved = true
|
edit.moved = true
|
||||||
}
|
}
|
||||||
if edit.x == board.width-1 {
|
if edit.x == board.width-1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
edit.x++
|
edit.x++
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorLeft move cursor left
|
// CursorLeft move cursor left
|
||||||
func (edit *Edit) CursorLeft() {
|
func (edit *Edit) CursorLeft() {
|
||||||
if !edit.moved {
|
if !edit.moved {
|
||||||
edit.moved = true
|
edit.moved = true
|
||||||
}
|
}
|
||||||
if edit.x < 1 {
|
if edit.x < 1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
edit.x--
|
edit.x--
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetColor sets the board color
|
// SetColor sets the board color
|
||||||
func (edit *Edit) SetColor(color tcell.Color) {
|
func (edit *Edit) SetColor(color tcell.Color) {
|
||||||
if edit.moved {
|
if edit.moved {
|
||||||
edit.moved = false
|
edit.moved = false
|
||||||
}
|
}
|
||||||
if edit.saved {
|
if edit.saved {
|
||||||
edit.saved = false
|
edit.saved = false
|
||||||
}
|
}
|
||||||
board.SetColor(edit.x, edit.y, color, -1)
|
board.SetColor(edit.x, edit.y, color, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RotateLeft rotates cell left
|
// RotateLeft rotates cell left
|
||||||
func (edit *Edit) RotateLeft() {
|
func (edit *Edit) RotateLeft() {
|
||||||
if edit.moved {
|
if edit.moved {
|
||||||
edit.moved = false
|
edit.moved = false
|
||||||
}
|
}
|
||||||
if edit.saved {
|
if edit.saved {
|
||||||
edit.saved = false
|
edit.saved = false
|
||||||
}
|
}
|
||||||
board.RotateLeft(edit.x, edit.y)
|
board.RotateLeft(edit.x, edit.y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RotateRight rotates cell right
|
// RotateRight rotates cell right
|
||||||
func (edit *Edit) RotateRight() {
|
func (edit *Edit) RotateRight() {
|
||||||
if edit.moved {
|
if edit.moved {
|
||||||
edit.moved = false
|
edit.moved = false
|
||||||
}
|
}
|
||||||
if edit.saved {
|
if edit.saved {
|
||||||
edit.saved = false
|
edit.saved = false
|
||||||
}
|
}
|
||||||
board.RotateRight(edit.x, edit.y)
|
board.RotateRight(edit.x, edit.y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawCursor draws the cursor location when cursor moves
|
// DrawCursor draws the cursor location when cursor moves
|
||||||
func (edit *Edit) DrawCursor() {
|
func (edit *Edit) DrawCursor() {
|
||||||
if !edit.moved {
|
if !edit.moved {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
board.DrawCursor(edit.x, edit.y)
|
board.DrawCursor(edit.x, edit.y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveBoard save board
|
// SaveBoard save board
|
||||||
func (edit *Edit) SaveBoard() {
|
func (edit *Edit) SaveBoard() {
|
||||||
if board.boardsIndex < numInternalBoards {
|
if board.boardsIndex < numInternalBoards {
|
||||||
edit.SaveBoardNew()
|
edit.SaveBoardNew()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
boards[board.boardsIndex].colors = board.colors
|
boards[board.boardsIndex].colors = board.colors
|
||||||
boards[board.boardsIndex].rotation = board.rotation
|
boards[board.boardsIndex].rotation = board.rotation
|
||||||
if !edit.saved {
|
if !edit.saved {
|
||||||
edit.saved = true
|
edit.saved = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveBoardNew save board as new board
|
// SaveBoardNew save board as new board
|
||||||
func (edit *Edit) SaveBoardNew() {
|
func (edit *Edit) SaveBoardNew() {
|
||||||
aBoards := Boards{name: time.Now().Format("Jan 2 3:4:5")}
|
aBoards := Boards{name: time.Now().Format("Jan 2 3:4:5")}
|
||||||
aBoards.colors = make([][]tcell.Color, len(board.colors))
|
aBoards.colors = make([][]tcell.Color, len(board.colors))
|
||||||
for i := 0; i < len(board.colors); i++ {
|
for i := 0; i < len(board.colors); i++ {
|
||||||
aBoards.colors[i] = append(aBoards.colors[i], board.colors[i]...)
|
aBoards.colors[i] = append(aBoards.colors[i], board.colors[i]...)
|
||||||
}
|
}
|
||||||
aBoards.rotation = make([][]int, len(board.rotation))
|
aBoards.rotation = make([][]int, len(board.rotation))
|
||||||
for i := 0; i < len(board.rotation); i++ {
|
for i := 0; i < len(board.rotation); i++ {
|
||||||
aBoards.rotation[i] = append(aBoards.rotation[i], board.rotation[i]...)
|
aBoards.rotation[i] = append(aBoards.rotation[i], board.rotation[i]...)
|
||||||
}
|
}
|
||||||
boards = append(boards, aBoards)
|
boards = append(boards, aBoards)
|
||||||
board.boardsIndex = len(boards) - 1
|
board.boardsIndex = len(boards) - 1
|
||||||
if !edit.saved {
|
if !edit.saved {
|
||||||
edit.saved = true
|
edit.saved = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteBoard deletes a board
|
// DeleteBoard deletes a board
|
||||||
func (edit *Edit) DeleteBoard() {
|
func (edit *Edit) DeleteBoard() {
|
||||||
if board.boardsIndex < numInternalBoards {
|
if board.boardsIndex < numInternalBoards {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
boards = append(boards[:board.boardsIndex], boards[board.boardsIndex+1:]...)
|
boards = append(boards[:board.boardsIndex], boards[board.boardsIndex+1:]...)
|
||||||
board.boardsIndex--
|
board.boardsIndex--
|
||||||
board.Clear()
|
board.Clear()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
baseDir, _ = filepath.Abs(filepath.Dir(os.Args[0]))
|
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)
|
logFile, err := os.OpenFile(baseDir+"/go-tetris.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatal("opening log file error:", err)
|
logger.Fatal("opening log file error:", err)
|
||||||
|
|
|
@ -22,7 +22,7 @@ func TestMain(m *testing.M) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupForTesting() {
|
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)
|
rand.Seed(1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue