Skip to content
Permalink
Browse files

Change layout

  • Loading branch information...
Raggaer committed Mar 28, 2019
1 parent 3413d4d commit bfe73bb98fd166a60375d0ac7f8c09d27aeeb0a6
Showing with 14 additions and 14 deletions.
  1. +4 −4 main.go
  2. +7 −0 output.go
  3. +3 −10 words.go
@@ -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:
@@ -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)
}
@@ -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))

@@ -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++ {
@@ -2,7 +2,6 @@ package main

import (
"encoding/json"
"fmt"
"math/rand"
"os"
"sync"
@@ -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)
}
}

0 comments on commit bfe73bb

Please sign in to comment.
You can’t perform that action at this time.