WEBVTT

00:00.000 --> 00:11.000
In this video, we will learn to use conditionals and logical operators to make decisions.

00:11.000 --> 00:17.000
Understand nested of statements for complex decisions in a text-based adventure game.

00:17.000 --> 00:20.000
Introduction and player choice.

00:20.000 --> 00:22.000
Step into a world of adventure.

00:22.000 --> 00:27.000
First, define story and choices.

00:27.000 --> 00:33.000
The player starts at the entrance of a forest and must decide whether to enter.

00:33.000 --> 00:39.000
If they enter, they will face a fork in the path and must choose between left or right.

00:39.000 --> 00:44.000
Each path will present a new challenge and the player must make another decision.

00:44.000 --> 00:51.000
The game will end with either a win by finding the treasure or a loss.

00:51.000 --> 00:54.000
Let's start the program by welcoming the player and setting the scene.

00:54.000 --> 01:01.000
We use the print function to display a welcome message and provide instructions for the player.

01:01.000 --> 01:02.000
Print.

01:02.000 --> 01:05.000
Welcome to the text-based adventure game.

01:05.000 --> 01:06.000
Print.

01:06.000 --> 01:09.000
You are at the entrance of a dark forest.

01:09.000 --> 01:12.000
Find the treasure.

01:12.000 --> 01:14.000
Ask the player if they want to enter the forest.

01:14.000 --> 01:17.000
The answer will be either yes or no.

01:17.000 --> 01:19.000
Choice 1 equals to input.

01:19.000 --> 01:21.000
Enter the forest.

01:21.000 --> 01:23.000
Yes, no.

01:23.000 --> 01:25.000
Dot lower.

01:25.000 --> 01:29.000
Here, the player's input is stored in the variable choice 1.

01:29.000 --> 01:33.000
Dot lower ensures the input is case-insensitive.

01:33.000 --> 01:38.000
For example, yes or yes both work.

01:38.000 --> 01:43.000
Players make choices at each step by typing specific inputs like this.

01:43.000 --> 01:50.000
The program uses if, else if, and else conditionals to check the player's choices and decide what happens next.

01:50.000 --> 01:53.000
Entering the forest first decision.

01:53.000 --> 01:56.000
If choice 1 is equal to yes.

01:56.000 --> 01:59.000
The program checks if the player typed yes.

01:59.000 --> 02:02.000
If true, the game continues.

02:02.000 --> 02:05.000
The player enters the forest and sees a fork in the path.

02:05.000 --> 02:10.000
They are asked to choose between going left or right.

02:10.000 --> 02:11.000
Print.

02:11.000 --> 02:14.000
You enter the forest and see a fork in the path.

02:14.000 --> 02:18.000
Choice 2 equals to input.

02:18.000 --> 02:20.000
Go left or right.

02:20.000 --> 02:22.000
Left right.

02:22.000 --> 02:24.000
Dot lower.

02:24.000 --> 02:27.000
Logical operators are used to combine or check conditions.

02:27.000 --> 02:30.000
Here, we used or operator.

02:30.000 --> 02:32.000
Path decisions.

02:32.000 --> 02:34.000
Nestative statements.

02:34.000 --> 02:37.000
If choice 2 is equal to left.

02:37.000 --> 02:42.000
If the player chose left, the program continues with this path.

02:42.000 --> 02:47.000
The player finds a river and must decide whether to swim across or look for a bridge.

02:48.000 --> 02:49.000
Print.

02:49.000 --> 02:51.000
You find a river.

02:51.000 --> 02:53.000
Choice 3 equals to input.

02:53.000 --> 02:55.000
Swim or look for a bridge.

02:55.000 --> 02:58.000
Swim bridge.

02:58.000 --> 03:00.000
Dot lower.

03:00.000 --> 03:03.000
If choice 3 is equal to bridge.

03:03.000 --> 03:08.000
If the player chooses bridge, they successfully cross the river and find the treasure.

03:08.000 --> 03:11.000
The game ends with a win.

03:11.000 --> 03:12.000
Print.

03:12.000 --> 03:14.000
You cross the bridge and find the treasure.

03:14.000 --> 03:16.000
You win.

03:17.000 --> 03:21.000
If the player chooses anything other than bridge.

03:21.000 --> 03:24.000
For example, if player chooses swim.

03:24.000 --> 03:29.000
They drown in the river and the game ends with a loss.

03:29.000 --> 03:30.000
Else.

03:30.000 --> 03:31.000
Print.

03:31.000 --> 03:33.000
You drown in the river.

03:33.000 --> 03:35.000
Game over.

03:35.000 --> 03:40.000
Nestative statements are used to handle decisions that depend on previous decisions.

03:40.000 --> 03:44.000
Else if choice 2 is equal to right.

03:44.000 --> 03:49.000
If the player chose right at the fork, the program continues with this path.

03:49.000 --> 03:56.000
The player encounters a wild bear and must decide whether to fight or run.

03:56.000 --> 03:57.000
Print.

03:57.000 --> 04:00.000
You see a wild bear.

04:00.000 --> 04:02.000
Choice 4 is equal to input.

04:02.000 --> 04:04.000
Fight or run.

04:04.000 --> 04:05.000
Fight run.

04:05.000 --> 04:07.000
Dot lower.

04:07.000 --> 04:11.000
Their choice is stored in the variable choice 4.

04:11.000 --> 04:15.000
If choice 4 is equal to run.

04:15.000 --> 04:20.000
If the player chooses run, they escape the bear and find the treasure.

04:20.000 --> 04:23.000
The game ends with a win.

04:23.000 --> 04:24.000
Print.

04:24.000 --> 04:26.000
You escape and find the treasure.

04:26.000 --> 04:29.000
You win.

04:29.000 --> 04:32.000
If the player chooses anything other than run.

04:32.000 --> 04:35.000
For example, if player chooses fight.

04:35.000 --> 04:39.000
The bear attacks them and the game ends with a loss.

04:39.000 --> 04:40.000
Else.

04:40.000 --> 04:41.000
Print.

04:41.000 --> 04:42.000
The bear attacks you.

04:42.000 --> 04:45.000
Game over.

04:45.000 --> 04:48.000
Invalid or exit choices.

04:48.000 --> 04:54.000
If the player enters an invalid choice, they get lost and the game ends.

04:54.000 --> 04:55.000
Else.

04:55.000 --> 04:56.000
Print.

04:56.000 --> 04:57.000
Invalid choice.

04:57.000 --> 04:59.000
You get lost.

04:59.000 --> 05:01.000
Game over.

05:01.000 --> 05:07.000
If the player chose no at the beginning, they decide not to enter the forest and the game ends.

05:07.000 --> 05:08.000
Else if.

05:08.000 --> 05:10.000
Choice 1 is equal to no.

05:10.000 --> 05:11.000
Print.

05:11.000 --> 05:13.000
You stay outside the forest.

05:13.000 --> 05:16.000
Game over.

05:16.000 --> 05:21.000
If the player enters an invalid choice, the program tells them to try again.

05:21.000 --> 05:22.000
Else.

05:22.000 --> 05:23.000
Print.

05:23.000 --> 05:25.000
Invalid choice.

05:25.000 --> 05:27.000
Try again.

05:27.000 --> 05:31.000
Save the program with a name like Adventure Game.

05:31.000 --> 05:37.000
Click the Run button and check whether you win or lose the game.

05:37.000 --> 05:47.000
You have learned how to use conditionals, logical operators, and nested IF statements to make decisions in a program through this Adventure Game.

