background top icon
background center wave icon
background filled rhombus icon
background two lines icon
background stroke rhombus icon

Download "Базовый курс С++ Часть #15. Рефакторинг сложного класса"

input logo icon
Table of contents
|

Table of contents

0:00
Рефакторинг сложного класса
1:42
Форматирование ссылок и указателей
3:58
Настройка выравнивания кода в Visual Studio
6:13
Выносим сущность шарика в класс ABall
10:50
Исправляем ошибки, разделяя сущности движка и шарика
29:15
Указатель на себя this
33:44
Переносим часть членов класса ABall в приватную секцию
35:53
Popcorn_11.zip: пишем код
36:22
Выносим сущность уровня в класс ALevel
55:07
Рефакторим метод Init_Engine()
1:02:11
Статический метод
1:05:21
Popcorn_12.zip: пишем код
1:05:39
Создаём функцию инициализации ABall::Init()
1:07:57
Выносим сущность платформы в класс AsPlatform
1:29:33
Рефакторим имена членов данных платформы
1:32:38
Popcorn_13.zip: пишем код
1:32:50
Выносим сущность рамки в класс AsBorder
1:40:26
Рефакторим имена методов
1:43:00
Подводим итог рефакторинга класса движка
1:43:46
Popcorn_14.zip: пишем код
Video tags
|

Video tags

С++
C++
Программирование
Курсы С++
Изучаем С++
Программирование в Windows
Popcorn
Subtitles
|

Subtitles

subtitles menu arrow
  • ruRussian
Download
00:00:00
[music]
00:00:16
we continue to start writing our
00:00:19
program, now we are in the process of
00:00:23
converting the prototype of our game
00:00:25
written in C into the actual
00:00:28
program itself written in C
00:00:30
plus plus
00:00:31
last time we converted the code of the
00:00:34
engine module into a class called c
00:00:37
engine we got pretty good a large
00:00:40
class that contains many
00:00:44
functions of
00:00:45
variables and constants, this class
00:00:48
itself is quite voluminous, such an abundance of code
00:00:51
in one class is, in principle, a completely
00:00:53
normal phenomenon, there is nothing wrong with
00:00:56
that, but in such a class there is another
00:00:58
problem; in fact, here, in addition to
00:01:00
the essence of
00:01:01
the engine, several more are described other
00:01:03
entities whose functionality is
00:01:06
scattered among the functions of our engine I
00:01:09
will press f5 to launch our game, please
00:01:10
note we have a ball
00:01:13
platform frame level bricks level
00:01:17
at least these four entities are not clearly
00:01:19
present among the code of our engine
00:01:22
such a class overloaded with logic
00:01:24
is a signal that
00:01:26
the programmer should
00:01:27
a3 factory this class and put the hidden
00:01:30
entity into separate classes, in other
00:01:33
words, we need to split our
00:01:36
engine class into several classes, each of
00:01:39
which will describe its own
00:01:40
entity,
00:01:41
but before we do this, I want to
00:01:44
customize our visual studio a little, I
00:01:47
noticed that last time when I
00:01:49
transferred the functions to the header file,
00:01:51
visual studio itself did
00:01:54
some formatting for me and
00:01:56
changed the code in a way that, in
00:01:58
my opinion, is not the best, I will
00:02:00
demonstrate this with an example, let's
00:02:02
take some function that
00:02:03
has parameters, for example, this fraction
00:02:06
free, I will copy it from here
00:02:10
I’ll paste here after the last function
00:02:14
to show how visual studio
00:02:16
automatically formats the code I
00:02:18
paste into empty lines I paste this
00:02:20
line, pay attention here in the
00:02:23
declaration of the paint parameter Perry we
00:02:26
have a name of type
00:02:27
rect then a space then an ampersand then a
00:02:31
variable name if I put a semicolon
00:02:33
the visual studio corrects this cat
00:02:36
because in its opinion it seems correct,
00:02:38
although in fact all these rules are
00:02:41
spelled out in the studio itself and we
00:02:43
can change them, in fact, I think
00:02:45
that it is better when our code remains in
00:02:49
this form, I will explain this on another page
00:02:51
For example, imagine that we have
00:02:53
a variable called a
00:02:55
and I can also declare another
00:02:58
variable called b and
00:03:00
is a reference to a value of type int,
00:03:03
so from the point of view of C plus plus we
00:03:05
can write like this, or we can write like this, for
00:03:08
example, both spellings are quite
00:03:11
acceptable and in the second case, the ampersand
00:03:15
that is written along with the type name
00:03:17
tells us that this is a reference to an
00:03:19
entire type, but in the first case, the birsan
00:03:22
before the variable name also says that
00:03:23
this is a link, however, I can declare a
00:03:26
variable in a string, for example, I can
00:03:29
write int and then declare variable b
00:03:33
which is a reference to an integer type
00:03:35
after that I can write for example a
00:03:37
pointer to a variable of an integer type
00:03:40
called c and in this case we have
00:03:43
an ampersand and an asterisk is already
00:03:46
part of the name they are of the type so I
00:03:49
suggest in our project and follow the
00:03:51
simple rule ampersand and and
00:03:53
put the asterisks close to the variable name and the
00:03:56
nickname of the type name so that visual studio does
00:03:59
n’t format it for us, but the cat doesn’t
00:04:01
do it because in my opinion it’s not very
00:04:03
good, we need to configure its
00:04:06
formatting options and about another
00:04:07
line of code and I’ll show this one game and
00:04:11
here we go to the tools menu, then to the
00:04:15
item about chance and here we have a
00:04:18
menu item texts editor, which
00:04:21
lists the rules for working with code
00:04:24
for each language, here is our C plus plus and
00:04:27
here we have if I click here or here I
00:04:30
will see the same window that lists the
00:04:33
main option, but the items that
00:04:36
I need are in the formatting sub-item
00:04:39
because they are related to formatting,
00:04:41
here I will uncheck this item,
00:04:44
which means I need to automatically
00:04:46
format the text when leaving a
00:04:48
semicolon, I also uncheck
00:04:50
this item which means
00:04:52
automatic formatting when
00:04:54
inserting a closing brace and this
00:04:57
checkbox, which also formats the code
00:05:00
when I edit
00:05:01
these curly braces by deleting them, adding them
00:05:04
or moving them in some way,
00:05:05
I click ok and now if I go
00:05:09
back to the source file I’ll take this
00:05:11
line and paste it here
00:05:15
when I I press the semicolon visual
00:05:18
studio will not format this code
00:05:20
in the same way it will not
00:05:21
format it if I open a curly
00:05:24
brace here, while visual studio puts the second closing
00:05:26
curly brace
00:05:27
itself if I
00:05:30
edit this text, for example,
00:05:32
leaving an empty line, then writing
00:05:34
our parameters is also not is changing, I
00:05:38
will remove this extra year, I will correct the
00:05:40
writing of the parameters so as not to
00:05:41
return to this issue, then
00:06:06
now it looks correct, of course,
00:06:09
this is my subjective opinion, and so
00:06:13
let's try to remove
00:06:15
one of the implicitly present
00:06:18
entities from our class, I suggest starting the
00:06:21
smallest element with a ball for description
00:06:24
ball, we have several variables here,
00:06:27
in particular these ones that set the position of the
00:06:29
ball, its speed and direction; perhaps there
00:06:32
are some other changes
00:06:34
that at first glance are difficult
00:06:35
to determine, but all of them will become
00:06:38
known to you during the transfer process; also here
00:06:40
there is a pair of functions 1 for drawing the ball
00:06:42
friend bob 2 for moving it to the floor and
00:06:46
these functions, along with these variables,
00:06:48
can be placed in a separate class for
00:06:50
this, here in the code, before describing the
00:06:52
class from the engine, I will add another section
00:06:57
with a comment and write a class and call
00:07:01
it bolt, and following my
00:07:04
notation system, I I’ll add a prefix to it with a
00:07:06
capital letter ы l and I could
00:07:10
also add a prefix c here, which means that it
00:07:12
should be in a single copy,
00:07:14
but the ball can be in multiple
00:07:17
copies. There is a game situation in which the ball
00:07:20
can get upset and turn into 3
00:07:22
balls, so our program
00:07:24
implies there are a lot of objects of
00:07:26
this class, so I just crossed mine
00:07:28
and I put a couple of curly braces and
00:07:33
now we have our new class, this is the
00:07:35
so-called empty class, all that
00:07:38
it has is only a name and this is a completely
00:07:39
valid entity in our program, but
00:07:42
I will transfer the function from our darling here
00:07:45
I’ll immediately make an open section here,
00:07:48
I’ll write my public page and
00:07:51
all the functions and data will be placed right in it, and
00:07:53
later we’ll transfer to the private section those
00:07:55
methods and data that should not be
00:07:58
accessible from the outside. I’ll take the Friend Bob function
00:08:06
and move it here as well as SBU
00:08:09
and also these are the variables
00:08:18
and now I take the name of this class and
00:08:20
declare an object of type ball in our
00:08:24
engine, I will put it for example here I write
00:08:29
the name of the class
00:08:30
the name of the object and now all the
00:08:33
functionality of the ball will have to
00:08:35
be inside the class and bolt and be
00:08:38
accessible through an instance of this class an
00:08:41
object named bean,
00:08:43
well, of course, this is not enough and
00:08:45
now I need to transfer a couple of these
00:08:47
methods from the class from engine to the bolt class,
00:08:51
for this I right-click
00:08:54
and select the item there, finish, but or
00:08:58
just click on 12 and go to the code of
00:09:00
this function in order this function
00:09:03
has moved from one class to another,
00:09:04
here instead of the name
00:09:06
with engine I need to write the name of this
00:09:08
other class, that is, ball, now the
00:09:13
method friend gender has become a method of another
00:09:15
class, I do the same with the second
00:09:18
method, press f12 and write here the name of the
00:09:22
new goat, but so these methods will be
00:09:25
scattered among the methods of the class with the
00:09:28
engine, and frankly speaking, this is a poor
00:09:30
design of the code; we have header files of the
00:09:32
class and God is above the boss from the
00:09:36
engine, so it would be quite logical if the
00:09:39
cat of the methods themselves would also be
00:09:41
spread out above the methods of the class from
00:09:43
kenji,
00:09:44
so I press f12 and cut
00:09:49
this whole method is from here and I insert it
00:09:54
before the first method of the CNG class
00:09:57
here when I place
00:10:00
several classes in one source file
00:10:02
I separate them among themselves with four
00:10:05
consecutive correct lines
00:10:10
which allows you to easily
00:10:13
find the place where 1 class ends
00:10:15
and another begins without scrolling, now I’ll move it here
00:10:17
and the second method I go to the
00:10:19
header file, press f12 and
00:10:22
cut out the move floor method from here and
00:10:29
paste it at the beginning of the file like this if
00:10:35
I now press compilation we will have a
00:10:37
lot of errors because such a change in
00:10:39
the code quite breaks its
00:10:41
structure and we will have to bear quite a
00:10:44
lot changes so that the code compiles again,
00:10:50
the compiler found us 84 errors, which is
00:10:54
of course a lot, and not all of them
00:10:56
are compilation errors, that is,
00:10:59
errors
00:11:00
marked with a cross in
00:11:02
a circle, there are also
00:11:04
many syntax errors
00:11:06
marked with this symbol, and BC and
00:11:09
visual studio dump these errors in a
00:11:11
common heap, although it can easily
00:11:13
happen so that by correcting one line of
00:11:15
code, I immediately remove many, almost a
00:11:17
dozen errors because these errors are
00:11:20
largely interrelated, but all
00:11:22
we can do is move either through the
00:11:24
list of these errors
00:11:25
or through the code itself, looking at these
00:11:29
underlined ones symbols and we can start
00:11:32
right from here that error means that
00:11:34
the variable b gpn is not defined and
00:11:37
indeed in the class by God we do not have a
00:11:41
variable with that name
00:11:42
because this variable still
00:11:44
remains in the class with engine
00:11:46
if I press f12 then I will go to
00:11:49
definitions variable inside the class with
00:11:52
angel,
00:11:53
this variable describes a pencil for
00:11:55
drawing the background and this variable is needed not
00:11:58
only by the ball but also by other functions
00:12:00
in the same class, so you
00:12:04
can’t take this variable from here like those others, it must remain here,
00:12:07
therefore we must
00:12:09
have a copy of this variable in our ball or
00:12:11
provide access to the common for these
00:12:14
two classes in a variable, but for now we
00:12:16
’ll go the simple way and just
00:12:18
copy, I’ll take the type hp
00:12:21
added here, take the variable name bgp
00:12:26
and add it here
00:12:29
now if I go to the source file,
00:12:31
there’s one less error and we have here is a
00:12:33
similar error, an unknown pg brush symbol
00:12:37
because this brush is described in another
00:12:40
class, it is also needed here, so
00:12:42
you can’t take it away, I’ll copy it and
00:12:47
add it to our class, the sky has become a little
00:12:51
easier, although there are still a lot of errors, the
00:12:53
next thing I don’t like about the studio is
00:12:55
that we refer to the
00:12:57
indefinite identifier of the
00:12:59
bonerex stops if I click and in 12 the visual
00:13:03
studio will find it in the class with engine and
00:13:07
indeed this structure and
00:13:09
this they describe the previous and current
00:13:12
position of the ball and it is quite appropriate if I
00:13:15
take these structures from here and
00:13:18
define them in the class was where they
00:13:21
should exist because it is
00:13:23
part of the
00:13:24
description of the ball entity, now here this
00:13:29
underlining is gone and we can move on to the
00:13:31
next name ball pen is not defined, press f12
00:13:36
and again we get into the definition of our
00:13:38
class and sender here this pencil and the
00:13:41
corresponding brush are needed only for
00:13:43
drawing a ball so from here I can
00:13:45
take this name and move it our
00:13:51
class the same thing with the r12 brush from here
00:13:58
we take it and move it here
00:14:04
look further I’ll even press f7 but there are also
00:14:10
a little fewer errors there were 80
00:14:13
-something now 58
00:14:15
now let’s sort out the complaints about the
00:14:18
next function here we have the name
00:14:21
ball says which is a static
00:14:24
constant in the class with engine
00:14:27
but it is quite logical that if the constant
00:14:29
describing the size of the ball will
00:14:32
be in classic describing the ball
00:14:34
so I take it from here and paste it here in the
00:14:37
class was look at the following
00:14:43
problem max expose this the same constant,
00:14:46
but this constant
00:14:48
can no longer be the private property of
00:14:49
the ball because the maximum value
00:14:52
in X is also needed by other entities in our
00:14:54
program, therefore, we can take this constant from here
00:14:57
from the class with the engine, we
00:14:58
cannot use it here,
00:15:01
we need it and in another coffee we can
00:15:04
do it quite simply in due to the fact
00:15:06
that this is a constant,
00:15:08
it is static and it exists neither in the
00:15:11
class object from the engine, but in the class,
00:15:14
therefore we can access this
00:15:16
constant not through a pointer or a reference
00:15:19
to the object, but by specifying the name of the class, that is, there is no
00:15:23
need to take the name of the Viz Angie class and
00:15:26
put it in front with the name of this
00:15:28
constant like this, now I really see in the
00:15:32
studio another complaint about saying that
00:15:34
this constant is not available, this is because the
00:15:38
max expose constant is in a private section
00:15:42
in this one, so I should take this
00:15:45
constant and move it to the public section
00:15:48
and it would be quite logical if I
00:15:49
transfer the max expose I will move imax y
00:15:53
post because they are logically closely
00:15:55
related to each other
00:15:56
from here we cut and paste into public
00:16:00
sections in the same course now
00:16:03
this is a constant here available I wanted
00:16:06
visual studio there were complaints about these
00:16:09
constants since they use the
00:16:11
value of other constants not yet described here
00:16:13
they are described below,
00:16:16
therefore I need to transfer these
00:16:18
constants from the private section to the public and
00:16:20
although I only need one, this
00:16:23
is paired with this one, so I take
00:16:26
both lines and add them here, the
00:16:29
same goes for the constant sat white,
00:16:32
compress the contra rf and take it
00:16:36
and a constant paired with it and move it here
00:16:42
now the error associated with the bow
00:16:45
says constant the bow says constant is not
00:16:48
known here because now it is a constant
00:16:50
belonging to another class so I
00:16:53
take the name of this other class and put
00:16:56
it here like this in a pony
00:17:01
naturally the constants
00:17:02
migrated from the private section to
00:17:04
publicly press f12 and move the
00:17:11
constant from here to the public grid and
00:17:17
add the class name, perhaps somewhere
00:17:23
else this constant is used
00:17:24
no no longer used now
00:17:29
look at this name f12 and take a
00:17:32
couple of these constants here and move the public
00:17:35
section
00:17:44
and those constant can also be where -it’s
00:17:46
still used, no, too,
00:17:48
but here
00:17:56
f12 is better,
00:18:02
oh well, the name is missing
00:18:14
f12
00:18:17
is a constant
00:18:20
12, and here we have to change tactics, the thing is
00:18:24
that I can’t write the
00:18:27
class name here because the platforms
00:18:30
expose is not a constant. a variable
00:18:33
is a variable present in an object of
00:18:36
type with engine, which means that to access
00:18:39
such a variable, an
00:18:40
object of type of our engine is not needed here,
00:18:43
that is, the function husband ball,
00:18:45
I must access the object with engine
00:18:47
in order to access its
00:18:49
platform variable expose, but this
00:18:52
problem is solved quite I just take the
00:18:55
name of this class from engine and pass a
00:19:00
type variable from Ranger to our function
00:19:03
I write a class I write an asterisk
00:19:06
which means that it will be a pointer
00:19:08
to an object of this type and write the name of this
00:19:11
variable engine that is 10 I
00:19:17
pass the function to the brain a pointer to our engine
00:19:20
but if I changed the format of the function of the entire
00:19:24
chain of the file, I must change it
00:19:27
and the header file and here so that
00:19:31
these descriptions are identical
00:19:33
and now I take the name of an object of the type of our
00:19:37
engine and here I write this name with a minus
00:19:43
sign greater
00:19:44
than to make an arrow and now I
00:19:47
I can refer to this variable,
00:19:49
sold visual studio, still a claim is made,
00:19:51
she says that this variable is
00:19:53
not available,
00:19:54
but this is another problem, they are available,
00:19:56
this is a variable because it is
00:19:58
in a private section, therefore there is no
00:20:01
need to remove this variable from the private
00:20:03
section and place it in the public one
00:20:06
here By the way, I’ll remove this empty line
00:20:09
between the static consultants, here’s
00:20:13
the cream to use a variable of our
00:20:15
engine and wherever this name appears, I
00:20:18
’ll put the name of the object and an arrow in front of it,
00:20:21
now let’s see what the
00:20:24
problem is with what name and this is a
00:20:29
static constant, I forgot
00:20:32
to put the name of the class here, I wonder
00:20:34
where it is -that is used until that's all here for now
00:20:39
and this is me f12 this is also a
00:20:44
variable
00:20:45
also in the private section of our engine
00:20:48
so I transfer it from the private section to the
00:20:51
public one and put in front of it the name of the
00:20:55
pointer and the arrow there are still
00:20:59
a few underscores left, this global
00:21:02
scale is a static constant
00:21:06
I’ll take it from here and put it here in the
00:21:09
public section of the class with the engine and
00:21:12
put the name in front of this constant and
00:21:17
everywhere where it is used I’ll fix it.
00:21:26
Now we also have a complaint about the
00:21:29
variable h vnd which is in the
00:21:33
private section and I’ll also open this
00:21:36
variable, that is, I’ll move it and from
00:21:37
private sections to public so that you
00:21:40
can access this variable through the pointer to our beetle, there
00:21:52
remains a claim regarding functions
00:21:55
because this function is check lego brick hit
00:21:57
if we press f12 then I will find this function in the
00:22:03
private sections of the class with engine
00:22:07
so I can take out this function
00:22:09
from here from the private section and place
00:22:12
it in the public section, but here there is one more point to put the
00:22:16
name of the pointer
00:22:20
since this
00:22:22
function in our class follows immediately
00:22:25
after the function it is a timer, it would be logical to
00:22:27
expect in the code that in the file C plus
00:22:30
plus is also located after functions there is a
00:22:32
timer, although now this is not the case, so I
00:22:35
press the f12 key, go to the code of this
00:22:38
function,
00:22:39
cut it out from here, return to the f12 class
00:22:44
and put it after the timer,
00:22:48
now we press f7 a little better and
00:22:53
there are not much fewer errors,
00:23:01
but at least you went through these
00:23:03
class methods and bombs and
00:23:06
they no longer have errors, it would seem
00:23:09
such a small ball, how many functions are there in it,
00:23:12
and so many actions
00:23:14
have to be taken to move it
00:23:17
into a separate entity,
00:23:18
but let's continue, in the
00:23:21
constructor of our engine there are four
00:23:23
errors
00:23:24
related to the fact that we are
00:23:26
initializing variables here which are
00:23:28
no longer in this class,
00:23:30
now these changes are in another
00:23:32
class, therefore, the initialization of these
00:23:36
changes must occur in another
00:23:38
eye, namely in the constructor of another class
00:23:41
bull, we don’t have this constructor yet,
00:23:43
so we need to write it, I go to the
00:23:48
beginning of the file and add more here one
00:23:53
feature feature will be called a
00:23:57
water highball. and God and imagine myself as a
00:24:02
designer, but since my husband’s header
00:24:05
files have not yet described him, the visual
00:24:07
studio immediately made a claim, I
00:24:11
copy this name from here and paste it
00:24:15
here, please
00:24:18
note, I format the text of
00:24:21
our class, breaking it into logical
00:24:24
groups with the correct lines, at the beginning
00:24:27
I have everything the constructor will come and a
00:24:29
class class can have many constructors,
00:24:31
so this is a separate section of code, then
00:24:33
I have methods of
00:24:35
our class, then variables, and
00:24:38
since we have a lot of variables,
00:24:40
I divided them into two groups, variables of
00:24:42
simple types and variables of
00:24:44
complex types, and then there is a section with
00:24:47
constants This division of the code
00:24:49
makes it easier to find information because
00:24:51
it is the search for information by code that we are
00:24:54
mainly engaged in when we write a
00:24:56
program, so let’s go back to the ball constructor. I
00:24:59
created a constructor and now I will transfer
00:25:04
the initialization of the variable to it from here, we
00:25:07
will take it and add it here, I press
00:25:16
compilation f7
00:25:20
here visual studio highlights for us
00:25:22
another problem,
00:25:23
although the mov function was written correctly,
00:25:27
the complaint is that this type
00:25:30
with the engine is unknown here at the
00:25:34
moment when visual studio analyzes the
00:25:36
header file, the fact is that
00:25:38
this type is defined later below and at the
00:25:42
time of compilation of this line of
00:25:44
visual code studio doesn’t know what the name with the
00:25:48
engine means, in order to eliminate this
00:25:50
error I have to tell visual studio
00:25:52
that this is kvass I can’t move the
00:25:54
description of this class
00:25:56
above before and ball because we have
00:26:00
men in this class itself here in
00:26:03
this case I I have to make a so
00:26:05
-called preliminary declaration
00:26:07
or in English forward declaration
00:26:10
I take the name of the class that I need
00:26:12
earlier and put it here on a separate
00:26:17
line I write kvass the name and a semicolon
00:26:22
this entry means that I marked the name
00:26:26
from the engine as a class
00:26:27
but have not yet described you visual studio
00:26:30
expect that the description will be somewhere further,
00:26:32
but now I can use this
00:26:34
name
00:26:35
visual studio will correctly
00:26:37
interpret it as a class name I click
00:26:42
compilation and for some reason we have this
00:26:45
suspiciously few errors, only 13
00:26:48
I go to the first point
00:26:51
identifier ball pen
00:26:53
This function is not defined and there is no engine that creates a
00:26:57
pair of pencil and brush for our
00:27:01
ball and writes down their corresponding
00:27:03
variables.
00:27:04
Well, since these variables are now
00:27:05
placed in a separate class, we need to
00:27:08
indicate here the name of the object to which
00:27:10
these variables belong, that is, we
00:27:13
have a bolt object
00:27:16
I can write bombs here.
00:27:20
there was ben like this the next error paul
00:27:27
frank is not defined and this error we
00:27:30
have a firewood function frame of our
00:27:32
engine and we could solve it we could just
00:27:35
write 10 the name of the object bolt and the
00:27:39
drabble function should also be called in this
00:27:42
object but this is not a very good
00:27:46
approach because here the function is
00:27:48
to decide whether to draw the ball or not,
00:27:51
which is actually the responsibility
00:27:53
of the ball with others, you need to let the
00:27:55
ball itself decide whether it can
00:27:58
draw itself or not, so I’ll take this
00:28:00
condition check, take it from here, I’ll press
00:28:04
12 and the function itself will do this check,
00:28:09
but there I need the opposite condition here,
00:28:12
that there is an intersection, there is nothing and
00:28:17
we don’t do anything here, the
00:28:18
intersection rectangle is missing, I press
00:28:20
control of and go to f3 to another
00:28:26
function where it is defined, I copy it,
00:28:29
I come back here and paste it when I
00:28:33
could write,
00:28:34
well, there is no need for a name here anymore object
00:28:38
since we inside the ball class have
00:28:40
direct access to our changes and all that
00:28:44
remains is to slightly correct the line with
00:28:46
the call, that is, remove the extra tab
00:28:50
so the code looks more neat and the pirates and I
00:28:53
inside the draw function have the
00:28:55
functionality for drawing the ball, press the
00:28:58
combination for everyone and look at the next
00:29:01
error
00:29:02
with the identifier y in the floor is undefined yes
00:29:05
because this function was previously called a
00:29:07
method of the
00:29:09
engine class and now it is a method of the class [ __ ] I
00:29:11
can call it on an object but our
00:29:15
function in its side must accept
00:29:18
pointers to the engine
00:29:20
and there is no variable here that is a
00:29:22
pointer to an
00:29:24
instance of cool CNG that is in other
00:29:26
words, in the
00:29:28
engine method, it is a timer when calling the ball function,
00:29:32
this object had to pass a
00:29:33
pointer to itself, and for this, everything plus
00:29:36
plus there is a special keyword
00:29:38
called viz, which
00:29:42
denotes a pointer to an object
00:29:46
whose method is described in this code,
00:29:47
in this case on the engine, perhaps you
00:29:50
it will not be entirely clear what the
00:29:52
keyword from means, in any case,
00:29:55
it was not immediately clear to me at one time, but in
00:29:57
principle there is nothing complicated here. I press
00:29:59
compilation, then everyone and in the engine method check
00:30:05
lego brick hit we modify the
00:30:08
bull direction variable, which is now
00:30:10
in the class and god in this, I’m writing here the name of the
00:30:13
object of this class and now we can
00:30:18
change this variable f7 and suddenly
00:30:23
the program has compiled,
00:30:25
let’s try to run it, well, it even somehow
00:30:28
works, although this trace from the ball
00:30:31
means that the background is redrawn
00:30:34
incorrectly, namely, it looks like the background
00:30:37
brush and pencil are not contain the correct
00:30:39
values ​​and indeed here is our class
00:30:43
floor here it has b g n and b g brush
00:30:49
which we use in the friend bean method
00:30:52
but these variables in this class were not
00:30:55
pierced by zero van and since in this
00:30:57
function we do not have a pointer to the engine then,
00:31:00
therefore, we cannot use
00:31:02
the variables that the engine has, the
00:31:05
simplest solution in this case would be to
00:31:07
simply add a pointer to our
00:31:09
engine here, namely, pass it as a
00:31:11
parameter to this function and use the
00:31:14
values ​​​​from the engine, that is, I will remove
00:31:19
this variable b in the class gpn and this run of the
00:31:22
respondent we will use from
00:31:24
our engine and I will take the name of the class and
00:31:29
add here
00:31:31
another parameter a pointer to our engine
00:31:35
here since we changed the name of the method here,
00:31:39
then we need to change it to fix it and here and
00:31:43
then I will take this indicator just its
00:31:47
name arrow and I’ll refer to the variable, so
00:31:53
that this variable is available, I’ll
00:31:55
then take it from here and move it from the
00:32:02
private section of the engine class to the
00:32:07
public section and do the same
00:32:09
for the brooch
00:32:16
and take it here and add it, let’s
00:32:19
see what happens in 7 here is the
00:32:26
firewood frame function when calling the function
00:32:29
friend floor is missing the 3rd parameter, a pointer
00:32:33
to the engine, that is, since this is a cool method, the
00:32:36
engine lacks a pointer to itself,
00:32:38
so I write in x,
00:32:41
compile, compile, run and
00:32:46
everything works and it’s good, well, what else I’ll
00:32:53
fix is ​​the name of the method that we
00:32:55
call us here it says balu.
00:32:58
friend ball and to be honest, this word is the
00:33:01
second bolt, it’s only a little bit, but this would be
00:33:04
considered the best draw to God,
00:33:06
so I click at 12, I’ll come to this
00:33:10
method again l12, I’ll go to the class and
00:33:13
remove these extra words from here, I press
00:33:17
alt and the left mouse button and correct
00:33:20
immediately by name, and here I remove this
00:33:26
piece and this one,
00:33:29
press f7 and adjust the places where
00:33:34
these methods are called, run it, it works,
00:33:43
and so we got it, we took from a
00:33:47
rather large class he's engine,
00:33:50
which clearly contained several
00:33:52
entities, we took from this class a
00:33:56
separate entity describing our ball
00:33:59
and described it as a separate class I, although
00:34:03
such a class looks quite normal
00:34:04
in my opinion, quite a lot of
00:34:06
elements are in the public section,
00:34:09
not all of these variables are needed to be
00:34:12
used externally, that is, change them from an
00:34:14
object like
00:34:15
bolt with others with you most of the
00:34:17
variables and constants of this class
00:34:19
should be private because these
00:34:21
are implementation details of this
00:34:23
class, but since we call these methods on an
00:34:26
object, I’m not sure about the variables,
00:34:28
let’s try to
00:34:30
put everything else in private sex I
00:34:33
tried to compile and got a bunch of
00:34:37
errors associated with the use of these
00:34:40
elements in particular ball says we
00:34:43
need coffee with the engine ball pen we
00:34:48
modify when we create a pencil
00:34:50
brush the direction we change from the functions
00:34:56
belonging to the engine
00:35:02
so I’ll try to move these elements
00:35:04
into the public section compile direction
00:35:16
f12 now with direction we move it to the
00:35:21
public section compile now
00:35:29
this class looks better Now those
00:35:31
elements that we use in an
00:35:33
object of type apple are available in the public
00:35:37
section, and those elements that we do not
00:35:39
use, that use the methods of
00:35:42
this class,
00:35:43
they remain in the private section.
00:35:46
Now we can consider that we have moved the
00:35:49
functionality of the ball into a separate
00:35:52
class. We will pause
00:35:55
now. try to take the ball out of your
00:35:58
engine into a separate class, it may
00:36:01
not be so easy, maybe
00:36:04
break everything altogether, but if anything you
00:36:06
should already have the skills and abilities to
00:36:08
return the project to its previous state, and
00:36:11
if you break everything, just try
00:36:13
again
00:36:14
this experience that you will gain taking the
00:36:16
code into a separate class will be great for you
00:36:18
later in your work, we
00:36:22
continue to refactor the class of our
00:36:25
game engine, this class is still
00:36:27
complex internally, there are still
00:36:30
several other entities and our task is
00:36:33
to move these entities into separate classes
00:36:35
so that in each class 1 entity is described
00:36:38
and the next candidate for a
00:36:40
separate class,
00:36:41
I think will be our level, I run the
00:36:44
program key f5 this array of
00:36:48
bricks in our project is called a
00:36:51
level and to describe the level in this
00:36:53
class we have several constants, these are
00:36:55
these, whether you are white-level hate or love
00:36:59
set a Also, this is the width and height of the
00:37:02
cell.
00:37:03
We have functions that
00:37:06
relate to this entity: drawing a
00:37:08
brick,
00:37:09
drawing a letter, and the Friend Lev function,
00:37:12
which draws the level itself,
00:37:13
and also perhaps some variables
00:37:16
are part of this entity. Now it’s not
00:37:19
obvious which ones should go into our
00:37:21
class, but as how we will transfer
00:37:23
the code and data from this class to another
00:37:25
visual studio will tell us with its
00:37:28
errors those places in the code that we
00:37:30
should correct in order to transfer the
00:37:32
essence of the describing level into a
00:37:34
separate class.
00:37:35
Here, in front of the engine class, I will create
00:37:39
another class as it describes you
00:37:43
waist level war for the ruble in English
00:37:45
left and I’ll put a prefix and mean
00:37:50
that this name is askew
00:37:52
I’ll immediately put a public section here and
00:37:55
transfer all the data and all the functions into it
00:37:58
and then we’ll transfer those of them that seem to be
00:38:00
service elements to the
00:38:03
private section I’ll take this I’ll move this pair of
00:38:07
constants and these pairs of constants
00:38:10
here,
00:38:15
I’ll take this function, even these
00:38:20
four functions and move them here, and
00:38:25
there’s also this function that
00:38:29
processes the collision of a ball with a
00:38:30
brick,
00:38:31
since these are traffic jams, which means it
00:38:34
should be in this class
00:38:36
Well, now it remains to transfer these
00:38:38
methods
00:38:39
from the office manager class to the Lego class.
00:38:42
By the way, I came here and they are on the left and
00:38:46
on the left because it implies that in
00:38:49
this I there may be many game levels
00:38:51
and again, I’m not sure about this, I’m just
00:38:53
guessing that there will be many game
00:38:56
levels,
00:38:57
but if later it turns out that the class
00:38:59
describing the level should be in a
00:39:01
single copy,
00:39:02
I’ll just change its name, but for now it will be
00:39:05
like this, copy this name, press f12 and go
00:39:10
to this method
00:39:12
and transfer this method to another braid
00:39:16
and at the same time I’ll take this code from here and cut it out
00:39:21
and I will insert it before the first function of the
00:39:26
class from the engine since we have
00:39:30
header files of goats and the left one
00:39:32
is located above the class from the engine in the
00:39:35
source file, we are also here you
00:39:37
will place it before the code of this class I
00:39:41
insert 4 empty lines
00:39:43
method and comments and also when I am in the
00:39:50
same file having several classes,
00:39:52
I also sign them with separate
00:39:55
comments, which slightly increases
00:39:58
the stability of the code,
00:40:11
and we continue to transfer the remaining
00:40:13
methods friend brik after him comes with bri
00:40:23
clitoris course this one and then drow brik
00:40:29
lecturer the
00:40:31
next direct method and / lego
00:40:38
these four methods in this source
00:40:42
file they also go one, we take it away, so I
00:40:44
immediately select everything and move it here, all that
00:40:56
remains is to change the class names
00:41:00
like this and that, but in principle you can
00:41:10
compile,
00:41:11
pressed everything, I get a whole bunch of
00:41:16
errors and I can, in principle, start from
00:41:19
this list, I can switch the source
00:41:22
file and go through here with all
00:41:24
the underlining that we
00:41:26
will encounter here, it
00:41:28
seems to me that it will probably be easier to go through the list,
00:41:32
so the first error is the class from the engine does not
00:41:36
have a member of the left head because
00:41:39
now it belongs to another class,
00:41:41
here it is, this is a constant, this is the tail,
00:41:45
so by changing here, after all, I am
00:41:49
correcting errors and also the
00:41:53
next error sng now does not have
00:41:57
such constants and that’s how it is, but this
00:42:04
function should now be called by it in the
00:42:06
engine and at the level, but I suggest returning to this error
00:42:09
a little later, but for now
00:42:12
we’ll deal with something like a pimple thing,
00:42:15
for example with this error I click f12
00:42:20
and we move on to the description of the brick
00:42:24
red pen variable which is in the class with
00:42:27
engine
00:42:28
and this variable describes the pencil for
00:42:31
drawing bricks
00:42:32
but it is obvious that this pencil should
00:42:35
already be in another guest so I
00:42:37
copy the hp type and paste it here
00:42:44
brick red band
00:42:46
I think and we'll take the brik blue pen from here,
00:42:51
and most likely we need to do the same with the brushes,
00:43:12
press compilation f7, there are
00:43:16
fewer errors and we can continue to go
00:43:18
through this list, so this is Ushakova later, we'll
00:43:22
look at this one, perhaps later, too,
00:43:25
because it's connected to our ball and this
00:43:28
error will be easier fix it because
00:43:30
it concerns only constants, press
00:43:32
f12 and find the Golgotha ​​constant
00:43:36
inside the class with engine
00:43:38
and we access this constant from the
00:43:42
left class,
00:43:44
therefore, since this is a static
00:43:47
constant, I just need to indicate the name of the
00:43:51
class, I can access this
00:43:55
constant
00:43:56
and everywhere where we use it
00:44:01
constant
00:44:02
I will put the class name in front of it, it
00:44:04
turns out to be a rather large
00:44:09
line of code, but sometimes the lines are
00:44:13
large here
00:44:19
I could use automatic
00:44:20
replacement, but we have several classes in this file
00:44:23
and such automatic
00:44:27
replacement
00:44:28
may be a bad decision
00:44:32
or even lead to additional
00:44:34
errors, so it is better if I
00:44:37
’ll do it all manually,
00:44:45
well, this is how
00:44:47
we compile and the next
00:44:52
problem is that the
00:44:53
bricklight identifier is not defined,
00:44:59
I press e and eleven, and indeed
00:45:02
these two static constants
00:45:04
are in the class with the engine,
00:45:07
although they describe the brick, which
00:45:09
is an element of the entity of our
00:45:13
level, so I’ll move them here
00:45:15
and although the brick itself is also an entity,
00:45:20
for now let it be an element of the entity
00:45:23
level, and for us this means that
00:45:26
later we will need to remove the
00:45:29
essence brick from the entity level,
00:45:32
unless of course we learn this into a separate
00:45:35
class, we compile from 7 errors there are even fewer
00:45:39
and here is another syntactic one error
00:45:42
constant so white I happen in the engine it is
00:45:48
no longer known this is because they
00:45:50
migrated
00:45:51
another class so I will put here
00:46:01
compile all the syntax errors
00:46:04
until there are no compilation errors left and
00:46:08
let's see what we can do with them
00:46:10
so balls for now I'll leave the error
00:46:14
name for so on. n. unknown in the draw function
00:46:21
brik liter
00:46:25
variable liter pen unknown press
00:46:28
f12 I go to the definition of these are
00:46:30
variables in another class with engine
00:46:33
but in principle here this variable is also
00:46:36
not needed I will take it from here and put it in the
00:46:42
class level so the next error
00:46:47
but by the way this is the variable letter pen
00:46:50
we create it in a function and there is no engine
00:46:53
when initializing our engine,
00:46:55
and since this variable is now a
00:46:57
member of the level class, I can use our level variable in this
00:47:00
code in our engine,
00:47:02
but
00:47:04
for this we must have an object in our engine that
00:47:07
describes the level, but it does
00:47:09
n’t exist yet so I'll take this class name
00:47:12
and create class earthlings here or
00:47:18
and then now I can use this name to
00:47:23
access its variable like this,
00:47:26
respectively, and here there are
00:47:39
fewer errors,
00:47:42
this is the constant I press 12 is defined
00:47:46
now the left bones so that in the
00:47:50
class method and sensein we could
00:47:52
use this constant, I should
00:47:54
put the class name here also here here here
00:47:59
and here we press f7
00:48:11
and there are very few errors left
00:48:15
or not found because now the
00:48:19
lego draw method is not a method of the
00:48:22
engine class but a method of the left class so I will
00:48:25
write here.
00:48:28
we will call this method on the object and at the same time
00:48:32
we will do the same thing as we
00:48:34
did with drawing a ball, if I
00:48:36
click on in volume 12 I will go to the method to
00:48:41
our ball and here inside this
00:48:43
method we check whether the
00:48:47
area that has changed on the screen intersects with the
00:48:50
ball itself if it doesn’t intersect, then we do
00:48:53
n’t draw anything in the same way, I
00:48:56
’ll do this here, I’ll take this code,
00:48:58
check this and move the function inside
00:49:02
here, but the condition will be different
00:49:07
if it doesn’t intersect to return, all
00:49:12
that’s left is to add the definition of
00:49:15
this rectangle
00:49:20
and pass this rectangle here
00:49:24
I I press control of, I go to where
00:49:27
the function is called, I
00:49:28
pass this parameter here
00:49:36
and here I receive it, I even wash 1 of 12
00:49:40
to go to the header file,
00:49:42
I insert this parameter here
00:49:46
and it remains to be corrected a little, it
00:49:51
presses compilation in 7 and this error
00:49:56
left rect
00:49:57
says the fact that in the class at least left
00:50:00
there is no such structure because it
00:50:03
is in kvass dreams, so I
00:50:07
also take it from here and move it here,
00:50:14
compile it
00:50:18
and get the following error, which says
00:50:21
that our engine now cannot
00:50:24
use this variable
00:50:26
because this structural variable
00:50:29
is part of the class was filled in, I press
00:50:32
alt, separate the vertical stripe and
00:50:36
insert the name of this object here and also
00:50:40
here and here
00:50:44
we compile, so there are two errors left
00:50:49
that need to be postponed for a while, then the first is
00:50:51
related to function 2, related to the ball,
00:50:54
this error is related to the fact that we are functions of a
00:50:58
man lego brick hit which is
00:51:01
in the class on the left we must change the values ​​of the
00:51:03
variable belonging to the ball, this
00:51:06
means that we would have to pass a
00:51:09
pointer to the ball here so that we can
00:51:11
access its variable,
00:51:13
but we can make it simpler, we can
00:51:14
pass a pointer to the variable itself
00:51:16
God direction or not even a pointer but a
00:51:19
link namely I’ll take this name,
00:51:24
press f12 to find this function in
00:51:27
the header files again, and in 12 I
00:51:30
’ll take this name and add a parameter here
00:51:32
since it was direction, we have the type
00:51:35
mined for the exchange, I’d need to change the name and
00:51:42
put ampersand, that is, I’ll pass a link to this
00:51:45
function to the direction of the ball
00:51:54
and then here I will use this
00:51:57
variable and our class can now
00:52:01
know nothing at all about the ball and this is
00:52:05
good, the less information is needed for
00:52:07
this class to work better,
00:52:10
but the truth is now we will have an error
00:52:12
associated with calling this function, I
00:52:14
click compilation and now we get
00:52:19
such an error that the engine does not have such a
00:52:22
function, now this function is located in
00:52:25
another class, now this is a class method and
00:52:29
therefore here we need to turn
00:52:32
not to the engine butt, which means that where
00:52:35
and before and pointers to the engine,
00:52:37
here I can pass the pointer to
00:52:39
our level, that is, add one more
00:52:41
parameter, the bread function asterisk, where
00:52:48
this form is declared at
00:52:50
twelve o’clock from working, I put
00:52:53
the cursor on the class name, press f12,
00:52:56
go to the class description from the
00:52:59
husband function here, I added the left one and then I can
00:53:04
call here this function cos or it is
00:53:08
not there, which is what is missing and the wonderful
00:53:10
parameter of the direction of the ball,
00:53:15
now from this wire there will be another
00:53:17
error for everyone
00:53:21
which will indicate that at the
00:53:23
time of compilation of the
00:53:25
class and ball we know nothing about
00:53:27
Lego because it is described below
00:53:31
but again, we can fix this by
00:53:33
adding a preliminary
00:53:35
declaration of
00:53:38
its class here and this error will go away when I add a
00:53:44
preliminary declaration of the class, in
00:53:46
fact, this is kind of logical and a
00:53:48
crutch, the presence of such preliminary
00:53:51
declarations,
00:53:52
this indicates that
00:53:54
the architecture of our project is not entirely
00:53:56
perfect in the correct architecture
00:53:59
should not have such preliminary
00:54:00
declarations and everything should
00:54:02
compile perfectly, so for us in the
00:54:04
future these are the places in the code that
00:54:07
need to be improved, that is, reorganizing the
00:54:10
structure of our classes so that we do not
00:54:12
have to put these
00:54:13
preliminary declarations in advance, but
00:54:16
we will fix this problem later for now I
00:54:17
click and that’s it and the last
00:54:21
error remains: the function of does not accept one
00:54:24
argument,
00:54:25
it takes 2 1 this is engine, return a
00:54:30
pointer to an object of type Angie and the words
00:54:33
viz are these pointers
00:54:35
and the second argument is a pointer to the
00:54:37
level level we have here, this
00:54:40
object is
00:54:41
on the left, so here I need to write the
00:54:44
name of this object, and since I need
00:54:47
a pointer, I put an ampersand in front of the name
00:54:49
and thus it becomes a
00:54:52
pointer to an object like
00:54:54
Lego, compile everything, compile,
00:54:59
run, well, it somehow works
00:55:04
and that’s good, there’s still one problem in this code,
00:55:09
even a few problems
00:55:12
that I would like to draw attention to
00:55:14
here we have a function
00:55:15
for initializing our engine 12
00:55:21
I go to the code and here in the
00:55:24
initialization function we initialize the
00:55:27
data members of other classes here here
00:55:31
here and here in fact this is not
00:55:35
entirely correct the thing is that this
00:55:38
engine class, frankly speaking, should not
00:55:40
worry at all about how to properly
00:55:42
parse and parse elements of other
00:55:44
classes, on the contrary, other classes
00:55:48
themselves must take care that their
00:55:50
variables are correctly
00:55:51
initialized, which means that
00:55:54
this code should not be in this class,
00:55:57
this code must be in the class on the left and there
00:56:00
initialize its
00:56:02
elements,
00:56:03
therefore we need to
00:56:05
initialize our level for this I
00:56:08
go to our level class and add
00:56:12
another initialization function here since it’s
00:56:14
like a special function, although in
00:56:16
fact it’s a regular function of this class, but it does
00:56:18
n’t make sense especially it should be called
00:56:21
once started, then I will place this function
00:56:24
also at the beginning of the class description and it is a one-time function
00:56:26
and there is no abbreviation for initialization, all that
00:56:30
remains is to describe this function
00:56:34
where the class code is located, I press f12
00:56:37
and go to
00:56:43
that is, this is not a constructor, this
00:56:46
initialization function is in In principle, the initialization
00:56:49
should be carried out by the constructor, but the
00:56:52
level object will be constructed before the
00:56:55
window is created in our program and
00:56:56
before the
00:56:58
graphic elements of this program become available to us.
00:57:00
Therefore, in a program on Windows, it is quite a
00:57:02
normal situation when we perform the
00:57:04
so-called delayed initialization,
00:57:07
that is, we initialize object after
00:57:10
it has already been created, why was the
00:57:12
initialization function invented, in
00:57:14
general, I go to our engine
00:57:17
function and there is no engine and take
00:57:21
this code here and transfer it to the
00:57:28
initialization function, since it would easily be
00:57:32
the name of the object, then here it is not needed,
00:57:39
we remain add a class name for the skill
00:57:41
constant
00:57:42
gabs that are in the engine,
00:57:57
but now you need to call this non-
00:57:59
socialization function when initializing our
00:58:02
M12 engine, here now, when
00:58:11
initializing the engine, we will call the
00:58:13
appropriate function that will
00:58:15
perform the correct initialization of
00:58:17
the level, well, since we have already made the
00:58:19
initialization function for the level then in an amicable way,
00:58:21
all the other lines of code that
00:58:24
deal with initialization also need to be
00:58:26
moved where, I can take this,
00:58:28
collect this at 12, put
00:58:34
f3 here, move to the next symbols, that is,
00:58:38
the function is returned and there is no engine, and these
00:58:43
two lines from here, take f12 here,
00:58:48
insert it like this it would be correct, I
00:58:52
remove the name of the bread because now these are
00:58:55
already parts of the class, this code, but we
00:58:59
have other errors and are related to the fact
00:59:01
that I am accessing elements in particular to
00:59:04
functions declared in another class,
00:59:06
if for the gobble skill constant it is not
00:59:09
enough to put the class name then for
00:59:14
level initialization, in order for me to access the function of
00:59:18
this crate paint brush, which is
00:59:20
actually declared in the class of our
00:59:25
engine, I
00:59:32
would need to pass pointers
00:59:34
to the engine to the initialization function of our level,
00:59:35
but this is not entirely correct, the fact is
00:59:38
that our engine
00:59:40
has a given member called level and
00:59:43
this means that our engine
00:59:45
owns an object of type left and passing
00:59:48
pointers to the engine to this object
00:59:50
so that our level cannot use
00:59:52
the functionality of the engine
00:59:53
is not entirely correct because we
00:59:55
end up with a looped dependency class
00:59:58
a stranger should know about left
01:00:03
a-level about with engine Such logical
01:00:07
loops are the source of the most serious
01:00:10
problems in programs and we must avoid them in every possible way,
01:00:12
we must complete all
01:00:14
hierarchical dependencies, that is, one
01:00:17
class must know about the other, this
01:00:20
other must not know anything about the one
01:00:22
who owns it, the part to solve this
01:00:25
problem is all plus plus there is one more a
01:00:28
wonderful feature:
01:00:29
once again we have a class and a class
01:00:33
that has an initialization method and we
01:00:35
need to use the function of another
01:00:38
class and at the same time we need not to pass a
01:00:41
pointer to another class here, in this
01:00:44
case we could use a
01:00:46
static method of another class as
01:00:50
you remember from us a class with an engine
01:00:54
has static constants that
01:00:58
are a special type of data, these
01:01:01
static constants are always
01:01:03
present in a single copy in
01:01:05
the program, and in addition to static
01:01:08
data elements, the class can have static
01:01:10
functions or other
01:01:13
static methods, these methods are not
01:01:15
static, these are ordinary methods of the class and
01:01:18
for in order to call them, you don’t need
01:01:20
an object
01:01:21
from which you can call these methods, but
01:01:23
I can also have
01:01:24
static methods and then I don’t need
01:01:27
an object, just the class itself is not enough,
01:01:31
let me try to show this with an
01:01:33
example, we need the function credit paint
01:01:36
brush let him take this function
01:01:38
first Firstly, we’ll put it in the public section
01:01:41
and secondly, we’ll write the keyword static in front of it
01:01:46
and now this function becomes
01:01:50
static, that is, in order to
01:01:52
call such a function you don’t need an object
01:01:55
in the form of a link or a pointer, but the class name,
01:02:01
just like that, click compile and project
01:02:09
peeler from Please note that we
01:02:12
took a function from our engine and made it
01:02:16
static, but not every method can be
01:02:19
taken and made static, the fact is
01:02:21
that this method is glue paint brush,
01:02:23
it does not use data elements of the
01:02:27
class with the engine, it does not access the
01:02:29
data members of this class at all, which means it
01:02:33
and can become static, for example,
01:02:35
this method is a timer, I can’t make it
01:02:37
static because it refers to the
01:02:40
visa keyword which substitutes a
01:02:44
pointer to an object, or for example,
01:02:47
I can’t make this method the core of platforms static either
01:02:50
because it
01:02:52
operates on data and press 12 which are
01:02:56
members of the class and only this method I
01:03:00
can make static because it
01:03:02
takes parameters and returns data
01:03:05
in the parameters, I’ll probably not explain very well
01:03:08
what static methods are,
01:03:10
perhaps not all of you will be able to understand how to
01:03:13
use them, but I hope that over
01:03:16
time, using an example other static
01:03:18
methods in our project, you will understand how to
01:03:20
use them and will be able to use this
01:03:23
feature of classes where it is
01:03:25
really needed, but since we
01:03:27
moved this method and now we have it in the
01:03:33
public section after the method it is a timer
01:03:36
in the source code it should be after
01:03:39
method, it’s a timer, which means it does
01:03:42
n’t need to be transferred, and one more problem that
01:03:45
I would like to draw attention to is that
01:03:48
we have all the elements in the public
01:03:50
section and now it’s worth transferring to the
01:03:52
private section so that it can’t
01:03:54
be used
01:03:55
outside, it’s not a function, well, we definitely
01:03:58
use it outside but I’m not sure about the rest,
01:03:59
so I declare a private
01:04:04
section and everything below it automatically
01:04:06
becomes a drive, I click compilation
01:04:09
and look at the errors required x love set
01:04:14
the theater constant became unavailable in
01:04:17
spears with the engine, which means they must be in the
01:04:20
public section this is this and this I
01:04:30
think that this couple of Konstantin then it
01:04:32
still needs to be left in the public
01:04:35
sector and everyone
01:04:40
this method is also used outside
01:04:43
is called for an object of type a level
01:04:47
I press e and eleven again at 12 and
01:04:50
move it there is a vodka section
01:04:54
in public
01:04:55
and also to the left also called an
01:05:00
object of type
01:05:01
and pecked at 12 at 12 from here we take it there and
01:05:06
transfer it x7 compiled without errors in
01:05:11
this natural way we
01:05:15
distributed the
01:05:16
members of the class to the left into two sections
01:05:20
private and public well
01:05:21
at this point we will
01:05:23
pause again now that we have taken the second
01:05:26
course from our engine,
01:05:27
our code has changed quite a lot and I
01:05:30
think you should also take this brew
01:05:34
out of your engine and compare it with the
01:05:36
result that I display at the link. By the
01:05:39
way, since we can take the initialization of
01:05:42
the level into a separate function, then
01:05:45
we should have done the same from the
01:05:47
initialization of the ball, here is the
01:05:50
init method The engine is engaged in initializing
01:05:53
data members of another class, which from the point of
01:05:56
view of programming on the op.
01:05:58
wrong, so we should put
01:06:01
this one line of code into a separate
01:06:04
initialization function for the ball, call
01:06:07
this initialization function in this method
01:06:10
of the class was, I will do it by analogy with the
01:06:14
method and no f12 and I’ll take it directly
01:06:17
from here and where our ball is, we
01:06:23
have a constructor after I
01:06:27
’ll paste this method here
01:06:37
and change it, so I copied and pasted this
01:06:42
initialization
01:06:49
and into this method I’ll transfer the code from another
01:06:53
control, press f3
01:06:56
f3 I go to the function not styling the
01:07:00
engine, we take this line from here and bf3
01:07:04
I ​​go back to our new function
01:07:08
I’ll paste and since this the method
01:07:10
is now an aesthetic method,
01:07:13
cool with the engine, then I need to
01:07:15
write the name of this class here and this
01:07:21
way I can call this function,
01:07:24
well, accordingly, we remove the name of the object
01:07:26
because we are already
01:07:28
modifying our own variables in this method,
01:07:32
well, all that remains is to call this function,
01:07:35
press f3
01:07:37
f3 and here, for the copyists, we
01:07:45
compile, we compile successfully,
01:07:50
we launch it and it works, now
01:07:55
it turns out more correctly, well, let’s
01:07:59
take out one more entity from our engine,
01:08:01
I propose to take out the
01:08:03
essence of the platform, the platform is described by
01:08:07
platform variables, expose from
01:08:10
white using
01:08:11
these two methods, and perhaps
01:08:15
some other methods in general, I’ll create
01:08:19
another class, call it platforms, and
01:08:25
I’ll put a prefix
01:08:27
and immediately add a public lecture, here’s an
01:08:33
empty class in which we transfer the
01:08:35
platform functionality, these two
01:08:37
variables, these two methods,
01:08:50
and this constant,
01:08:59
oops in the wrong place, and now I I’ll change the
01:09:06
class name
01:09:08
of the method of crying platforms and take this
01:09:14
method from childhood 1 of me and take these
01:09:18
two methods
01:09:20
from here, we cut and paste them before the
01:09:26
first method of our engine because the
01:09:30
goat platform goes before the class of engines
01:09:34
34
01:09:41
and for beauty I write all these methods
01:09:44
comments and compile them and we get
01:09:51
another hundreds of errors, I’ll probably
01:09:54
go through these red underlines,
01:09:57
press f12 and take these two structures
01:10:02
describing the position of the platform
01:10:04
from the class from the engine and transfer the goats of
01:10:09
the platform to this globe,
01:10:13
press f12, it’s definitely in our
01:10:16
engineer so that we can use it from
01:10:20
class a and platforms and I’ll leave here the name of the
01:10:25
class and 22 and the keys
01:10:33
and by the way regarding the name of the class in our
01:10:41
game there can be only one platform, we don’t
01:10:44
mean many platforms, that is, there
01:10:48
needs to be one object of type and platforms, so I’ll
01:10:50
mark it with the prefix s
01:10:53
which will tell me what the object of this
01:10:56
like it should be in a single
01:10:57
copy and now we press f12 and
01:11:06
we take this constant from the class and son
01:11:10
John we move it here I press all the errors
01:11:17
became slightly minji and here we have a
01:11:20
call to the disabled function and a track with an
01:11:23
unknown variable h vnd
01:11:26
and we have recently similar change the line of code
01:11:29
somehow and the best option
01:11:31
would be to see how we did it, I
01:11:33
press control of and pv3 go to all
01:11:36
places in the code where a call to this function occurs, this is
01:11:39
how we solved this situation in the
01:11:43
ball class, we passed a pointer to our
01:11:46
engine and they took the variable as much as
01:11:52
n.d. maybe this is not the best solution, but
01:11:54
it already works for our program, so
01:11:57
I’ll duplicate it, take this parameter from here
01:12:00
and go to the place in the code
01:12:04
where we were just and add
01:12:08
this parameter here, but if I add it,
01:12:12
then after catching 12 I can no longer
01:12:13
switch to
01:12:14
the header file where this method is described,
01:12:17
so I first switch to
01:12:20
the header file to
01:12:23
find somewhere this is located and then
01:12:27
insert the parameter here
01:12:28
and here, and here through the arrow I access the
01:12:36
war variable h. We also
01:12:43
seem to have already solved this problem somewhere
01:12:45
when calling or the select a jet function and
01:12:48
somehow resolve this error, I press
01:12:50
counter f, and of course there were
01:12:54
quite a lot of such places in the code, but if your
01:12:57
offtrack runs through them, then I’m
01:13:00
going to go to a cafe with an engine, this is not that, here in the
01:13:05
class of
01:13:06
God again Let’s pass here as a
01:13:09
parameter
01:13:10
pointers to the engine and take this
01:13:14
variable from it, let’s use the same method, but
01:13:16
here in favor of contra father, so I go by f12 to
01:13:23
our function here and where we
01:13:26
drew the platform, I’ll pass
01:13:29
this parameter here too, press f12 and I insert
01:13:34
this parameter here
01:13:41
and I already take this change from it. To be
01:13:50
honest, I don’t like this
01:13:51
approach when we have to pass a
01:13:54
pointer to our engine everywhere, the
01:13:55
thing is that our engine owns an
01:13:57
instance of the platform and therefore
01:14:00
the platform should no longer know anything about the
01:14:02
engine, so this is the transfer
01:14:04
parameter to take a
01:14:06
pencil brush from it, this is a temporary solution, we
01:14:09
are using it for now in order to
01:14:11
somehow separate the complex from the cool simple
01:14:14
and other errors remain if I press
01:14:18
f12 that I will find in the class with the engine a
01:14:23
pencil for drawing a ball platform
01:14:26
as well as the inside of the platform
01:14:28
well and of course, it’s better
01:14:32
to transfer these elements to the platform itself, the
01:14:41
same goes for brushes, I’m
01:14:45
copying these moves
01:14:50
here, I’m deleting them, and we’re inserting
01:15:00
Gab’s skill here, this constant is from the class with
01:15:05
engine,
01:15:08
but it’s quite a lot of replacements that will have to be
01:15:10
made, so I’ll do an auto replacement, I’ll
01:15:14
replace
01:15:15
this word, I press control and
01:15:20
in this window I have a description of what word we are changing and here to
01:15:23
what word I paste the name of class 2 here:
01:15:28
I copy this name and now I
01:15:33
will replace this line with the view, but so that it
01:15:35
is not throughout the code,
01:15:37
I will highlight this one part here, click
01:15:42
selection and now all changes in the code
01:15:46
will happen only in the place where I
01:15:48
selected I click replace all elements
01:15:52
visual studio red I changed the code in
01:15:55
twenty-two places, this complaint remains
01:16:03
f12 and the circles constant
01:16:08
turns out to be related to the platform,
01:16:12
we transfer it to class from the form a
01:16:17
invite and platforms x step is a
01:16:22
variable that I will take from the class with
01:16:25
benjen
01:16:26
and put it in the class with platforms and
01:16:31
we also have a highway pen this is a pencil with
01:16:34
which we draw the highlight on the
01:16:36
black ball or rather on the ball
01:16:38
I will transfer the water to the class with platforms,
01:16:43
press f7 and we still have a lot of errors,
01:16:48
and these errors indicate that here
01:16:51
in the constructor we are initializing a
01:16:54
variable that is no longer a
01:16:56
member of the data of this class because
01:17:00
we transferred them to another class on our
01:17:02
platform, these are these four variables,
01:17:05
so I need this It’s not a goal
01:17:08
to do this in another class, I’ll take
01:17:11
this whole method directly, I’ll copy it, I’ll
01:17:15
go in the code to the first method of our
01:17:18
platform, I’ll press and in 12 and paste the
01:17:21
whole constructor, it’s clear that all that remains is to
01:17:23
change the class name and align the church,
01:17:28
and it seems right,
01:17:31
and declare this constructor in the
01:17:34
description of the goats here all that
01:17:41
remains is to return to the designer of
01:17:44
our engine about 12 of them and select from here
01:17:47
this problem,
01:17:49
well, f7 has become a little better and due to the fact
01:17:55
that some constants have moved to
01:17:58
another class, we have
01:17:59
additional errors, but this is normal, I
01:18:03
take the name of the class and this one the
01:18:07
platform constant is lit pos I mark it with a different
01:18:10
name,
01:18:11
respectively, and here and this and here we
01:18:18
already need to access the variable from the
01:18:20
platform they are from the engine in the method of the minds of the
01:18:26
ball, we transferred the entire engine here
01:18:29
to take from it a variable
01:18:31
related to the platform and to the window
01:18:35
all the way to Venda, therefore Now here we
01:18:37
have to pass pointers to an object of the type of
01:18:40
our platform, so I
01:18:45
1212 so here I will pass the parameter of
01:18:48
our platform forum
01:18:53
to the truck
01:19:09
and I’ll take it from this pointer and now
01:19:13
they are like
01:19:16
this I think that now that we
01:19:24
have moved the platform functionality into a separate
01:19:26
class
01:19:27
we need create an instance of this class,
01:19:30
that is, an object inside our engine,
01:19:34
here I will add an object of the platform type after the level
01:19:38
so that we can call its
01:19:42
functions and access Kiev before I click
01:19:46
on 7 errors, there are still quite a lot of order
01:19:53
xs-12 and visual studio transfers me
01:19:57
to platforms expose they but this name
01:20:01
but this will slightly turn on already visual studio
01:20:04
this happens I can just press
01:20:06
control shift and press find all and find
01:20:11
all the places in the horse and there is this border x
01:20:14
offset this is a constant
01:20:17
that is defined in the engine this I take
01:20:21
the name of the engine and put it here so that indicate
01:20:25
where this is a constant, but here
01:20:31
and for everyone,
01:20:36
and we again come to our
01:20:38
engine initialization function, which
01:20:41
initializes variables that
01:20:42
have already moved to another class, so
01:20:45
here I’ll simply add
01:20:47
another function for initialization by analogy,
01:20:58
and by analogy with other functions I
01:21:00
’ll go, for example, by f12 to this function
01:21:03
but it is very large f3 for example on this
01:21:08
ball f12 it is a small function here I
01:21:13
will copy it all and copy-paste it,
01:21:17
but for the platform here after the
01:21:20
constructor I press f12 and paste
01:21:24
this code here I now have an
01:21:28
initialization function that is empty for now but
01:21:32
it is already called somewhere in this club,
01:21:35
so I’ll add a header file here,
01:21:41
press f3 and go to where we call
01:21:45
this function, I take this line of code in 12, I
01:21:51
insert f3 here, I take these two lines from here,
01:21:58
f12, I insert ev3 here, but basically that’s
01:22:05
it initialization of the platform
01:22:06
ends, we are already using it,
01:22:08
so here I will put
01:22:10
the name of the object in which the functions of the
01:22:13
platform core are called, all that remains is to fix
01:22:15
this function, initialization since I
01:22:18
call static methods, take the mole,
01:22:22
I can put the name of the class and
01:22:26
thus the error goes away and everyone compiles
01:22:32
dogs slightly less and go to the
01:22:37
fraction frame function, but here we’re
01:22:40
just acting by analogy, we’ll take
01:22:43
this line no, I’ll take it a little later,
01:22:45
we’ll call this drop function from the form
01:22:48
on the platform object and move this
01:22:54
check
01:22:55
inside this function 12
01:23:00
here and change the conditions if it does not
01:23:05
intersect,
01:23:07
to return, add here, add
01:23:16
interception ed here and pass the trust point here,
01:23:20
I press control p.f.
01:23:24
I go to for in this function using the f3 key
01:23:28
to take the parameter p and heavy f12 in
01:23:34
12 and add it here
01:23:43
like this f3
01:23:46
and here we have to draw the platform we
01:23:49
call the function, we pass it two
01:23:51
variables that are already in the
01:23:54
platform so I just won’t do them
01:23:57
here pass to 12 and here,
01:24:04
accordingly, this function no longer
01:24:06
accepts variables from the outside, it will
01:24:09
use
01:24:10
variables that are members of the goats,
01:24:12
that is, wherever we used x
01:24:15
and it is used a lot here y, too,
01:24:19
I will use these two variables,
01:24:24
this is a constant,
01:24:26
but so as not increase the amount of code
01:24:29
that is here and so much I will do like
01:24:32
this I will introduce a variable x
01:24:36
which will have the value of this
01:24:40
variable and a variable y
01:24:43
which will have the value of this
01:24:46
constant
01:24:49
so the code here will not have to be
01:24:52
changed and everything will work the same as
01:24:56
before for everyone and still the machine is something
01:25:02
under our form that is difficult to separate from the
01:25:05
engine since these variables
01:25:09
are now part of the platform
01:25:11
i.e.
01:25:14
then I will put the name of the object in front of their name
01:25:17
from the ready one I will take these
01:25:19
variables here so here it is so
01:25:42
f7
01:25:47
and here is the error that says there are
01:25:50
too few arguments for the call
01:25:53
we here had to pass a pointer
01:25:55
to the engine
01:25:56
and since this cat is inside the
01:25:58
method from engine to the pointers to the jump
01:26:01
will be in the forest, that is, to everyone and here,
01:26:08
too, there is not enough a pointer to the engine, that
01:26:12
is, to itself and the printer and everyone
01:26:23
here we add from
01:26:30
and here we are missing a platform and the platform of
01:26:34
this us is now described by the
01:26:36
platforms object, so I put
01:26:39
the platform here and ampersand
01:26:41
which takes the address of this object and
01:26:44
makes it a pointer to the platform and
01:26:47
in seven and we are faced with the same
01:26:54
problem that we already encountered at
01:26:56
the time of compilation,
01:26:58
the header files of this line of code
01:27:00
do not know what the name from the platforms means,
01:27:03
so I will make a preliminary
01:27:06
declaration of this class and this is also a
01:27:10
logical crutch that we will later
01:27:12
correct for everyone and suddenly there is one
01:27:17
error left, there is not enough
01:27:22
des because the pointer to I see will be
01:27:26
dm7,
01:27:28
everything
01:27:30
remains a warning that this
01:27:32
variable is not used because
01:27:35
we transferred all the code to the corresponding
01:27:37
function,
01:27:38
so I remove it here, run this
01:27:47
form it’s running, it means it’s redrawn
01:27:50
correctly, the ball is being bounced, it means it’s
01:27:53
working correctly, therefore the code transfer
01:27:56
went correctly, but it remains to
01:28:00
figure out the private section for this
01:28:03
class, since there is no function exactly
01:28:06
called by the platform object,
01:28:07
then I can write about it here and
01:28:10
see what’s really needed,
01:28:12
what no platforms y paz we need and also
01:28:20
expose and width these two parameters the
01:28:26
platform expose and platforms white
01:28:32
go to the public section f7 platforms
01:28:38
y paz also goes to the public lecture
01:28:44
in 7
01:28:47
red hole under the form on top of 12 I go to
01:28:52
this function and also drop platforms both of
01:28:55
these methods
01:28:56
will be needed in the public section in 7,
01:29:04
so this is not a cat form x
01:29:11
public and that’s it, and we got
01:29:18
one more class describing our
01:29:20
platform, after which the class of our engine
01:29:24
became quite small, although it
01:29:27
still contains one more entity
01:29:29
copies, its flavor of our level,
01:29:32
before we take out the functionality of the framework, I
01:29:36
would like to make another small improvement
01:29:38
for the platform class if I click,
01:29:41
for example, on this variable control
01:29:44
shift f then I will find a place in the code where this
01:29:49
variable is used and for example
01:29:51
here we get the text of the
01:29:54
platform type.
01:29:55
platform expose turns out to be some
01:29:58
tautology, and in this form
01:30:01
it would read a little better than platforms.
01:30:04
expose, respectively, with other names
01:30:08
would also look a little better, so
01:30:11
I’ll fix it and the topic on for this I
01:30:14
put the cursor on the variable that
01:30:16
I want to change, press control shift
01:30:18
and a window appears that allows you to
01:30:22
mass replace the
01:30:24
text in the source code, here I indicate in this
01:30:27
window what to change this line
01:30:30
automatically came here from under the cursor
01:30:32
and here I indicate what to change I
01:30:35
will leave the same line and delete the excess, it
01:30:39
is important that these two checkboxes
01:30:43
are checked 1 means that Zhol
01:30:46
studio should pay attention to the case of
01:30:48
characters and not confuse capital
01:30:50
letters with small letters of the author
01:30:52
means that the line of platforms expose
01:30:55
should be replaced only if it
01:30:57
is found in its entirety if it is
01:31:00
part of some other word here such
01:31:02
lines will be skipped
01:31:04
when I press reprise
01:31:07
visual studio says to be
01:31:10
able to cancel this action all
01:31:13
files in which it will be found and antifreeze
01:31:15
will remain open for editing,
01:31:18
you can then save or cancel the
01:31:21
change in each file, well, I usually
01:31:23
press the district
01:31:25
visual studio made 12 replacements, the
01:31:30
same with other elements Kondrashev h
01:31:34
here I change it
01:31:37
to a different name 4 replacements if I go to the
01:31:46
class itself, then here we have more
01:31:48
platforms y positions and from I can already change
01:32:04
this variable
01:32:16
and this constant
01:32:21
and
01:32:28
we compile everything, compiled,
01:32:33
run everything works and that’s good,
01:32:40
I suggest taking a break and now it’s your
01:32:44
turn to take the essence of the platform out of the engine into a
01:32:47
separate class, and now it remains to
01:32:51
take out the functionality of the frame in a
01:32:54
separate class
01:32:55
we have two methods drop parterre and
01:32:58
bounce fraction which relates
01:33:00
specifically to drawing a frame 10 source
01:33:04
pencils and brushes maybe something else that’s all it bring it
01:33:06
I’m creating
01:33:09
a lot of kvass here I’ll call it border I’ll leave
01:33:16
the prefix kay
01:33:17
and so on like the frame in our game there will
01:33:20
always be one that supplies the prefix c and
01:33:27
here we transfer these two constants,
01:33:36
these two methods and four variables,
01:33:44
well, it seems that everything remains to change the name of the
01:33:47
braid of these methods, press f12 /
01:33:53
border each bounds and take them from here and
01:34:00
so on like our goat border is located in front of the
01:34:04
engine class, you from 12 go to the
01:34:08
first engine method, insert four
01:34:10
lines and our methods
01:34:20
just like that, all that remains is to fix everything,
01:34:23
click compile, we get another
01:34:28
bunch of errors, but we already know what to do with it
01:34:31
global skill is a constant from
01:34:34
ours engine and, in principle, everywhere in this
01:34:43
code,
01:34:47
even in this method, I will make a mass
01:34:49
replacement, I select the code of this method,
01:34:54
press control hash, insert the
01:35:01
name of this constant here, and here is the correct
01:35:06
name of the constant,
01:35:07
so you have removed this text selection,
01:35:09
select it again and press replace 24
01:35:16
replacements
01:35:18
compile
01:35:22
this bgp this variable is from our
01:35:26
engine and last time we eliminated this joke by
01:35:30
adding a pointer
01:35:32
to our engine as a parameter,
01:35:33
press f12 at 12 and paste it here from
01:35:41
Angie Angie and now I can use
01:35:53
variables by Lepse pointers
01:36:04
and go through the list of errors class engine does not
01:36:08
have a member border x
01:36:11
and that’s all because now this constant
01:36:14
is in a class with a mess and this is a
01:36:24
constant also for
01:36:29
dealers the next error is compiling the
01:36:43
drop border function expects more
01:36:46
parameters yes here there is not enough pointer to the engine
01:36:50
therefore you need to pass the
01:36:52
pointer to the engine here as a parameter
01:36:56
I’ll take this parameter here
01:36:59
and add this
01:37:05
bounce fraction to pass it
01:37:09
here to the controller and we come to the conclusion
01:37:20
that we should have a method for
01:37:22
initializing our frame in which we will
01:37:24
write these parameters,
01:37:26
I’ll do it by analogy, but we don’t have
01:37:34
such an object of
01:37:35
such a member yet so there is no need to
01:37:37
take the name of this class here and add
01:37:41
another member, well, just like that, but the
01:37:47
classes with border itself don’t have an initialization method,
01:37:51
I’ll take it again by copy-paste, for example,
01:37:54
from here that ball
01:38:00
Indian is the first method of our burger and
01:38:04
paste here
01:38:05
what I copied and pasted This is an addition
01:38:19
and now we transfer these 2 functions to this method,
01:38:28
and since this method is a
01:38:30
static method for the class with Hyun Jin,
01:38:34
that is, the move, otherwise I need to put the
01:38:39
class name 2 GB.
01:38:42
We press compilation and there are
01:38:46
very few errors / bounce The flock identification was
01:38:50
not found because now this is a method of a
01:38:55
class with border accessible through the
01:38:59
border variable and this method
01:39:03
also needs a pointer to the engine, and since we
01:39:06
call this method in the engine method, that
01:39:09
means a pointer to itself
01:39:14
and so here border x offset is now a
01:39:18
constant in
01:39:19
the class with a burger and that means here we need to
01:39:24
write this class, compile and
01:39:31
compile, run it and it even
01:39:34
works, the ball is reflected from the frame, well,
01:39:38
this is generally great, so now we
01:39:42
need to hide in a private section those
01:39:44
methods and data that are not called
01:39:46
outside I’m writing
01:39:48
privacy, but to me you’re not exactly called
01:39:51
from outside, but let’s see about these 6 and
01:39:53
everyone has border i have set and
01:40:00
players site we need from the outside too,
01:40:02
namely from the cobol class method, so
01:40:08
from here we collect them for everyone
01:40:14
and the friend method bounce and v12 it should also
01:40:21
be public, we compile, it compiled perfectly,
01:40:26
and to be honest, I would change the
01:40:29
name of this method a little, I could search for this
01:40:34
name by code, this is how we call
01:40:37
this code, but if we pay attention to the
01:40:40
other calls,
01:40:42
then we could change the other
01:40:44
methods so that it looked uniform,
01:40:47
that is, not / bounce, but just a fraction method,
01:40:50
then there would be a bureau dr dr side by side,
01:40:54
that is, this method I press control
01:40:57
chic all the way and change
01:41:01
fraction for fraction throughout the code,
01:41:08
we compile it
01:41:11
turned out fine and here are these
01:41:14
methods from others
01:41:15
I’ll also replace the droppod form classes with
01:41:19
just a friend, what
01:41:34
if she’s also just a friend
01:41:41
and already at this stage we can notice
01:41:45
that we have some
01:41:48
uniform behavior emerging in our objects,
01:41:51
namely the drone method which accepts the
01:41:54
hdc
01:41:55
paint aria parameter and the pointing engine and
01:41:59
perhaps in in the future we will be able to combine
01:42:02
these methods with common functionality, but
01:42:05
for now this is not obvious and therefore we
01:42:08
will not do this for now, and since we are changing
01:42:13
the names of the function, I would also change this
01:42:16
name because the border class has a /
01:42:20
border method that does not draw a frame,
01:42:22
draws a frame element and I’ll change this name to
01:42:26
firewood border element or even simpler
01:42:29
to fraction element
01:42:43
before I didn’t make such a replacement
01:42:45
because we didn’t operate on the
01:42:48
board entity for which we now have a
01:42:50
new class, but
01:42:51
now that we’ve added a new name it’s
01:42:54
quite normal if we correct it a little
01:42:56
exactly the methods of this class,
01:42:59
well, here we are and the A3 factory is a large and
01:43:02
complex kvass from the engine complex because
01:43:05
it contained several other
01:43:07
entities and divided this class into 5
01:43:10
classes, here we have a list of entities
01:43:15
that are used in this file, you
01:43:16
can find them here the name of these
01:43:20
classes and this class with the engine has become
01:43:24
very small, all that it has
01:43:27
is essentially objects of other types and
01:43:29
some methods that ensure the
01:43:32
operation of our game engine of
01:43:34
code, we got quite a lot
01:43:37
in one source file, we
01:43:39
have a lot of essence there and this is it the same
01:43:42
problem and we will solve this problem a little
01:43:44
later, but for now I suggest taking
01:43:47
another pause, try to complete the
01:43:49
factory class of the engine and move the
01:43:53
functionality of the framework into a separate class and
01:43:55
compare with the result that
01:43:57
I got

Description:

Часть #15. Рефакторинг сложного класса. (Базовый курс программирования на С++) Самые лучшие бесплатные курсы по C++, Ассемблеру и Unreal Engine 5! Все части в плейлисте: https://www.youtube.com/playlist?list=PLlheCABZdy3OZoIh9VwlYUbTSCWwDUee6 Оглавление курса на Википедии: https://ru.wikiversity.org/wiki/%D0%91%D0%B0%D0%B7%D0%BE%D0%B2%D1%8B%D0%B9_%D0%BA%D1%83%D1%80%D1%81_%D0%A1%2B%2B 00:00 - Рефакторинг сложного класса 01:42 - Форматирование ссылок и указателей 03:58 - Настройка выравнивания кода в Visual Studio 06:13 - Выносим сущность шарика в класс ABall 10:50 - Исправляем ошибки, разделяя сущности движка и шарика 29:15 - Указатель на себя this 33:44 - Переносим часть членов класса ABall в приватную секцию 35:53 - Popcorn_11.zip: пишем код 36:22 - Выносим сущность уровня в класс ALevel 55:07 - Рефакторим метод Init_Engine() 01:02:11 - Статический метод 01:05:21 - Popcorn_12.zip: пишем код 01:05:39 - Создаём функцию инициализации ABall::Init() 01:07:57 - Выносим сущность платформы в класс AsPlatform 01:29:33 - Рефакторим имена членов данных платформы 01:32:38 - Popcorn_13.zip: пишем код 01:32:50 - Выносим сущность рамки в класс AsBorder 01:40:26 - Рефакторим имена методов 01:43:00 - Подводим итог рефакторинга класса движка 01:43:46 - Popcorn_14.zip: пишем код Popcorn_11.zip https://drive.google.com/open?id=1eXtYryEBoauBjJXsL-tgI3G92smqqwzS Popcorn_12.zip https://drive.google.com/open?id=1txBSML3A1G6My_xdoqaYK6I7uEIBuAsF Popcorn_13.zip https://drive.google.com/open?id=1UfHvgeoV8hvOQfehlK0VU4mG56oMnWaV Popcorn_14.zip https://drive.google.com/open?id=17k7rLh-yEYs8HCAzkHAZSQOuS-iVRUfg

Preparing download options

popular icon
Popular
hd icon
HD video
audio icon
Only sound
total icon
All
* — If the video is playing in a new tab, go to it, then right-click on the video and select "Save video as..."
** — Link intended for online playback in specialized players

Questions about downloading video

mobile menu iconHow can I download "Базовый курс С++ Часть #15. Рефакторинг сложного класса" video?mobile menu icon

  • http://unidownloader.com/ website is the best way to download a video or a separate audio track if you want to do without installing programs and extensions.

  • The UDL Helper extension is a convenient button that is seamlessly integrated into YouTube, Instagram and OK.ru sites for fast content download.

  • UDL Client program (for Windows) is the most powerful solution that supports more than 900 websites, social networks and video hosting sites, as well as any video quality that is available in the source.

  • UDL Lite is a really convenient way to access a website from your mobile device. With its help, you can easily download videos directly to your smartphone.

mobile menu iconWhich format of "Базовый курс С++ Часть #15. Рефакторинг сложного класса" video should I choose?mobile menu icon

  • The best quality formats are FullHD (1080p), 2K (1440p), 4K (2160p) and 8K (4320p). The higher the resolution of your screen, the higher the video quality should be. However, there are other factors to consider: download speed, amount of free space, and device performance during playback.

mobile menu iconWhy does my computer freeze when loading a "Базовый курс С++ Часть #15. Рефакторинг сложного класса" video?mobile menu icon

  • The browser/computer should not freeze completely! If this happens, please report it with a link to the video. Sometimes videos cannot be downloaded directly in a suitable format, so we have added the ability to convert the file to the desired format. In some cases, this process may actively use computer resources.

mobile menu iconHow can I download "Базовый курс С++ Часть #15. Рефакторинг сложного класса" video to my phone?mobile menu icon

  • You can download a video to your smartphone using the website or the PWA application UDL Lite. It is also possible to send a download link via QR code using the UDL Helper extension.

mobile menu iconHow can I download an audio track (music) to MP3 "Базовый курс С++ Часть #15. Рефакторинг сложного класса"?mobile menu icon

  • The most convenient way is to use the UDL Client program, which supports converting video to MP3 format. In some cases, MP3 can also be downloaded through the UDL Helper extension.

mobile menu iconHow can I save a frame from a video "Базовый курс С++ Часть #15. Рефакторинг сложного класса"?mobile menu icon

  • This feature is available in the UDL Helper extension. Make sure that "Show the video snapshot button" is checked in the settings. A camera icon should appear in the lower right corner of the player to the left of the "Settings" icon. When you click on it, the current frame from the video will be saved to your computer in JPEG format.

mobile menu iconWhat's the price of all this stuff?mobile menu icon

  • It costs nothing. Our services are absolutely free for all users. There are no PRO subscriptions, no restrictions on the number or maximum length of downloaded videos.