[DreamHack] ๋๋ฆผํต ์นํดํน : Carve Party
https://dreamhack.io/wargame/challenges/96/
Carve Party
Description ํ ๋ก์ ํํฐ๋ฅผ ๊ธฐ๋ ํ๊ธฐ ์ํด ํธ๋ฐ์ ์ค๋นํ์ต๋๋ค! ํธ๋ฐ์ 10000๋ฒ ํด๋ฆญํ๊ณ ํ๋๊ทธ๋ฅผ ํ๋ํ์ธ์!
dreamhack.io
๋ฌธ์ ํ์ผ ์ฌ๋๋ฒ
๋ฌธ์ ํ์ผ์ ๋ค์ด๋ก๋ํ๊ณ ์์ถ์ ํ๋ฉด .html ํ์ผ ํ๋๊ฐ ๋์จ๋ค.
์ด๋ฅผ ๋ธ๋ผ์ฐ์ (์จ์ผ, ํฌ๋กฌ, ์ฌํ๋ฆฌ ๋ฑ)์ ๋์ด์ค๋ฉด ํ์ผ์ด ์ด๋ฆฐ๋ค
ํ์ด
ํธ๋ฐ์ 10000๋ฒ ํด๋ฆญํ๋ฉด ํ๋๊ทธ๋ฅผ ๋ฐ์ ์ ์๋ค๊ณ ํ๋ค.
์ฒ์์ ์ฝ๊ฒ ๊ฐ๋ฐ์ ๋๊ตฌ๋ฅผ ์ด์ด์ ์ฝ๋๋ฅผ ์ดํด๋ณด์
F12 -> source
var pumpkin = [ 124, 112, 59, 73, 167, 100, 105, 75, 59, 23, 16, 181, 165, 104, 43, 49, 118, 71, 112, 169, 43, 53 ];
var counter = 0;
var pie = 1;
function make() {
if (0 < counter && counter <= 1000) {
$('#jack-nose').css('opacity', (counter) + '%');
}
else if (1000 < counter && counter <= 3000) {
$('#jack-left').css('opacity', (counter - 1000) / 2 + '%');
}
else if (3000 < counter && counter <= 5000) {
$('#jack-right').css('opacity', (counter - 3000) / 2 + '%');
}
else if (5000 < counter && counter <= 10000) {
$('#jack-mouth').css('opacity', (counter - 5000) / 5 + '%');
}
if (10000 < counter) {
$('#jack-target').addClass('tada');
var ctx = document.querySelector("canvas").getContext("2d"),
dashLen = 220, dashOffset = dashLen, speed = 20,
txt = pumpkin.map(x=>String.fromCharCode(x)).join(''), x = 30, i = 0;
ctx.font = "50px Comic Sans MS, cursive, TSCu_Comic, sans-serif";
ctx.lineWidth = 5; ctx.lineJoin = "round"; ctx.globalAlpha = 2/3;
ctx.strokeStyle = ctx.fillStyle = "#1f2f90";
(function loop() {
ctx.clearRect(x, 0, 60, 150);
ctx.setLineDash([dashLen - dashOffset, dashOffset - speed]); // create a long dash mask
dashOffset -= speed; // reduce dash length
ctx.strokeText(txt[i], x, 90); // stroke letter
if (dashOffset > 0) requestAnimationFrame(loop); // animate
else {
ctx.fillText(txt[i], x, 90); // fill final letter
dashOffset = dashLen; // prep next char
x += ctx.measureText(txt[i++]).width + ctx.lineWidth * Math.random();
ctx.setTransform(1, 0, 0, 1, 0, 3 * Math.random()); // random y-delta
ctx.rotate(Math.random() * 0.005); // random rotation
if (i < txt.length) requestAnimationFrame(loop);
}
})();
}
else {
$('#clicks').text(10000 - counter);
}
}
$(function() {
$('#jack-target').click(function () {
counter += 1;
if (counter <= 10000 && counter % 100 == 0) {
for (var i = 0; i < pumpkin.length; i++) {
pumpkin[i] ^= pie;
pie = ((pie ^ 0xff) + (i * 10)) & 0xff;
}
}
make();
});
});
counter ๋ผ๋ ๋ณ์๊ฐ 10000์ด ๋๋ฉด ๋ ๊ฒ ๊ฐ๋ค.
console ํญ์ ์ด์ด์ ์ด ๋ณ์๋ฅผ ์ง์ 9000์ผ๋ก ๋ฐ๊ฟ์ฃผ์๋ค.
์ ์๋ํ๋ ๊ฒ ๊ฐ์์ ๋ฐ๋ก 10000์ผ๋ก ๋ฐ๊ฟ๋ดค๋๋ฐ..
๋ญ๊ฐ ์ด์ํ๋ค.
์๋ฌด๋๋ ๋ฐ๋ก ์ ๊ทผํ๋๊ฑด ๋ถ๊ฐ๋ฅํ ๊ฒ ๊ฐ๋ค.
์ค์ ๋ก ์ฌ๋์ด ๋๋ฅด๋ ๊ฒ ์ฒ๋ผ 1์ฉ ์ฆ๊ฐ์์ผ์ผ ํ ๊ฒ ๊ฐ๋ค.
function mecro() {
$('#jack-target').click(function () {
counter += 1;
if (counter <= 10000 && counter % 100 == 0) {
for (var i = 0; i < pumpkin.length; i++) {
pumpkin[i] ^= pie;
pie = ((pie ^ 0xff) + (i * 10)) & 0xff;
}
}
make();
}
for(let i=0; i<10000; i++) {
mecro();
}
์์ค์ฝ๋ ์์ ์๋ ํด๋ฆญ์ ๋ฐ์ํ๋ ํจ์๋ฅผ ๊ทธ๋๋ก ๋ณต๋ถํด์ mecro๋ผ๋ ์ด๋ฆ์ ๋ถ์ฌ์ ์ ์ธํด์ฃผ์๋ค.
๊ทธ ํ ์ด ํจ์๋ฅผ ๋ง๋ฒ ์คํ์์ผ์ฃผ๋ฉด
์ฑ๊ณต