-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdice-advanced.js
129 lines (106 loc) · 2.98 KB
/
dice-advanced.js
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// This is a simple Tabris.js app. by MR. M. - Feel free to modify as you please.
const {
Button,
TextView,
ui,
ImageView,
AlertDialog,
app, TextInput
} = require('tabris');
const IMAGE_PATH = 'https://mrmccormack.github.io/imd-learning-tabris/images/';
const MY_GITHUB_REPO = 'https://github.com/mrmccormack/imd-learning-tabris'
// global variables
let numWins = 0;
// Create a text input field with input finished listener
let userText = new TextInput({
top: 20, left: '20%', right: '20%',
message: 'Your name: '
}).on('accept', ({text}) => {
new TextView({
top: 'prev() 20', left: '20%',
text: text
}).appendTo(ui.contentView);
}).appendTo(ui.contentView);
let casinoimage = new ImageView({
top: 'prev() 10',
centerX: 0,
image: IMAGE_PATH + 'casino.jpg'
}).appendTo(ui.contentView);
let button = new Button({
centerX: 0,
top: 'prev() 10',
text: 'Roll Dice'
})
.on('select', () => {
casinoimage.height = 1;
var rand = 1 + Math.floor(Math.random() * 6);
image1.image = IMAGE_PATH + rand + '.png';
if (rand == 6) {
label.text = userText.text + '- WINNER, you got a 6';
numWins = numWins + 1 ;
winnerimage.image = IMAGE_PATH + 'winner.jpg';
} else {
label.text = userText.text + ' - Try again- Wins so far ' + numWins;
winnerimage.image = '';
}
if (numWins == 5){
label.text = 'You WON with 5 wins!';
image1.image = IMAGE_PATH + 'whitedice.png';
winnerimage.image = '';
numWins = 0;
}
}).appendTo(ui.contentView);
// Create a text view and add it too
let label = new TextView({
centerX: 0,
top: 'prev() 10',
font: '14px',
text: 'Welcome to Mr. M. Casino'
}).appendTo(ui.contentView);
// Display images with different scale modes
let image1 = new ImageView({
top: 'prev() 10',
width: 100,
height: 100,
centerX: 0,
scaleMode: 'fill',
image: IMAGE_PATH + 'whitedice.png'
}).appendTo(ui.contentView);
let winnerimage = new ImageView({
top: 'prev() 10',
width: 100,
height: 100,
centerX: 0,
scaleMode: 'fill',
}).appendTo(ui.contentView);
let resetbutton = new Button({
centerX: 0,
top: 'prev() 10',
text: 'Reset'
})
.on('select', () => {
casinoimage.height = 109;
label.text = 'New Game';
winnerimage.image = '';
numWins = 0;
image1.image = 'https://assets-cdn.github.com/images/modules/logos_page/Octocat.png';
}).appendTo(ui.contentView);
new Button({
left: 16, top: 'prev() 16', right: 16,
text: '© INFO'
}).on('select', () => {
new AlertDialog({
message: '© 2018 Mr. M. - Free to use',
buttons: {ok: 'OK'}
}).open();
}).appendTo(ui.contentView);
new Button({
alignment: 'center', centerX: 0, top: 'prev() 10',
image: IMAGE_PATH + 'github32.png',
font: '10px',
text: 'View source code on my Github Repository'
}).on({
select: () => app.launch(MY_GITHUB_REPO)
.then(() => label.text = 'Url has been launched')
.catch((e) => label.text = e)
}).appendTo(ui.contentView);