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
f035f9cc
Commit
f035f9cc
authored
Nov 26, 2023
by
Муратханов Тимурхан
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Создал дочерний класс InRepairState, импортировал необходимые классы
related #4
parent
c7055ffb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
1 deletion
+48
-1
Truck.ts
src/Truck.ts
+8
-1
TruckState.ts
src/TruckState/TruckState.ts
+8
-0
InBaseState.ts
src/TruckState/state/InBaseState.ts
+4
-0
InRepairState.ts
src/TruckState/state/InRepairState.ts
+26
-0
InRunState.ts
src/TruckState/state/InRunState.ts
+2
-0
No files found.
src/Truck.ts
View file @
f035f9cc
import
{
Driver
}
from
"./Driver"
;
import
{
TruckState
}
from
"./TruckState/TruckState"
;
import
{
InBaseState
}
from
"./TruckState/state/InBaseState"
;
export
class
Truck
{
id
:
number
;
...
...
@@ -11,7 +13,12 @@ export class Truck {
this
.
id
=
id
;
this
.
name
=
name
;
this
.
driver
=
driver
;
this
.
_state
=
new
BaseState
();
this
.
_state
=
new
In
BaseState
();
this
.
_stringState
=
this
.
_state
.
name
;
this
.
_state
.
setTruck
(
this
);
};
changeState
(
state
:
TruckState
)
{
this
.
_state
=
state
;
};
};
\ No newline at end of file
src/TruckState/TruckState.ts
View file @
f035f9cc
import
{
Truck
}
from
"../Truck"
;
export
abstract
class
TruckState
{
protected
truck
!
:
Truck
;
public
setTruck
(
truck
:
Truck
)
{
this
.
truck
=
truck
;
};
public
abstract
name
:
string
;
public
abstract
changeDriver
():
void
;
...
...
src/TruckState/state/InBaseState.ts
View file @
f035f9cc
import
{
TruckState
}
from
"../TruckState"
;
import
{
InRepairState
}
from
"./InRepairState"
;
import
{
InRunState
}
from
"./InRunState"
;
export
class
InBaseState
extends
TruckState
{
public
name
:
string
=
'На базе'
;
...
...
@@ -8,10 +10,12 @@ export class InBaseState extends TruckState {
};
public
startRun
():
void
{
this
.
truck
.
changeState
(
new
InRunState
());
console
.
log
(
'Грузовик успешно выдвинулся в путь'
);
};
public
startRepair
():
void
{
this
.
truck
.
changeState
(
new
InRepairState
());
console
.
log
(
'Грузовик успешно отправился на починку'
);
};
};
\ No newline at end of file
src/TruckState/state/InRepairState.ts
0 → 100644
View file @
f035f9cc
import
{
TruckState
}
from
"../TruckState"
;
import
{
InBaseState
}
from
"./InBaseState"
;
import
{
InRunState
}
from
"./InRunState"
;
export
class
InRepairState
extends
TruckState
{
public
name
:
string
=
'На починке'
;
public
changeDriver
():
void
{
console
.
log
(
'Ошибка. Нельзя поменять водителя в пути!'
);
};
public
startRun
():
void
{
let
ranNum
:
number
=
Math
.
random
()
*
2
if
(
ranNum
=
0
)
{
this
.
truck
.
changeState
(
new
InBaseState
());
console
.
log
(
'Грузовик успешно отправился на базу'
);
}
else
if
(
ranNum
=
1
)
{
this
.
truck
.
changeState
(
new
InRunState
());
console
.
log
(
'Грузовик успешно отправился в путь'
);
};
};
public
startRepair
():
void
{
console
.
log
(
'Ошибка. Грузовик уже находится в ремонте!'
);
};
};
\ No newline at end of file
src/TruckState/state/InRunState.ts
View file @
f035f9cc
import
{
TruckState
}
from
"../TruckState"
;
import
{
InRepairState
}
from
"./InRepairState"
;
export
class
InRunState
extends
TruckState
{
public
name
:
string
=
'В пути'
;
...
...
@@ -12,6 +13,7 @@ export class InRunState extends TruckState {
};
public
startRepair
():
void
{
this
.
truck
.
changeState
(
new
InRepairState
());
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