-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
60 lines (55 loc) · 2.25 KB
/
main.ts
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
import inquirer from "inquirer";
let aiChoice:any
let roll
let rollArr
let playerScore:number=0
let aiScore:number=0
let drawScore:number=0
console.log("*****WELCOME TO ROCK PAPER SCISSORS VS AI*****\n","CAN YOU BEAT A SIMPLE MATH.RANDOM FUNCTION?")
async function startRPS() {
let playerDetails = await inquirer.prompt([
{
type:'input',
name:'playerName',
message:'Enter your name'
},
])
while(true){
let playerInput = await inquirer.prompt([
{
type:'list',
name:'playerSelection',
message:'SELECT YOUR MOVE',
choices: ['Rock', 'Paper','Scissors','Quit']
}
])
if (playerInput.playerSelection === 'Quit') {
console.log('Thanks for playing! \n'+'FINAL SCORE!')
console.log('DRAW='+drawScore+'\t'+'AI='+aiScore+'\t'+playerDetails.playerName+'='+playerScore+'\t')
break;
}
roll=Math.floor(Math.random()*3)
rollArr=['Rock','Paper','Scissors']
aiChoice=rollArr[roll]
console.log(playerDetails.playerName+' Chose '+playerInput.playerSelection+'\tVS\t'+'AI Chose '+aiChoice)
if(playerInput.playerSelection===aiChoice){
drawScore++
console.log("its a draw")
console.log('DRAW='+drawScore+'\t'+'AI='+aiScore+'\t'+playerDetails.playerName+'='+playerScore+'\t')
}
else if(
(playerInput.playerSelection==='Paper'&&aiChoice==='Rock')||
(playerInput.playerSelection==='Rock'&&aiChoice==='Scissors')||
(playerInput.playerSelection==='Scissors'&&aiChoice==='Paper')){
playerScore++
console.log("Player "+playerDetails.playerName+" WINS")
console.log('DRAW='+drawScore+'\t'+'AI='+aiScore+'\t'+playerDetails.playerName+'='+playerScore+'\t')
}
else{
aiScore++
console.log("Player "+playerDetails.playerName+" LOST")
console.log('DRAW='+drawScore+'\t'+'AI='+aiScore+'\t'+playerDetails.playerName+'='+playerScore+'\t')
}
}
}
startRPS()