This repository has been archived by the owner on Aug 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtf-lottery.html
153 lines (120 loc) · 2.81 KB
/
tf-lottery.html
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
152
153
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<style>
body, input {
font-family: arial, helvetica, sans-serif;
font-size: 24px;
}
table {
background-color: #c1d2ee;
margin: 20px;
margin-left: auto;
margin-right: auto;
}
td.player {
background-color: #d6dff7;
text-align: center;
width: 150px;
}
</style>
<script>
window.onload = function() {
buildTables();
document.getElementById( 'year' ).innerHTML = ( new Date() ).getFullYear();
};
// Competition Participants
var names = [
'Arturek',
'Ewelinka',
'Fredzio',
'Grzesiu',
'Kubuś',
'Maciuś',
'Marunio',
'Michaś',
'Oluś',
'PJuś',
'Piotruś',
'Robercik',
'Wikciu',
'Wioletka'
];
// Those who should not play together :D
var girls = { 'Ewelinka': 1, 'Wioletka': 1, 'Oluś': 1 };
var loop = 0;
function run() {
var partnerGender;
names.randomize();
for ( var i = 1; i < names.length + 1; i++ ) {
var name = names[ i - 1 ];
if ( !partnerGender )
partnerGender = girls[ name ] ? 'F' : 'M';
else {
if ( girls[ name ] && partnerGender == 'F' ) {
run();
return;
}
partnerGender = 0;
}
document.getElementById( 'p' + i ).innerHTML = name;
}
loop++;
if ( loop < 30 ) {
setTimeout( run, 100 );
}
}
// http://www.htmlblog.us/random-javascript-array
Array.prototype.randomize = function() {
var i = this.length, j, temp;
while ( --i ) {
j = Math.floor( Math.random() * (i - 1) );
temp = this[ i ];
this[ i ] = this[ j ];
this[ j ] = temp;
}
};
var matchCount = 0,
playerCount = 0;
function getTable() {
matchCount++;
var table = document.getElementById( 'template' ).cloneNode( true );
table.id = 'match' + matchCount;
table.style.display = '';
table.getElementsByTagName( 'th' )[ 0 ].innerHTML = 'Match ' + matchCount;
for ( var i = 1; i <= 4; i++ ) {
playerCount++;
var playerCell = table.getElementsByClassName( 'player' + i )[ 0 ];
playerCell.id = 'p' + playerCount;
}
return table;
}
function buildTables() {
var tableCount = Math.ceil( names.length / 4 );
for ( var i = 0; i < tableCount; i++ ) {
document.body.appendChild( getTable() );
}
}
</script>
</head>
<body>
<h1 style="text-align: center">Table-Football Tournament <span id="year"></span></h1>
<p style="text-align: center;"><input type="button" value="Start!" onclick="this.disabled=true;run();"></p>
<table id="template" style="display:none">
<tr>
<th colspan="3"> </th>
</tr>
<tr>
<td class="player player1"> </td>
<td rowspan="2">vs</td>
<td class="player player3"> </td>
</tr>
<tr>
<td class="player player2"> </td>
<td class="player player4"> </td>
</tr>
</table>
</body>
</html>