사용자:James0321/common.js
참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.
- 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
- 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
- 인터넷 익스플로러 / 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
- 오페라: Ctrl-F5를 입력.
/** 플러그인 SimMD5***************************
* 마법의 MD-5 시뮬레이터 게임에 사용되는 스크립트로, 인터페이스와 배틀시스템을 구현합니다.
* 버전 => 1.3
* 작성자 : [[사용자:Gustmd7410|Gustmd7410]]
* JSON => SimMD5 = {"name":"SimMD5","descript":"마법의 MD-5 시뮬레이터 게임에 사용되는 스크립트로, 인터페이스와 배틀시스템을 구현합니다.","version":"1.3","local":true,"creat":"Gustmd7410","state":"마법의 MD-5 시뮬레이터/플러그인","executable":true};
*/
function plugin_SimMD5(){
if($("[data-name='SimMD5']").length >= 1){
// 이부분에 코드 입력 //
mw.loader.using('oojs-ui-widgets').done(function() {
function prepare() {
function responsible(event) {
var button = $('#input-time .oo-ui-numberInputWidget-plusButton, #input-time .oo-ui-numberInputWidget-minusButton');
if(event.matches) {
button.css('display', 'none');
input.time.$label.css('margin-right', null);
} else {
button.css('display', 'null');
input.time.$label.css('margin-right', '30px');
}
}
function encode(string) {
return string
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/{/g, '{')
.replace(/\|/g, '|')
.replace(/=/g, '=')
.replace(/}/g, '}')
.replace(/\[/g, '[')
.replace(/\]/g, ']')
.replace(/_/g, '_');
}
function cancel(btn) {
if(stat.length) {
battle.done = null;
battle.turn = 0;
battle.attack = null;
battle.sequence = null;
battle.combo = null;
battle.temp = null;
bar = [];
bar[0] = new OO.ui.ProgressBarWidget({
progress: 100
});
bar[1] = new OO.ui.ProgressBarWidget({
progress: 100
});
bar[0].$bar.css({
background: '#3366CC'
});
bar[0].$element.css({
'border-right': 'none',
'border-top-right-radius': 0,
'border-bottom-right-radius': 0
});
bar[1].$bar.css({
background: '#FF5500'
});
bar[1].$element.css({
'border-left': 'none',
'border-top-left-radius': 0,
'border-bottom-left-radius': 0
});
input.start.setLabel('재시작');
input.reset.setLabel('초기화');
$('#stat-turn').text(0);
$('.stat-0.stat-currentHP').data('value', stat[0].HP).text(stat[0].HP.toFixed(2)).css('color', '#3366CC');
$('.stat-1.stat-currentHP').data('value', stat[1].HP).text(stat[1].HP.toFixed(2)).css('color', '#FF5500');
$('.stat-0.stat-HPbar').html(bar[0].$element);
$('.stat-1.stat-HPbar').html(bar[1].$element);
if(btn) $('#log')[0].innerText += '\n다시 시작하려면 재시작 버튼을 눌러주세요.';
}
}
function stop() {
clearInterval(battle.work);
$('#input-stop').hide();
$('#input-start').show();
input.reset.setDisabled(false);
input[0].setDisabled(false);
input[1].setDisabled(false);
input.time.setDisabled(false);
input.swap.setDisabled(false);
}
var input = {};
input[0] = new OO.ui.TextInputWidget({
placeholder: '선',
title: '후',
value: new URLSearchParams(location.search).get('p0') || ''
});
input.start = new OO.ui.ButtonInputWidget({
type: 'submit',
flags: ['primary', 'progressive'],
label: '시작'
});
input.stop = new OO.ui.ButtonInputWidget({
flags: ['primary', 'destructive'],
label: '정지'
});
input[1] = new OO.ui.TextInputWidget({
placeholder: '후',
title: '후',
value: new URLSearchParams(location.search).get('p1') || ''
});
input.time = new OO.ui.NumberInputWidget({
value: 1,
min: 0,
label: '초 간격'
});
input.reset = new OO.ui.ButtonInputWidget({
type: 'reset',
flags: ['destructive'],
label: '초기화'
});
input.swap = new OO.ui.ButtonInputWidget({
label: $('<div />').css({
height: '20px',
width: '20px',
'background-image': 'url("/wiki/Special:Redirect/file/Ambox_move_black.svg")',
'background-size': 'cover'
}),
title: '교체',
framed: false
});
input.table = new OO.ui.ToggleSwitchWidget({
value: true
});
input.icon = new OO.ui.ButtonWidget({
framed: false,
icon: $('#mw-customcollapsible-input-option').hasClass('mw-collapsed')? 'expand' : 'collapse'
});
input.log = new OO.ui.ButtonWidget({
label: '기록 복사'
});
input.url = new OO.ui.ButtonWidget({
label: 'URL 복사'
});
input.box = new OO.ui.MultilineTextInputWidget();
var media = matchMedia('(max-width: 800px)');
var stat = [];
var bar = [];
var battle = {
turn: 0,
attack: null,
done: null,
work: null,
sequence: null,
combo: null,
temp: null
};
$('#input').wrap('<form />');
$('#input-0').html(input[0].$element);
$('#input-start').html(input.start.$element);
$('#input-stop').html(input.stop.$element);
$('#input-1').html(input[1].$element);
$('#input-time').html(input.time.$element);
$('#input-reset').html(input.reset.$element);
$('#input-swap').html(input.swap.$element);
$('#input-table').html(input.table.$element).append(' 스탯');
$('#input-icon').html(input.icon.$element);
$('#stat-load').html(new OO.ui.ProgressBarWidget().$element);
$('#log').text('시작하시려면 상단에 대결할 상대의 이름을 입력해 주세요. (1.3)');
$('#share-log').html(input.log.$element);
$('#share-url').html(input.url.$element);
$('#share-cvbox').html(input.box.$element);
input.box.$input.attr('readonly', '').css('height', '2.5em');
$('#stat-bar').hide();
$('#share').hide();
responsible(media);
media.addListener(responsible);
new MutationObserver(function(mutation) {
input.icon.setIcon($(mutation[0].target).hasClass('mw-collapsed')? 'expand' : 'collapse');
}).observe($('#mw-customcollapsible-input-option')[0], {
attributes: true,
attributeFilter: ['class']
});
input.swap.$element.click(function() {
if(!input.swap.disabled) {
var val = [input[1].value, input[0].value];
input[0].setValue(val[0]);
input[1].setValue(val[1]);
if(stat.length) {
stat = [stat[1], stat[0]];
$('#stat-turn').text(0);
$('.stat-0').each(function() {
if($(this).hasClass('stat-name')) $(this).text(stat[0].name);
else if($(this).hasClass('stat-attack')) $(this).text(stat[0].attack);
else if($(this).hasClass('stat-quick')) $(this).text(stat[0].quick);
else if($(this).hasClass('stat-defense')) $(this).text(stat[0].defense);
else if($(this).hasClass('stat-hit')) $(this).text(stat[0].hit);
else if($(this).hasClass('stat-luck')) $(this).text(stat[0].luck);
else if($(this).hasClass('stat-fullHP')) $(this).text(stat[0].HP);
else if($(this).hasClass('stat-currentHP')) $(this).data('value', stat[0].HP).text(stat[0].HP.toFixed(2));
else if($(this).hasClass('stat-HPbar')) $(this).html(bar[0].$element);
});
$('.stat-1').each(function() {
if($(this).hasClass('stat-name')) $(this).text(stat[1].name);
else if($(this).hasClass('stat-attack')) $(this).text(stat[1].attack);
else if($(this).hasClass('stat-quick')) $(this).text(stat[1].quick);
else if($(this).hasClass('stat-defense')) $(this).text(stat[1].defense);
else if($(this).hasClass('stat-hit')) $(this).text(stat[1].hit);
else if($(this).hasClass('stat-luck')) $(this).text(stat[1].luck);
else if($(this).hasClass('stat-fullHP')) $(this).text(stat[1].HP);
else if($(this).hasClass('stat-currentHP')) $(this).data('value', stat[1].HP).text(stat[1].HP.toFixed(2));
else if($(this).hasClass('stat-HPbar')) $(this).html(bar[1].$element);
});
var url = new URL(location);
url.searchParams.set('p0', input[0].value);
url.searchParams.set('p1', input[1].value);
history.replaceState(null, '', url);
cancel();
input.start.setLabel('시작');
}
}
});
input.table.$element.click(function() {
if(input.table.value) {
if($('#stat-turn').text()) $('#stat-table').show(500);
} else {
$('#stat-table').hide(500);
}
});
input.reset.$button[0].form.addEventListener('reset', function(event) {
event.preventDefault();
if(!input.reset.disabled) {
if(battle.done || battle.done === null) {
var url = new URL(location);
url.searchParams['delete']('p0');
url.searchParams['delete']('p1');
history.replaceState(null, '', url);
stat = [];
input[0].setValue();
input[1].setValue();
input.time.setValue(1);
input.table.setValue(true);
input.start.setLabel('시작');
$('#share').hide();
$('#share-cvbox').hide();
$('#stat-table').hide(500);
$('#stat-bar').hide(500);
$('#stat-turn, .stat-0, .stat-1').text('');
$('#log-time').hide();
$('#log').show();
$('#log').text('시작하시려면 상단에 대결할 상대의 이름을 입력해 주세요.');
$('.stat-HPbar').html('');
} else cancel(true);
}
});
input.start.$button[0].form.addEventListener('submit', function(event) {
function last() {
$('#input-stop').show();
$('#input-start').hide();
input.reset.setLabel('취소');
input[0].setDisabled(true);
input[1].setDisabled(true);
input.time.setDisabled(true);
input.reset.setDisabled(true);
input.swap.setDisabled(true);
input.start.setLabel('재개');
battle.work = start(battle, stat.map(function(obj, index) {
return new Proxy(obj, {
get: function(target, key, receiver) {
if(key === 'HP') return +$('.stat-' + index + '.stat-currentHP').data('value');
else return Reflect.get(target, key, receiver);
},
set: function(target, key, value) {
if(key === 'HP') {
if(value < 0) {
value = 0;
$('.stat-' + index + '.stat-currentHP').css('color', '#000000');
}
$('.stat-' + index + '.stat-currentHP').data('value', value).text(value.toFixed(2));
bar[index].setProgress(value / target.HP * 100);
}
}
});
}), input.time.value * 1000, function(msg) {
$('#log')[0].innerText += msg;
$('#log').scrollTop($('#log')[0].scrollHeight);
if(battle.sequence === 0) {
$('#stat-turn').text(battle.turn);
$('.stat-' + battle.attack + '.stat-name').css({
background: battle.attack? '#FF5500' : '#3366CC',
color: '#FFFFFF'
});
$('.stat-' + (battle.attack ^ 1) + '.stat-name').css({
background: '#EAECF0',
color: battle.attack? '#3366CC' : '#FF5500'
});
}
}, function(msg) {
$('#log')[0].innerText += msg;
$('#log')[0].innerText += '\n\n백괴스러운 MD-5 시뮬레이터 [https://game.uncyclopedia.kr/wiki/마법의_MD-5_시뮬레이터]';
$('#log').scrollTop($('#log')[0].scrollHeight);
$('#share').show();
stop();
battle.done = true;
battle.turn = 0;
battle.attack = null;
battle.sequence = null;
battle.combo = null;
battle.temp = null;
input.start.setLabel('재시작');
input.reset.setLabel('초기화');
});
}
event.preventDefault();
if(!input.start.disabled) {
$('#share').hide();
$('#share-cvbox').hide();
if(input.time.value >= 0) {
$('#log-time').hide();
$('#log').show();
if(!stat.length) $.get({
url: '/w/api.php',
data: {
action: 'parse',
format: 'json',
title: '마법의 MD-5 시뮬레이터',
text: '[{{#invoke:SimMD5|stat|' + encode(input[0].value) + '|AJAX}},{{#invoke:SimMD5|stat|' + encode(input[1].value) + '|AJAX}}]',
prop: 'text',
disablelimitreport: true,
formatversion: 2
},
beforeSend: function() {
if($('#stat-bar').html()) {
$('#stat-bar').hide();
$('#stat-load').show();
} else $('#stat-load').show(500);
$('#log').text('스탯 계산중입니다. 잠시만 기다려 주세요.');
var url = new URL(location);
url.searchParams.set('p0', input[0].value);
url.searchParams.set('p1', input[1].value);
history.replaceState(null, '', url);
},
success: function(callback) {
stat = JSON.parse($(callback.parse.text).text());
bar = [];
bar[0] = new OO.ui.ProgressBarWidget({
progress: 100
});
bar[1] = new OO.ui.ProgressBarWidget({
progress: 100
});
bar[0].$bar.css({
background: '#3366CC'
});
bar[0].$element.css({
'border-right': 'none',
'border-top-right-radius': 0,
'border-bottom-right-radius': 0
});
bar[1].$bar.css({
background: '#FF5500'
});
bar[1].$element.css({
'border-left': 'none',
'border-top-left-radius': 0,
'border-bottom-left-radius': 0
});
$('#stat-turn').text(0);
$('.stat-0').each(function() {
if($(this).hasClass('stat-name')) $(this).text(stat[0].name);
else if($(this).hasClass('stat-attack')) $(this).text(stat[0].attack);
else if($(this).hasClass('stat-quick')) $(this).text(stat[0].quick);
else if($(this).hasClass('stat-defense')) $(this).text(stat[0].defense);
else if($(this).hasClass('stat-hit')) $(this).text(stat[0].hit);
else if($(this).hasClass('stat-luck')) $(this).text(stat[0].luck);
else if($(this).hasClass('stat-fullHP')) $(this).text(stat[0].HP);
else if($(this).hasClass('stat-currentHP')) $(this).data('value', stat[0].HP).text(stat[0].HP.toFixed(2));
else if($(this).hasClass('stat-HPbar')) $(this).html(bar[0].$element);
});
$('.stat-1').each(function() {
if($(this).hasClass('stat-name')) $(this).text(stat[1].name);
else if($(this).hasClass('stat-attack')) $(this).text(stat[1].attack);
else if($(this).hasClass('stat-quick')) $(this).text(stat[1].quick);
else if($(this).hasClass('stat-defense')) $(this).text(stat[1].defense);
else if($(this).hasClass('stat-hit')) $(this).text(stat[1].hit);
else if($(this).hasClass('stat-luck')) $(this).text(stat[1].luck);
else if($(this).hasClass('stat-fullHP')) $(this).text(stat[1].HP);
else if($(this).hasClass('stat-currentHP')) $(this).data('value', stat[1].HP).text(stat[1].HP.toFixed(2));
else if($(this).hasClass('stat-HPbar')) $(this).html(bar[1].$element);
});
$('.stat-0.stat-currentHP').css('color', '#3366CC');
$('.stat-1.stat-currentHP').css('color', '#FF5500');
$('#stat-load').hide();
if(input.table.value) $('#stat-table').show(500);
$('#stat-bar').show();
$('#log').text('');
$('#log')[0].innerText += '[' + stat[0].name + '] 공격력: ' + stat[0].attack + ' / 방어력: ' + stat[0].defense + ' / 민첩: ' + stat[0].quick + ' / 명중: ' + stat[0].quick + ' / 운: ' + stat[0].luck + ' / HP: ' + stat[0].HP + '\n';
$('#log')[0].innerText += '[' + stat[1].name + '] 공격력: ' + stat[1].attack + ' / 방어력: ' + stat[1].defense + ' / 민첩: ' + stat[1].quick + ' / 명중: ' + stat[1].quick + ' / 운: ' + stat[1].luck + ' / HP: ' + stat[1].HP + '\n';
$('#log')[0].innerText += '\n';
battle.turn = 1;
battle.done = false;
battle.attack = 0;
battle.sequence = 0;
battle.combo = [0, 0];
battle.temp = {};
last();
},
error: function(error) {
$('#stat-load').hide(500);
$('#log').text('스탯 계산에 오류가 발생하였습니다. 다시 시도해 주십시오. (' + error.status + ')');
}
});
else if(battle.done || battle.done === null) {
if(battle.done) cancel();
$('#log').text('');
$('#log')[0].innerText += '[' + stat[0].name + '] 공격력: ' + stat[0].attack + ' / 방어력: ' + stat[0].defense + ' / 민첩: ' + stat[0].quick + ' / 명중: ' + stat[0].quick + ' / 운: ' + stat[0].luck + ' / HP: ' + stat[0].HP + '\n';
$('#log')[0].innerText += '[' + stat[1].name + '] 공격력: ' + stat[1].attack + ' / 방어력: ' + stat[1].defense + ' / 민첩: ' + stat[1].quick + ' / 명중: ' + stat[1].quick + ' / 운: ' + stat[1].luck + ' / HP: ' + stat[1].HP + '\n';
$('#log')[0].innerText += '\n';
battle.turn = 1;
battle.done = false;
battle.attack = 0;
battle.sequence = 0;
battle.combo = [0, 0];
battle.temp = {};
last();
} else last();
} else {
$('#log-time').show();
$('#log').hide();
}
}
});
input.stop.$element.click(function() {
if(!input.stop.disabled) stop();
});
input[0].$input.focus(function() {
cancel();
stat = [];
input.start.setLabel('시작');
$(this).select();
});
input[1].$input.focus(function() {
cancel();
stat = [];
input.start.setLabel('시작');
$(this).select();
});
input.log.$button.click(function() {
input.box.setValue($('#log').text());
$('#share-cvbox').show();
input.box.$input.select();
document.execCommand('copy');
});
input.url.$button.click(function() {
var url = new URL('/wiki/마법의_MD-5_시뮬레이터', location);
var search = new URLSearchParams(location.search);
url.searchParams.set('p0', search.get('p0'));
url.searchParams.set('p1', search.get('p1'));
input.box.setValue(url);
$('#share-cvbox').show();
input.box.$input.select();
document.execCommand('copy');
});
input.box.$input.click(function() {
$(this).select();
});
}
function start(battle, stat, time, each, last) {
function rand(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function range(weight) {
var range = [-0.5, -0.25, 0, 0.25, 0.5].map(function(ratio, index) {
return 20 + (weight - 50) * ratio;
});
range.reduce(function(acc, current, index, prob) {
return prob[index] += acc;
});
return range;
}
function rank(range, val) {
return range.findIndex(function(current, index) {
return (index === 0 || range[index - 1] < val) && val <= current;
});
}
function power(stat, rank) {
return stat * (((rank === 0)? 0 : rand(1 + 25 * (rank - 1), 25 * rank)) / 100);
}
function bonus(plus, minus, rank) {
rank -= 2;
if(rank === 0) return 0;
return ((rank > 0)? plus : minus) * (rand(1 + 50 * (rank - 1), 50 * rank) / 100);
}
function josa(text, exist, not, only) {
text = text.normalize('NFD');
var code = text.charCodeAt(text.length - 1);
if(0x1161 <= code && code <= 0x11A7) return ((only)? '' : text) + not;
else if(0x11A8 <= code && code <= 0x11FF) return ((only)? '' : text) + exist;
else return ((only)? '' : text) + exist + '(' + not + ')';
}
return setInterval(function() {
var attacker = battle.attack;
var defender = attacker ^ 1;
if(stat[0].HP > 0 && stat[1].HP > 0) {
switch(battle.sequence) {
case 0:
var scale = range(stat[attacker].luck);
var adv = bonus(stat[attacker].hit, stat[defender].quick, rank(range(50), 50 + ((battle.combo[defender])? 0 : battle.combo[defender]) - ((battle.combo[attacker])? 0: battle.combo[attacker])));
var grade = {
attack: rank(scale, rand(1, 100)),
defense: rank(range(stat[defender].luck), rand(1, 100)),
};
var damage = power(stat[attacker].attack, grade.attack) - power(stat[defender].defense, grade.defense) + adv;
battle.temp = {
rank: rank(scale, damage),
damage: (damage > 0)? damage : 0
};
if(battle.temp.damage > stat[attacker].attack) battle.temp.rank = 5;
if(battle.temp.damage) {
if(!battle.temp.rank) battle.temp.rank = 1;
if(battle.combo[attacker] < 0) battle.combo[attacker] = 0;
battle.combo[attacker]++;
} else {
battle.temp.rank = 0;
if(battle.combo[attacker] > 0) battle.combo[attacker] = 0;
battle.combo[attacker]--;
}
each('[' + stat[attacker].name + ']의 공격 ');
battle.sequence++;
break;
case 1:
var rankText = ['MISS', 'HIT', 'GOOD', 'NICE', 'PERFECT', 'CRITICAL'][battle.temp.rank];
each(rankText + '! ');
battle.sequence++;
break;
case 2:
stat[defender].HP -= battle.temp.damage;
var msg = (battle.temp.rank === 0)? '공격을 피했다. (' : (+battle.temp.damage.toFixed(2)) + '의 대미지를 받았다. (' + ((battle.combo[attacker] > 0)? battle.combo[attacker] : 0) + ' COMBO, ';
each('[' + stat[defender].name + ']' + josa(stat[defender].name, '은', '는', true) + ' ' + msg + '남은 HP: ' + (+stat[defender].HP.toFixed(2)) + ')\n');
if(attacker === 1) battle.turn++;
battle.sequence = 0;
battle.attack = defender;
break;
}
} else last('\n[' + stat[defender].name + '] 승! (' + battle.turn + '턴)');
}, time);
}
$(prepare);
});
// 여기까지 코드 입력 //
}
}
$( plugin_SimMD5 );
/* SimMD5 끝 */
/** 플러그인 UncyBeat***************************
* 버그 수정
* 버전 => 1.03
* 작성자 : [[사용자:Bd3076|Bd3076]]
* JSON => UncyBeat = {"name":"UncyBeat","descript":"버그 수정","version":"1.03","local":true,"creat":"Bd3076","state":"UncyBeat/plugin","executable":true};
*/
function plugin_UncyBeat(){
if($("[data-name='UncyBeat']").length >= 1){
// 이부분에 코드 입력 //
var getParameters = function (paramName) {
var returnValue;
var url = location.href;
console.log(url);
if(url[8] == 'f'){
return 0;
}
var parameters = (url.slice(url.indexOf('?') + 1, url.length)).split('&');
for (var i = 0; i < parameters.length; i++) {
var varName = parameters[i].split('=')[0];
if (varName.toUpperCase() == paramName.toUpperCase()) {
returnValue = parameters[i].split('=')[1];
return decodeURIComponent(returnValue);
}
}
};
function updateURLParameter(url, param, paramVal){
var newAdditionalURL = "";
var tempArray = url.split("?");
var baseURL = tempArray[0];
var additionalURL = tempArray[1];
var temp = "";
if (additionalURL) {
tempArray = additionalURL.split("&");
for (var i=0; i<tempArray.length; i++){
if(tempArray[i].split('=')[0] != param){
newAdditionalURL += temp + tempArray[i];
temp = "&";
}
}
}
var rows_txt = temp + "" + param + "=" + paramVal;
return baseURL + "?" + newAdditionalURL + rows_txt;
}
function Queue(){
this.arr = [];
this.s = 0;
this.e = 0;
this.size = 0;
this.front = function(){
return arr[s];
}
this.pop = function(){
s++;
size--;
return;
}
this.push = function(k){
arr[e++] = k;
size--;
return;
}
this.empty = function(){
return size==0;
}
}
var timer = 0;
function calculateTimer(){
timer += 1;
}
var cvs = document.getElementById('spanArea');
cvs.innerHTML = "<canvas width='720' height='720' id='spanCanvas'></canvas>"
var canvas = document.getElementById('spanCanvas');
var ctx = canvas.getContext('2d');
var level = getParameters('level');
const levelCount = 1;
const levelNames = [
'Dreams'
];
const levelMusicLink = [
'https://k003.kiwi6.com/hotlink/9f13ktbumx/bensound-dreams.mp3'
];
function clearCanvas(){
ctx.clearRect(0, 0, 720, 720);
}
function makeGameArea(){
clearCanvas();
ctx.strokeStyle = "black";
ctx.strokeRect(20, 20, 680, 680);
for(var i=0; i<5; i++){
for(var j=0; j<5; j++){
ctx.strokeRect(40+i*132, 40+j*132, 112, 112);
}
}
}
function playGameMusic(){
console.log(level);
var audioElement = new Audio(levelMusicLink[level]);
var audio = audioElement.play();
audioElement.onended = function(){
setTimeout(levelEnd, 3000);
};
setInterval(calculateTimer, 50);
}
var x = 2;
var y = 2;
var color = 0;
var perfect = 0;
var good = 0;
var miss = 0;
var score = 0;
function levelEnd(){
var totalNotes = perfect+good+miss;
score = (perfect / totalNotes) * 1000000 + (good / totalNotes) * 500000;
clearInterval(calculateTimer);
clearInterval(showCursor);
clearInterval(displayNotes);
console.log(score);
var nowScore = getParameters('progress'+level);
var maxScore = nowScore < score ? score : nowScore;
location.href = updateURLParameter(location.href, 'progress'+level, maxScore);
}
var noteTimer = new Array(5);
for(var i=0; i<5; i++){
noteTimer[i] = new Array(5);
for(var j=0; j<5; j++){
noteTimer[i][j] = -400;
}
}
var noteColor = new Array(5);
for(var i=0; i<5; i++){
noteColor[i] = new Array(5);
}
function showCursor(){
for(var i=0; i<5; i++){
for(var j=0; j<5; j++){
ctx.fillStyle = noteColor[i][j]==0?"red":"blue";
if(noteTimer[i][j] > 0){
ctx.fillRect(40+i*132, 40+j*132, (400-noteTimer[i][j]) * 112 / 400, 112);
}
else{
ctx.clearRect(40+i*132, 40+j*132, 112, 112);
}
if(i==x && j==y){
ctx.strokeStyle = color==0?"red":"blue";
}
else{
ctx.strokeStyle = "black";
}
ctx.strokeRect(40+i*132, 40+j*132, 112, 112);
}
}
}
function perfect_(x, y){
perfect++;
noteTimer[x][y] = -400;
}
function good_(x, y){
good++;
noteTimer[x][y] = -400;
}
function miss_(x, y){
miss++;
}
function onKeyDown(e){
var ek = e.keyCode;
console.log(ek);
if(37 <= ek && ek <= 40){
if(ek == 37){
if(x!=0) x--;
}
else if(ek==38){
if(y!=0) y--;
}
else if(ek==39){
if(x!=4) x++;
}
else if(ek==40){
if(y!=4) y++;
}
console.log(x + "and" + y);
var point = Math.abs(noteTimer[x][y]);
if(point <= 20 && color == noteColor[x][y]){
perfect_(x, y);
}
else if((point <= 40 || noteTimer[x][y] > 20) && color == noteColor[x][y]){
good_(x, y);
}
}
else if(ek==32){
color = !color;
}
}
window.addEventListener("keydown", onKeyDown, false);
var levelData = [
"0|2|1|0/21|2|2|0/52|2|3|0/72|2|2|0/101|1|2|0/121|2|2|0/153|3|2|0/172|2|2|0/203|2|1|0/223|2|0|0/256|2|1|0/274|2|2|0/305|2|3|0/323|2|4|0/355|2|3|0/375|2|2|0/406|2|1|0/419|3|1|0/431|3|2|0/443|2|2|0/456|1|2|0/469|1|3|0/481|2|3|0/493|2|2|0/506|2|1|0/519|1|1|0/528|1|2|0/544|2|2|0/558|3|2|0/571|3|3|0/583|2|3|0/595|2|2|0/608|2|1|0/621|1|1|0/633|1|2|0/646|2|2|0/659|3|2|0/672|3|1|0/683|2|1|0/697|2|2|0/709|2|3|0/723|3|3|0/735|3|2|0/749|2|2|0/760|1|2|0/772|1|3|0/784|2|3|0/798|2|2|0/811|2|1|0/823|2|0|0/836|2|1|0/850|2|2|0/862|3|2|0/874|4|2|0/888|3|2|0/900|2|2|0/912|1|2|0/924|0|2|0/936|1|2|0/950|2|2|0/964|2|3|0/976|2|4|0/988|2|3|0/1001|2|2|0/1015|2|1|0/1033|2|2|0/1063|2|3|0/1082|2|2|0/1113|1|2|0/1133|2|2|0/1166|3|2|0/1184|2|2|0/1216|2|1|0/1227|2|0|0/1239|1|0|0/1252|0|0|0/1265|0|1|0/1277|0|2|0/1290|1|2|0/1302|2|2|0/1315|3|2|0/1328|4|2|0/1341|4|3|0/1353|4|4|0/1366|3|4|0/1379|2|4|0/1392|2|3|0/1404|2|2|0/1417|3|2|0/1431|4|2|0/1442|3|2|0/1454|2|2|0/1468|1|2|0/1480|0|2|0/1494|1|2|0/1506|2|2|0/1519|3|2|0/1533|4|2|0/1544|4|1|0/1557|4|0|0/1568|3|0|0/1581|2|0|0/1594|2|1|0/1607|2|2|0/1620|2|3|0/1633|2|4|0/1645|2|3|0/1658|2|2|0/1670|2|1|0/1683|2|0|0/1695|2|1|0/1708|2|2|0/1721|2|3|0/1733|2|4|0/1746|1|4|0/1759|0|4|0/1771|0|3|0/1783|0|2|0/1796|1|2|0/1809|2|2|0/1822|2|1|0/1837|2|0|0/1847|2|1|0/1859|2|2|0/1871|1|2|0/1885|0|2|0/1898|1|2|0/1910|2|2|0/1922|2|3|0/1935|2|4|0/1948|2|3|0/1959|2|2|0/1972|3|2|0/1984|4|2|0/1998|3|2|0/2010|2|2|0/2024|2|1|0/2042|2|0|0/2073|1|0|0/2091|0|0|0/2121|0|1|0/2142|0|2|0/2173|1|2|0/2193|2|2|0/2225|3|2|0/2244|4|2|0/2277|4|3|0/2295|4|4|0/2326|3|4|0/2345|2|4|0/2380|2|3|0/2396|2|2|0/2427|1|2|0/2445|0|2|0/2477|1|2|0/2496|2|2|0/2528|3|2|0/2547|4|2|0/2578|3|2|0/2597|2|2|0/2629|2|3|0/2655|2|2|0/2680|2|1|0/2705|2|2|0/2730|1|2|0/2754|2|2|0/2781|3|2|0/2804|2|2|0/2832|2|3|0/2841|3|3|0/2850|3|2|0/2856|3|1|0/2863|2|1|0/2866|1|1|0/2880|1|2|0/2891|1|3|0/2900|2|3|0/2907|3|3|0/2912|4|3|0/2932|3|3|0/2941|2|3|0/2951|1|3|0/2957|1|2|0/2961|1|1|0/2963|1|0|0/2982|2|0|0/2991|2|1|0/3001|2|2|0/3034|1|2|0/3044|0|2|0/3052|1|2|0/3059|2|2|0/3063|3|2|0/3069|3|3|0/3084|2|3|0/3095|2|2|0/3104|2|1|0/3109|1|1|0/3112|0|1|0/3115|0|2|0/3118|0|3|0/3134|1|3|0/3144|2|3|0/3152|2|2|0/3155|2|1|0/3158|2|0|0/3160|3|0|0/3185|3|1|0/3195|3|2|0/3202|2|2|0/3205|1|2|0/3208|1|3|0/3211|2|3|0/3236|2|2|0/3254|2|1|0/3285|2|2|0/3304|2|3|0/3330|2|2|0/3336|1|2|0/3356|2|2|0/3387|2|1|0/3406|2|2|0/3436|3|2|0/3457|2|2|0/3487|1|2|0/3507|2|2|0/3538|2|1|0/3557|2|2|0/3589|2|3|0/3608|2|2|0/3639|1|2|0/3660|2|2|0/3691|3|2|0/3712|2|2|0/3741|2|1|0/3759|2|2|0/3791|2|3|0/3810|2|2|0/3842|1|2|0/3860|2|2|0/3892|3|2|0/3912|2|2|0/3943|2|1|0/3960|2|2|0/3991|2|3|0/4011|2|2|0/4045|1|2|0/4063|2|2|0/4093|3|2|0/4113|2|2|0/"
];
var startIndex = 0;
var endIndex = 0;
var data;
var dataLength;
function calculateNotes(t, x, y, c){
noteTimer[x][y] = 400;
noteColor[x][y] = c;
}
function displayNotes(){
for(var i=0; i<5; i++){
for(var j=0; j<5; j++){
if(noteTimer[i][j] != -400) noteTimer[i][j] -= 20;
if(noteTimer[i][j] < -40 && noteTimer[i][j] != -400){
noteTimer[i][j] = -400;
miss_(i, j);
}
}
}
}
function setInit(){
data = levelData[level];
dataLength = String(data).length;
}
function playNotes(){
setInterval(displayNotes, 20);
console.log(dataLength + ', ' + data);
for(; endIndex < dataLength;){
var tt, tx, ty, tc;
while(data[endIndex] != '|') endIndex++;
tt = data.substring(startIndex, endIndex);
startIndex = ++endIndex;
while(data[endIndex] != '|') endIndex++;
tx = data.substring(startIndex, endIndex);
startIndex = ++endIndex;
while(data[endIndex] != '|') endIndex++;
ty = data.substring(startIndex, endIndex);
startIndex = ++endIndex;
while(data[endIndex] != '/') endIndex++;
tc = data.substring(startIndex, endIndex);
startIndex = ++endIndex;
console.log(tt + ', ' + tx + ', ' + ty + ', ' + tc);
setTimeout(calculateNotes, tt*50-400+3100, tt, tx, ty, tc);
}
}
function playGame(){
makeGameArea();
setInterval(showCursor, 30);
setTimeout(playGameMusic, 3000);
setInit();
playNotes();
}
playGame();
// 여기까지 코드 입력 //
}
}
$( plugin_UncyBeat );
/* UncyBeat 끝 */