-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_rock_paper_scissors
46 lines (39 loc) · 1.11 KB
/
simple_rock_paper_scissors
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
import 'dart:io';
import 'dart:math';
enum Move { rock, paper, scissors }
void main() {
while (true) {
stdout.write(
'Welcome to (Rock, Paper or Scissors / Quit) - (r, p or s / q) --------> ');
final input = stdin.readLineSync();
//Selecting Player Move
var playerMove;
if (input == 'r') {
playerMove = Move.rock;
} else if (input == 'p') {
playerMove = Move.paper;
} else if (input == 's') {
playerMove == Move.scissors;
} else if (input == 'q') {
break;
} else {
print('Invalid Input');
}
// Select Ai Move
final randomNumber = Random().nextInt(3);
final aiMove = Move.values[randomNumber];
// Showing Player Move & Ai Move
print('You Played: $playerMove');
print('Ai Played: $aiMove');
// Game Logic
if (playerMove == Move.rock && aiMove == Move.scissors ||
playerMove == Move.paper && aiMove == Move.rock ||
playerMove == Move.scissors && aiMove == Move.paper) {
print('You Win');
} else if (playerMove == aiMove) {
print('Draw');
} else {
print('You Loose');
}
}
}