Skip to content

Commit

Permalink
Change layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Raggaer committed Mar 28, 2019
1 parent 3413d4d commit bfe73bb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ func handleInput(screen tcell.Screen, quit chan struct{}) {
go handleGameScore(screen, gameRows)
go handleGameOver(screen)
} else {
clearRow(screen, 13)
clearRow(screen, gameRows+3)
handleWordInput(screen, currentInput)
currentInput = ""
}
case tcell.KeyBackspace, tcell.KeyBackspace2:
if len(currentInput) > 0 {
clearRow(screen, 13)
clearRow(screen, gameRows+3)
currentInput = currentInput[0 : len(currentInput)-1]
}
case tcell.KeyEscape:
Expand Down Expand Up @@ -112,7 +112,7 @@ func handleGameOver(screen tcell.Screen) {
func handleGameInput(screen tcell.Screen, max int) {
for {
if gameIsAlive {
writexy(screen, 1, max+3, fmt.Sprintf("Input: %s", currentInput))
writexy(screen, 0, max+3, fmt.Sprintf("INPUT: %s", currentInput))
}
time.Sleep(time.Millisecond * 100)
}
Expand All @@ -121,7 +121,7 @@ func handleGameInput(screen tcell.Screen, max int) {
func handleGameScore(screen tcell.Screen, max int) {
for {
if gameIsAlive {
writexy(screen, 1, max+5, fmt.Sprintf("Game Score: %d", gamePoints))
writexy(screen, 0, max+2, fmt.Sprintf("SCORE: %d", gamePoints))
}
time.Sleep(time.Duration(speed))

Expand Down
7 changes: 7 additions & 0 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ var (
style = tcell.StyleDefault
)

func fillRow(screen tcell.Screen, row int, content string) {
width := maxWordsWidth(screen)
for i := 0; i <= width+1; i++ {
screen.SetContent(i, row, rune(content[0]), []rune{}, style)
}
}

func clearRow(screen tcell.Screen, row int) {
width, _ := screen.Size()
for i := 0; i <= width; i++ {
Expand Down
13 changes: 3 additions & 10 deletions words.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"encoding/json"
"fmt"
"math/rand"
"os"
"sync"
Expand Down Expand Up @@ -79,20 +78,14 @@ func loadWords(path string) ([]string, error) {
func startWordColumns(screen tcell.Screen, n int) {
width := maxWordsWidth(screen)
go handleColumnsSpeed(screen)
go renderColumnsSpeed(screen, n)
for i := 0; i < n; i++ {
columnsLocks[i] = &sync.Mutex{}
writexy(screen, width+2, i, "|")
go executeColumn(screen, i)
}
}

func renderColumnsSpeed(screen tcell.Screen, max int) {
for {
if gameIsAlive {
writexy(screen, 1, max+4, fmt.Sprintf("Game Speed: %d", speed))
if i == n-1 {
writexy(screen, width+2, i+1, "-")
fillRow(screen, i+1, "-")
}
time.Sleep(time.Second * 2)
}
}

Expand Down

0 comments on commit bfe73bb

Please sign in to comment.