This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quiz.js
81 lines (66 loc) · 1.86 KB
/
quiz.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
//robots
//type 1; decepticons:
//megatron
//soundwave
//medium hp, medium dmg
//type 2; dynobots
//grimlock
//snarl
//high hp, low dmg
//type 3; gundams:
//tallgeese
//heavyarms
//low hp, high dmg
$(function() {
var player1 = {};
var player2 = {};
var p1bot;
var p2bot;
$( "#select1" )
.change(function () {
$( "#select1 option:selected" ).each(function() {
p1bot = $(this).text();
$("#img1Div").html("<img src='" + p1bot + ".jpg'>")
})
})
$( "#select2" )
.change(function () {
$( "#select2 option:selected" ).each(function() {
p2bot = $(this).text();
$("#img2Div").html("<img src='" + p2bot + ".jpg'>")
})
})
$("#battleButton").click(function () {
if ($("#player1").val() == "" || $("#player2").val() == "" ) {
alert("Enter names plz")
} else if ($("#select1").val() == null || $("#select2").val() == null ) {
alert("Choose both fighters plz")
} else {
var playerName1 = $("#player1").val();
var playerName2 = $("#player2").val();
// player1 = new RBD.Robots.Robofighter(playerName1)
// player2 = new RBD.Robots.Robofighter(playerName2)
player1 = new RBD.Robots[p1bot](playerName1);
player2 = new RBD.Robots[p2bot](playerName2);
console.log(player1)
console.log(player2)
$(".battleButton").toggleClass("hidden");
console.log("test");
}
})
$("#fightButton").click(function () {
player1.health -= player2.damage
player2.health -= player1.damage
console.log(player1, player2)
if ((player1.health <= 0) && (player2.health <= 0)) {
alert("Everyone is dead!")
$("#fightButton").toggleClass("hidden")
} else if (player2.health <= 0) {
alert(player1.playerName + " wins!")
$("#fightButton").toggleClass("hidden")
} else if (player1.health <= 0) {
alert(player2.PlayerName + " wins!")
$("#fightButton").toggleClass("hidden")
}
})
}); //end doc ready