forked from kokonior/PHP-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FikriFarzani.php
103 lines (79 loc) · 2.71 KB
/
FikriFarzani.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
<?php
//set kelereng awal
$kelerengBot = 10;
$kelerengUser = 10;
//Deklasari
$namaUser;
$tebakanUser;
$taruhanUser;
$taruhanKelereng;
$tebakanBot;
echo "\n";
echo "Selamat Datang di SquidGame Kelereng \n";
//Get userName
echo "Masukan nama anda : ";
$namaUser = trim(fgets(STDIN));
echo "\n";
//Check if user fill name or not
if($namaUser == TRUE){
echo "Hai ".$namaUser." selamat bermain!";
echo "\n";
echo "Kelereng Bot : ".$kelerengBot;
echo "\n";
echo "Kelereng Kamu : ".$kelerengUser;
echo "\n";
do{
echo "\n";
//Get Tebakan User
echo "Masukan Tebakan (Ganjil/Genap) : ";
$tebakanUser = strtolower(trim(fgets(STDIN)));
//Get Taruhan User
echo "Masukan Taruhan 1 - 10 : ";
$taruhanUser = trim(fgets(STDIN));
echo "\n";
//Get Rand number for bot
$taruhanKelereng = rand(1,$kelerengBot);
//cek ganjil genap
if($taruhanKelereng % 2 == 0 ){
$tebakanBot = "genap";
}else{
$tebakanBot = "ganjil";
}
//main function
if($tebakanUser == $tebakanBot){
//update when user win
$kelerengBot -= $taruhanUser;
$kelerengUser += $taruhanUser;
echo "Tebakan Kamu Benar \n";
echo "Tebakan Bot : ".$tebakanBot."(".$taruhanKelereng.")";
echo "\n";
echo "Tebakan Kamu : ".$tebakanUser;
echo "\n\n";
echo "Kelereng Bot : ".$kelerengBot;
echo "\n";
echo "Kelereng Kamu : ".$kelerengUser;
}else{
//update when user lose
$kelerengBot += $taruhanUser;
$kelerengUser -= $taruhanUser;
echo "Tebakan Kamu Salah \n";
echo "Tebakan Bot : ".$tebakanBot."(".$taruhanKelereng.")";
echo "\n";
echo "Tebakan Kamu : ".$tebakanUser;
echo "\n\n";
echo "Kelereng Bot : ".$kelerengBot;
echo "\n";
echo "Kelereng Kamu : ".$kelerengUser;
echo "\n";
}
}while($kelerengUser > 0 && $kelerengUser <= 19);
//check winner
if($kelerengUser == 20){
echo "Selamat Kamu Menang";
}else{
echo "Kamu Kalah ! DOR";
}
}else{
echo "Kamu belum memasukan nama harap mulai kembali! \n";
}
?>