Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
lab10
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Анамария Морено
lab10
Commits
1d168a0d
Commit
1d168a0d
authored
Nov 26, 2023
by
Муратханов Тимурхан
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил логику изменения водителя
related #4
parent
fa72463e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
3 deletions
+17
-3
TruckState.ts
src/TruckState/TruckState.ts
+2
-1
InBaseState.ts
src/TruckState/state/InBaseState.ts
+15
-2
No files found.
src/TruckState/TruckState.ts
View file @
1d168a0d
import
{
Driver
}
from
"../Driver"
;
import
{
Truck
}
from
"../Truck"
;
import
{
Truck
}
from
"../Truck"
;
export
abstract
class
TruckState
{
export
abstract
class
TruckState
{
...
@@ -9,7 +10,7 @@ export abstract class TruckState {
...
@@ -9,7 +10,7 @@ export abstract class TruckState {
public
abstract
name
:
string
;
public
abstract
name
:
string
;
public
abstract
changeDriver
():
void
;
public
abstract
changeDriver
(
driver
:
Driver
):
void
;
public
abstract
startRun
():
void
;
public
abstract
startRun
():
void
;
...
...
src/TruckState/state/InBaseState.ts
View file @
1d168a0d
import
{
Driver
}
from
"../../Driver"
;
import
{
TruckState
}
from
"../TruckState"
;
import
{
TruckState
}
from
"../TruckState"
;
import
{
InRepairState
}
from
"./InRepairState"
;
import
{
InRepairState
}
from
"./InRepairState"
;
import
{
InRunState
}
from
"./InRunState"
;
import
{
InRunState
}
from
"./InRunState"
;
function
getRandomDriver
():
Driver
{
const
names
:
string
[]
=
[
'Петя'
,
'Вася'
,
'Миша'
,
'Саша'
,
'Кирилл'
,
'Иван'
,
'Матвей'
];
const
surnames
:
string
[]
=
[
'Иванов'
,
'Дмитриенко'
,
'Петрушка'
,
'Царёв'
,
'Победнский'
];
const
age
:
number
=
Math
.
floor
(
Math
.
random
()
*
(
100
-
25
)
+
25
);
const
experience
:
number
=
Math
.
floor
(
Math
.
random
()
*
((
age
-
18
)
-
1
)
+
1
);
const
ranName
=
names
[
Math
.
floor
(
Math
.
random
()
*
(
names
.
length
-
0
)
+
0
)];
const
ranSurName
=
surnames
[
Math
.
floor
(
Math
.
random
()
*
(
surnames
.
length
-
0
)
+
0
)];
return
new
Driver
(
ranName
,
ranSurName
,
age
,
experience
);
};
export
class
InBaseState
extends
TruckState
{
export
class
InBaseState
extends
TruckState
{
public
name
:
string
=
'На базе'
;
public
name
:
string
=
'На базе'
;
public
changeDriver
():
void
{
public
changeDriver
(
driver
:
Driver
):
void
{
this
.
truck
.
driver
=
getRandomDriver
();
console
.
log
(
'Водитель поменян успешно'
);
console
.
log
(
'Водитель поменян успешно'
);
};
};
...
@@ -18,4 +30,5 @@ export class InBaseState extends TruckState {
...
@@ -18,4 +30,5 @@ export class InBaseState extends TruckState {
this
.
truck
.
changeState
(
new
InRepairState
());
this
.
truck
.
changeState
(
new
InRepairState
());
console
.
log
(
'Грузовик успешно отправился на починку'
);
console
.
log
(
'Грузовик успешно отправился на починку'
);
};
};
};
};
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment