Advertisement
jTruBela

Multiplication Game Both Views Unfinished

Jan 6th, 2022
1,242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 8.41 KB | None | 0 0
  1. //View 1
  2.  
  3. //
  4. //  MenuView.swift
  5. //  MultiplicationPractice Game
  6. //
  7. //  Created by Justin Trubela on 1/5/22.
  8. //  Note each view is on separate files in the navigator menu
  9. //
  10.  
  11. import SwiftUI
  12.  
  13. struct MenuView: View {
  14.     var numberOfQuestions = [5,10,20]
  15.     @State private var selectedNumber = 5
  16.     @State private var timesTableNumber: Double = 2
  17.     @State private var menuView = true                  //maybeee needed for transition???????
  18.    
  19.     var body: some View {
  20.         NavigationView{
  21.             ZStack{
  22.                 Color.yellow.ignoresSafeArea()
  23.                 VStack {
  24.                                                                                 //Add shuffled animal
  25.                     Image("buffalo")                                            //Add repeating animation
  26.                         .padding()
  27.                         .shadow(color: .black, radius: 5, x: 2, y: 2)
  28.                     VStack {
  29.                         Text("Pick how many questions you want")
  30.                         Picker("How many questions", selection: $selectedNumber){
  31.                             ForEach(numberOfQuestions, id: \.self) {
  32.                                 Text("\($0)")
  33.                             }
  34.                         }
  35.                         .pickerStyle(.segmented)
  36.                         .padding()
  37.                     }
  38.                     .addBoxOverlay()
  39.                    
  40.                    
  41.                    
  42.                                                                                 //Add shuffled animal
  43.                     Image("dog")                                                //Add repeating animation
  44.                         .padding()
  45.                         .shadow(color: .black, radius: 5, x: 2, y: 2)
  46.                     VStack{
  47.                         Text("Pick a number to multiply by")
  48.                             .font(.headline)
  49.                         HStack{
  50.                             //Minus Sign
  51.                             Button(){
  52.                                 if timesTableNumber == 2{
  53.                                     timesTableNumber = timesTableNumber
  54.                                 }
  55.                                 else{
  56.                                     timesTableNumber -= 1
  57.                                 }
  58.                             } label: {
  59.                                 Text("\(Image(systemName: "minus"))")
  60.                                     .font(.largeTitle)
  61.                                     .foregroundColor(.red)
  62.                                     .bold()
  63.                             }
  64.                            
  65.                             Slider(value: $timesTableNumber, in: 2...12, step: 1){
  66.                                 minimumScaleFactor(2)
  67.                                
  68.                             }
  69.                             //Plus Sign
  70.                             Button(){
  71.                                 if timesTableNumber == 12{
  72.                                     timesTableNumber = timesTableNumber
  73.                                 }
  74.                                 else{
  75.                                     timesTableNumber += 1
  76.                                 }
  77.                             } label: {
  78.                                 Text("\(Image(systemName: "plus"))")
  79.                                     .font(.largeTitle)
  80.                                     .foregroundColor(.green)
  81.                                     .bold()
  82.                             }
  83.                         }
  84.                         .padding()
  85.                         .accentColor(Color.blue)
  86.                     }.addBoxOverlay()
  87.                    
  88.                    
  89.                    
  90.                    
  91.                     Text("\(Int(timesTableNumber))")
  92.                         .font(.largeTitle)
  93.                         .foregroundColor(.blue)
  94.                         .clipShape(RoundedRectangle(cornerRadius: 20))
  95.                         .frame(width: 320, height: 50, alignment: .center)
  96.                     Spacer()
  97.                    
  98.                 }
  99.                 .padding(30)
  100.                 .navigationBarTitle("Times Tables")
  101.             }.toolbar{
  102.                 Button("Play", action: playGame)
  103.             }
  104.         }
  105.         NavigationLink(destination: ContentView()){
  106.         }
  107.        
  108.     }
  109.    
  110.     func playGame() {
  111.         //MenuView() TOMORROWS ANOTHER DAYYYYY
  112.     }
  113.    
  114. }
  115.  
  116.  
  117.  
  118.  
  119. struct boxOverlay: ViewModifier {
  120.     func body(content: Content) -> some View {
  121.         content
  122.             .font(.headline)
  123.             .overlay(
  124.                 RoundedRectangle(cornerRadius: 5.0)
  125.                     .stroke(lineWidth: 2.0)
  126.                     .foregroundColor(Color.black)
  127.             )
  128.     }
  129. }
  130. extension View {
  131.     func addBoxOverlay() -> some View {
  132.         modifier(boxOverlay())
  133.     }
  134. }
  135.  
  136. struct MenuView_Previews: PreviewProvider {
  137.     static var previews: some View {
  138.         ContentView()
  139.     }
  140. }
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. //              END VIEW 1               //
  149.  
  150.  
  151. // New File Starts here
  152.  
  153. //
  154. //  ContentView.swift
  155. //  MultiplicationPractice
  156. //
  157. //  Created by Justin Trubela on 1/5/22.
  158. //
  159.  
  160. import SwiftUI
  161.  
  162. struct ContentView: View {
  163.     @State private var gameView = false
  164.     var body: some View {
  165.        
  166.         NavigationView {
  167.             ZStack{
  168.                     LinearGradient(gradient:
  169.                                     Gradient(
  170.                                         colors: [.yellow,.yellow,.white,.white]),
  171.                                    startPoint: .top, endPoint: .bottom
  172.                     ).ignoresSafeArea()
  173.     //Stack
  174.                     VStack{
  175.                         ZStack{
  176.                            
  177.                             Image("FunBoard")                       //Maybe some animation
  178.                                 .clipShape(RoundedRectangle(cornerRadius: 10))
  179.                                 .shadow(radius: 5)
  180.                                 .shadow(color: .black, radius: 5, x: 5, y: 5)
  181.                            
  182.                             ZStack{
  183.                                
  184.                                 Rectangle()
  185.                                     .frame(width: 180, height: 50, alignment: .center)
  186.                                     .clipShape(RoundedRectangle(cornerRadius: 20))
  187.  
  188.                                 Text("5     X     3")               //Userbased choice, random number to multiply by
  189.                                     .font(.largeTitle).bold()
  190.                                     .foregroundColor(.yellow)
  191.                             }
  192.                            
  193.                         }
  194.                        
  195.                         VStack{
  196.                             Image("snake")     //Make this an image with animation
  197.                             Button("20", role: .none){              //Add animation
  198.                             }.addButtonModifier()
  199.                            
  200.                             Image("zebra")
  201.                             Button("15", role: .none){
  202.                             }.addButtonModifier()
  203.                            
  204.                             Image("bear")
  205.                             Button("10", role: .none){
  206.                                
  207.                             }.addButtonModifier()
  208.                             Spacer()
  209.                         }
  210.                         .frame(width: 300, height: 460, alignment: .center)
  211.                         .clipShape(RoundedRectangle(cornerRadius: 20))
  212.                         .foregroundColor(.black)
  213.                         .font(.title2)
  214.                     }                           //add number here
  215.             }.navigationBarTitle("Multiply By 5")
  216.         }
  217.     }
  218.     func playGame() {
  219.         gameView.toggle()           // Not sure if this is needed
  220.     }
  221. }
  222.    
  223. struct buttonModifier: ViewModifier {
  224.     func body(content: Content) -> some View {
  225.         content
  226.             .frame(width: 290, height: 30, alignment: .center)
  227.                 .background(Color.green)
  228.                 .clipShape(RoundedRectangle(cornerRadius: 30))
  229.                 .shadow(color: .black, radius: 1, x: 3, y: 3)
  230.     }
  231. }
  232.  
  233. extension View {
  234.     func addButtonModifier() -> some View {
  235.         modifier(buttonModifier())
  236.     }
  237. }
  238.  
  239.     struct ContentView_Previews: PreviewProvider {
  240.         static var previews: some View {
  241.             ContentView()
  242.         }
  243.     }
  244.  
  245.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement