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()
}

Fyne GoLang GUI Course

 

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 9 comments
Vineet - last year

Bro where do i find the dice images.

Reply
    Tony BB - last year

    Already sent you email 🙂

    Reply
Vineet - last year

Bro where do i find the dice images…

Reply
Ramu - last year

bro Kindly send the dicee imgage please.

Reply
    Tony BB - last year

    Check your email 🙂

    Reply
sauskeu - last year

Bro please send me the dicee image.

Reply
Raihan - 11 months ago

Please give me image link

Reply
walter - 10 months ago

images link folder plz ser

Reply
    Tony BB - 10 months ago

    Sent

    Reply

Leave a Reply: