Post

Replies

Boosts

Views

Activity

Develop in Swift build a bouncy ball game
I've been learning how to code swift with "Develop in Swift" by Apple, and it has been great! However, I have a problem, I made a function, and it gives me an error on lines 78, 80, and 121. Can someone explain my error? Thank you for your time. var barriers: [Shape] = [] let ball = OvalShape(width: 40, height:40) let barrierWidth = 300.0 let barrierHeight = 25.0 let barrierPoints = [     Point(x:0, y:0),     Point(x:0, y:barrierHeight),     Point(x:barrierWidth, y:barrierHeight),     Point(x:barrierWidth, y:0) ] let barrier = PolygonShape(points:barrierPoints) let funnelPoints = [     Point(x:0, y:50),     Point(x:80, y:50),     Point(x:60, y:0),     Point(x:20, y:0) ] let funnel = PolygonShape(points:funnelPoints) let targetPoints=[     Point(x:10, y:0),     Point(x:0, y:10),     Point(x:10, y:20),     Point(x:20, y:10) ] let target = PolygonShape(points:targetPoints) func setUpTarget(){     target.position = Point(x:200, y:400)     target.hasPhysics = true     target.isImmobile = true     target.isImpermeable = false     target.fillColor = .yellow     target.name = "Target"     //target.isDraggable = false          scene.add(target)      } /* The setup() function is called once when the app launches. Without it, your app won't compile. Use it to set up and start your app. You can create as many other functions as you want, and declare variables and constants, at the top level of the file (outside any function). You can't write any other kind of code, for example if statements and for loops, at the top level; they have to be written inside of a function. */ fileprivate func setUpBall() {     ball.position = Point(x: 250, y:400)     scene.add(ball)     ball.hasPhysics = true     ball.fillColor = .blue     ball.onCollision = ballCollided(with:)     ball.isDraggable = false     scene.trackShape(ball)     ball.onExitedScene = ballExitedScene     ball.onTapped = resetGame     ball.bounciness = 0.6 } fileprivate func addBarrier(at position: Point, width: Double, height: Double, angle: Double){     //Add a barrier to the scene.     let barrierPoints = [         Point:(x: 0, y: 0),         Point:(x: 0, y: height),         Point(x: width, y: height),         Point(x: width, y: 0)     ]     let barrier = PolygonShape(points:barrierPoints)     barrier.append(barrier)          barrier.position = Point(x:200, y:150)     barrier.hasPhysics = true     scene.add(barrier)     barrier.isImmobile = true     barrier.angle = 0.1 } fileprivate func setUpFunnel() {     //Adds a funnel to the scene     funnel.position = Point(x:200, y:scene.height - 25)     scene.add(funnel)     funnel.onTapped = dropBall     funnel.isDraggable = false } func ballCollided(with otherShape: Shape){     if otherShape.name != "Target"{return}          otherShape.fillColor = .green } func ballExitedScene (){     barrier.isDraggable = true } func resetGame (){     ball.position = Point(x:0, y:-80) } func printPosition(of shape: Shape){     print(shape.position) } func setup() {          setUpBall()          addBarrier()          setUpFunnel()          setUpTarget()          resetGame()          scene.onShapeMoved = printPosition(of:)           } func dropBall() {     ball.position = funnel.position     ball.stopAllMotion()     barrier.isDraggable = false }
1
1
1.4k
Aug ’21
Checking for characters
I'm having trouble coding this. I'm learning swift via develop with swift by Apple, and when I try to code this, it stop at "Please add a digit." Can someone explain what I'm doing wrong? Thanks! let tenMostCommonPasswords = [     "123456",     "password",     "12345678",     "qwerty",     "12345",     "123456789",     "letmein",     "1234567",     "football",     "iloveyou" ] let digits = "0123456789" let punctuation = "!@#$%^&*(),.<>;'`~[]{}\|/?_-+= " let password = "Pasword12!" for _ in tenMostCommonPasswords{    if tenMostCommonPasswords.contains(password){     print("Please change your password")    }    else{     for _ in digits{         if digits.contains(password){             for _ in punctuation{                 if punctuation.contains(password){                     print("You're good to go!")                 }                 else{                     print("Please add a punctuation")                 }             }         }         else{             print("Please add a digit.")         }     }    } }
1
0
798
Aug ’21