Merge: doc: fixed some typos and other misc. corrections
[nit.git] / examples / rosettacode / pig_the_dice_game.nit
1 #!/usr/bin/env nit
2 #
3 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # This program is public domain
5
6 # Task: Pig the dice game
7 # SEE: http://rosettacode.org/wiki/Pig_the_dice_game
8
9 var player = 0
10 var score = [0, 0]
11 var turnscore = 0
12 var max_score = 100
13 loop
14 if (score[player] + turnscore) >= max_score then
15 print "Congratulation Player {player + 1}! You won with {score[player]} points! "
16 return
17 end
18 print "Player {player +1}"
19 print "Total score : {score[player]}"
20 print "What do you want to do? (\"1\" to roll, \"0\" to hold)"
21 if stdin.eof then break
22 var input = gets
23 if input == "1" then
24 var roll = 6.rand + 1
25 if roll == 1 then
26 turnscore = 0
27 print "You rolled 1! all points lost for this turn"
28 print ""
29 player = 1 - player
30 else
31 turnscore += roll
32 print "rolled: {roll}"
33 print "score this turn: {turnscore}"
34 print ""
35 end
36 else if input == "0" then
37 score[player] += turnscore
38 print "Scored: {turnscore}"
39 print "New Score: {score[player]}"
40 print ""
41 player = 1 - player
42 turnscore = 0
43 end
44 end