Enums for classes

Hi,

 

Can an enum contain a list of classes?

 

I have a superclass Activity: SKScene { }, which has sub-private class Activity01: Activity { }, sub-private class Activity02: Activity { } and a sub-private class Activity03: Activity { }.

Each sub-private class contains a timed activity. When the timer runs out before the user solves the activity, a GameOver scene (class GameOver: Activity { }) pops up (with text “Bad luck try again”). I am trying to create an enum in the GameOver class to be triggered in touches began to return the user to their last activity but I cannot solve this one. When tapped it always returns to Activity01. Is there a way to return to Activity02 or Activity03 if they were the last activity?

 

Here is my attempt:

 

 

…}  // Activity03 sub-private class closure

 

    class GameOver: Activity {

      

        enum classes {

            case Activity01

            case Activity02

            case Activity03

                  }

      

        var firstClass = classes.Activity01

        var secondClass = classes.Activity02

        var thirdClass = classes.Activity03

     

        let restartGameText = SKLabelNode(fontNamed: “AvenirNext-HeavyItalic”)

      

        init(size: CGSize, won:Bool) {

            super.init(size: size)

          

            startGameText.removeFromParent()

          

            restartGameText.text = “Bad luck try again”

            restartGameText.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center

            restartGameText.verticalAlignmentMode = SKLabelVerticalAlignmentMode.center

            restartGameText.fontSize = 60

            restartGameText.fontColor = SKColor(red: 230/255, green: 60/255, blue: 70/255, alpha: 1)

            restartGameText.position = CGPoint(x: scene!.size.width/2.0, y: scene!.size.height/2.0)

            restartGameText.zPosition = 5

            addChild(restartGameText)

          

            let pulseAction = SKAction.sequence([SKAction.fadeAlpha(to: 1, duration: 1), SKAction.fadeAlpha(to: 0.7, duration: 1)])

            restartGameText.run(SKAction.repeatForever(pulseAction))

          

        }

      

        required init(coder aDecoder: NSCoder) {

            fatalError(“init(coder:) has not been implemented”)

        }

      

      

        override func touchesBegan(_ touches: Set, with event: UIEvent?) {

          

            if firstClass == classes.Activity01 {

              

                let transition = SKTransition.fade(withDuration: 2.0)

                let activity01 = Activity01(size: size)

                view?.presentScene(activity01, transition: transition)

              

            } else if secondClass == classes.Activity02 {

              

                let transition = SKTransition.fade(withDuration: 2.0)

                let activity02 = Activity02(size: size)

                view?.presentScene(activity02, transition: transition)

              

            } else if thirdClass == classes.Activity03 {

              

                let transition = SKTransition.fade(withDuration: 2.0)

                let activity03 = Activity03(size: size)

                view?.presentScene(activity03, transition: transition)

              

            }

        }

    }   //GameOver class closure

}  // Activity Superclass closure

 

 

Thank you in advance

h

Powered by WPeMatico

About

You may also like...

Comments are closed.