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

 

[easy_media_download url=”http://blogvali.com/wp-content/uploads/fyne-golang-downloads/main17.go” text=”Download Code” color=”red_darker”]
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 0 comments

Leave a Reply: