1
00:00:00,210 --> 00:00:03,580
In this lesson we will be creating the course.

2
00:00:03,600 --> 00:00:06,980
First I want you to go to the models folder.

3
00:00:07,140 --> 00:00:09,540
We want to create a new python file.

4
00:00:09,600 --> 00:00:13,290
So right click on the folder and choose new.

5
00:00:13,290 --> 00:00:15,370
Then click on python file.

6
00:00:15,420 --> 00:00:17,500
Let's set the name to course and hit.

7
00:00:17,550 --> 00:00:26,170
OK now on this new file we'll start by importing the first one we'll be importing logging.

8
00:00:26,190 --> 00:00:31,820
Also we will be using time then from the drone app models base.

9
00:00:31,890 --> 00:00:36,430
We will import Singleton which we made in the previous lessons.

10
00:00:36,450 --> 00:00:39,060
Don't forget to set the logger to logging.

11
00:00:39,090 --> 00:00:43,660
Get logger underscore name based on PIP AIDS.

12
00:00:43,680 --> 00:00:50,100
We would need to set two black lines here but I don't think we can fit all the codes in the screen so

13
00:00:50,100 --> 00:00:54,420
I'll have to set aside the PEP 8 code stall for now.

14
00:00:54,420 --> 00:01:01,600
First we set a class called base course later on this lesson we will be creating different courses like

15
00:01:01,630 --> 00:01:03,350
course a and core speed.

16
00:01:03,780 --> 00:01:11,490
But this base class will be the base for all courses the middle class will be set to Singleton.

17
00:01:11,490 --> 00:01:19,260
Next we will set the edit followed by self name of the course and the drone that will be flying the

18
00:01:19,260 --> 00:01:22,230
course as an argument self.

19
00:01:22,230 --> 00:01:29,220
Name will be set to name so we can distinguish the courses we will set the status initially.

20
00:01:29,250 --> 00:01:31,630
This will be set to 0.

21
00:01:31,920 --> 00:01:41,280
The status will be used to operate the drone for example status 1 will be takeoff Status 2 will be flip.

22
00:01:41,280 --> 00:01:44,850
Also we want to check if the drone is flying through the course.

23
00:01:44,850 --> 00:01:47,370
So we set is running.

24
00:01:47,370 --> 00:01:49,080
This will be set to false.

25
00:01:49,110 --> 00:01:52,070
The game will be based on competing the time.

26
00:01:52,560 --> 00:01:54,300
So we need to get the start time.

27
00:01:54,300 --> 00:01:56,310
This we can set to None.

28
00:01:56,310 --> 00:02:02,280
Also we need to get the elapsed time also set to None.

29
00:02:02,280 --> 00:02:08,060
Lastly we set the drone to the drone attribute.

30
00:02:08,070 --> 00:02:12,760
Now we go on to define the start method once the race starts.

31
00:02:12,780 --> 00:02:18,870
We want to record the start time the start time will be set to the current time.

32
00:02:19,380 --> 00:02:25,190
Once the drone is in the race we want to change is running to true.

33
00:02:25,410 --> 00:02:28,230
Next we need a stop method.

34
00:02:28,320 --> 00:02:34,660
If the drone is not in the race we don't need to stop the drone so we can return false.

35
00:02:35,070 --> 00:02:38,240
If the drone is in the race we need to stop.

36
00:02:38,250 --> 00:02:43,560
So we set is running to false as we set the drone to stop.

37
00:02:43,560 --> 00:02:48,660
We need to set the status go back to zero again.

38
00:02:48,680 --> 00:02:52,070
Next we need to figure out how long the race is taking.

39
00:02:52,100 --> 00:03:00,260
So we set an update elapsed method if the drone is not in the race there is no elapsed time so we need

40
00:03:00,260 --> 00:03:02,670
to return a nun.

41
00:03:02,960 --> 00:03:09,020
If the drone is in the race we need to calculate the elapsed time which will be current time minus start

42
00:03:09,020 --> 00:03:10,110
time.

43
00:03:10,250 --> 00:03:13,280
Then the lapse time should be returned.

44
00:03:13,280 --> 00:03:17,120
Next will be the method to run the drone on the course.

45
00:03:17,120 --> 00:03:19,790
This will be underscore run.

46
00:03:19,790 --> 00:03:27,010
This method will be invoked from the courses to make the drone take off or to fly forward or back.

47
00:03:27,080 --> 00:03:31,830
So we want this method to override in this base class.

48
00:03:31,850 --> 00:03:39,840
We will set to raise an error if the method is invoked before it's implemented.

49
00:03:39,870 --> 00:03:41,580
Now we set the run method.

50
00:03:42,090 --> 00:03:46,710
If the drone is not running we need to return false.

51
00:03:46,710 --> 00:03:54,720
If the drone is running the status will be changed by adding 1 then the underscore run will be invoked

52
00:03:55,680 --> 00:03:58,870
and the update elapse method will be invoked.

53
00:03:58,870 --> 00:03:59,120
OK.

54
00:03:59,130 --> 00:04:05,010
This part seems a bit complicated so let's go through the code so I can explain what will happen once

55
00:04:05,010 --> 00:04:06,830
the smartphone is shaped.

56
00:04:06,930 --> 00:04:14,760
This run method will be invoked then the status will be changed to 1 and the underscore run method will

57
00:04:14,760 --> 00:04:17,360
be invoked in this underscore run.

58
00:04:17,430 --> 00:04:24,510
If all the commands will to be defined based on the status number every time there is a shake the drone

59
00:04:24,510 --> 00:04:32,250
will fly according to the status and with update elapsed we will receive how much time it took to complete

60
00:04:32,250 --> 00:04:33,750
the course.

61
00:04:33,750 --> 00:04:39,900
Once the course is finished the stop method will be invoked and all the values will go back to the initial

62
00:04:39,900 --> 00:04:40,920
settings.

63
00:04:40,920 --> 00:04:43,460
Now let's start by creating course a.

64
00:04:43,530 --> 00:04:46,200
So you will get a better understanding set.

65
00:04:46,200 --> 00:04:55,030
Class course a witch will inherit the base course defined the underscore run so it can overwrite.

66
00:04:55,050 --> 00:05:00,900
Now we will set the actions to the status number starting with Status 1.

67
00:05:01,080 --> 00:05:10,770
The drone will take off next let's set status 10 in the run method we set to add 1 to the status which

68
00:05:10,770 --> 00:05:12,990
means to get to the next action.

69
00:05:12,990 --> 00:05:15,900
We need to shake the smartphone 10 times.

70
00:05:15,900 --> 00:05:21,060
Once it hits 10 the drone will rotate clockwise 90 degrees.

71
00:05:21,120 --> 00:05:23,470
You can customize the actions on your program.

72
00:05:23,530 --> 00:05:27,550
Before this lesson we'll set it to clockwise.

73
00:05:27,690 --> 00:05:35,990
We can also add status 15 and 20 and 25 since the drone will be moving 90 degrees each time.

74
00:05:36,420 --> 00:05:41,820
By the time we reach 25 the drone will be facing where it started.

75
00:05:41,820 --> 00:05:43,950
Next we'll set the state is 30.

76
00:05:43,950 --> 00:05:47,880
To flip the drone front forward then at State is 40.

77
00:05:47,880 --> 00:05:51,760
We set the drone to flip back.

78
00:05:51,940 --> 00:05:58,900
Lastly at status is 50 we will set the drone to land and run the stop method so the status will go back

79
00:05:58,900 --> 00:06:00,990
to the initial settings.

80
00:06:01,010 --> 00:06:04,740
Imagine that this is of course a Mario Kart.

81
00:06:04,900 --> 00:06:06,320
Next let's set course.

82
00:06:06,330 --> 00:06:10,750
B Again this will inherit the base course class.

83
00:06:10,750 --> 00:06:17,050
I'll go on and create the Course B but you can customize the entire course if you wish to do so.

84
00:06:17,080 --> 00:06:25,870
First we define underscore run and override at state as one we will set the drone to take off at status

85
00:06:25,870 --> 00:06:26,430
10.

86
00:06:26,650 --> 00:06:31,630
We set the drone to flip front the flips are quite fun to watch.

87
00:06:31,630 --> 00:06:35,730
So you should definitely have it in the course at status 20.

88
00:06:35,740 --> 00:06:41,340
We set the drone to flip back here we will set another status.

89
00:06:41,350 --> 00:06:50,410
If self elapsed is not a nun and the elapsed time is bigger than 10 and smaller than 15 the status will

90
00:06:50,410 --> 00:06:51,910
skip to status 45

91
00:06:55,670 --> 00:07:02,800
next we sit status 30 which will flip the drone to the right as we added the if statement to state is

92
00:07:02,800 --> 00:07:03,500
20.

93
00:07:03,680 --> 00:07:10,820
Once all the condition is cleared the status will jump to 45 skipping status is in between.

94
00:07:10,820 --> 00:07:16,150
Let's copy status 30 to make status 40 and set this to flip left.

95
00:07:16,190 --> 00:07:22,070
You can think of this as a bonus stage in Mario Kart where you get a certain item that helps you warp

96
00:07:22,490 --> 00:07:26,360
to a better position.

97
00:07:26,360 --> 00:07:32,870
Lastly we set status 50 to land and not to forget to stop as we just seen.

98
00:07:32,930 --> 00:07:39,990
You can use elapsed to create a bonus stage or even set back statuses to make the course more interesting.

99
00:07:40,010 --> 00:07:47,430
It's all up to you so have fun creating the courses next suit we want to create a global function name.

100
00:07:47,430 --> 00:07:57,590
Get courses this function will create the course and return the value.

101
00:07:57,890 --> 00:08:05,900
The first course will be number one with course a as the course name followed by an argument drone.

102
00:08:05,930 --> 00:08:11,990
This will be the same for the next course we main course name will be course be followed by an argument

103
00:08:12,020 --> 00:08:14,420
set to drone as we said.

104
00:08:14,450 --> 00:08:16,190
Each course to Singleton.

105
00:08:16,190 --> 00:08:24,020
Even if the get course function is invoked multiple times the present course A or B will be returned

106
00:08:25,330 --> 00:08:26,300
in our next lesson.

107
00:08:26,300 --> 00:08:29,660
We will go to the server P Y file to invoke the horse.
