-
Notifications
You must be signed in to change notification settings - Fork 0
/
battle_royal.php
125 lines (116 loc) · 4.88 KB
/
battle_royal.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
include('player.php');
// Stop the script giving time out errors..
set_time_limit(0);
$obj = new Player;
$battle='N';
// This opens standard in ready for interactive input..
define('STDIN',fopen("php://stdin","r"));
echo "#=====================================================#\n\n";
echo "# Welcome to Battle Arena #\n";
echo "#-----------------------------------------------------#\n";
echo "# Description : #\n";
echo '# 1. ketik "new" untuk membuat karakter # ';
echo "\n";
echo '# 2. ketik "start" untuk memulai pertarungan # ';
echo "\n";
echo "#-----------------------------------------------------#\n";
echo "# Current Player : #\n";
echo "# - #\n";
echo "# * max player 2 atau 3 #\n";
echo "#-----------------------------------------------------#\n";
$new_char=FALSE;
$num_char=0;
while(!feof(STDIN))
{
// Decide what menu option to select based on input..
$var = trim(fgets(STDIN,256));
if(!empty($var)){
if($var=="new"){
echo "#=====================================================#\n\n";
echo "# Welcome to Battle Arena #\n";
echo "#-----------------------------------------------------#\n";
echo "# Description : #\n";
echo '# 1. ketik "new" untuk membuat karakter # ';
echo "\n";
echo '# 2. ketik "start" untuk memulai pertarungan # ';
echo "\n";
echo "#-----------------------------------------------------#\n";
echo "# Masukkan Nama Player :<nama_player> #\n";
echo "# - #\n";
echo "# * max player 2 atau 3 #\n";
echo "#-----------------------------------------------------#\n";
$new_char=TRUE;
}elseif($var=="start"){
echo "#=====================================================#\n\n";
echo "# Welcome to Battle Arena #\n";
echo "#-----------------------------------------------------#\n";
echo "Battle Start : \n";
echo "siapa yang akan menyerang : <nama_player_1> \n";
echo "siapa yang di serang : <nama_player_2> \n";
$battle = 'Y';
$penyerang = 'Y';
}else{
if($battle=='Y' && $penyerang=='Y'){
for($i=1;$i<=$num_char;$i++){
if($player[$i]['name'] == $var){
$nama_1 = $player[$i]['name'];
$player[$i]['manna'] = $player[$i]['manna']-20;
$mana_1 = $player[$i]['manna'];
$blood_1 = $player[$i]['blood'];
}
}
$penyerang = 'N';
}elseif($battle=='Y' && $penyerang=='N'){
for($i=1;$i<=$num_char;$i++){
if($player[$i]['name'] == $var){
$nama_2 = $player[$i]['name'];
$player[$i]['blood'] = $player[$i]['blood']-20;
$mana_2 = $player[$i]['manna'];
$blood_2 = $player[$i]['blood'];
}
}
$battle = 'N';
echo "#=====================================================#\n\n";
echo "# Welcome to Battle Arena #\n";
echo "#-----------------------------------------------------#\n";
echo "Battle Start : \n";
echo "siapa yang akan menyerang : $nama_1 \n";
echo "siapa yang di serang : $nama_2 \n";
if($mana_1>0){
echo "Description : \n";
echo "$nama_1 : manna =$mana_1,blood=$blood_1 \n";
echo "$nama_2 : manna =$mana_2,blood=$blood_2 \n";
}else{
echo "$nama_1 ( Game Over )";
exit();
}
}else{
if($new_char==TRUE && $num_char<3){
$num_char++;
//$char[$num_char]= $var;
$player[$num_char] = (array)$obj->set_player($var);
}
echo "#=====================================================#\n\n";
echo "# Welcome to Battle Arena #\n";
echo "#-----------------------------------------------------#\n";
echo "# Description : #\n";
echo '# 1. ketik "new" untuk membuat karakter # ';
echo "\n";
echo '# 2. ketik "start" untuk memulai pertarungan # ';
echo "\n";
echo "#-----------------------------------------------------#\n";
echo "# Current Player :$num_char #\n";
for($i=1;$i<=$num_char;$i++){
echo "# - ".$player[$i]['name'] ." #\n";
}
echo "# * max player 2 atau 3 #\n";
echo "#-----------------------------------------------------#\n";
$new_char=FALSE;
}
}
}
}
// Close standard in..
fclose(STDIN);
?>