go-roflcopter/main.go

81 lines
1.4 KiB
Go

package main
import (
"log"
"sync"
"time"
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
"morozovad.ddns.net/lnd212/go-roflcopter/roflcopter"
)
var (
count time.Duration = 0
)
const (
frame1 = " ROFL:ROFL: \n _^____ \n L __/ [] \\ \n O ===__ \\ \n L \\________] \n I I \n --------/ \n"
frame2 = " :ROFL:ROFL\n _^____ \n __/ [] \\ \nLOL===__ \\ \n \\________] \n I I \n --------/ \n"
)
var wg sync.WaitGroup
func copter(delay time.Duration) {
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
defer ui.Close()
p := widgets.NewParagraph()
p.Text = frame1
p.SetRect(0, 0, 25, 10)
ui.Render(p)
nextframe := 2
count = 15 * time.Second
go timecounter(1 * time.Second)
for {
switch nextframe {
case 1:
{
p.Text = frame1 + count.String()
ui.Render(p)
time.Sleep(delay * time.Millisecond)
nextframe = 2
}
case 2:
{
p.Text = frame2 + count.String()
ui.Render(p)
time.Sleep(delay * time.Millisecond)
nextframe = 1
}
}
}
}
func timecounter(step time.Duration) {
for count > 0 {
count -= step
time.Sleep(step)
}
}
func player() {
roflcopter.Sound(&wg, false)
wg.Wait()
player()
}
func main() {
//fmt.Println("HW")
//roflcopter.Sound(&wg, false)
go player()
go copter(120)
time.Sleep(15 * time.Second)
}