-
Notifications
You must be signed in to change notification settings - Fork 0
/
chohan2func_Q.php
110 lines (108 loc) · 1.91 KB
/
chohan2func_Q.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* 課題:以下の処理を関数定義を行い、処理を分割、整理せよ
* ヒント:処理を文章の段落のように分け、処理内容を分別させることを念頭に考える
**/
$dice = array(mt_rand(1, 6),mt_rand(1, 6));
echo "サイコロ1:{$dice[0]}\n";
echo "サイコロ2:{$dice[1]}\n";
// http://php.net/manual/ja/function.sort.php
sort($dice);
$result = "";
if($dice[0] === 1){
switch ($dice[1]) {
case 1:
$result .= "ピンゾロ";
break;
case 2:
$result .= "イチニ";
break;
case 3:
$result .="サンミチ";
break;
case 4:
$result .="ヨイチ";
break;
case 5:
$result .="グイチ";
break;
case 6:
$result .="イチロク";
break;
default:
break;
}
}elseif($dice[0] === 2){
switch ($dice[1]) {
case 2:
$result .="ニゾロ";
break;
case 3:
$result .="サニ";
break;
case 4:
$result .="シニ";
break;
case 5:
$result .="グニ";
break;
case 6:
$result .="ニロク";
break;
default:
break;
}
}elseif($dice[0] === 3){
switch ($dice[1]) {
case 3:
$result .="サンゾロ";
break;
case 4:
$result .="シソウ";
break;
case 5:
$result .="グサン";
break;
case 6:
$result .="サブロク";
break;
default:
break;
}
}elseif($dice[0] === 4){
switch ($dice[1]) {
case 4:
$result .="シゾロ";
break;
case 5:
$result .="グシ";
break;
case 6:
$result .="シロク";
break;
default:
break;
}
}elseif($dice[0] === 5){
switch ($dice[1]) {
case 5:
$result .="ゴゾロ";
break;
case 6:
$result .="ゴロク";
break;
default:
break;
}
}elseif($dice[0] === 6){
switch ($dice[1]) {
case 6:
$result .="ロクゾロ";
break;
default:
break;
}
}
// 三項演算子(http://www.phpbook.jp/tutorial/if/index8.html)
$result .= (($dice[0] + $dice[1]) % 2 === 0) ? "丁":"半";
echo "結果は:{$result}";