Drawer

Slots app

Slots app - student project

the app (iPhone, iPad and Mac): https://youtu.be/1JnpPjQQXjg

I added a few stuff to the app

I think you can improve the IF statements and the way to hide the text at the bottom

 

here is the code:

 

import SwiftUI

import SwiftData

 

struct ContentView: View {

    

    

    @Environment (\.verticalSizeClass) var verticalSizeClass

    @Environment (\.horizontalSizeClass) var horizontalSizeClass

    

    @State private var slot1 = "fruit1"

    @State private var slot2 = "fruit2"

    @State private var slot3 = "fruit3"

    @State private var score = 1000

    @State private var applePoints = "0"

    @State private var cherryPoints = "+5"

    @State private var starPoints = "+7"

    @State private var allMatchPoints = "-25"

    @State private var slot1Info = " "

    @State private var slot2Info = " "

    @State private var slot3Info = " "

    @State private var rules = "Apple= 0  Cherry= +5  Star= +7  All match= -25"

    

    

    var body: some View {

        

        VStack {

            Text("SwiftUI Slots!")

                .font(.title)

                .fontWeight(.bold)

                .padding(.top, 40.0)

            Spacer()

            Text("Credits "+String(score))

            Spacer()

            HStack{

                VStack{

                    Image(slot1)

                        .resizable()

                        .aspectRatio(contentMode: .fit)

                    Text(slot1Info)

                }

                VStack{

                    Image(slot2)

                        .resizable()

                        .aspectRatio(contentMode: .fit)

 

 

                    Text(slot2Info)

                }

                VStack{

                    Image(slot3)

                        .resizable()

                        .aspectRatio(contentMode: .fit)

 

                    Text(slot3Info)

                }

            }

            .padding(/*@START_MENU_TOKEN@*/.all/*@END_MENU_TOKEN@*/)

            .frame(maxWidth: .infinity)

            

            

 

            

            Spacer()

            Button(action: {

                

                let slot1Rand = Int.random(in: 1...3)

                let slot2Rand = Int.random(in: 1...3)

                let slot3Rand = Int.random(in: 1...3)

                

                slot1 = "fruit" + String(slot1Rand)

                slot2 = "fruit" + String(slot2Rand)

                slot3 = "fruit" + String(slot3Rand)

                

                if slot1 == slot2 && slot1 == slot3 {

                    score -= 25

                    slot1Info = " "

                    slot2Info = allMatchPoints

                    slot3Info = " "

                    rules = " "

 

                    

                } else {if slot1 == "fruit1" {

                    score += 0

                    slot1Info  = applePoints

                    rules = ""

                } else if slot1 == "fruit2" {

                    score += 5

                    slot1Info  = cherryPoints

                    rules = ""

                } else if slot1 == "fruit3" {

                    score += 7

                    slot1Info  = starPoints

                    rules = ""

                }

                    

                if slot2 == "fruit1" {

                    score += 0

                    slot2Info  = applePoints

                    rules = ""

                } else if slot2 == "fruit2" {

                    score += 5

                    slot2Info  = cherryPoints

                    rules = ""

                } else if slot2 == "fruit3" {

                    score += 7

                    slot2Info  = starPoints

                    rules = ""

                }

                    

                if slot3 == "fruit1" {

                    score += 0

                    slot3Info  = applePoints

                    rules = ""

                } else if slot3 == "fruit2" {

                    score += 5

                    slot3Info  = cherryPoints

                    rules = ""

                } else if slot3 == "fruit3" {

                    score += 7

                    slot3Info  = starPoints

                    rules = ""

                }}

                

                

 

                

            }

                   , label: {

                /*@START_MENU_TOKEN@*/Text("Spin")

                    .foregroundColor(Color.white)

                    .multilineTextAlignment(.center)

                    .padding(.vertical, 10.0)

                    .padding(.horizontal, 35.0)

                    .background(Color.red)

                    .cornerRadius(30)

 

                    /*@END_MENU_TOKEN@*/

            })

            Spacer()

            Text(rules)

                .font(.footnote)

                .foregroundColor(Color.gray)

                .padding(.bottom)

        }

    }

}

 

 

struct ContentView_Preview: PreviewProvider {

        static var previews: some View {

            ContentView()

        }

    }