사용자:으시안오옹/common.js: 두 판 사이의 차이
(플러그인 haircut설치) |
(플러그인 real369설치) |
||
75번째 줄: | 75번째 줄: | ||
$( plugin_haircut ); | $( plugin_haircut ); | ||
/* haircut 끝 */ | /* haircut 끝 */ | ||
/** 플러그인 real369*************************** | |||
* real369 플레이 | |||
* 버전 => 1.1.7 | |||
* 작성자 : [[사용자:BANIP|BANIP]] | |||
* JSON => real369 = {"name":"real369","descript":"real369 플레이","version":"1.1.7","local":true,"creat":"BANIP","state":"Real 369/플러그인","executable":true}; | |||
*/ | |||
function plugin_real369(){ | |||
if($("[data-name='real369']").length >= 1){ | |||
/** | |||
* 지금 박수를 쳐야되는지 숫자를 외쳐야 하는지 알아 냅니다 | |||
* @param {number} number 지금 순서가 몇번째인지 넣는 칸. | |||
* @return {number|Array[number]} 박수를 쳐야되는 상황이면 배열 안에 숫자를 담아 반환하고 아니면 파라미터를 반환. | |||
*/ | |||
function getAnswer(number) { | |||
var rawNumber = number + ""; | |||
var targetNumber = rawNumber.replace(/3|6|9/g, ""); | |||
var diff = rawNumber.length - targetNumber.length; | |||
if (diff === 0) | |||
return number + ""; | |||
else | |||
return "짝!".repeat(diff); | |||
} | |||
function isMobile() { | |||
return !(navigator.userAgent.match(/Android|iPhone|iPad|iPod/i) === null); | |||
} | |||
var GUI = /** @class */ (function () { | |||
function GUI() { | |||
this.domList = { | |||
retry: document.querySelector("#gamewrap .gamelink .retry"), | |||
answer: document.querySelector("#gamewrap .answer"), | |||
dialog: document.querySelector("#gamewrap .dialog"), | |||
progress: document.querySelector("#gamewrap .progress"), | |||
gamelink: document.querySelector("#gamewrap .gamelink") | |||
}; | |||
this.bindOtherEvent(); | |||
//this.start(); | |||
} | |||
GUI.prototype.start = function () { | |||
this.domList.answer.innerHTML = "시작!"; | |||
this.domList.dialog.innerHTML = ""; | |||
this.domList.gamelink.style.display = "none"; | |||
createGame(gui); | |||
input.setGame(game); | |||
}; | |||
GUI.prototype.bindOtherEvent = function () { | |||
var _this = this; | |||
this.domList.retry.addEventListener("click", function () { | |||
if (game !== null) | |||
game.gameOver(); | |||
_this.start(); | |||
}); | |||
}; | |||
GUI.prototype.message = function (message) { | |||
var dialogNode = this.domList.dialog; | |||
var messageNode = document.createElement("li"); | |||
messageNode.innerHTML = message; | |||
dialogNode.appendChild(messageNode); | |||
dialogNode.scrollTop = dialogNode.scrollHeight; | |||
}; | |||
GUI.prototype.initOrder = function (userCount, startUser) { | |||
var orderStringCount = 8; | |||
var orderString = new Array(orderStringCount).fill("1") | |||
.map(function (v, i) { return (startUser + i) % userCount === 0 ? username : "COM" + (startUser + i) % userCount; }) | |||
.join(" => "); | |||
this.message("게임이 시작되었습니다!!!"); | |||
this.message("게임순서 : " + orderString + "..."); | |||
}; | |||
GUI.prototype.getProgressColor = function (progress) { | |||
var interval = [30, 60, 100]; | |||
var color = ["green", "yellow", "red"]; | |||
var index = interval.indexOf(interval.filter(function (v) { return v > progress; })[0]); | |||
return color[index]; | |||
}; | |||
GUI.prototype.resetTime = function (duration) { | |||
var _this = this; | |||
clearInterval(this.timerInterval); | |||
var startTime = Date.now(); | |||
this.timerInterval = setInterval(function () { | |||
var now = Date.now(); | |||
var progress = (now - startTime) / duration * 100 - 1; | |||
var progressColor = _this.getProgressColor(progress); | |||
_this.domList.progress.style.background = "linear-gradient(to right," + progressColor + " " + (100 - progress) + "%,white " + (100 - progress + 0.1) + "%)"; | |||
}, 10); | |||
}; | |||
GUI.prototype.setEnemyTurn = function (order) { | |||
this.nextUser = "COM" + order; | |||
}; | |||
GUI.prototype.setMyTurn = function () { | |||
this.nextUser = username; | |||
}; | |||
GUI.prototype.gameOver = function (reason, lastCount) { | |||
this.domList.answer.innerHTML = reason; | |||
this.message("게임이 끝났습니다!!"); | |||
this.message("최종 카운트: " + lastCount); | |||
input.setGame(null); | |||
this.domList.gamelink.style.display = "block"; | |||
clearInterval(this.timerInterval); | |||
}; | |||
GUI.prototype.setNumber = function (number) { | |||
this.domList.answer.innerHTML = number; | |||
}; | |||
GUI.prototype.sayNumber = function (number, name) { | |||
if (name === void 0) { name = this.nextUser; } | |||
this.message(name + " : " + number); | |||
}; | |||
GUI.prototype.setHandClab = function (clab) { | |||
this.domList.answer.innerHTML = clab; | |||
}; | |||
return GUI; | |||
}()); | |||
var Game = /** @class */ (function () { | |||
function Game(gui, playerCount, time) { | |||
if (playerCount === void 0) { playerCount = 3; } | |||
if (time === void 0) { time = 1000; } | |||
this.gui = gui; | |||
this.playerCount = playerCount; | |||
this.time = time; | |||
this.order = Math.floor(Math.random() * playerCount); | |||
this.number = 1; | |||
gui.initOrder(playerCount, this.order); | |||
this.turnStart(); | |||
} | |||
Game.prototype.next = function () { | |||
var prevNumber = getAnswer(Number(this.number)); | |||
this.gui.sayNumber(prevNumber); | |||
this.order = (this.order + 1) % this.playerCount; | |||
this.handClab = ""; | |||
this.number++; | |||
this.turnStart(); | |||
}; | |||
Game.prototype.turnStart = function () { | |||
this.gui.resetTime(this.time); | |||
if (this.order === 0) | |||
this.myTurn(); | |||
else | |||
this.enemyTurn(); | |||
}; | |||
Game.prototype.enemyTurn = function () { | |||
var _this = this; | |||
this.gui.setEnemyTurn(this.order); | |||
this.turnTimeout = setTimeout(function () { | |||
_this.shortenTime(); | |||
_this.next(); | |||
}, this.time * Math.random()); | |||
}; | |||
Game.prototype.myTurn = function () { | |||
var _this = this; | |||
this.gui.setMyTurn(); | |||
this.turnTimeout = setTimeout(function () { | |||
if (getAnswer(_this.number) === _this.handClab) | |||
_this.next(); | |||
else | |||
_this.gameOver("시간 초과!"); | |||
}, this.time); | |||
}; | |||
Game.prototype.sayNumber = function (answer) { | |||
clearTimeout(this.turnTimeout); | |||
var reasonGameOver = null; | |||
if (this.order > 0) | |||
reasonGameOver = "내 차례가 아닌데 말해버림!"; | |||
else if (getAnswer(this.number) === answer) | |||
null; | |||
else | |||
reasonGameOver = "오답!"; | |||
if (reasonGameOver === null) | |||
this.next(); | |||
else { | |||
gui.sayNumber(answer, username); | |||
this.gameOver(reasonGameOver); | |||
} | |||
}; | |||
Game.prototype.setHandClab = function (clab) { | |||
this.handClab = clab; | |||
}; | |||
Game.prototype.gameOver = function (reason) { | |||
clearTimeout(this.turnTimeout); | |||
this.gui.gameOver(reason, this.number); | |||
game = null; | |||
}; | |||
Game.prototype.shortenTime = function () { | |||
this.time *= 0.94; | |||
}; | |||
return Game; | |||
}()); | |||
var Input = /** @class */ (function () { | |||
function Input(game, gui) { | |||
this.game = game; | |||
this.gui = gui; | |||
this.clickEventType = isMobile() ? "touchstart" : "click"; | |||
this.resetNumber(); | |||
this.bindKeyBoardEvent(); | |||
this.bindKeyPadEvent(); | |||
} | |||
Input.prototype.setGame = function (game) { | |||
this.game = game; | |||
}; | |||
Input.prototype.bindKeyBoardEvent = function () { | |||
var _this = this; | |||
document.addEventListener("keydown", function (e) { | |||
var key = e.key; | |||
if (["Enter", "Space"].some(function (v) { return v === key; })) | |||
return _this.pressEnter(); | |||
else if (key === "BackSpace") | |||
_this.number = _this.number.slice(0, -1); | |||
else if (isNaN(parseInt(key))) | |||
return; | |||
else | |||
_this.number += key; | |||
_this.gui.setNumber(_this.number); | |||
}); | |||
}; | |||
Input.prototype.bindKeyPadEvent = function () { | |||
var _this = this; | |||
document.querySelectorAll(".keypad .key").forEach(function (node) { | |||
node.addEventListener(_this.clickEventType, function (e) { | |||
e.preventDefault(); | |||
_this.number += e.target.dataset.num; | |||
_this.gui.setNumber(_this.number); | |||
}); | |||
}); | |||
document.querySelector(".keypad .enter").addEventListener(this.clickEventType, function (e) { | |||
e.preventDefault(); | |||
_this.pressEnter(); | |||
}); | |||
document.querySelector(".keypad .reset").addEventListener(this.clickEventType, function (e) { | |||
e.preventDefault(); | |||
_this.resetNumber(); | |||
_this.gui.setNumber(_this.number); | |||
}); | |||
}; | |||
Input.prototype.pressEnter = function () { | |||
var _this = this; | |||
if (game == null || game == undefined) | |||
this.gui.message("아직 게임이 시작되지 않았어요."); | |||
clearTimeout(this.enterTimeout); | |||
if (this.number == "") { | |||
this.enterCount++; | |||
var answer_1 = "짝!".repeat(this.enterCount); | |||
this.gui.setHandClab(answer_1); | |||
this.game.setHandClab(answer_1); | |||
this.enterTimeout = setTimeout(function () { | |||
if (_this.game.order === 0) { | |||
_this.game.sayNumber(answer_1); | |||
} | |||
_this.resetNumber(); | |||
}, 800); | |||
} | |||
else { | |||
this.game.sayNumber(this.number); | |||
this.resetNumber(); | |||
} | |||
}; | |||
; | |||
Input.prototype.resetNumber = function () { | |||
this.number = ""; | |||
this.enterCount = 0; | |||
this.gui.setNumber(this.number); | |||
}; | |||
return Input; | |||
}()); | |||
var game = null; | |||
var createGame = function (gui) { return game = new Game(gui, 4, 5000); }; | |||
var username = mw.config.values.wgUserName; | |||
var gui = new GUI(); | |||
//createGame(gui); | |||
var input = new Input(game, gui); | |||
} | |||
} | |||
$( plugin_real369 ); | |||
/* real369 끝 */ |
2025년 1월 4일 (토) 21:03 기준 최신판
/** 플러그인 haircut***************************
* 게임 진행에 필요합니다.
* 버전 => 2.0
* 작성자 : [[사용자:Lemminkäinen|Lemminkäinen]]
* JSON => haircut = {"name":"haircut","descript":"게임 진행에 필요합니다.","version":"2.0","local":true,"creat":"Lemminkäinen","state":"머리 자르기/js","executable":true};
*/
function plugin_haircut(){
if($("[data-name='haircut']").length >= 1){
// 이부분에 코드 입력 //
/*Elements Load 시작*/
var cut_res_container=document.getElementById("cut_res_container");
var cut_container=document.getElementById("cut_container");
var cut_linehair=document.getElementById("cut_line");
var cuthair=document.getElementById("cuthair");
/*Load 끝*/
var rand=function(r1,r2){
return Math.floor(Math.random()*r1)+r2;
}
var cut_now=rand(400,600);
var cut_line=rand(200,300);
var cut_initial=cut_now-cut_line;
var cdf=document.getElementById("cut_diff").innerHTML;
var cut_diff=(cdf<=0 || isNaN(cdf) || cdf>2)?(0.5):(Number(cdf));
var cut_speed=cut_now/cut_diff;
var cut_result1=0; var cut_result2=0;
cut_res_container.style.display="none";
cut_container.style.height=cut_now+"px";
cut_linehair.style.height=cut_line+"px";
if(cut_initial<=0) { alert('머리가 너무 짧아 자를 수 없습니다!'); throw("WTF your hair is already short"); }
function cut_again(){
$('#scissors').animate({ top:"100%" },cut_speed,'linear',function(){ $('#scissors').animate({ top:0 },cut_speed,'linear',function(){ cut_again() }); });
}//animate는 자스로 대체하려니 setInterval이나 setTimeout 등으로 해야 하는데 여어어엉 귀찮아서..
cut_again();
function cut_calc(pos){
if(pos<cut_line){
cut_rescalc(pos);
return;
}
cut_now=pos;
cut_speed=cut_now/cut_diff;
cut_container.style.height=cut_now+"px";
cuthair.innerHTML=cut_now;
}
function cut_rescalc(pos){
document.getElementById("cuthair_info").style.display="none";
cut_container.style.display="none";
document.getElementById("cut").style.display="none";
cut_res_container.style.display="block";
cut_result1=(100*(1-(cut_now-cut_line)/cut_initial));
cut_result2=(100*(pos/cut_line));
document.getElementById("cut_result1").innerHTML=cut_result1;
document.getElementById("cut_result2").innerHTML=cut_result2;
var cut_stories1=document.getElementsByClassName("cut_story");
var cut_stories2=document.getElementsByClassName("cuts_story");
if(cut_result1===0){ cut_stories1[0].style.display="block"; document.getElementById('cuts_story').style.display="none"; }
else if(cut_result1<90){ cut_stories1[1].style.display="block"; }
else if(cut_result1<95){ cut_stories1[2].style.display="block"; }
else if(cut_result1<98){ cut_stories1[3].style.display="block"; }
else if(cut_result1<=100){ cut_stories1[4].style.display="block"; }
/* story2 (cut_result2, cuts) */
if(cut_result2<90){ cut_stories2[0].style.display="block"; }
else if(cut_result2<95){ cut_stories2[1].style.display="block"; }
else if(cut_result2<98){ cut_stories2[2].style.display="block"; }
else if(cut_result2<=100){ cut_stories2[3].style.display="block"; }
}
$('#cut').click(function(){ cut_calc($('#scissors').position().top ); });//addEventListener...그냥 생각하길 관두고
// 여기까지 코드 입력 //
}
}
$( plugin_haircut );
/* haircut 끝 */
/** 플러그인 real369***************************
* real369 플레이
* 버전 => 1.1.7
* 작성자 : [[사용자:BANIP|BANIP]]
* JSON => real369 = {"name":"real369","descript":"real369 플레이","version":"1.1.7","local":true,"creat":"BANIP","state":"Real 369/플러그인","executable":true};
*/
function plugin_real369(){
if($("[data-name='real369']").length >= 1){
/**
* 지금 박수를 쳐야되는지 숫자를 외쳐야 하는지 알아 냅니다
* @param {number} number 지금 순서가 몇번째인지 넣는 칸.
* @return {number|Array[number]} 박수를 쳐야되는 상황이면 배열 안에 숫자를 담아 반환하고 아니면 파라미터를 반환.
*/
function getAnswer(number) {
var rawNumber = number + "";
var targetNumber = rawNumber.replace(/3|6|9/g, "");
var diff = rawNumber.length - targetNumber.length;
if (diff === 0)
return number + "";
else
return "짝!".repeat(diff);
}
function isMobile() {
return !(navigator.userAgent.match(/Android|iPhone|iPad|iPod/i) === null);
}
var GUI = /** @class */ (function () {
function GUI() {
this.domList = {
retry: document.querySelector("#gamewrap .gamelink .retry"),
answer: document.querySelector("#gamewrap .answer"),
dialog: document.querySelector("#gamewrap .dialog"),
progress: document.querySelector("#gamewrap .progress"),
gamelink: document.querySelector("#gamewrap .gamelink")
};
this.bindOtherEvent();
//this.start();
}
GUI.prototype.start = function () {
this.domList.answer.innerHTML = "시작!";
this.domList.dialog.innerHTML = "";
this.domList.gamelink.style.display = "none";
createGame(gui);
input.setGame(game);
};
GUI.prototype.bindOtherEvent = function () {
var _this = this;
this.domList.retry.addEventListener("click", function () {
if (game !== null)
game.gameOver();
_this.start();
});
};
GUI.prototype.message = function (message) {
var dialogNode = this.domList.dialog;
var messageNode = document.createElement("li");
messageNode.innerHTML = message;
dialogNode.appendChild(messageNode);
dialogNode.scrollTop = dialogNode.scrollHeight;
};
GUI.prototype.initOrder = function (userCount, startUser) {
var orderStringCount = 8;
var orderString = new Array(orderStringCount).fill("1")
.map(function (v, i) { return (startUser + i) % userCount === 0 ? username : "COM" + (startUser + i) % userCount; })
.join(" => ");
this.message("게임이 시작되었습니다!!!");
this.message("게임순서 : " + orderString + "...");
};
GUI.prototype.getProgressColor = function (progress) {
var interval = [30, 60, 100];
var color = ["green", "yellow", "red"];
var index = interval.indexOf(interval.filter(function (v) { return v > progress; })[0]);
return color[index];
};
GUI.prototype.resetTime = function (duration) {
var _this = this;
clearInterval(this.timerInterval);
var startTime = Date.now();
this.timerInterval = setInterval(function () {
var now = Date.now();
var progress = (now - startTime) / duration * 100 - 1;
var progressColor = _this.getProgressColor(progress);
_this.domList.progress.style.background = "linear-gradient(to right," + progressColor + " " + (100 - progress) + "%,white " + (100 - progress + 0.1) + "%)";
}, 10);
};
GUI.prototype.setEnemyTurn = function (order) {
this.nextUser = "COM" + order;
};
GUI.prototype.setMyTurn = function () {
this.nextUser = username;
};
GUI.prototype.gameOver = function (reason, lastCount) {
this.domList.answer.innerHTML = reason;
this.message("게임이 끝났습니다!!");
this.message("최종 카운트: " + lastCount);
input.setGame(null);
this.domList.gamelink.style.display = "block";
clearInterval(this.timerInterval);
};
GUI.prototype.setNumber = function (number) {
this.domList.answer.innerHTML = number;
};
GUI.prototype.sayNumber = function (number, name) {
if (name === void 0) { name = this.nextUser; }
this.message(name + " : " + number);
};
GUI.prototype.setHandClab = function (clab) {
this.domList.answer.innerHTML = clab;
};
return GUI;
}());
var Game = /** @class */ (function () {
function Game(gui, playerCount, time) {
if (playerCount === void 0) { playerCount = 3; }
if (time === void 0) { time = 1000; }
this.gui = gui;
this.playerCount = playerCount;
this.time = time;
this.order = Math.floor(Math.random() * playerCount);
this.number = 1;
gui.initOrder(playerCount, this.order);
this.turnStart();
}
Game.prototype.next = function () {
var prevNumber = getAnswer(Number(this.number));
this.gui.sayNumber(prevNumber);
this.order = (this.order + 1) % this.playerCount;
this.handClab = "";
this.number++;
this.turnStart();
};
Game.prototype.turnStart = function () {
this.gui.resetTime(this.time);
if (this.order === 0)
this.myTurn();
else
this.enemyTurn();
};
Game.prototype.enemyTurn = function () {
var _this = this;
this.gui.setEnemyTurn(this.order);
this.turnTimeout = setTimeout(function () {
_this.shortenTime();
_this.next();
}, this.time * Math.random());
};
Game.prototype.myTurn = function () {
var _this = this;
this.gui.setMyTurn();
this.turnTimeout = setTimeout(function () {
if (getAnswer(_this.number) === _this.handClab)
_this.next();
else
_this.gameOver("시간 초과!");
}, this.time);
};
Game.prototype.sayNumber = function (answer) {
clearTimeout(this.turnTimeout);
var reasonGameOver = null;
if (this.order > 0)
reasonGameOver = "내 차례가 아닌데 말해버림!";
else if (getAnswer(this.number) === answer)
null;
else
reasonGameOver = "오답!";
if (reasonGameOver === null)
this.next();
else {
gui.sayNumber(answer, username);
this.gameOver(reasonGameOver);
}
};
Game.prototype.setHandClab = function (clab) {
this.handClab = clab;
};
Game.prototype.gameOver = function (reason) {
clearTimeout(this.turnTimeout);
this.gui.gameOver(reason, this.number);
game = null;
};
Game.prototype.shortenTime = function () {
this.time *= 0.94;
};
return Game;
}());
var Input = /** @class */ (function () {
function Input(game, gui) {
this.game = game;
this.gui = gui;
this.clickEventType = isMobile() ? "touchstart" : "click";
this.resetNumber();
this.bindKeyBoardEvent();
this.bindKeyPadEvent();
}
Input.prototype.setGame = function (game) {
this.game = game;
};
Input.prototype.bindKeyBoardEvent = function () {
var _this = this;
document.addEventListener("keydown", function (e) {
var key = e.key;
if (["Enter", "Space"].some(function (v) { return v === key; }))
return _this.pressEnter();
else if (key === "BackSpace")
_this.number = _this.number.slice(0, -1);
else if (isNaN(parseInt(key)))
return;
else
_this.number += key;
_this.gui.setNumber(_this.number);
});
};
Input.prototype.bindKeyPadEvent = function () {
var _this = this;
document.querySelectorAll(".keypad .key").forEach(function (node) {
node.addEventListener(_this.clickEventType, function (e) {
e.preventDefault();
_this.number += e.target.dataset.num;
_this.gui.setNumber(_this.number);
});
});
document.querySelector(".keypad .enter").addEventListener(this.clickEventType, function (e) {
e.preventDefault();
_this.pressEnter();
});
document.querySelector(".keypad .reset").addEventListener(this.clickEventType, function (e) {
e.preventDefault();
_this.resetNumber();
_this.gui.setNumber(_this.number);
});
};
Input.prototype.pressEnter = function () {
var _this = this;
if (game == null || game == undefined)
this.gui.message("아직 게임이 시작되지 않았어요.");
clearTimeout(this.enterTimeout);
if (this.number == "") {
this.enterCount++;
var answer_1 = "짝!".repeat(this.enterCount);
this.gui.setHandClab(answer_1);
this.game.setHandClab(answer_1);
this.enterTimeout = setTimeout(function () {
if (_this.game.order === 0) {
_this.game.sayNumber(answer_1);
}
_this.resetNumber();
}, 800);
}
else {
this.game.sayNumber(this.number);
this.resetNumber();
}
};
;
Input.prototype.resetNumber = function () {
this.number = "";
this.enterCount = 0;
this.gui.setNumber(this.number);
};
return Input;
}());
var game = null;
var createGame = function (gui) { return game = new Game(gui, 4, 5000); };
var username = mw.config.values.wgUserName;
var gui = new GUI();
//createGame(gui);
var input = new Input(game, gui);
}
}
$( plugin_real369 );
/* real369 끝 */