사용자:Chabiytb0792/common.js: 두 판 사이의 차이
보이기
imported>Chabiytb0792 플러그인 jsRULLET설치 |
imported>Chabiytb0792 플러그인 real369설치 |
||
24번째 줄: | 24번째 줄: | ||
$( plugin_jsRULLET ); | $( plugin_jsRULLET ); | ||
/* jsRULLET 끝 */ | /* jsRULLET 끝 */ | ||
/** 플러그인 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 끝 */ |
2023년 5월 27일 (토) 15:16 판
/** 플러그인 jsRULLET***************************
* 랜덤 룰렛을 위한 플러그인
* 버전 => 1.0.4
* 작성자 : [[사용자:Cheongseong9473|Cheongseong9473]]
* JSON => jsRULLET = {"name":"jsRULLET","descript":"랜덤 룰렛을 위한 플러그인","version":"1.0.4","local":true,"creat":"Cheongseong9473","state":"자바월드/랜덤룰렛/플러그인","executable":true};
*/
function plugin_jsRULLET(){
if($("[data-name='jsRULLET']").length >= 1){
for (var i=0;i<6;i++)
{
alert(randomRange(1,60));
}
function randomRange(n1, n2) {
return Math.floor( (Math.random() * (n2 - n1 + 1)) + n1 );
}
}
}
$( plugin_jsRULLET );
/* jsRULLET 끝 */
/** 플러그인 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 끝 */