-
Notifications
You must be signed in to change notification settings - Fork 0
/
floor.php
74 lines (64 loc) · 1.65 KB
/
floor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
class Elevator_System {
// 电梯
public static $elevator;
// 楼层
public static $floor;
// 电梯升降状态
public $elevator_status = ['up' ,'down' ,'free'];
// 默认电梯参数
public $elevator_default = ['status'=>'free','floor'=>1];
// 每楼层按钮
public $button_action = ['up'=>1,'down'=>1];
// 全部调度信息
public static $control = ['up','down'];
// 使用者信息
public $user = ['floor','button_action'];
// 初始化
public function __construct($num,$floor){
$this->floor = $floor;
for($i=1; $i<=$num; $i++){
$this->elevator[$i] = $elevator_default;
}
}
// 电梯运行
public function run($elevator_arr){
if($elevator_arr){
foreach ($elevator_arr as $key => $value) {
$this->elevator[$i]['go'];
}
}
}
// 电梯停止
public function stop(){
}
/**
* 楼层按钮点击事件
* user = ['floor'=>1, 'button_action'=>'up'];
*/
public function button_onclick($user){
// 检查用户输入的动作是否与电梯状态相同
$elevator_status = get_elevator_status();
if ( !empty($elevator_status['free']) ){
// 有空闲的
$this->control($user, $elevator_status['free']);
} elseif (!empty($elevator_status[$user['button_action']])) {
// 有相同
$this->control($user, $elevator_status[$user['button_action']]);
} else {
$this->control($user);
}
}
// 检查当前电梯状态与目标是否一致
public function get_elevator_status(){
$result = [];
foreach ($this->elevator as $key => $value) {
$result[$value['status']] = $key;
}
return $result;
}
// 调度信息
public function control($user, $elevator_arr){
}
}
$floor = [-2,-1,1,2,3,4,5,6,7,8];