-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.js
More file actions
135 lines (101 loc) · 2.84 KB
/
util.js
File metadata and controls
135 lines (101 loc) · 2.84 KB
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
var words={'blue':[],'grey':[],'red':[]}
var assassin="";
var turn=0;
var players=["blue","red"];
var count={'blue':0,'grey':0,'red':0};
var wordData=[];
var playerNames = {'blue':"",'red':""};
//These functions are used to control which HTML elements are hidden or not
//throughout gameplay.
function turnOn(elements){
for(var i=0;i<elements.length;i++){
elements[i].style.display="block";
}
}
function turnOff(elements){
for(var i=0;i<elements.length;i++){
elements[i].style.display="none";
}
}
//Below are the routinely used functions
function reset(){
words={'blue':[],'grey':[],'red':[]}
assassin="";
turn=0;
count={'blue':0,'grey':0,'red':0};
}
function endTurn(){
alert("Wrong choice! Your turn is over");
BtoM.send(["turn", turn]);
makeTurn();
}
function wins(color){
alert("Team "+color+" wins!!");
if(who=="breaker"){
BreakerWin();
}
}
function makeTurn(){
turn=(turn+1)%2;
document.getElementById("turn").style.borderColor = players[turn];
document.getElementById("turnText").innerText = "It is "+playerNames[players[turn]]+"'s turn.";
}
function getRandInt(min, max){
min =Math.ceil(min);
max=Math.floor(max);
return Math.floor(Math.random()*(max-min))+min
}
function permute(arr){
var perm = [];
while(arr.length>0){
var ind=getRandInt(0,arr.length);
perm.push(arr[ind]);
arr.splice(ind, 1);
}
return perm;
}
//pickWord() selects a word and creates an element to be added to the Breaker
//Board
function pickWord(){
newWord=document.createElement("TD");
newWord.setAttribute("name","wordBox");
newWord.width=78;
newWord.height="50";
newWord.innerText = getWord();
return newWord;
}
//the function getWord ensures words cannot be repeated by checking against
//those that have already been chosen, stored in activeWords
var activeWords = [];
function getWord(){
var good = false;
while(good==false){
var newWord = wordData[getRandInt(0,wordData.length)];
if(!activeWords.includes(newWord)){good=true;}
}
activeWords.push(newWord);
return newWord;
}
//Create Category Selection Boxes
function addCategories(){
for(var i=0;i<Object.keys(categories).length; i++){
newCat = document.createElement("TR");
boxCell = document.createElement("TD");
catBox = document.createElement("INPUT");
catBox.setAttribute("type","checkbox");
catBox.setAttribute("name","category");
catBox.setAttribute("value",Object.keys(categories)[i]);
boxCell.appendChild(catBox);
newCat.appendChild(boxCell);
labelCell=document.createElement("TD");
labelCell.innerText=Object.keys(categories)[i];
newCat.appendChild(labelCell);
document.getElementById("selection").appendChild(newCat);
}
}
//Input Player names
function getNames(){
blueName = prompt("Please enter the name of the Blue player", "");
redName = prompt("Please enter the name of the Red player","");
return({'blue':blueName,'red':redName});
}