-
Notifications
You must be signed in to change notification settings - Fork 0
/
console-ver.html
103 lines (91 loc) · 3.14 KB
/
console-ver.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Saber, Archer, Lancer!</title>
</head>
<body>
<script>
let playerScore=0;
let computerScore=0;
//score updates
function updatePlayerScore(){
return playerScore++;
}
function updateComputerScore(){
return computerScore++;
}
//computer randomly chooses between saber archer or lancer
function computerPlay(){
let result= Math.floor(Math.random()*3)+1;
if(result==1){
return "saber";
}
else if (result==2){
return "archer";
}
else{
return "lancer";
}
}
//function for playing one round
function playRound(playerChoice, computerChoice){
//if its a tie
if (playerChoice === computerChoice){
console.log("It's a tie! They're evenly matched!");
console.log(`Current Score: You-${playerScore} Computer-${computerScore}`);
}
//if player is the winner
else if ((playerChoice == "saber") && (computerChoice =="lancer")){
console.log("You win! Saber killed Lancer!");
updatePlayerScore();
console.log(`Current Score: You-${playerScore} Computer-${computerScore}`);
}
else if ((playerChoice == "lancer") && (computerChoice =="archer")){
console.log("You win! Lancer killed Archer!");
updatePlayerScore();
console.log(`Current Score: You-${playerScore} Computer-${computerScore}`);
}
else if((playerChoice == "archer") && (computerChoice == "saber")){
console.log("You win! Archer killed Saber!");
updatePlayerScore();
console.log(`Current Score: You-${playerScore} Computer-${computerScore}`);
}
//if computer is the winner
else if ((computerChoice =="saber") && (playerChoice =="lancer")){
console.log("Argh.. Computer Wins! Saber killed Lancer!");
updateComputerScore();
console.log(`Current Score: You-${playerScore} Computer-${computerScore}`);
}
else if ((computerChoice =="lancer") && (playerChoice =="archer")){
console.log("Argh.. Computer Wins! Lancer killed Archer!");
updateComputerScore();
console.log(`Current Score: You-${playerScore} Computer-${computerScore}`);
}
else if((computerChoice =="archer") && (playerChoice =="saber")){
console.log("Argh.. Computer Wins! Archer killed Saber!");
updateComputerScore();
console.log(`Current Score: You-${playerScore} Computer-${computerScore}`);
}
else{
return "Something seems wrong.. Please try again.";
}
}
function game(){
for(let i=0;i<5;i++){
//take input from player
let playerChoice = prompt("Choose your servant!").toLowerCase();
playRound(playerChoice,computerPlay());
}
}
game();
if(playerScore>computerScore){
console.log('Congrats! You obtained the Holy Grail!')
}
else if (playerScore<computerScore){
console.log('You Died.')
}
</script>
</body>
</html>