김한준

html -> main.js 연동

Showing 1 changed file with 163 additions and 0 deletions
1 +var data;
2 +
3 +function dice(n, s, b) {
4 + var out = 0;
5 + for (i = 0; i < n; i++) {
6 + out += Math.ceil(s * Math.random());
7 + }
8 + return out + b;
9 +}
10 +
11 +function count() {
12 + // console.log($('#inputnum').val());
13 +
14 + var numberSort = function(a, b) {
15 + return a[0] - b[0];
16 + };
17 + $('#lottotable').html(""); //초기화
18 + var win1 = 0;
19 + var win2 = 0;
20 + var win3 = 0;
21 + var win4 = 0;
22 + var win5 = 0;
23 +
24 + (function engine(i) {
25 + setTimeout(function() {
26 + var list_length = ($('#lottotable li').length + 1);
27 + var list = "";
28 + var val = [
29 + [0, 0], //[번호, 당첨여부]
30 + [0, 0],
31 + [0, 0],
32 + [0, 0],
33 + [0, 0],
34 + [0, 0]
35 + ];
36 + var match = 0; //몇개 숫자가 적중했나
37 + var match_b = 0; //보너스숫자가 적중했나
38 +
39 + for (j = 0; j < 6; j++) {
40 + // val[j][0] = dice(1, 45, 0);
41 +
42 + function roll(n) {
43 + if (j == 0) {
44 + val[j][0] = n;
45 + } else {
46 + for (l = 0; l < j; l++) {
47 + // console.log(n);
48 + if (n == val[l][0]) {
49 + roll(dice(1, 45, 0));
50 + } else {
51 + val[j][0] = n;
52 + }
53 + }
54 + }
55 + }
56 + roll(dice(1, 45, 0));
57 +
58 + // console.log("No." + (list_length) + ": " + val);
59 + for (m = 0; m < 6; m++) {
60 + if (val[j][0] == data.nums[m]) {
61 + val[j][1] = 1;
62 + match++;
63 + }
64 + }
65 + // console.log("No." + (list_length) + ": " + val);
66 + if (val[j][0] == data.bnum) {
67 + val[j][1] = 2;
68 + match_b = 1;
69 + }
70 + }
71 + // console.log("before sort: "+val);
72 + val.sort(numberSort);
73 + // console.log("after sort: "+val);
74 +
75 +
76 + for (j = 0; j < 6; j++) {
77 + function setColorClass() {
78 + if (val[j][0] <= 10) {
79 + num_class = "c1 ";
80 + } else if (val[j][0] <= 20) {
81 + num_class = "c2 ";
82 + } else if (val[j][0] <= 30) {
83 + num_class = "c3 ";
84 + } else if (val[j][0] <= 40) {
85 + num_class = "c4 ";
86 + } else {
87 + num_class = "c5 ";
88 + }
89 + if (val[j][1] == 1) {
90 + num_class += "match ";
91 + } else if (val[j][1] == 2) {
92 + num_class += "match_b ";
93 + }
94 + }
95 +
96 + var num_class;
97 + setColorClass();
98 + list += '<div class="output ' + num_class + '">' + val[j][0] + '</div>';
99 + // console.log(match);
100 + }
101 + var win_class;
102 + if (match == 6) {
103 + win_class = 'win win1';
104 + win1++;
105 + console.log('win1');
106 + } else if (match == 5 && match_b == 1) {
107 + win_class = 'win win2';
108 + win2++;
109 + console.log('win2');
110 + } else if (match == 5) {
111 + win_class = 'win win3';
112 + win3++;
113 + console.log('win3');
114 + } else if (match == 4) {
115 + win_class = 'win win4';
116 + win4++;
117 + console.log('win4');
118 + } else if (match == 3) {
119 + win_class = 'win win5';
120 + win5++;
121 + console.log('win5');
122 + }
123 + $('#stats').html(
124 + '1등: ' + win1 + "<span class='translation'>(" + (win1 / list_length * 100).toFixed(2) + "%)</span>" +
125 + ' | 2등: ' + win2 + "<span class='translation'>(" + (win2 / list_length * 100).toFixed(2) + "%)</span>" +
126 + ' | 3등: ' + win3 + "<span class='translation'>(" + (win3 / list_length * 100).toFixed(2) + "%)</span>" +
127 + ' | 4등: ' + win4 + "<span class='translation'>(" + (win4 / list_length * 100).toFixed(2) + "%)</span>" +
128 + ' | 5등: ' + win5 + "<span class='translation'>(" + (win5 / list_length * 100).toFixed(2) + "%)</span>" +
129 + " | 총당첨율: " + ((win1 + win2 + win3 + win4 + win5) / list_length * 100).toFixed(2) + "%" +
130 + '<br><progress value="' + list_length + '" max="' + totalbuy + '"></progress>'
131 + );
132 + $('#lottotable').append('<li class="' + win_class + '">' + list + '</li>');
133 + // break;
134 + if (--i) engine(i);
135 + }, 0)
136 + })($('#inputnum').val());
137 +
138 + var totalmatch = (win1 + win2 + win3 + win4 + win5)
139 + var totalbuy = $('#inputnum').val();
140 +}
141 +
142 +function loadlot(a) {
143 + $("#lottok").html('제 ' + a.gno + '회차 당첨 결과(' + a.gdate + ')'); // + '<br/>' +
144 + //a.nums + a.bnum;
145 + a.nums[6] = a.bnum;
146 + for (i = 0; i < 7; i++) {
147 + $('#output' + i).text(a.nums[i]);
148 + }
149 + for (i = 0; i < 7; i++) {
150 + if (a.nums[i] <= 10) {
151 + $('#output' + i).addClass("c1");
152 + } else if (a.nums[i] <= 20) {
153 + $('#output' + i).addClass("c2");
154 + } else if (a.nums[i] <= 30) {
155 + $('#output' + i).addClass("c3");
156 + } else if (a.nums[i] <= 40) {
157 + $('#output' + i).addClass("c4");
158 + } else {
159 + $('#output' + i).addClass("c5");
160 + }
161 + }
162 + data = a;
163 +}