iOS foundation course, Module 1, Lesson 13, Answer:
//
// ContentView.swift
// Project-2
//
// Created by Sam Grover on 15/05/22.
//
import SwiftUI
struct ContentView: View {
@State var score = 0
@State var place1 = "apple"
@State var place2 = "cherry"
@State var place3 = "star"
var array: Array = [ "apple", "cherry", "star"]
var body: some View {
VStack
{
Spacer()
Text("Swift UI Slots")
.font(.title)
.fontWeight(.bold)
Spacer()
let reply = "Score: " + String(score)
Text(reply)
Spacer()
HStack
{
Spacer()
Image(place1).resizable().aspectRatio(contentMode: .fit)
Spacer()
Image(place2).resizable().aspectRatio(contentMode: .fit)
Spacer()
Image(place3).resizable().aspectRatio(contentMode: .fit)
Spacer()
}
Spacer()
Button
{
func declare()
{
let a = Int.random(in: 0...2)
let b = Int.random(in: 0...2)
let c = Int.random(in: 0...2)
place1 = array[a]
place2 = array[b]
place3 = array[c]
if (a == b)
{
if(b == c){
score += 100
//score will get increase by 100
}else{
score += 50
//score will increase by 50
}
}else if(b == c){
if(c == a){
score += 100
//score will get increase by 100
}else{
score += 50
//score will increase by 50
}
}else if (a == c){
if(c == b){
score += 100
//score will get increase by 100
}else{
score += 50
//score will increase by 50
}
}else{
score+=0
//score will be increased by 0
}
}
declare()
} label: {
Text("Spin")
.accentColor(/*@START_MENU_TOKEN@*/.white/*@END_MENU_TOKEN@*/)
}
.padding(.horizontal, 20.0)
.padding(.top, 5.0)
.padding(.bottom, 5.0)
.background(/*@START_MENU_TOKEN@*//*@PLACEHOLDER=View@*/Color(hue: 0.07, saturation: 0.819, brightness: 0.908)/*@END_MENU_TOKEN@*/)
.cornerRadius(/*@START_MENU_TOKEN@*/9.0/*@END_MENU_TOKEN@*/)
Spacer()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}