wrenpp/examples/dieroll/main.wren

48 lines
1.1 KiB
Text
Raw Permalink Normal View History

2020-05-02 20:41:58 +00:00
import "random" for Random
class Game {
construct new() {
_player_money = 6
_my_money = 6
}
foreign static user_input()
//foreign static random()
play_game() {
System.print("Welcome to wrengame!")
while (true) {
System.print("/me rolls a die... *roll* *roll*")
System.print("Your balance is %(_player_money)€ and I have %(_my_money)€, pay 1€ and guess the number!")
var roll = Random.new().int(6) + 1
var guess = Num.fromString(Game.user_input())
_player_money = _player_money - 1
_my_money = _my_money - 2
if (roll == guess) {
System.print("I rolled %(roll)! You win 3€!")
_player_money = _player_money + 3
} else {
_my_money = _my_money + 3
System.print("I rolled %(roll), you lose!")
}
if (_my_money < 2 || _player_money < 1) {
break
}
}
if (_my_money < _player_money) {
System.print("Game finished, you win!")
} else {
System.print("Game finished, I win!")
}
System.print("Final balance is %(_player_money)€ for you and %(_my_money)€ for me")
System.print("Let's play again soon!")
}
}
var the_game = Game.new()