forked from kokonior/PHP-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAseliBola
69 lines (55 loc) · 1.7 KB
/
AseliBola
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
<?php
//set bola awal
$bolaBot = 10;
$bolaUser = 10;
//Deklasari
$namaUser;
$tebakanUser;
$taruhanUser;
$taruhanBola;
$tebakanBot;
echo "\n";
echo "Selamat Datang di Aseli Bola \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 "Bola Bot : ".$BolaBot;
echo "\n";
echo "Bola Kamu : ".$BolaUser;
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
$taruhanBola = rand(1,$BolaBot);
//cek ganjil genap
if($taruhanBola % 2 == 0 ){
$tebakanBot = "genap";
}else{
$tebakanBot = "ganjil";
}
//main function
if($tebakanUser == $tebakanBot){
//update when user win
$BolaBot -= $taruhanUser;
$BolaUser += $taruhanUser;
echo "Tebakan Kamu Benar \n";
echo "Tebakan Bot : ".$tebakanBot."(".$taruhanBola.")";
echo "\n";
echo "Tebakan Kamu : ".$tebakanUser;
echo "\n\n";
echo "Bola Bot : ".$BolaBot;
echo "\n";
echo "Bola Kamu : ".$BolaUser;
?>