사용자:백괴투/common.js: 두 판 사이의 차이

리버티게임, 모두가 만들어가는 자유로운 게임
백괴게임>백괴투
(플러그인 uncytick설치)
 
백괴게임>Manymaster
편집 요약 없음
 
(다른 사용자 한 명의 중간 판 4개는 보이지 않습니다)
182번째 줄: 182번째 줄:
$( plugin_uncytick );
$( plugin_uncytick );
/* uncytick 끝 */
/* uncytick 끝 */
/** 플러그인 numbase***************************
* 숫자야구 remake
* 버전 => 1.41
* 작성자 : [[사용자:Riemann|Riemann]]
* JSON => numbase = {"name":"numbase","descript":"숫자야구 remake","version":"1.41","local":true,"creat":"Riemann","state":"사용자:Riemann/numbase","executable":true};
*/
function plugin_numbase(){
  if($("[data-name='numbase']").length >= 1){
var title = mw.config.get('wgPageName');
if (title.slice( -1 ) == "4") {
    var no = 4
    }
else {
    var no = 3
}
var trial = 0;
var d = new Date();
$("#sBtn").click(function(){
    $("#description").css("display", "none");
    $("#sBtn").css("display", "none");
    $("#res").css("display", "table");
    cpuNum = initNumbase();
    document.getElementById('count').innerHTML = "시도 횟수: " + trial;
    var bDate = d.getTime();
    numGuess(bDate);
});
function initNumbase() {
var choice = "";
var initArray = [0,1,2,3,4,5,6,7,8,9];
var i, j;
for (i = 0; i < no; i++) {
    j = Math.floor(Math.random() * initArray.length);
    choice += initArray[j];
    initArray.splice(j,1);
}
return choice;
}
function numGuess(bDate) {
document.getElementById('disp').style.display = 'table';
document.getElementById('numList').style.display = 'block';
var numb = document.getElementById('numList');
var numBlocks = "";
var disp = "";
document.getElementById('disp').innerHTML = disp;
for (i = 0; i < 10; i++) {
    numBlocks += "<div id=\"numBlock" + i + "\" class=\"numBlock\">" + i + "</div>";
}
numBlocks += "<div id=\"numBlockC\" class=\"numBlockC\">C</div>";
numBlocks += "<div id=\"numBlockX\" class=\"numBlockC\">입력</div>";
numb.innerHTML = numBlocks;
function restrictLen(l,n) {
  if (l.length < no) {
        l += n;
  } else {
        alert(no + " 자리로 입력하세요.");
  }
  return l;
}
$("#numBlock0").click(function(){
    disp = restrictLen(disp,0);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock0").css("display", "none");
});
$("#numBlock1").click(function(){
    disp = restrictLen(disp,1);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock1").css("display", "none");
});
$("#numBlock2").click(function(){
    disp = restrictLen(disp,2);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock2").css("display", "none");
});
$("#numBlock3").click(function(){
    disp = restrictLen(disp,3);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock3").css("display", "none");
});
$("#numBlock4").click(function(){
    disp = restrictLen(disp,4);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock4").css("display", "none");
});
$("#numBlock5").click(function(){
    disp = restrictLen(disp,5);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock5").css("display", "none");
});
$("#numBlock6").click(function(){
    disp = restrictLen(disp,6);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock6").css("display", "none");
});
$("#numBlock7").click(function(){
    disp = restrictLen(disp,7);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock7").css("display", "none");
});
$("#numBlock8").click(function(){
    disp = restrictLen(disp,8);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock8").css("display", "none");
});
$("#numBlock9").click(function(){
    disp = restrictLen(disp,9);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock9").css("display", "none");
});
$("#numBlockC").click(function(){
    disp = "";
    document.getElementById('disp').innerHTML = disp;
    $(".numBlock").css("display", "inline-flex");
});
$("#numBlockX").click(function(){
    if (disp.length < no) {
        alert(no + " 자리로 입력하세요.")
    } else {
        trial += 1
        document.getElementById('count').innerHTML = "시도 횟수: " + trial;
        v = valid(disp,cpuNum);
        $("#res").append("<tr><td>" + trial + "</td><td>" + disp + "</td><td>" + v + "</td></tr>");
        disp = "";
        document.getElementById('disp').innerHTML = disp;
        $(".numBlock").css("display", "inline-flex");
        if ((v == "0B 3S" && no == 3) || (v == "0B 4S" && no == 4)) {
            var dd = new Date();
            var duration = Math.floor((dd.getTime() - bDate) / 1000);
            document.getElementById('end').innerHTML = "축하합니다. 정수를 맞히셨습니다. " + trial + "회, " + duration + "초가 소비되었습니다. 이용해주셔서 감사합니다.";
            $("#disp").css("display", "none");
            $("#numList").css("display", "none");
            $("#end").css("display", "inline");
            return 0;
        }
    }
});
}
function valid(u,c) {
    var b = 0;
    var s = 0;
    var bs;
    for (i = 0; i < no; i++) {
        for (j = 0; j < no; j++) {
            if (u[i] == c[j]) {
                if (i == j) {
                    s += 1;
                }
                else {
                    b += 1;
                }
            }
        }
    }
    bs = "" + b + "B " + s + "S"
    return bs;
}
  }
}
$( plugin_numbase );
/* numbase 끝 */
/** 플러그인 msgame***************************
* 스톱워치 게임
* 버전 => 0.942
* 작성자 : [[사용자:Riemann|Riemann]]
* JSON => msgame = {"name":"msgame","descript":"스톱워치 게임","version":"0.942","local":true,"creat":"Riemann","state":"사용자:Riemann/msgame","executable":true};
*/
function plugin_msgame(){
  if($("[data-name='msgame']").length >= 1){
  // 이부분에 코드 입력 //
sc = 0
cb = 0
bl = false;
$(document.body).keydown(function() {
  if (bl == false) {
  bl = true
    startF();
  } else {
    bl = false
    stopF();
  }
});
$("#msgame-start").click(function() {
  bl = true
startF();
});
$("#msgame-stop").click(function() {
  bl = false
stopF();
});
function startF() {
  obj = Math.floor(Math.random() * 10) + 5;
  $("#msgame-start").css("display", "none");
  $("#msgame-stop").css("display", "block");
  it = new Date();
  si = setInterval(clockUpdate, 20)
  $("#msgame-console").text(obj + " 초를 세세요.");
}
function stopF() {
  $("#msgame-clockText").css("display", "inline");
  $("#msgame-stop").css("display", "none");
  $("#msgame-start").css("display", "block");
  clearInterval(si);
  ie = new Date();
  ifin = ie - it;
  $("#msgame-clockText").text(toMilliSec(ifin));
  finished(obj, ifin);
}
function clockUpdate() {
  ic = new Date();
  id = ic - it;
  ii = toMilliSec(id);
  $("#msgame-clockText").text(ii);
  if (obj * 1000 - id < 500 * cb && cb > 4 ) {
    $("#msgame-clockText").fadeOut();
  }
}
function toMilliSec(d) {
  return (Math.floor(d / 1000) + "\"" + ("" + d % 1000).padStart(3, "0")).padStart(6, "0");
}
function finished(a, b) {
  ath = a * 1000
  if (ath == b) {
    cbm = Math.floor(Math.pow(800, (1 + cb / 10)))
    $("#msgame-console").text("정확하시군요. " + cbm + " 점 드리겠습니다.");
    sc += cbm
    cb += 1
  } else if (Math.abs(ath - b) < 100) {
    cbm = Math.floor(Math.pow((500 / Math.abs(ath - b)), (1 + cb / 10)))
    $("#msgame-console").text("정확하시군요. " + cbm + " 점 드리겠습니다.");
    sc += cbm
    cb += 1
  } else {
    $("#msgame-console").text("안타깝습니다. 조금 더 노력해 보세요!");
    cb = 0
  }
  $("#msgame-score").text(sc);
  $("#msgame-combo").text(cb);
}
// 여기까지 코드 입력 //
  }
}
$( plugin_msgame );
/* msgame 끝 */

2019년 2월 5일 (화) 10:59 기준 최신판

/** 플러그인 uncytick***************************
* 게임 실행용 플러그인
* 버전 => 1.0.0
* 작성자 : [[사용자:BANIP|BANIP]] 
* JSON => uncytick = {"name":"uncytick","descript":"게임 실행용 플러그인","version":"1.0.0","local":true,"creat":"BANIP","state":"사용자:BANIP/틱택토 live/플러그인","executable":true}; 
*/ 
function plugin_uncytick(){
  if($("[data-name='uncytick']").length >= 1){
		  // 이부분에 코드 입력 //

jQuery.getScript("https://socket-io-chat.now.sh/socket.io/socket.io.js")
.done(function(){
var Socket = /** @class */ (function () {
    function Socket(url, username) {
        if (username === void 0) { username = Math.random().toString(); }
        this.username = username;
        this.socket = io(url);
        this.defineJoin();
        this.bindSocketListener();
    }
    Socket.prototype.defineJoin = function () {
        this.socket.emit("join", { username: this.username });
    };
    Socket.prototype.bindSocketListener = function () {
        var _this = this;
        var socket = this.socket;
        socket.on("newuser", function (_a) {
            var username = _a.username;
            Chat.server(username + "\uB2D8\uC774 \uB4E4\uC5B4\uC654\uC5B4\uC694.");
        });
        socket.on("passuser", function (_a) {
            var username = _a.username;
            Chat.server(username + "\uB2D8\uC774 \uB098\uAC14\uC5B4\uC694.");
        });
        socket.on("getuserlist", function (data) {
            var buttonClickListener = function ($li, username, id) {
                socket.emit("requestjoin", { targetId: id });
                $(".activePull").removeClass();
                $li.addClass("activePull");
                Chat.server(username + "에게 게임신청을 했어요.");
            };
            var $lis = data
                .map(function (userData) {
                if (userData == null)
                    return;
                var username = userData.username, id = userData.id;
                var $li = $("<li />")
                    .text(username)
                    .data("id", id);
                if (username != _this.username) {
                    var $button = $("<button>").text("게임 신청").addClass("btn-request");
                    $button.click(function () { return buttonClickListener($li, username, id); });
                    $li.append($button);
                }
                return $li;
            });
            $("#userlist").html($lis);
        });
        socket.on("servermessage", function (data) {
            Chat.server(data.message);
        });
        socket.on("receivemessage", function (data) {
            Chat.client(data.username, data.message);
        });
        socket.on("gamestart", function (_a) {
            var enemyUsername = _a.enemyUsername;
            var canStartGame = _this.game == undefined || _this.game.isGameEnd == true;
            if (canStartGame) {
                _this.game = new Game(socket, _this.username, enemyUsername);
            }
            else {
                Chat.server(_this.game.enemyUsername + "\uACFC\uC758 \uAC8C\uC784\uC774 \uC544\uC9C1 \uB05D\uB098\uC9C0 \uC54A\uC558\uC5B4\uC694.");
            }
        });
    };
    return Socket;
}());
var Chat = /** @class */ (function () {
    function Chat() {
    }
    Chat.server = function (message) {
        var $li = $("<li></li>").text(message);
        $("#messages").append($li);
        Chat.moveBottom();
    };
    Chat.client = function (username, message) {
        var $li = $("\n            <li>\n                <span class='username' /> : <span class='message'>\n            </li>");
        $li.find(".username").text(username);
        $li.find(".message").text(message);
        $("#messages").append($li);
        Chat.moveBottom();
    };
    Chat.moveBottom = function () {
        $("#messages").scrollTop($("#messages")[0].scrollHeight);
    };
    return Chat;
}());
var Game = /** @class */ (function () {
    function Game(socket, username, ememyusername) {
        this.socket = socket;
        this.isGameEnd = false;
        this.enemyUsername = ememyusername;
        Chat.server(ememyusername + "과의 게임이 시작되었어요!");
        $(".btn-request").fadeOut();
        var bindClick = function ($target, axis) {
            var x = axis[0], y = axis[1];
            $target.text("H").click(function () {
                console.log([x, y]);
                socket.emit("draw", {
                    axis: [x, y]
                });
            });
        };
        $("#gamepan").slideDown().find("> div")
            .each(function (x) {
            $(this).find("> a").each(function (y) { bindClick($(this), [x, y]); });
        });
        this.bindSocketListener();
    }
    Game.prototype.bindSocketListener = function () {
        var socket = this.socket;
        var self = this;
        socket.on("renewgamepan", function (_a) {
            var gamepan = _a.gamepan;
            gamepan.forEach(function (hori, x) {
                return hori.forEach(function (cell, y) {
                    var textType = {
                        "1": "O",
                        "0": "H",
                        "-1": "X",
                    };
                    var text = textType[cell];
                    $("#gamepan").find("div").eq(x).find("a").eq(y)
                        .data("x", x).data("y", y)
                        .text(text);
                    console.log(x, y);
                });
            });
        });
        socket.on("gameend", function (_a) {
            var state = _a.state;
            var hideGamePan = function () { return $("#gamepan").slideUp(); };
            var messageType = {
                "win": "게임 승리!! 축하드려요!",
                "lose": "윽... 져버렸네요...",
                "draw": "비겼어요!",
            };
            var endMessage = messageType[state];
            Chat.server(endMessage);
            $(".btn-request").fadeIn();
            setTimeout(hideGamePan, 3000);
            self.isGameEnd = true;
            self.removesocketListener();
        });
    };
    Game.prototype.removesocketListener = function () {
        $("#gamepan").find("a").off("click");
        this.socket.off("gameend").off("renewgamepan");
    };
    return Game;
}());
var gamehtml = '<div id="gamepan"><div><a></a><a></a><a></a></div><div><a></a><a></a><a></a></div><div><a></a><a></a><a></a></div></div><div class="wrap"><ul id="userlist" class="scrollbox"></ul><ul id="messages" class="scrollbox"></ul><input id="chat" placeholder="메세지를 입력하세요..."/></div>';
$("#gamewindow").html(gamehtml);
var thisSocket = new Socket("https://banip.tk" + "/uncytt",mw.config.values.wgUserName);

$("#chat").keypress(function (e) {
    if (e.key === "Enter" && $(this).val() != "") {
        thisSocket.socket.emit("sendmessage", { message: $(this).val() });
        $(this).val("");
    }
});

});
 // 여기까지 코드 입력 //

		
  }

}
$( plugin_uncytick );
/* uncytick 끝 */


/** 플러그인 numbase***************************
* 숫자야구 remake
* 버전 => 1.41
* 작성자 : [[사용자:Riemann|Riemann]] 
* JSON => numbase = {"name":"numbase","descript":"숫자야구 remake","version":"1.41","local":true,"creat":"Riemann","state":"사용자:Riemann/numbase","executable":true}; 
*/ 
function plugin_numbase(){
  if($("[data-name='numbase']").length >= 1){
		 
var title = mw.config.get('wgPageName');
if (title.slice( -1 ) == "4") {
    var no = 4
    }
else {
    var no = 3
}

var trial = 0;
var d = new Date();
$("#sBtn").click(function(){
    $("#description").css("display", "none");
    $("#sBtn").css("display", "none");
    $("#res").css("display", "table");
    cpuNum = initNumbase();
    document.getElementById('count').innerHTML = "시도 횟수: " + trial;
    var bDate = d.getTime();
    numGuess(bDate);
});

function initNumbase() {
var choice = "";
var initArray = [0,1,2,3,4,5,6,7,8,9];
var i, j;
for (i = 0; i < no; i++) {
    j = Math.floor(Math.random() * initArray.length);
    choice += initArray[j];
    initArray.splice(j,1);
}
return choice;
}

function numGuess(bDate) {
document.getElementById('disp').style.display = 'table';
document.getElementById('numList').style.display = 'block';
var numb = document.getElementById('numList');
var numBlocks = "";
var disp = "";
document.getElementById('disp').innerHTML = disp;
for (i = 0; i < 10; i++) {
    numBlocks += "<div id=\"numBlock" + i + "\" class=\"numBlock\">" + i + "</div>";
}
numBlocks += "<div id=\"numBlockC\" class=\"numBlockC\">C</div>";
numBlocks += "<div id=\"numBlockX\" class=\"numBlockC\">입력</div>";
numb.innerHTML = numBlocks;

function restrictLen(l,n) {
   if (l.length < no) {
        l += n;
   } else {
        alert(no + " 자리로 입력하세요.");
   }
   return l;
}

$("#numBlock0").click(function(){
    disp = restrictLen(disp,0);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock0").css("display", "none");
});
$("#numBlock1").click(function(){
    disp = restrictLen(disp,1);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock1").css("display", "none");
});
$("#numBlock2").click(function(){
    disp = restrictLen(disp,2);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock2").css("display", "none");
});
$("#numBlock3").click(function(){
    disp = restrictLen(disp,3);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock3").css("display", "none");
});
$("#numBlock4").click(function(){
    disp = restrictLen(disp,4);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock4").css("display", "none");
});
$("#numBlock5").click(function(){
    disp = restrictLen(disp,5);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock5").css("display", "none");
});
$("#numBlock6").click(function(){
    disp = restrictLen(disp,6);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock6").css("display", "none");
});
$("#numBlock7").click(function(){
    disp = restrictLen(disp,7);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock7").css("display", "none");
});
$("#numBlock8").click(function(){
    disp = restrictLen(disp,8);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock8").css("display", "none");
});
$("#numBlock9").click(function(){
    disp = restrictLen(disp,9);
    document.getElementById('disp').innerHTML = disp;
    $("#numBlock9").css("display", "none");
});
$("#numBlockC").click(function(){
    disp = "";
    document.getElementById('disp').innerHTML = disp;
    $(".numBlock").css("display", "inline-flex");
});
$("#numBlockX").click(function(){
    if (disp.length < no) {
        alert(no + " 자리로 입력하세요.")
    } else {
        trial += 1
        document.getElementById('count').innerHTML = "시도 횟수: " + trial;
        v = valid(disp,cpuNum);
        $("#res").append("<tr><td>" + trial + "</td><td>" + disp + "</td><td>" + v + "</td></tr>");
        disp = "";
        document.getElementById('disp').innerHTML = disp;
        $(".numBlock").css("display", "inline-flex");
        if ((v == "0B 3S" && no == 3) || (v == "0B 4S" && no == 4)) {
            var dd = new Date();
            var duration = Math.floor((dd.getTime() - bDate) / 1000);
            document.getElementById('end').innerHTML = "축하합니다. 정수를 맞히셨습니다. " + trial + "회, " + duration + "초가 소비되었습니다. 이용해주셔서 감사합니다.";
            $("#disp").css("display", "none");
            $("#numList").css("display", "none");
            $("#end").css("display", "inline");
            return 0;
        }
    }
});
}

function valid(u,c) {
    var b = 0;
    var s = 0;
    var bs;
    for (i = 0; i < no; i++) {
        for (j = 0; j < no; j++) {
            if (u[i] == c[j]) {
                if (i == j) {
                    s += 1;
                }
                else {
                    b += 1;
                }
            }
        }
    }
    bs = "" + b + "B " + s + "S"
    return bs;
}

		
  }

}
$( plugin_numbase );
/* numbase 끝 */


/** 플러그인 msgame***************************
* 스톱워치 게임
* 버전 => 0.942
* 작성자 : [[사용자:Riemann|Riemann]] 
* JSON => msgame = {"name":"msgame","descript":"스톱워치 게임","version":"0.942","local":true,"creat":"Riemann","state":"사용자:Riemann/msgame","executable":true}; 
*/ 
function plugin_msgame(){
  if($("[data-name='msgame']").length >= 1){
		  // 이부분에 코드 입력 //
sc = 0
cb = 0

bl = false;
$(document.body).keydown(function() {
  if (bl == false) {
  	bl = true
    startF();
  } else {
    bl = false
    stopF();
  }
});

$("#msgame-start").click(function() {
  bl = true
	startF();
});

$("#msgame-stop").click(function() {
  bl = false
	stopF();
});

function startF() {
  obj = Math.floor(Math.random() * 10) + 5;
  $("#msgame-start").css("display", "none");
  $("#msgame-stop").css("display", "block");
  it = new Date();
  si = setInterval(clockUpdate, 20)
  $("#msgame-console").text(obj + " 초를 세세요.");
}

function stopF() {
  $("#msgame-clockText").css("display", "inline");
  $("#msgame-stop").css("display", "none");
  $("#msgame-start").css("display", "block");
  clearInterval(si);
  ie = new Date();
  ifin = ie - it;
  $("#msgame-clockText").text(toMilliSec(ifin));
  finished(obj, ifin);
}

function clockUpdate() {
  ic = new Date();
  id = ic - it;
  ii = toMilliSec(id);
  $("#msgame-clockText").text(ii);
  if (obj * 1000 - id < 500 * cb && cb > 4 ) {
    $("#msgame-clockText").fadeOut();
  }
}

function toMilliSec(d) {
  return (Math.floor(d / 1000) + "\"" + ("" + d % 1000).padStart(3, "0")).padStart(6, "0");
}

function finished(a, b) {
  ath = a * 1000
  if (ath == b) {
    cbm = Math.floor(Math.pow(800, (1 + cb / 10)))
    $("#msgame-console").text("정확하시군요. " + cbm + " 점 드리겠습니다.");
    sc += cbm
    cb += 1
  } else if (Math.abs(ath - b) < 100) {
    cbm = Math.floor(Math.pow((500 / Math.abs(ath - b)), (1 + cb / 10)))
    $("#msgame-console").text("정확하시군요. " + cbm + " 점 드리겠습니다.");
    sc += cbm
    cb += 1
  } else {
    $("#msgame-console").text("안타깝습니다. 조금 더 노력해 보세요!");
    cb = 0
  }
  $("#msgame-score").text(sc);
  $("#msgame-combo").text(cb);
}
 // 여기까지 코드 입력 //

		
  }

}
$( plugin_msgame );
/* msgame 끝 */