go-tetris/view.go

464 lines
15 KiB
Go
Raw Normal View History

2017-03-27 15:07:29 -05:00
package main
import (
"fmt"
"math/rand"
2017-03-27 15:07:29 -05:00
"time"
2019-12-01 15:03:27 -06:00
"github.com/gdamore/tcell"
2017-03-27 15:07:29 -05:00
)
2018-10-02 20:21:08 -05:00
// NewView creates a new view
func NewView() {
2019-12-01 15:03:27 -06:00
var err error
screen, err = tcell.NewScreen()
if err != nil {
logger.Fatal("NewScreen error:", err)
}
err = screen.Init()
2017-03-27 15:07:29 -05:00
if err != nil {
2019-12-01 15:03:27 -06:00
logger.Fatal("screen Init error:", err)
2017-03-27 15:07:29 -05:00
}
2019-12-01 15:03:27 -06:00
screen.Clear()
view = &View{}
2017-03-27 15:07:29 -05:00
}
2018-10-02 20:21:08 -05:00
// Stop stops the view
2017-03-27 15:07:29 -05:00
func (view *View) Stop() {
2018-06-01 10:16:36 -05:00
logger.Println("View Stop start")
2017-03-27 15:07:29 -05:00
2019-12-01 15:03:27 -06:00
screen.Fini()
2017-03-27 15:07:29 -05:00
2018-06-01 10:16:36 -05:00
logger.Println("View Stop end")
2017-03-27 15:07:29 -05:00
}
2019-12-01 15:03:27 -06:00
// RefreshScreen refreshes the updated view to the screen
2017-03-27 15:07:29 -05:00
func (view *View) RefreshScreen() {
2019-12-01 15:03:27 -06:00
switch engine.mode {
case engineModeRun, engineModeRunWithAI:
view.drawBoardBoarder()
view.drawPreviewBoarder()
view.drawTexts()
board.DrawBoard()
board.DrawPreviewMino()
board.DrawDropMino()
board.DrawCurrentMino()
screen.Show()
case engineModePaused:
screen.Fill(' ', tcell.StyleDefault.Foreground(tcell.ColorBlack).Background(tcell.ColorBlack))
view.drawBoardBoarder()
view.drawPreviewBoarder()
view.drawTexts()
view.drawPaused()
screen.Show()
case engineModeGameOver:
view.drawBoardBoarder()
view.drawPreviewBoarder()
view.drawTexts()
view.drawGameOver()
view.drawRankingScores()
screen.Show()
case engineModePreview:
screen.Fill(' ', tcell.StyleDefault.Foreground(tcell.ColorBlack).Background(tcell.ColorBlack))
view.drawBoardBoarder()
view.drawPreviewBoarder()
view.drawTexts()
board.DrawBoard()
view.drawGameOver()
screen.Show()
2019-01-09 20:30:45 -06:00
2019-12-01 15:03:27 -06:00
case engineModeEdit:
screen.Fill(' ', tcell.StyleDefault.Foreground(tcell.ColorBlack).Background(tcell.ColorBlack))
view.drawBoardBoarder()
board.DrawBoard()
2019-01-09 20:30:45 -06:00
if edit.boardSize {
view.drawEditTextsBoardSize()
} else {
edit.DrawCursor()
view.drawEditTexts()
}
2019-12-01 15:03:27 -06:00
screen.Show()
2019-01-09 20:30:45 -06:00
}
2017-03-27 15:07:29 -05:00
}
2019-12-01 15:03:27 -06:00
// drawBoardBoarder draws the board boarder
2019-01-09 20:30:45 -06:00
func (view *View) drawBoardBoarder() {
2017-03-27 15:07:29 -05:00
xOffset := boardXOffset
yOffset := boardYOffset
xEnd := boardXOffset + board.width*2 + 4
yEnd := boardYOffset + board.height + 2
2019-12-01 15:03:27 -06:00
styleBoarder := tcell.StyleDefault.Foreground(tcell.ColorBlack).Background(tcell.ColorLightGray)
styleBoard := tcell.StyleDefault.Foreground(tcell.ColorLightGray).Background(tcell.ColorBlack)
2017-03-27 15:07:29 -05:00
for x := xOffset; x < xEnd; x++ {
for y := yOffset; y < yEnd; y++ {
2019-12-01 15:03:27 -06:00
if x == xOffset || x == xOffset+1 || x == xEnd-1 || x == xEnd-2 || y == yOffset || y == yEnd-1 {
screen.SetContent(x, y, ' ', nil, styleBoarder)
2017-03-27 15:07:29 -05:00
} else {
2019-12-01 15:03:27 -06:00
screen.SetContent(x, y, ' ', nil, styleBoard)
2017-03-27 15:07:29 -05:00
}
}
}
2019-01-09 20:30:45 -06:00
}
2017-03-27 15:07:29 -05:00
2019-01-09 20:30:45 -06:00
// drawPreviewBoarder draws the preview boarder
func (view *View) drawPreviewBoarder() {
xOffset := boardXOffset + board.width*2 + 8
yOffset := boardYOffset
xEnd := xOffset + 14
yEnd := yOffset + 6
2019-12-01 15:03:27 -06:00
styleBoarder := tcell.StyleDefault.Foreground(tcell.ColorBlack).Background(tcell.ColorLightGray)
styleBoard := tcell.StyleDefault.Foreground(tcell.ColorLightGray).Background(tcell.ColorBlack)
2017-03-27 15:07:29 -05:00
for x := xOffset; x < xEnd; x++ {
for y := yOffset; y < yEnd; y++ {
2019-12-01 15:03:27 -06:00
if x == xOffset || x == xOffset+1 || x == xEnd-1 || x == xEnd-2 || y == yOffset || y == yEnd-1 {
screen.SetContent(x, y, ' ', nil, styleBoarder)
2017-03-27 15:07:29 -05:00
} else {
2019-12-01 15:03:27 -06:00
screen.SetContent(x, y, ' ', nil, styleBoard)
2017-03-27 15:07:29 -05:00
}
}
}
}
2018-10-02 20:21:08 -05:00
// drawTexts draws the text
2017-03-27 15:07:29 -05:00
func (view *View) drawTexts() {
xOffset := boardXOffset + board.width*2 + 8
2017-03-27 15:07:29 -05:00
yOffset := boardYOffset + 7
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "SCORE:", tcell.ColorLightGray, tcell.ColorDarkBlue)
view.drawText(xOffset+7, yOffset, fmt.Sprintf("%7d", engine.score), tcell.ColorBlack, tcell.ColorLightGray)
2017-03-27 15:07:29 -05:00
yOffset += 2
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "LINES:", tcell.ColorLightGray, tcell.ColorDarkBlue)
view.drawText(xOffset+7, yOffset, fmt.Sprintf("%7d", engine.deleteLines), tcell.ColorBlack, tcell.ColorLightGray)
2017-03-27 15:07:29 -05:00
yOffset += 2
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "LEVEL:", tcell.ColorLightGray, tcell.ColorDarkBlue)
view.drawText(xOffset+7, yOffset, fmt.Sprintf("%4d", engine.level), tcell.ColorBlack, tcell.ColorLightGray)
2017-03-27 15:07:29 -05:00
yOffset += 2
// ascii arrow characters add extra two spaces
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "← - left", tcell.ColorLightGray, tcell.ColorBlack)
2017-03-27 15:07:29 -05:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "→ - right", tcell.ColorLightGray, tcell.ColorBlack)
2017-03-27 15:07:29 -05:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "↓ - soft drop", tcell.ColorLightGray, tcell.ColorBlack)
2017-03-27 15:07:29 -05:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "↑ - hard drop", tcell.ColorLightGray, tcell.ColorBlack)
2017-03-27 15:07:29 -05:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "sbar - hard drop", tcell.ColorLightGray, tcell.ColorBlack)
2017-03-27 15:07:29 -05:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "z - rotate left", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "x - rotate right", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "p - pause", tcell.ColorLightGray, tcell.ColorBlack)
2017-03-27 15:07:29 -05:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "q - quit", tcell.ColorLightGray, tcell.ColorBlack)
2017-03-27 15:07:29 -05:00
}
2019-01-09 20:30:45 -06:00
// drawEditTexts draws the edit text
func (view *View) drawEditTexts() {
xOffset := boardXOffset + board.width*2 + 8
yOffset := boardYOffset
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "Name:", tcell.ColorLightGray, tcell.ColorDarkBlue)
view.drawText(xOffset+7, yOffset, boards[board.boardsIndex].name, tcell.ColorBlack, tcell.ColorLightGray)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "Saved:", tcell.ColorLightGray, tcell.ColorDarkBlue)
2019-01-09 20:30:45 -06:00
if edit.saved {
2019-12-01 15:03:27 -06:00
view.drawText(xOffset+7, yOffset, "yes", tcell.ColorBlack, tcell.ColorLightGray)
2019-01-09 20:30:45 -06:00
} else {
2019-12-01 15:03:27 -06:00
view.drawText(xOffset+7, yOffset, "no", tcell.ColorBlack, tcell.ColorLightGray)
2019-01-09 20:30:45 -06:00
}
yOffset += 2
// ascii arrow characters add extra two spaces
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "← - left", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "→ - right", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "↓ - down", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "↑ - up", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "z - rotate left", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "x - rotate right", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "c - cyan", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "b - blue", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "w - white", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "e - yellow", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "g - green", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "a - magenta", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "r - red", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "f - free", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "ctrl b - change board size", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "ctrl s - save board", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "ctrl n - save board as new", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "ctrl k - delete board", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "ctrl o - empty board", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "ctrl q - quit", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
}
// drawEditTextsBoardSize draws the edit text for board size mode
func (view *View) drawEditTextsBoardSize() {
xOffset := boardXOffset + board.width*2 + 8
yOffset := boardYOffset
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "Name:", tcell.ColorLightGray, tcell.ColorDarkBlue)
view.drawText(xOffset+7, yOffset, boards[board.boardsIndex].name, tcell.ColorBlack, tcell.ColorLightGray)
2019-01-09 20:30:45 -06:00
yOffset += 2
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "Size:", tcell.ColorLightGray, tcell.ColorDarkBlue)
view.drawText(xOffset+7, yOffset, fmt.Sprintf("%2d X %2d", edit.width, edit.height), tcell.ColorBlack, tcell.ColorLightGray)
2019-01-09 20:30:45 -06:00
yOffset += 2
// ascii arrow characters add extra two spaces
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "← - board width decrement", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "→ - board width increment", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "↓ - board height decrement", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "↑ - board height increment", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
yOffset++
2019-12-01 15:03:27 -06:00
view.drawText(xOffset, yOffset, "q - done", tcell.ColorLightGray, tcell.ColorBlack)
2019-01-09 20:30:45 -06:00
}
2018-10-02 20:21:08 -05:00
// DrawPreviewMinoBlock draws the preview mino
2019-12-01 15:03:27 -06:00
func (view *View) DrawPreviewMinoBlock(x int, y int, color tcell.Color, rotation int, length int) {
char1 := '█'
char2 := '█'
2019-01-09 20:30:45 -06:00
switch rotation {
case 0:
char1 = '▄'
char2 = '▄'
case 1:
2019-12-01 15:03:27 -06:00
char2 = ' '
2019-01-09 20:30:45 -06:00
case 2:
char1 = '▀'
char2 = '▀'
case 3:
2019-12-01 15:03:27 -06:00
char1 = ' '
2017-03-27 15:07:29 -05:00
}
xOffset := 2*x + 2*board.width + boardXOffset + 11 + (4 - length)
2019-12-01 15:03:27 -06:00
style := tcell.StyleDefault.Foreground(color).Background(color).Dim(true)
screen.SetContent(xOffset, y+boardYOffset+2, char1, nil, style)
screen.SetContent(xOffset+1, y+boardYOffset+2, char2, nil, style)
2017-03-27 15:07:29 -05:00
}
2018-10-02 20:21:08 -05:00
// DrawBlock draws a block
2019-12-01 15:03:27 -06:00
func (view *View) DrawBlock(x int, y int, color tcell.Color, rotation int) {
char1 := '█'
char2 := '█'
2019-01-09 20:30:45 -06:00
switch rotation {
case 0:
char1 = '▄'
char2 = '▄'
case 1:
2019-12-01 15:03:27 -06:00
char2 = ' '
2019-01-09 20:30:45 -06:00
case 2:
char1 = '▀'
char2 = '▀'
case 3:
2019-12-01 15:03:27 -06:00
char1 = ' '
2017-03-27 15:07:29 -05:00
}
2019-12-01 15:03:27 -06:00
if color == colorBlank {
// colorBlank means drop Mino
style := tcell.StyleDefault.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver).Bold(true)
screen.SetContent(2*x+boardXOffset+2, y+boardYOffset+1, char1, nil, style)
screen.SetContent(2*x+boardXOffset+3, y+boardYOffset+1, char2, nil, style)
2017-03-27 15:07:29 -05:00
} else {
2019-12-01 15:03:27 -06:00
style := tcell.StyleDefault.Foreground(color).Background(color).Dim(true)
screen.SetContent(2*x+boardXOffset+2, y+boardYOffset+1, char1, nil, style)
screen.SetContent(2*x+boardXOffset+3, y+boardYOffset+1, char2, nil, style)
2017-03-27 15:07:29 -05:00
}
}
2018-10-02 20:21:08 -05:00
// drawPaused draws Paused
func (view *View) drawPaused() {
yOffset := (board.height+1)/2 + boardYOffset
2019-12-01 15:03:27 -06:00
view.drawTextCenter(yOffset, "Paused", tcell.ColorWhite, tcell.ColorBlack)
}
2018-10-02 20:21:08 -05:00
// drawGameOver draws GAME OVER
2017-03-27 15:07:29 -05:00
func (view *View) drawGameOver() {
yOffset := boardYOffset + 2
2019-12-01 15:03:27 -06:00
view.drawTextCenter(yOffset, " GAME OVER", tcell.ColorWhite, tcell.ColorBlack)
yOffset += 2
2019-12-01 15:03:27 -06:00
view.drawTextCenter(yOffset, "sbar for new game", tcell.ColorWhite, tcell.ColorBlack)
2019-12-01 15:03:27 -06:00
if engine.mode == engineModePreview {
return
}
2017-03-27 15:07:29 -05:00
yOffset += 2
// ascii arrow characters add extra two spaces
2019-12-01 15:03:27 -06:00
view.drawTextCenter(yOffset, "←previous board", tcell.ColorWhite, tcell.ColorBlack)
2017-03-27 15:07:29 -05:00
yOffset += 2
2019-12-01 15:03:27 -06:00
view.drawTextCenter(yOffset, "→next board", tcell.ColorWhite, tcell.ColorBlack)
}
2018-10-02 20:21:08 -05:00
// drawRankingScores draws the ranking scores
func (view *View) drawRankingScores() {
yOffset := boardYOffset + 10
2017-03-27 15:07:29 -05:00
for index, line := range engine.ranking.scores {
2019-12-01 15:03:27 -06:00
view.drawTextCenter(yOffset+index, fmt.Sprintf("%1d: %6d", index+1, line), tcell.ColorWhite, tcell.ColorBlack)
2017-03-27 15:07:29 -05:00
}
}
2018-10-02 20:21:08 -05:00
// drawText draws the provided text
2019-12-01 15:03:27 -06:00
func (view *View) drawText(x int, y int, text string, fg tcell.Color, bg tcell.Color) {
style := tcell.StyleDefault.Foreground(fg).Background(bg)
2017-03-27 15:07:29 -05:00
for index, char := range text {
2019-12-01 15:03:27 -06:00
screen.SetContent(x+index, y, rune(char), nil, style)
2017-03-27 15:07:29 -05:00
}
}
2018-10-02 20:21:08 -05:00
// drawTextCenter draws text in the center of the board
2019-12-01 15:03:27 -06:00
func (view *View) drawTextCenter(y int, text string, fg tcell.Color, bg tcell.Color) {
xOffset := board.width - (len(text)+1)/2 + boardXOffset + 2
2019-12-01 15:03:27 -06:00
style := tcell.StyleDefault.Foreground(fg).Background(bg)
for index, char := range text {
2019-12-01 15:03:27 -06:00
screen.SetContent(index+xOffset, y, rune(char), nil, style)
}
}
2017-03-27 15:07:29 -05:00
2018-10-02 20:21:08 -05:00
// ShowDeleteAnimation draws the delete animation
func (view *View) ShowDeleteAnimation(lines []int) {
2017-03-27 15:07:29 -05:00
view.RefreshScreen()
for times := 0; times < 3; times++ {
for _, y := range lines {
2019-12-01 15:03:27 -06:00
view.colorizeLine(y, tcell.ColorLightGray)
2017-03-27 15:07:29 -05:00
}
2019-12-01 15:03:27 -06:00
screen.Show()
2017-03-27 15:07:29 -05:00
time.Sleep(140 * time.Millisecond)
view.RefreshScreen()
time.Sleep(140 * time.Millisecond)
}
}
2018-10-02 20:21:08 -05:00
// ShowGameOverAnimation draws one randomily picked gave over animation
2017-03-27 15:07:29 -05:00
func (view *View) ShowGameOverAnimation() {
2018-06-01 10:16:36 -05:00
logger.Println("View ShowGameOverAnimation start")
switch rand.Intn(3) {
case 0:
2019-12-01 15:03:27 -06:00
logger.Println("View ShowGameOverAnimation case 0")
for y := board.height - 1; y >= 0; y-- {
2019-12-01 15:03:27 -06:00
view.colorizeLine(y, tcell.ColorLightGray)
screen.Show()
time.Sleep(60 * time.Millisecond)
}
2017-03-27 15:07:29 -05:00
case 1:
2019-12-01 15:03:27 -06:00
logger.Println("View ShowGameOverAnimation case 1")
for y := 0; y < board.height; y++ {
2019-12-01 15:03:27 -06:00
view.colorizeLine(y, tcell.ColorLightGray)
screen.Show()
time.Sleep(60 * time.Millisecond)
}
2017-03-27 15:07:29 -05:00
case 2:
2019-12-01 15:03:27 -06:00
logger.Println("View ShowGameOverAnimation case 2")
sleepTime := 50 * time.Millisecond
topStartX := boardXOffset + 3
topEndX := board.width*2 + boardXOffset + 1
topY := boardYOffset + 1
rightStartY := boardYOffset + 1
rightEndY := board.height + boardYOffset + 1
rightX := board.width*2 + boardXOffset + 1
bottomStartX := topEndX - 1
bottomEndX := topStartX - 1
bottomY := board.height + boardYOffset
leftStartY := rightEndY - 1
leftEndY := rightStartY - 1
leftX := boardXOffset + 2
2019-12-01 15:03:27 -06:00
style := tcell.StyleDefault.Foreground(tcell.ColorLightGray).Background(tcell.ColorLightGray)
for topStartX <= topEndX && rightStartY <= rightEndY {
for x := topStartX; x < topEndX; x++ {
2019-12-01 15:03:27 -06:00
screen.SetContent(x, topY, ' ', nil, style)
}
topStartX++
topEndX--
topY++
for y := rightStartY; y < rightEndY; y++ {
2019-12-01 15:03:27 -06:00
screen.SetContent(rightX, y, ' ', nil, style)
}
rightStartY++
rightEndY--
rightX--
for x := bottomStartX; x > bottomEndX; x-- {
2019-12-01 15:03:27 -06:00
screen.SetContent(x, bottomY, ' ', nil, style)
}
bottomStartX--
bottomEndX++
bottomY--
for y := leftStartY; y > leftEndY; y-- {
2019-12-01 15:03:27 -06:00
screen.SetContent(leftX, y, ' ', nil, style)
}
leftStartY--
leftEndY++
leftX++
2019-12-01 15:03:27 -06:00
screen.Show()
time.Sleep(sleepTime)
sleepTime += 4 * time.Millisecond
}
2017-03-27 15:07:29 -05:00
}
2018-06-01 10:16:36 -05:00
logger.Println("View ShowGameOverAnimation end")
2017-03-27 15:07:29 -05:00
}
2018-10-02 20:21:08 -05:00
// colorizeLine changes the color of a line
2019-12-01 15:03:27 -06:00
func (view *View) colorizeLine(y int, color tcell.Color) {
style := tcell.StyleDefault.Foreground(tcell.ColorBlack).Background(color)
for x := 0; x < board.width; x++ {
2019-12-01 15:03:27 -06:00
screen.SetContent(x*2+boardXOffset+2, y+boardYOffset+1, ' ', nil, style)
screen.SetContent(x*2+boardXOffset+3, y+boardYOffset+1, ' ', nil, style)
2017-03-27 15:07:29 -05:00
}
}
2019-01-09 20:30:45 -06:00
// DrawCursor draws current cursor location
2019-12-01 15:03:27 -06:00
func (view *View) DrawCursor(x int, y int, color tcell.Color) {
style := tcell.StyleDefault.Foreground(color).Background(tcell.ColorBlack)
if color == colorBlank {
style = tcell.StyleDefault.Foreground(tcell.ColorBlack).Background(tcell.ColorLightGrey)
}
screen.SetContent(x*2+boardXOffset+2, y+boardYOffset+1, '◄', nil, style)
screen.SetContent(x*2+boardXOffset+3, y+boardYOffset+1, '►', nil, style)
screen.Show()
2019-01-09 20:30:45 -06:00
}