commit | author | age
|
7f8ceb
|
1 |
<!DOCTYPE html> |
JK |
2 |
<html> |
|
3 |
<head> |
|
4 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|
5 |
<meta name="viewport" content="width=device-width, user-scalable=no" /> |
|
6 |
<title>Obliczenia brydżowe</title> |
|
7 |
<link rel="stylesheet" href="bridge.css" type="text/css" /> |
|
8 |
</head> |
|
9 |
<body> |
|
10 |
<form oninput="javascript:compute()"> |
|
11 |
|
|
12 |
<p> |
|
13 |
<label><input type="radio" name="kontrakt" value="0" checked="checked"/> <span>4 pasy</span></label> |
|
14 |
<label><input type="radio" name="kontrakt" value="1"/> <span>1</span></label> |
|
15 |
<label><input type="radio" name="kontrakt" value="2"/> <span>2</span></label> |
|
16 |
<label><input type="radio" name="kontrakt" value="3"/> <span>3</span></label> |
|
17 |
<label><input type="radio" name="kontrakt" value="4"/> <span>4</span></label> |
|
18 |
<label><input type="radio" name="kontrakt" value="5"/> <span>5</span></label> |
|
19 |
<label><input type="radio" name="kontrakt" value="6"/> <span>6</span></label> |
|
20 |
<label><input type="radio" name="kontrakt" value="7"/> <span>7</span></label> |
|
21 |
</p> |
|
22 |
|
|
23 |
<p> |
|
24 |
<label><input type="radio" name="typ" value="0" checked="checked" /> <span>♣/♦</span></label> |
|
25 |
<label><input type="radio" name="typ" value="1" /> <span>♥/♠</span></label> |
|
26 |
<label><input type="radio" name="typ" value="2" /> <span>NT</span></label> |
|
27 |
<span style="display: inline-block; margin-left:1.5em;"></span> |
|
28 |
<label><input type="radio" name="kontra" value="0" checked="checked" /> <span>norm.</span></label> |
|
29 |
<label><input type="radio" name="kontra" value="1" /> <span>ktr.</span></label> |
|
30 |
<label><input type="radio" name="kontra" value="2" /> <span>rektr.</span></label> |
|
31 |
</p> |
|
32 |
|
|
33 |
<p> |
|
34 |
<label><input type="radio" name="partia" value="0" checked="checked"/> <span>przed/przed</span></label> |
|
35 |
<label><input type="radio" name="partia" value="1" /> <span>przed/po</span></label> |
|
36 |
<label><input type="radio" name="partia" value="2" /> <span>po/przed</span></label> |
|
37 |
<label><input type="radio" name="partia" value="3" /> <span>po/po</span></label> |
|
38 |
</p> |
|
39 |
|
|
40 |
<table class="range"> |
|
41 |
<tr> |
|
42 |
<td>PC:</td> <td width="100%"><input type="range" name="punkty" value="0" min="0" max="40" step="1" oninput="punktyvalue.value=value" /></td> <td><output id="punktyvalue">0</output></td> |
|
43 |
</tr> |
|
44 |
<tr> |
|
45 |
<td>Lewy:</td> <td width="100%"><input type="range" name="lewy" value="0" min="0" max="13" step="1" oninput="lewyvalue.value=value" /></td> <td><output id="lewyvalue">0</output></td> |
|
46 |
</tr> |
|
47 |
</table> |
|
48 |
|
|
49 |
<p id="result"></p> |
|
50 |
</form> |
|
51 |
|
450db0
|
52 |
<script type="text/javascript" src="bridge_compute.js"></script> |
7f8ceb
|
53 |
<script type="text/javascript"> |
JK |
54 |
var zapis; |
|
55 |
|
|
56 |
function compute() { |
|
57 |
var kontraktField = document.querySelector('input[name=kontrakt]:checked'); |
|
58 |
var kontraktChoice = document.querySelector('input[name=typ]:checked'); |
|
59 |
var kontraChoice = document.querySelector('input[name=kontra]:checked'); |
|
60 |
var partiaChoice = document.querySelector('input[name=partia]:checked'); |
|
61 |
var punktyField = document.querySelector('input[name=punkty]'); |
|
62 |
var lewyField = document.querySelector('input[name=lewy]'); |
|
63 |
var kontrakt, typ, kontra, partia, punkty, lewy; |
|
64 |
|
|
65 |
kontrakt = parseInt(kontraktField.value, 10); |
|
66 |
typ = parseInt(kontraktChoice.value, 10); |
|
67 |
kontra = parseInt(kontraChoice.value, 10); |
|
68 |
partia = parseInt(partiaChoice.value, 10); |
|
69 |
punkty = parseInt(punktyField.valueAsNumber, 10); |
|
70 |
lewy = parseInt(lewyField.valueAsNumber, 10); |
|
71 |
resultText = { |
|
72 |
setText: function(text) { |
|
73 |
document.getElementById('result').innerText = text; |
|
74 |
} |
|
75 |
}; |
|
76 |
|
|
77 |
if( kontrakt < 0 || kontrakt > 7 ) { |
|
78 |
resultText.setText("Niepoprawny kontrakt."); |
|
79 |
return; |
|
80 |
} |
|
81 |
|
|
82 |
if( typ != 0 && typ != 1 && typ != 2 ) { |
|
83 |
resultText.setText("Niepoprawny typ kontraktu."); |
|
84 |
return; |
|
85 |
} |
|
86 |
|
|
87 |
if( kontra < 0 || kontra > 2 ) { |
|
88 |
resultText.setText("Niepoprawna informacja o kontrze."); |
|
89 |
return; |
|
90 |
} |
|
91 |
|
|
92 |
if( partia < 0 || partia > 3) { |
|
93 |
resultText.setText("Niepoprawna informacja o partii."); |
|
94 |
return; |
|
95 |
} |
|
96 |
|
|
97 |
if( punkty < 0 || punkty > 40 ) { |
|
98 |
resultText.setText("Niepoprawna ilość punktów"); |
|
99 |
return; |
|
100 |
} |
|
101 |
|
|
102 |
if( lewy < 0 || lewy > 13 ) { |
|
103 |
resultText.setText("Niepoprawna ilość wziętych lew."); |
|
104 |
return; |
|
105 |
} |
|
106 |
|
|
107 |
if( kontrakt == 0 && punkty < 20 ) { |
|
108 |
resultText.setText("Przy czterech pasach podaj większą liczę punktów."); |
|
109 |
return; |
|
110 |
} |
|
111 |
|
|
112 |
var wynik = BrydzLicz.policz(kontrakt, typ, kontra, partia, punkty, lewy); |
|
113 |
|
|
114 |
resultText.setText((wynik.dla == 0 ? "Zapis dla rozgrywających" : "Zapis dla przeciwników.")+ |
|
115 |
"\nPunktów (bez PC): "+wynik.punkty_przed+ |
|
116 |
"\nPunktów (z PC): "+wynik.punkty+ |
|
117 |
"\nIMP-ów: "+wynik.IMP+ |
|
118 |
"\nProcent: "+wynik.procent); |
|
119 |
zapis = wynik; |
|
120 |
} |
|
121 |
|
|
122 |
function send() { |
|
123 |
window.opener.postMessage(zapis, '*'); |
|
124 |
window.close(); |
|
125 |
} |
|
126 |
|
|
127 |
if(window.opener) { |
|
128 |
var button = document.createElement('button'); |
|
129 |
button.onclick = send; |
|
130 |
button.innerText = 'Zapisz'; |
|
131 |
document.body.appendChild(button); |
|
132 |
} |
|
133 |
</script> |
|
134 |
</body> |
|
135 |
</html> |