5

Dicee GAME – Fyne GUI Golang tutorial 17

Dicee GAME – Fyne GUI Golang tutorial 17

Want to Create your first Game in Fyne and Golang?

I think Now we have enough skills and knowledge to create a small game in Fyne & Golang.

 

Lets do it.

 

 

package main
// import fyne
import (
    "fmt"
    "math/rand"
    "fyne.io/fyne/v2"
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/canvas"
    "fyne.io/fyne/v2/container"
    "fyne.io/fyne/v2/widget"
)
func main() {
    // New app
    a := app.New()
    // New window and Title
    w := a.NewWindow("Dicee Game")
    // resize Window
    w.Resize(fyne.NewSize(400, 400))
    // image of Dice
    img := canvas.NewImageFromFile("c:/dice/dice6.jpg")
    img.FillMode = canvas.ImageFillOriginal
    // button
    btn1 := widget.NewButton("Play", func() {
        // UI is finished.. Now Logic part
        rand := rand.Intn(6) + 1 // ignore zero 0+1=1
        img.File = fmt.Sprintf("c:/dice/dice%d.jpg", rand)
        img.Refresh()
    })
    // Setup content and finish UI
    w.SetContent(
        // NewVBox.. More than on Widgets
        container.NewVBox(
            img,
            btn1,
        ),
    )
    // show and run app
    w.ShowAndRun()
}

Download Code
Tony BB
 

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 5 comments
Vineet - a few days ago

Bro where do i find the dice images.

Reply
    Tony BB - a couple of days ago

    Already sent you email 🙂

    Reply
Vineet - a few days ago

Bro where do i find the dice images…

Reply
Ramu - a day ago

bro Kindly send the dicee imgage please.

Reply
    Tony BB - yesterday

    Check your email 🙂

    Reply

Leave a Reply: