Real 369/플러그인: 두 판 사이의 차이

리버티게임, 모두가 만들어가는 자유로운 게임
백괴게임>BANIP
잔글편집 요약 없음
백괴게임>BANIP
잔글 (BANIP님이 사용자:BANIP/real369 remaster/플러그인 문서를 Real 369/플러그인 문서로 이동했습니다: 플러그인 이동)
(차이 없음)

2018년 3월 25일 (일) 01:57 판

요령 => 아래 변수들의 첫번째 인자들을 내용에 맞게 자르고 붙여넣어주세요

!!!!!!!!!!!!!!!! 플러그인 정보 입력 구간 윗부분은 만지지 마시오 절대로!!!!!!!!!!!!!!!!!






!!!!!!!!!!!!!!!! 플러그인 정보 입력 구간 끝 아래는 만지지 마시오!!!!!!!!!!!!!!!!!

이 플러그인에 대한 설명문서는 Real 369/플러그인/설명문서에서 만들 수 있습니다.

		 
/**
 * 지금 박수를 쳐야되는지 숫자를 외쳐야 하는지 알아 냅니다
 * @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);