Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //View 1
- //
- // MenuView.swift
- // MultiplicationPractice Game
- //
- // Created by Justin Trubela on 1/5/22.
- // Note each view is on separate files in the navigator menu
- //
- import SwiftUI
- struct MenuView: View {
- var numberOfQuestions = [5,10,20]
- @State private var selectedNumber = 5
- @State private var timesTableNumber: Double = 2
- @State private var menuView = true //maybeee needed for transition???????
- var body: some View {
- NavigationView{
- ZStack{
- Color.yellow.ignoresSafeArea()
- VStack {
- //Add shuffled animal
- Image("buffalo") //Add repeating animation
- .padding()
- .shadow(color: .black, radius: 5, x: 2, y: 2)
- VStack {
- Text("Pick how many questions you want")
- Picker("How many questions", selection: $selectedNumber){
- ForEach(numberOfQuestions, id: \.self) {
- Text("\($0)")
- }
- }
- .pickerStyle(.segmented)
- .padding()
- }
- .addBoxOverlay()
- //Add shuffled animal
- Image("dog") //Add repeating animation
- .padding()
- .shadow(color: .black, radius: 5, x: 2, y: 2)
- VStack{
- Text("Pick a number to multiply by")
- .font(.headline)
- HStack{
- //Minus Sign
- Button(){
- if timesTableNumber == 2{
- timesTableNumber = timesTableNumber
- }
- else{
- timesTableNumber -= 1
- }
- } label: {
- Text("\(Image(systemName: "minus"))")
- .font(.largeTitle)
- .foregroundColor(.red)
- .bold()
- }
- Slider(value: $timesTableNumber, in: 2...12, step: 1){
- minimumScaleFactor(2)
- }
- //Plus Sign
- Button(){
- if timesTableNumber == 12{
- timesTableNumber = timesTableNumber
- }
- else{
- timesTableNumber += 1
- }
- } label: {
- Text("\(Image(systemName: "plus"))")
- .font(.largeTitle)
- .foregroundColor(.green)
- .bold()
- }
- }
- .padding()
- .accentColor(Color.blue)
- }.addBoxOverlay()
- Text("\(Int(timesTableNumber))")
- .font(.largeTitle)
- .foregroundColor(.blue)
- .clipShape(RoundedRectangle(cornerRadius: 20))
- .frame(width: 320, height: 50, alignment: .center)
- Spacer()
- }
- .padding(30)
- .navigationBarTitle("Times Tables")
- }.toolbar{
- Button("Play", action: playGame)
- }
- }
- NavigationLink(destination: ContentView()){
- }
- }
- func playGame() {
- //MenuView() TOMORROWS ANOTHER DAYYYYY
- }
- }
- struct boxOverlay: ViewModifier {
- func body(content: Content) -> some View {
- content
- .font(.headline)
- .overlay(
- RoundedRectangle(cornerRadius: 5.0)
- .stroke(lineWidth: 2.0)
- .foregroundColor(Color.black)
- )
- }
- }
- extension View {
- func addBoxOverlay() -> some View {
- modifier(boxOverlay())
- }
- }
- struct MenuView_Previews: PreviewProvider {
- static var previews: some View {
- ContentView()
- }
- }
- // END VIEW 1 //
- // New File Starts here
- //
- // ContentView.swift
- // MultiplicationPractice
- //
- // Created by Justin Trubela on 1/5/22.
- //
- import SwiftUI
- struct ContentView: View {
- @State private var gameView = false
- var body: some View {
- NavigationView {
- ZStack{
- LinearGradient(gradient:
- Gradient(
- colors: [.yellow,.yellow,.white,.white]),
- startPoint: .top, endPoint: .bottom
- ).ignoresSafeArea()
- //Stack
- VStack{
- ZStack{
- Image("FunBoard") //Maybe some animation
- .clipShape(RoundedRectangle(cornerRadius: 10))
- .shadow(radius: 5)
- .shadow(color: .black, radius: 5, x: 5, y: 5)
- ZStack{
- Rectangle()
- .frame(width: 180, height: 50, alignment: .center)
- .clipShape(RoundedRectangle(cornerRadius: 20))
- Text("5 X 3") //Userbased choice, random number to multiply by
- .font(.largeTitle).bold()
- .foregroundColor(.yellow)
- }
- }
- VStack{
- Image("snake") //Make this an image with animation
- Button("20", role: .none){ //Add animation
- }.addButtonModifier()
- Image("zebra")
- Button("15", role: .none){
- }.addButtonModifier()
- Image("bear")
- Button("10", role: .none){
- }.addButtonModifier()
- Spacer()
- }
- .frame(width: 300, height: 460, alignment: .center)
- .clipShape(RoundedRectangle(cornerRadius: 20))
- .foregroundColor(.black)
- .font(.title2)
- } //add number here
- }.navigationBarTitle("Multiply By 5")
- }
- }
- func playGame() {
- gameView.toggle() // Not sure if this is needed
- }
- }
- struct buttonModifier: ViewModifier {
- func body(content: Content) -> some View {
- content
- .frame(width: 290, height: 30, alignment: .center)
- .background(Color.green)
- .clipShape(RoundedRectangle(cornerRadius: 30))
- .shadow(color: .black, radius: 1, x: 3, y: 3)
- }
- }
- extension View {
- func addButtonModifier() -> some View {
- modifier(buttonModifier())
- }
- }
- struct ContentView_Previews: PreviewProvider {
- static var previews: some View {
- ContentView()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement