This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrabble.js
125 lines (100 loc) · 2.96 KB
/
frabble.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
$(document).ready(function() {
startGame();
$('#start').click(function(e) {
startGame();
e.preventDefault();
});
$('#answer').click(function(e) {
testAnswer();
e.preventDefault();
});
$('#actorhint').click(function(e) {
actorHint();
e.preventDefault();
});
$('#directorhint').click(function(e) {
directorHint();
e.preventDefault();
});
$('#yearhint').click(function(e) {
yearHint();
e.preventDefault();
});
$('#genrehint').click(function(e) {
genreHint();
e.preventDefault();
});
});
function startGame() {
$('#imagelist').html('<h5 class="subheader">Loading your next movie title... Please wait!</h5>');
$('#myanswer').val('');
$('#theanswer').removeClass("winner");
$.getJSON('/ajax.php?method=getNewMovie', function(data) {
var items = [];
words = data.words;
$.each(words, function(index, word) {
if(word.type == 'text'){
items.push('<li class="'+ word.type +'">' + word.result + '</li>');
} else {
items.push('<li class="'+ word.type +'"><img src="' + word.result + '" /></li>');
}
});
$('#imagelist').html(items.join(''));
}).error(function() {
alert("We're sorry - We couldn't load a movie title at this time. We're using a lot of beta APIs here and one of them returned something we didn't expect.");
});;
$('#theanswer').replaceWith('<div id="theanswer" class="block">Awaiting answer...</div>');
$('#actorhintval').empty();
$('#directorhintval').empty();
$('#yearhintval').empty();
$('#genrehintval').empty();
$('#actorhint').show();
$('#directorhint').show();
$('#yearhint').show();
$('#genrehint').show();
return(false);
}
function testAnswer() {
var thefinalanswer = $('#myanswer').val();
$.getJSON('/ajax.php?method=guessMovie&answer='+thefinalanswer, function(data) {
var items = [];
if(data.correct == true){
items.push('Correct!');
$('#theanswer').addClass("winner");
}
else{
items.push('Try Again...');
$('#theanswer').removeClass("winner");
}
$('#theanswer').html(items.join(''));
});
return(false);
}
function actorHint() {
$.getJSON('/ajax.php?method=revealHint&type=starring', function(data) {
$('#actorhintval').html(data.hint.value);
$('#actorhint').hide();
});
return(false);
}
function yearHint() {
$.getJSON('/ajax.php?method=revealHint&type=year', function(data) {
$('#yearhintval').html(data.hint.value);
$('#yearhint').hide();
});
return(false);
}
function directorHint() {
$.getJSON('/ajax.php?method=revealHint&type=director', function(data) {
$('#directorhintval').html(data.hint.value);
$('#directorhint').hide();
});
return(false);
}
function genreHint() {
$.getJSON('/ajax.php?method=revealHint&type=genre', function(data) {
$('#genrehintval').html(data.hint.value);
$('#genrehint').hide();
});
return(false);
}