Text Based Game Swift 5
0.0 (0 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
5 students enrolled

Text Based Game Swift 5

Learn How To Code With Swift 5 And Xcode 10
0.0 (0 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
5 students enrolled
Created by Gerard Grundy
Last updated 6/2019
English
Current price: $139.99 Original price: $199.99 Discount: 30% off
5 hours left at this price!
30-Day Money-Back Guarantee
This course includes
  • 4 hours on-demand video
  • 33 articles
  • 29 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
Training 5 or more people?

Get your team access to 4,000+ top Udemy courses anytime, anywhere.

Try Udemy for Business
What you'll learn
  • Learn how to create a simple text game with the Swift Programming Language
Course content
Expand all 67 lectures 04:04:44
+ Introduction
2 lectures 01:43

Welcome.  Here I will be posting challenges to help you learn how to make apps and programming with the Swift Programming Language.

Things needed:

  • Mac running at least 10.11 with Xcode 9.0

  • I'll be using Xcode 10 with Mojave so that would be even better to have

  • Patience

  • Willingness to learn

 

Learn how to make a text base game.


Thank you for deciding to take this course.  This is a course I developed for a school called Code Club.  The children who took the course were children from the ages 10 to 16 though is good for anyone wanting to learn how to make an app and get familiar with Swift and Xcode.  It is focused around making a game that uses text that quizzes the user and the user has to input the answer fast to get a good score.


Lets begin.


Hi
00:34
+ Text Game Part 1
15 lectures 29:50

For the Pro Programmers try doing these things without watching the video.

If you can do all these things then awesome! If not then check out the Challenges videos in this section of the course.

Challenges

  1. Create a Single View Application

  2. Add a UITextView to the View

  3. Connect the UITextView to your ViewController Class

  4. Change the text in the UITextView to say "Introduction" when you run the simulator

  5. Change the colour of the View to Black for both the UITextView and the main view

  6. Change the colour of the text to green

  7. Increase the size of the text in the UITextView

  8. Once the view loads after a delay of 5 seconds make the text in the UITextView disappear.

  9. Save a code snippet so that you can use it again later


The above challengesshould be heaps to do. If you can complete some of those great.  The more you try to do these things on your own the more you will learn.  Be prepared to make lots of mistakes and don't worry as long as you ask the right questions you will be able to solve your errors in your code.

The videos of how to do the challenges are found in the next lessons.

If you have done all of the challenges already time yourself and see how quickly you can do it all again. :) I'll do one myself, see if you can beat my time.

If you cannot do any of the above challenges go to the next video and we will start doing them together. :) 

Start Here - All challenges
01:00

Challenge

  • Create a single view application in Xcode

If you have no idea....watch the video. :)

Though please try to follow the video.

Good Luck!

Preview 00:05

Challenge

  • Add a UITextView to the view

If you have no idea....watch the video. :)

Though please try to follow the video.

Good Luck!

Preview 00:05

Challenge

  • Connect the UItextview to the Viewcontroller Class

If you have no idea....watch the video. :)

Though please try to follow the video.

Good Luck!

Preview 00:05

Challenge

  • Change the text

If you have no idea....watch the video. :)

Though please try to follow the video in the next Lecture.

Good Luck!


Are you stuck? The code is in the next Lecture.

Though please try to follow the video again.

Go through the steps. 

The more you try to figure out the error yourself the more you will learn.

If not no worries check your code with mine to see if you can find the problem.

Good Luck!

Preview 00:18

Challenge

  • Change the colour of the background ( you will need to change the background colour of the UITextview and the main Viewcontroller)

  • Change the colour of the text

  • Change the size of the text

  • Change the font

  • Add constraints 

  • Run and see how it looks in the simulator

If you really struggled here is the code and the video.

Though please try to follow the video.

If not no worries check your code with mine to see if you can find the problem.

Good Luck!

Preview 00:19

Challenge

  • Create a snippet of code that will delay when a line of code is executed

  • Make the text disappear 

If you really struggled here is the code and the video.

Though please try to follow the video.

If not no worries check your code with mine to see if you can find the problem.

Good Luck!

The finished Project is in the next lesson.

Well Done completing this level you are a level 1 coding ninja!

DESCRIPTION - Challenge 8.9. Make Text Disappear - Snippets
00:17
Challenge 8.9. Make Text Disappear - Snippets
10:13

This is what we have done so far. Well done!


Project So Far
00:04
+ Text Game Part 2
10 lectures 28:16

For the pro developers here are your challenges.

  1. Make keyboard appear after text disappears

  2. Change the colour of the UITextview curser

  3. Detect when the user writes into the textview

  4. When the answer is correct print "Well Done"

  5. Score a point

Check out the Demo video to see what it will look like when you've done these challenges.

Challenges for Part 2
00:12

The solution is in the next Lecture

Challenge - Make the keyboard appear
00:03

If you really struggled here is the code. Though please try to follow the video. If not no worries try checking your code with mine to see if you can find the problem. Good Luck!

2.1 Show the keyboard
06:27

The solution is in the next Lecture

Challenge - Change the tint colour of the TextView
00:03

If you really struggled here is the code. Though please try to follow the video. If not no worries try checking your code with mine to see if you can find the problem. Good Luck!If you really struggled here is the code. Though please try to follow the video. If not no worries try checking your code with mine to see if you can find the problem. Good Luck!

2.2 Change the colour of the UITextView Curser
03:50

The solution is in the next Lecture

Challenge - Detect changes in the UITextView
00:01

If you really struggled here is the code.

Though please try to follow the video.

If not no worries check your code with mine to see if you can find the problem.

Good Luck!

2.3 Detect Text View Changes
06:39
  1. Show "Well done" to the UITextView if you get the correct answer

  2. Score a point for every correct answer.

Challenge Description
00:04

Are you stuck? Check out the code provided.


Though please try to follow the video again.


Go through the steps.


The more you try to figure out the error yourself the more you will learn.


If not no worries check your code with mine to see if you can find the problem.


Good Luck!

2.4 and 2.5 Scoring
10:38
+ Text Game Part 3
8 lectures 23:29

Challenges

1. Add sound effects
2. Make it speak
3. Background music
4. Success Sound

Check the video in the next Lecture to see the final result.

Download the Audio.zip file as you will need these for the later challenges in Section 3.

Challenges
00:09

Add to the top of your class:

import AVFoundation


func sayIt(sentenceToSay:String) { let utterance = AVSpeechUtterance(string: sentenceToSay) utterance.voice = AVSpeechSynthesisVoice(language: "en-GB") utterance.rate = 0.4 let synthesizer = AVSpeechSynthesizer() synthesizer.speak(utterance) }



Are you stuck? Check out the code.

Though please try to follow the video again.

Go through the steps.

The more you try to figure out the error yourself the more you will learn.

If not no worries check your code with mine to see if you can find the problem.

Good Luck!

3.1 DESCRIPTION
00:17
3.1 Speech Utterance
06:47

Challenge

  • Add background music to the game

If you have no idea....watch the video in the next Lecture. :)

Also if you are really struggling the code is there too.

Though please try to follow the video.

If you get stuck try checking your code with mine to see if you can find the problem.

Good Luck!

3.2 DESCRIPTION
00:12

Are you stuck? Here is the code.

Though please try to follow the video again.

Go through the steps.

The more you try to figure out the error yourself the more you will learn.

If not no worries check your code with mine to see if you can find the problem.

Good Luck!

3.2 BackGround Music
12:30

Challenge

  • Make an effect when a successful answer is done


If you have no idea....watch the video in the next Lecture. :)

Also if you are really struggling the code is there too.

Though please try to follow the video.

If you get stuck try checking your code with mine to see if you can find the problem.

Good Luck!

3.3 Challenge
00:13
3.3 Play Effects
03:02
+ Text Game Part 4
15 lectures 01:22:13

Challenges / Plan

  1. Have an option to turn the music on and off

  2. When we complete the task it says well done in the screen

  3. Then it loads a new task

Plan and Challenges
01:41

Challenge

  • Make a way for the user to turn the music on and off

If you have no idea....watch the video in the next Lecture. :)

Also if you are really struggling the code is there too.

Though please try to follow the video.

If you get stuck try checking your code with mine to see if you can find the problem.

Good Luck!

4.1 Description
00:14
4.1 Music On/Off
10:35

Challenge

  • When the user selects the right answer print and say "Well Done"

  • Then load the next question

If you have no idea....watch the video in the next Lecture. :)

Also if you are really struggling the code is there too.

Though please try to follow the video.

If you get stuck try checking your code with mine to see if you can find the problem.

Good Luck!

4.2 Challenge
00:15

In this lesson we are going to learn how to reuse code. The more we can remove the need to repeat similar tasks will make our code easier to read and use.

/********************************************/

Challenges

1.How would you tell the user Well Done when they get a correct answer?

[toggle title = "Show me the Answer" border="on" icon="off]Hint it has something to do with where you check the answer.[/toggle]

2. Load a new question.

3. How would you stop the text that you type as the answer from automatically capitalising the text and checking the spelling?

/********************************************/

If you have tried and have no idea don't worry here's a way to do it below.

 

Are you stuck? Here is the code.

Though please try to follow the video again.

Go through the steps.

The more you try to figure out the error yourself the more you will learn.

If not no worries check your code with mine to see if you can find the problem.

Good Luck!

4.2 Well Done / Finish and Load next Question
11:42

Challenges

1. Create a new class called "Challenges"

2. Whats the short cut for creating a new file?

→Command + N

3. Create a dictionary with the format

var challenges = [1:"Place Your Question in here"]

4. Create a dictionary like above called answers.

5. Try making your own questions and answers.

/********************************************/

If you have no idea....watch the video in the next Lecture. :)

Also if you are really struggling the code is there too.

Though please try to follow the video.

If you get stuck try checking your code with mine to see if you can find the problem.

Good Luck!

4.3 Challenge
00:22
4.3 Check the next answer
05:59
4.4 Challenges
00:54
4.4 Part 1 How to use the Challenges
14:31

Challenges

1.  When you get to the end of the questions have the program say "Congratulations you have reached level 2"

2.  How would you find out how many challenges are in the dictionary?

→ch.challenges.count

If you really struggled here is the code.

Though please try to follow the video.

If not no worries check your code with mine to see if you can find the problem.

Good Luck!


Still struggling.

The solution code is the start project for 4.5 Animate the typing.

(Text-Game4_4-Challenge-Next-Level-SOLUTION.zip)

4.4 Challenge
00:54
4.4 Part 2 How to create a new level
15:53

(When you down load the project it'll be called → Text-Game4_4-Challenge-Next-Level-SOLUTION.zip)

Challenges:

Can you make the text type to the screen character by character like it is being typed?

If not, no worries it's all in the video.


The code you need:

// MARK: - Step 1 extension UITextView {          func textWithTypeAnimation(typedText: String, characterDelay: TimeInterval = 5.0, completion: @escaping (Bool) -> ()) {         text = ""         var writingTask: DispatchWorkItem?         writingTask = DispatchWorkItem { [weak weakSelf = self] in             for character in typedText {                 DispatchQueue.main.async {                     weakSelf?.text!.append(character)                 }                 Thread.sleep(forTimeInterval: characterDelay/100)             }             completion(true)         }                  if let task = writingTask {             let queue = DispatchQueue(label: "typespeed", qos: DispatchQoS.userInteractive)             queue.asyncAfter(deadline: .now() + 0.05, execute: task)         }     }      }

 

Final Project

(When you down load the project it'll be called →  Text-Game4_5_AnimateTyping.zip)

4.5 Animate Typing resources and Challenges
00:24
4.5 Animate the typing
08:18

Here is the starting project if you need it. (It is the final project from the previous lesson)

Download the typingSound.mp3 too for this Lecture.

Challenge:

  • change the playSoundEffect method to accepts an argument → nameOfEffect

  • in the completion block place stop effectPlayer so that the typing stops when the typing animation stops

If you have no idea....watch the video. :)

4.6 Challenges
00:13
4.6 Add typing Sound
10:17
+ A Better Way to Score The Game
10 lectures 43:02

Here's a demo of what we are trying to do.


Check out the video.


5.0 Animate the score
01:17

Rather than just getting points for this game let's give the person 1 minute to answer the question and the faster they answer it is the score they receive.


For this we will need:

- a timer

- and a way to animate the score to make it look cooler.


Challenge:

  1. make a new project and create a timer that counts down from 60


If you have no idea....watch the video in the next Lecture. :)

Also if you are really struggling the code is there too.

Though please try to follow the video.

If you get stuck try checking your code with mine to see if you can find the problem.

Good Luck!

5.1 Challenges
00:26
5.1 More exciting score
12:13

CHALLENGE

  • Add the left over time from the timer to the score label amount

 

If you have no idea....watch the video. :)

Also if you are really struggling here is the code to check your code.

Though please try to follow the video.

If you get stuck try checking your code with mine to see if you can find the problem. 

Good Luck!

5.2 Challenges
00:14
5.2 Add score from the timer
07:47
5.3 Animate the score label Demo
00:09

CHALLENGE

  • Try to animate the score label so that rather than the numbers just appearing.  Be able to see the number increasing like in the previous DEMO.


  • If you have no idea....watch the video. :)

Though please try to follow the video.

If you get stuck try checking your code with mine to see if you can find the problem.

Good Luck!


Code for this lesson:

func animateLabel(speedTime:Double, addAmount:Int, label:UILabel)     {         // MARK: - Step 8         // change the scorelabel in the Main to just 0         let labelCurrentDoubleAmount = Int(label.text!)!         let amountToAnimateTo = labelCurrentDoubleAmount + timerToCountDown         let animationPeriod: Float = Float(speedTime)         DispatchQueue.global(qos: .default).async(execute: {             for i in labelCurrentDoubleAmount..<(amountToAnimateTo + 1) {                 usleep(useconds_t(animationPeriod / 100 * 1000000)) // sleep in microseconds                 DispatchQueue.main.async(execute: {                     // MARK: - Step 7 - change label to scoreLabel                     self.scoreLabel.text = "\(i)"                 })             }         })                       }

 

Also if you are really struggling check out the final code.


5.3 Challenges
00:30
5.3 Animate the score label
04:13

Your Challenge is:

  • Add the timer and score animation code to the main project.

 

If you have no idea....watch the video. :)

5.4 Add the Animation to the main project
00:05
5.4 Add the animate score to the project
16:07
+ Save Score
7 lectures 36:10

Challenge

  • save the high score with UserDefaults

 

  • Create a new Single View App

  • Add a UiTextField

  • Add a Button that triggers and action

  • add a Label to give us an update of what is going on

  • place an amount into the textfield and have it save to user defaults

  • Check that the score is the highest and only save a high score

 

If you have no idea....watch the video. :)


Also if you are really struggling check out the code.

Though please try to follow the video.

If you get stuck try checking your code with mine to see if you can find the problem.

Good Luck!

6.1 Challenge
00:24
6.1 User Defaults
11:20

Great we did a lot of work in the last project now we need to add this to our project.

Add all the code from 6.1(Score-1.zip) to our current project (5_4AnimatedScoreAddedFINAL.zip).

If you have no idea....watch the video. :)

6.2 Challenges
00:09
6.2 Add Score Saver To Project
07:39

Challenges

  • Create a game over scene

  • You will need to add a new view controller

  • Add a new class called GameOverViewController


If you have no idea....watch the video in the next Lecture. :)

Also if you are really struggling the code is there too.

Though please try to follow the video.

If you get stuck try checking your code with mine to see if you can find the problem.

Good Luck!

6.3 Challenges
00:15
6.3 Add Game Over Scene
15:54

Thank you for doing this course.  If you have any negative feedback please contact me first to see if I can update the course and fix the issue.  I'm here to learn too! so I need to hear from you.  If you enjoyed the course please leave a review.  I'm sure this project could go even further.  See what you can do and if you release something based around this project I would love to hear what you did with it.  All the best and good luck with your coding challenges.

See if you can complete the course just by following the challenges and not watching the videos.

Good luck and thanks again!

Congratulations
00:27
Requirements
  • A Macbook Pro or iMac with Xcode 10 installed
Description

Let's make a text based game.  This course will help you create animated text that instructs the user what to do. The text will also be announced by the built in speech generators that are included in the Swift modules.  The app that is in these lectures is a quiz like game that quizzes you on the basic knowledge of Swift though you can adapt it to whatever quiz material you would like to focus on.

Who this course is for:
  • Beginner to Advanced