forked from josephkim583/Medication_Sorting_Game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedication.js
151 lines (133 loc) · 6.63 KB
/
medication.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
var my_hand = {"count": 0, "type": "none"};
var medicine_count = {"red": 10, "blue": 10};
var calendar_count = {"Mon1r": 0, "Mon2r": 0, "Mon3r": 0, "Mon4r": 0, "Mon1b": 0, "Mon2b": 0, "Mon3b": 0, "Mon4b": 0, "Tues1r": 0, "Tues2r": 0, "Tues3r": 0, "Tues4r": 0, "Tues1b": 0, "Tues2b": 0, "Tues3b": 0, "Tues4b": 0, "Wed1r": 0, "Wed2r": 0, "Wed3r": 0, "Wed4r": 0, "Wed1b": 0, "Wed2b": 0, "Wed3b": 0, "Wed4b": 0, "Thurs1r": 0, "Thurs2r": 0, "Thurs3r": 0, "Thurs4r": 0, "Thurs1b": 0, "Thurs2b": 0, "Thurs3b": 0, "Thurs4b": 0, "Fri1r": 0, "Fri2r": 0, "Fri3r": 0, "Fri4r": 0, "Fri1b": 0, "Fri2b": 0, "Fri3b": 0, "Fri4b": 0, "Sat1r": 0, "Sat2r": 0, "Sat3r": 0, "Sat4r": 0, "Sat1b": 0, "Sat2b": 0, "Sat3b": 0, "Sat4b": 0, "Sun1r": 0, "Sun2r": 0, "Sun3r": 0, "Sun4r": 0, "Sun1b": 0, "Sun2b": 0, "Sun3b": 0, "Sun4b": 0}
function calender_click(clicked_id)
{
var calendar_val = Number(document.getElementById(clicked_id).innerHTML);
var calendar_type = clicked_id.substr(-1);
var hand_val = my_hand["count"];
var hand_type = my_hand["type"];
if (hand_val == 1){
if (hand_type == calendar_type && calendar_type == 'r'){
var id = clicked_id + calendar_count[clicked_id ]
calendar_count[clicked_id ] += 1
var img = document.createElement("img");
img.src = "redpill.jpg";
img.id = id;
img.setAttribute("height" , 30);
document.getElementById(clicked_id).appendChild(img);
document.getElementById("hand").innerHTML = Number(0);
my_hand["count"] = 0;
my_hand["type"] = "none"
}
else if (hand_type == "b" && hand_type == calendar_type){
var id = clicked_id + calendar_count[clicked_id ]
calendar_count[clicked_id ] += 1
var img = document.createElement("img");
img.src = "bluepill.jpg";
img.id = id;
img.setAttribute("height" , 30);
document.getElementById(clicked_id).appendChild(img);
document.getElementById("hand").innerHTML = Number(0);
my_hand["count"] = 0;
my_hand["type"] = "none"
}
else{
alert("You are butting the pill in a wrong container!!");
}
}
else if(hand_val == 0){
if (calendar_count[clicked_id] > 0){
var id = clicked_id + String(calendar_count[clicked_id] - 1);
document.getElementById(id).remove();
calendar_count[clicked_id] -= 1;
document.getElementById("hand").innerHTML = hand_val + 1;
my_hand["count"] = 1;
my_hand["type"] = calendar_type;
}
else{
alert("The hand is empty!");
}
}
}
function red_instruction(){
alert("Red pill instructions!");
}
function blue_instruction(){
alert("Blue pill instructions!");
}
function blue_medicine_click(){
var hand_val = my_hand["count"];
var hand_type = my_hand["type"];
if (hand_val == 1 && hand_type == "r"){
alert("You can't put a red pill inside a blue bottle!");
}
else if (hand_val == 1 && hand_type == "b"){
medicine_count["blue"] += 1;
var id = "blue" + String(medicine_count["blue"])
var img = document.createElement("img");
img.src = "bluepill.jpg";
img.id = id;
img.setAttribute("height", "42");
// img.setAttribute("width", "42");
document.getElementById("blue_bottle").appendChild(img);
// document.getElementById(id).style.backgroundColor = "blue";
document.getElementById("hand").innerHTML = hand_val - 1;
my_hand["count"] = 0;
my_hand["type"] = "none"
}
else if (hand_val == 0){
if (medicine_count["blue"] > 0) {
var id = "blue" + String(medicine_count["blue"])
document.getElementById(id).remove();
document.getElementById("hand").innerHTML = hand_val + 1;
medicine_count["blue"] -= 1;
my_hand["count"] = 1
my_hand["type"] = "b"
}
else{
alert("Red medicine bottle is empty");
}
}
else{
alert("Wrong operation!");
}
}
function red_medicine_click(){
var hand_val = my_hand["count"];
var hand_type = my_hand["type"];
document.body.style.cursor = "url('redpill.jpg')";
if (hand_val == 1 && hand_type == "b"){
alert("You can't put a blue pill inside a red bottle!");
}
else if (hand_val == 1 && hand_type == "r"){
medicine_count["red"] += 1;
var id = "red" + String(medicine_count["red"])
var img = document.createElement("img");
img.src = "redpill.jpg";
img.id = id;
img.setAttribute("height" , 42);
document.getElementById("red_bottle").appendChild(img);
document.getElementById("hand").innerHTML = hand_val - 1;
my_hand["count"] = 0;
my_hand["type"] = "none"
}
else if (hand_val == 0){
if (medicine_count["red"] > 0) {
var id = "red" + String(medicine_count["red"])
document.getElementById(id).remove();
document.getElementById("hand").innerHTML = hand_val + 1;
medicine_count["red"] -= 1;
my_hand["count"] = 1
my_hand["type"] = "r"
}
else{
alert("Red medicine bottle is empty");
}
}
else{
alert("Wrong operation!");
}
}
var json = {"day" : { "Sun": { "1": { "red" : 0, "blue" : 0 } , "2": { "red" : 0, "blue" : 0 } , "3": { "red" : 0, "blue" : 0 } , "4": { "red" : 0, "blue" : 0 } } , "Mon": { "1": { "red" : 0, "blue" : 0 } , "2": { "red" : 0, "blue" : 0 } , "3": { "red" : 0, "blue" : 0 } , "4": { "red" : 0, "blue" : 0 } } , "Tues": { "1": { "red" : 0, "blue" : 0 } , "2": { "red" : 0, "blue" : 0 } , "3": { "red" : 0, "blue" : 0 } , "4": { "red" : 0, "blue" : 0 } } , "Wed": { "1": { "red" : 0, "blue" : 0 } , "2": { "red" : 0, "blue" : 0 } , "3": { "red" : 0, "blue" : 0 } , "4": { "red" : 0, "blue" : 0 } } , "Thurs": { "1": { "red" : 0, "blue" : 0 } , "2": { "red" : 0, "blue" : 0 } , "3": { "red" : 0, "blue" : 0 } , "4": { "red" : 0, "blue" : 0 } } , "Fri": { "1": { "red" : 0, "blue" : 0 } , "2": { "red" : 0, "blue" : 0 } , "3": { "red" : 0, "blue" : 0 } , "4": { "red" : 0, "blue" : 0 } } , "Sat": { "1": { "red" : 0, "blue" : 0 } , "2": { "red" : 0, "blue" : 0 } , "3": { "red" : 0, "blue" : 0 } , "4": { "red" : 0, "blue" : 0 } } } }
// console.log(json["day"]["Sun"]["1"]["red"]);