分享賭博+小遊戲系列JS (21點、寶石連線、排列組合、踩地雷、老虎機)

這些資源是從對岸拿到的,我也不記得是從哪個拿的,就分享一下我比較常逛的論壇:
楓業物語論壇冒險島私服論壇
我記得原本是可以輸入賭注的,但是我架的服輸入問題還沒解決,所以全部改為統一賭注,
如果有需要輸入賭注的話可以自己修改掉。
有一些已經很多人分享過了,我這邊就再貼一次順便加上一些註解

在開始之前先說幾個重點函數:

  1. Math.random() 函數隨機產生一數在範圍[0,1),從0(包括0)往上,但是不包括1(排除1)。
  2. Math.floor() 函式會回傳無條件捨去後的最大整數。
    其他可以參考MDN

端口常用的函數:

  1. cm.getPlayer().getCSPoints(1)//判斷玩家GASH數 (1是GASH,2是楓葉點數
  2. cm.getPlayer().modifyCSPoints(1, -50, true); //給予或扣除GASH
  3. cm.haveItem(物品id,數); //判断玩家背包是否有此道具
  4. cm.gainItem(物品id,數); //给予或者收取指定物品
  5. cm.getPlayer().itemQuantity(物品id) //判斷玩家背包中這個物品有多少數
  6. cm.getPlayer().getMeso() //判斷玩家楓幣數
  7. cm.gainMeso(-10000000); //給予或扣除玩家楓幣
  8. cm.getPlayer().getLevel() //判斷玩家等級
  9. cm.worldMessage(6,"公告"); //6為藍字廣播,5為紅字廣播

21點




JS

/*
 * 賭博21点
 *
 *
 */

var text = "";
var text1 = "";
var score = 0;
var zhuangScore = 0;
var xianScore = 0;
var paiArray = Array("A", 2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K");
var paiArray2 = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10);
var ran = -1;


function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) {
        cm.dispose();
    } else {
        if (status == 0 && mode == 0) {

            cm.sendOk("歡迎下次光臨~");
            cm.dispose();
            return;
        }
        if (mode == 1) {
            status++;
        } else {
            if (status == 0) {
                cm.sendNext("歡迎下次光臨~");
                cm.dispose();
            }
            status--;
        }
        if (status == 0) {
            score = cm.getMeso();
            text += "#fUI/UIWindow/Quest/icon3/6# ";
            text += "你好,在我這裡可以玩21點,一次#r50GASH#k哦。";
            text += " #fUI/UIWindow/Quest/icon3/6#\r\n";
            text += "#L0# 開始遊戲 #l\r\n";
            text += "#L1# 遊戲說明 #l\r\n";
            cm.sendSimple(text);
        } else if (status == 1) {
            if (selection == 0) {
                cm.sendOk("賭友你要繼續下注嗎?");
            } else if (selection == 1) {
                text1 += "#fUI/UIWindow/Quest/icon3/6# ";
                text1 += "玩法說明:";
                text1 += " #fUI/UIWindow/Quest/icon3/6#\r\n";
                text1 += "    莊家的點數會在15點-22點之間(#r莊家也有可能爆掉#k),你有4次要牌的機會,如果你的點數大於莊家的點數即贏得你下注的金額,如果大於21點或者小於等於莊家的點數,即輸掉你所下注的金額,10、J、Q、K都算十點,小賭怡情,大賭傷人,請慎重。";
                cm.sendOk(text1);
                cm.dispose();
            }
        }
        //-------------第一次要牌-----------------//
        else if (status == 2) {
            if (cm.getPlayer().getLevel() < 70) {    //這邊可以設定玩家等級限制
                cm.sendOk("必須達到70級才能使用。");
                cm.dispose();
            } else if (cm.getPlayer().getCSPoints(1) < 50) { //這邊可以設置賭注
                cm.sendOk("你沒有50GASH");
                cm.dispose();
            } else {
                cm.getPlayer().modifyCSPoints(1, -50, true);
                zhuangScore = parseInt(Math.random() * 8 + 15);
                ran = parseInt(Math.random() * paiArray.length);
                xianScore = paiArray2[ran];
                var text2 = "";
                text2 += "拿到了 #r#e" + paiArray[ran] + "#n#k,您目前的點數為: #r#e" + xianScore + "#n#k ,";
                text2 += "您繼續要牌嗎? \r\n";
                text2 += "#L2# 要  \r\n";
                text2 += "#L3# 不要  \r\n";
                cm.sendSimple(text2);
            }

        }

        //------------第二次要牌------------------//

        else if (status == 3) {
            if (selection == 2) {
                ran = parseInt(Math.random() * paiArray.length);
                xianScore += paiArray2[ran];
                if (xianScore > 21) {
                    cm.sendOk("對不起,您的點數大於21點,您輸了。");
                    cm.dispose();
                } else {
                    text2 = "";
                    text2 += "拿到了 #r#e" + paiArray[ran] + "#n#k,您目前的點數為: #r#e" + xianScore + "#n#k ,";
                    text2 += "您繼續要牌嗎? \r\n";
                    text2 += "#L4# 要  \r\n";
                    text2 += "#L5# 不要  \r\n";
                    cm.sendSimple(text2);
                }
            } else if (selection == 3) {
                if ((xianScore < 22 && xianScore <= zhuangScore && zhuangScore < 22) || (xianScore >= 22 && zhuangScore >= 22)) {
                    cm.sendOk("莊家的點數為 #r#e" + zhuangScore + "#n#k,您的點數為 #r#e" + xianScore + "#n#k,您輸了。");
                    cm.dispose();
                } else {
                    cm.sendOk("#fUI/UIWindow/Quest/reward#\r\n  莊家的點數為 #r#e" + zhuangScore + "#n#k,您的點數為 #r#e" + xianScore + "#n#k,您贏了。");
                    cm.worldMessage(6,"[賭博公告]:玩家 " + cm.getPlayer().getName() + " ,在賭場二十一點贏了,將籌碼翻了【兩倍】獲得100點GASH!");
                    cm.getPlayer().modifyCSPoints(1, 100, true);
                    cm.gainItem(4031189,1); //這裡可以另外設定獎勵,不要的話可刪除
                    cm.dispose();
                }
            }


        }
        //-----------第三次要牌---------------
        else if (status == 4) {
            if (selection == 4) {
                ran = parseInt(Math.random() * paiArray.length);
                xianScore += paiArray2[ran];
                if (xianScore > 21) {
                    cm.sendOk("對不起,您的點數大於21點,您輸了");
                    cm.dispose();
                } else {
                    text2 = "";
                    text2 += "拿到了 #r#e" + paiArray[ran] + "#n#k,您目前的點數為: #r#e" + xianScore + "#n#k ,";
                    text2 += "您繼續要牌嗎? \r\n";
                    text2 += "#L6# 要  \r\n";
                    text2 += "#L7# 不要  \r\n";
                    cm.sendSimple(text2);
                }
            } else if (selection == 5) {
                if ((xianScore < 22 && xianScore <= zhuangScore && zhuangScore < 22) || (xianScore >= 22 && zhuangScore >= 22)) {
                    cm.sendOk("莊家的點數為 #r#e" + zhuangScore + "#n#k,您的點數為 #r#e" + xianScore + "#n#k,您輸了。");
                    cm.dispose();
                } else {
                    cm.sendOk("#fUI/UIWindow/Quest/reward#\r\n  莊家的點數為 #r#e" + zhuangScore + "#n#k,您的點數為 #r#e" + xianScore + "#n#k,您贏了。");
                    cm.worldMessage(6,"[賭博公告]:玩家 " + cm.getPlayer().getName() + " ,在賭場二十一點贏了,將籌碼翻了【兩倍】獲得100點GASH!");
                    cm.getPlayer().modifyCSPoints(1,100, true);
                    cm.gainItem(4031189,1);
                    cm.dispose();
                }
            }


        }

        //--------第四次要牌----------
        else if (status == 5) {
            if (selection == 6) {
                ran = parseInt(Math.random() * paiArray.length);
                xianScore += paiArray2[ran];
                if (xianScore > 21) {
                    cm.sendOk("對不起,您的點數大於21點,您輸了");
                    cm.dispose();
                } else {
                    if ((xianScore < 22 && xianScore <= zhuangScore && zhuangScore < 22) || (xianScore >= 22 && zhuangScore >= 22)) {
                        cm.sendOk("莊家的點數為 #r#e" + zhuangScore + "#n#k,您的點數為 #r#e" + xianScore + "#n#k,您輸了。");
                        cm.dispose();
                    } else {
                        cm.sendOk("#fUI/UIWindow/Quest/reward#\r\n  莊家的點數為 #r#e" + zhuangScore + "#n#k,您的點數為 #r#e" + xianScore + "#n#k,您贏了。");
                        cm.worldMessage(6,"[賭博公告]:玩家 " + cm.getPlayer().getName() + " ,在賭場二十一點贏了,將籌碼翻了【兩倍】獲得100點GASH!");
                        cm.getPlayer().modifyCSPoints(1, 100, true);
                        cm.gainItem(4031189,1);
                        cm.dispose();
                    }
                }

            } else if (selection == 7) {
                if ((xianScore < 22 && xianScore <= zhuangScore && zhuangScore < 22) || (xianScore >= 22 && zhuangScore >= 22)) {
                    cm.sendOk("莊家的點數為 #r#e" + zhuangScore + "#n#k,您的點數為 #r#e" + xianScore + "#n#k,您是輸了。");
                    cm.dispose();
                } else {
                    cm.sendOk("#fUI/UIWindow/Quest/reward#\r\n  莊家的點數為 #r#e" + zhuangScore + "#n#k,您的點數為 #r#e" + xianScore + "#n#k,您贏了。");
                    cm.worldMessage(6,"[賭博公告]:玩家 " + cm.getPlayer().getName() + " ,在賭場二十一點贏了,將籌碼翻了【兩倍】獲得100點GASH!");
                    cm.getPlayer().modifyCSPoints(1, 100, true);
                    cm.gainItem(4031189,1);
                    cm.dispose();
                }
            }
        }
    }
}

十倍賭博機

其實就只是一個靠運氣的機器,沒有什麼玩法。



這是贏的時候會有的廣播

JS

var status = 0;
var fee;
var chance = Math.floor(Math.random() * 12 + 1); //這裡可以設定機率

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) {
        cm.dispose();
    } else {
        if (mode == 0) {
            cm.sendOk("#i3994125# - 我會繼續在這裡等著你。");
            cm.dispose();
            return;
        }
        if (mode == 1)
            status++;
        else
            status--;
        if (status == 0) {
            cm.sendAcceptDecline("#r【十倍賭博機】\r\n#d-看來你的心很大啊,其他賭博機滿足不了你了嗎?#i3994125# #k\r\n ");
        } else if (status == 1) {
            cm.sendOk("#i3994125#\r\n如果你能贏我,我會將你的籌碼數倍奉還,而且還有神秘禮品");
        } else if (status == 2) {
            fee = cm.getText();
            cm.sendYesNo("#i3994125# - 你確認要繼續下注嗎?一次消耗#r50GASH#k。");
        } else if (status == 3) {
            if (cm.getPlayer().getLevel() < 70) {
                cm.sendOk("必須達到70級才能使用。");
                cm.dispose();
            } else if (cm.getPlayer().getCSPoints(1) < 50) {
                cm.sendOk("你沒有50GASH");
                cm.dispose();
            } else {
                if (chance <= 1) {
                    cm.getPlayer().modifyCSPoints(1, -50, true);
                    cm.sendNext("#i3994125# - #r你輸了#k");
                   // cm.worldMessage(6, "[賭場公告]:玩家 " + cm.getChar().getName() + " ,在賭場十倍賭博機輸了,看來今天並不被女神眷顧!");
                    cm.dispose();
                } else if (chance == 2) {
                    cm.sendNext("#i3994125# - #r這把不算,重新再來,你手不要抖動。#k");
                    cm.dispose();
                } else if (chance == 3) {
                    cm.getPlayer().modifyCSPoints(1, -50, true);
                    cm.sendNext("#i3994125# - #r你輸了#k");
                    cm.dispose();
                } else if (chance == 4) {
                    cm.getPlayer().modifyCSPoints(1, -50, true);
                    cm.sendNext("#i3994125# - #r你輸了#k");
                    cm.dispose();
                } else if (chance == 5) {
                    cm.sendNext("#i3994125# - #r這把不算,重新再來,你手不要抖動。#k");
                    cm.dispose();
                } else if (chance == 6) {
                    cm.getPlayer().modifyCSPoints(1, -50, true);
                    cm.sendNext("#i3994125# - #r你輸了#k");
                    cm.dispose();
                } else if (chance == 7) {
                    cm.sendNext("#i3994125# - #r這把不算,重新再來,你手不要抖動。#k");
                    cm.dispose();
                } else if (chance == 8) {
                    cm.getPlayer().modifyCSPoints(1, -50, true);
                    cm.sendNext("#i3994125# - #r你輸了#k");
                    cm.dispose();
                } else if (chance == 9) {
                    cm.getPlayer().modifyCSPoints(1, -50, true);
                    cm.sendNext("#i3994125# - #r你輸了#k");
                    cm.dispose();
                } else if (chance == 10) {
                    cm.getPlayer().modifyCSPoints(1, -50, true);
                    cm.sendNext("#i3994125# - #r你輸了#k");
                    cm.dispose();
                } else if (chance == 11) {
                    cm.getPlayer().modifyCSPoints(1, -50, true);
                    cm.sendNext("哦··你的運氣不怎麼好哦··哈哈 再來一把嘛!");
                    cm.dispose();
                } else if (chance >= 12) {
                    cm.getPlayer().modifyCSPoints(1, 500, true);
                    cm.gainItem(4031189,1);
                    cm.sendNext("#i3994125# -#r不錯哦,恭喜你贏了,我願賭服輸!獲得500點數");
                    cm.worldMessage(6,"[賭場公告]:玩家 " + cm.getPlayer().getName() + " ,在賭場十倍賭博機贏了,將籌碼翻了【十倍】獲得500點數!");
                    cm.dispose();
                }
            }
        }
    }
}

比大小




JS

var status = 0;
//var 黑水晶 = 4021008;
//var 藍色箭頭 = "#fUI/UIWindow/Quest/icon2/7#";
//var 紅色箭頭 = "#fUI/UIWindow/Quest/icon6/7#";
//var 圓形 = "#fUI/UIWindow/Quest/icon3/6#";
//var 美化new = "#fUI/UIWindow/Quest/icon5/1#";
//var 驚嘆號 = "#fUI/UIWindow/Quest/icon0#";
var 正方箭頭 = "#fUI/Basic/BtHide3/mouseOver/0#";
/*以上都是小圖示路徑,用來裝飾的,可以修改*/
function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) {
        cm.dispose();
    } else {
        if (status >= 0 && mode == 0) {
            cm.dispose();
            return;
        }
        if (mode == 1)
            status++;
        else
            status--;
        if (status == 0) {
            var a1 = "#L1##b" + 正方箭頭 + " 50 GASH 【大】【小】\r\n";
            var a2 = "#L2##b" + 正方箭頭 + " 250GASH 【大】【小】\r\n";
            var a3 = "#L3##b" + 正方箭頭 + " 500GASH 【大】【小】\r\n";


            cm.sendSimple("\r\n#d-來來來,買大買小,買定離手#i3994122# #r【大小賭博機】\r\n#r  【賠率】1:2【概率】5:5\r\n" + a1 + "" + a2 + "" + a3 + "");

        } else if (selection == 1) {
            if (cm.getPlayer().getLevel() < 70) {
                cm.sendOk("必須達到70級才能使用。");
                cm.dispose();
                return;
            } else {
                if (cm.getPlayer().getCSPoints(1) >= 50) {
                    cm.getPlayer().modifyCSPoints(1, -50, true);
                    var rand = Math.floor(Math.random() * 100);
                    if (rand < 50) {
                        cm.getPlayer().modifyCSPoints(1, 100, true);
                        cm.gainItem(4031189,1);
                        cm.sendOk("恭喜你,贏了");
                        cm.dispose();
                        cm.worldMessage(6,"[賭場公告]:玩家 " + cm.getPlayer().getName() + " ,在賭場選大小點贏了,將籌碼x1翻了【兩倍】獲得100點GASH!");
                        return;
                    } else {
                        cm.sendOk("唉,輸了");
                        cm.dispose();
                        return;
                    }
                } else {
                    cm.sendOk("你沒有足夠的GASH.~");
                    cm.dispose();
                    return;
                }
            }
        } else if (selection == 2) {
            if (cm.getPlayer().getLevel() < 25) {
                cm.sendOk("必須達到25級才能使用。");
                cm.dispose();
                return;
            } else {

                if (cm.getPlayer().getCSPoints(1) >= 250) {
                    cm.getPlayer().modifyCSPoints(1, -250, true);
                    var rand = Math.floor(Math.random() * 100);
                    if (rand < 50) {
                        cm.getPlayer().modifyCSPoints(1, 500, true);
                        cm.gainItem(4031189,1);
                        cm.sendOk("恭喜你,贏了");
                        cm.dispose();
                        cm.worldMessage(6,"[賭場公告]:玩家 " + cm.getPlayer().getName() + " ,在賭場選大小點贏了,將籌碼x5翻了【兩倍】獲得500點GASH!");
                        return;
                    } else {
                        cm.sendOk("唉,輸了");
                        cm.dispose();
                        return;
                    }
                } else {
                    cm.sendOk("你沒有足夠的GASH~");
                    cm.dispose();
                    return;
                }
            }
        } else if (selection == 3) {
            if (cm.getPlayer().getLevel() < 25) {
                cm.sendOk("必須達到25級才能使用。");
                cm.dispose();
                return;
            } else {
                if (cm.getPlayer().getCSPoints(1) >= 500) {
                    cm.getPlayer().modifyCSPoints(1, -500, true);
                    var rand = Math.floor(Math.random() * 100);
                    if (rand < 50) {
                        cm.getPlayer().modifyCSPoints(1, 1000, true);
                        cm.gainItem(4031189,1);
                        cm.sendOk("恭喜你,贏了");
                        cm.dispose();
                        cm.worldMessage(6,"[賭場公告]:玩家 " + cm.getPlayer().getName() + " ,在賭場選大小點贏了,將籌碼x10翻了【兩倍】獲得1000點GASH!");
                        return;
                    } else {
                        cm.sendOk("唉,輸了");
                        cm.dispose();
                        return;
                    }
                } else {
                    cm.sendOk("你沒有足夠的GASH~");
                    cm.dispose();
                    return;
                }
            }
        }
    }
}

踩地雷




勝利的時候也會有時間顯示

JS

var DEBUG = false;
var HIDDEN_ITEM = 4031325, MINE_ITEM = 5021013, EXPLODED_ITEM = 5120009;//這邊可以設定隱藏的圖示(HIDDEN_ITEM)、鞭炮的圖示(EXPLODED_ITEM)、地雷的圖示(MINE_ITEM)
var Modes = [
    ["#d簡單#k", 5, 5, 4], //5*5 , 有3個地雷+1個鞭炮
    ["#b中等#k", 6, 6, 8], //6*6 , 有7個地雷+1個鞭炮
    ["#r困難#k", 7, 7, 15] //7*7 , 有14個地雷+1個鞭炮
];
var text = "";

var status;
var Board, Revealed;
var VALUE_REVEALED = 1, VALUE_HIDDEN = 0;
var ModeSelected = -1, StartTime = -1, NumCols = -1,
        NumRows = -1, NumMines = -1, LeftToBeRevealed = -1;
var Neighbors = [
    [-1, -1], [-1, 0], [-1, 1], [0, -1],
    [0, 1], [1, -1], [1, 0], [1, 1]
];
var Numbers = [ //這邊可以設定數字的樣式,預設是裝飾聖誕樹的紅色數字
    3990009, 3990000, 3990001, 3990002, 3990003,
    3990004, 3990005, 3990006, 3990007, 3990008
];

function start() {
    status = -1;
    action(1, 0, 0);
}
function Header() {
    return "#d============ 踩地雷 ============#k\r\n\r\n";
}
function ConstructModeSelectionString() {
    var ret = "";
    for (var i = 0; i < Modes.length; i++) {
        ret += "#L" + i + "#" + Modes[i][0] + " (" + Modes[i][1] + "x" + Modes[i][2] + ") 地雷數: " + Modes[i][3] + "#l\r\n";
    }
    return ret;
}
function InitializeBoard() {

    NumCols = Modes[ModeSelected][1];
    NumRows = Modes[ModeSelected][2];

    NumMines = Modes[ModeSelected][3];

    LeftToBeRevealed = NumCols * NumRows - NumMines;
    if (LeftToBeRevealed == 21) {
        text = "簡單模式";
    } else if (LeftToBeRevealed == 28) {
        text = "中等模式";
    } else if (LeftToBeRevealed == 34) {
        text = "困難模式";
    }
    Board = new Array(NumCols);
    for (var i = 0; i < NumCols; i++) {
        Board[i] = new Array(NumRows);
    }
    Revealed = new Array(NumCols);
    for (i = 0; i < NumCols; i++) {
        Revealed[i] = new Array(NumRows);
        for (var j = 0; j < NumRows; j++) {
            Revealed[i][j] = VALUE_HIDDEN;
        }
    }
    InitializeMines();
    InitializeMineCounts();
    InitializeBlankSpaces();
}
function InitializeMines() {
    var AllPosition = new Array(NumRows * NumCols);
    for (var i = 0; i < NumCols; i++) {
        for (var j = 0; j < NumRows; j++) {
            AllPosition[(i * NumCols) + j] = [i, j];
        }
    }
    Shuffle(AllPosition);
    for (i = 0; i < NumMines && AllPosition.length > 0; i++) {
        var NewMine = AllPosition.pop();
        Board[NewMine[0]][NewMine[1]] = MINE_ITEM;
    }
}
function InitializeMineCounts() {
    for (var r = 0; r < NumCols; r++) {
        for (var c = 0; c < NumRows; c++) {
            if (Board[r][c] != MINE_ITEM) {
                var Count = 0;
                for (var k = 0; k < Neighbors.length; k++) {
                    var NewR = r + Neighbors[k][0];
                    var NewC = c + Neighbors[k][1]
                    if (ValidPosition(NewR, NewC) && Board[NewR][NewC] == MINE_ITEM) {
                        Count++;
                    }
                }
                Board[r][c] = Numbers[Count];
            }
        }
    }
}
function InitializeBlankSpaces() {
    for (var i = 0; i < NumCols; i++) {
        for (var j = 0; j < NumRows; j++) {
            if (Board[i][j] == null) {
                Board[i][j] = HIDDEN_ITEM;
            }
        }
    }
}
function ConstructBoardString() {
    var ret = "剩下的數字數目: " + LeftToBeRevealed + "\r\n";
    var num = 0;
    for (var i = 0; i < NumCols; i++) {
        for (var j = 0; j < NumRows; j++) {
            if (Revealed[i][j] == VALUE_REVEALED) {
                ret += "#L" + num + "##v" + Board[i][j] + "##l";
            } else {
                if (DEBUG && Board[i][j] == MINE_ITEM) {
                    ret += "#L" + num + "##v" + MINE_ITEM + "##l";
                } else {
                    ret += "#L" + num + "##v" + HIDDEN_ITEM + "##l";
                }
            }
            num++;
        }
        ret += "\r\n";
    }
    return ret;
}
function ConstructEndBoardString() {
    var ret = "";
    var num = 0;
    for (var i = 0; i < NumCols; i++) {
        for (var j = 0; j < NumRows; j++) {
            if (Revealed[i][j] == VALUE_REVEALED) {
                if (Board[i][j] == MINE_ITEM) {
                    ret += "#v" + EXPLODED_ITEM + "#";
                } else {
                    ret += "#v" + Board[i][j] + "#";
                }
            } else {
                if (Board[i][j] == MINE_ITEM) {
                    ret += "#v" + MINE_ITEM + "#";
                } else {
                    ret += "#v" + HIDDEN_ITEM + "#";
                }
            }
            num++;
        }
        ret += "\r\n";
    }
    return ret;
}
function Shuffle(arr) {
    var i = arr.length;
    if (i == 0)
        return;
    while (--i) {
        var j = Math.floor(Math.random() * (i + 1));
        var tempi = arr[i];
        var tempj = arr[j];
        arr[i] = tempj;
        arr[j] = tempi;
    }
}
function ValidPosition(r, c) {
    return r >= 0 && r < NumRows && c >= 0 && c < NumCols;
}
function GetPositionFromSelection(sel) {
    return [(sel / NumCols) | 0, (sel % NumCols) | 0];
}
function IsGameOver() {
    return LeftToBeRevealed == 0;
}
function GetGameTime(End) {
    var Diff = End - StartTime;
    var MilliSec = (Diff % 1000) | 0;
    Diff /= 1000;
    var Min = (Diff / 60) | 0;
    var Sec = (Diff % 60) | 0;
    return ((Min < 10) ? "0" + Min : Min) + ":" + ((Sec < 10) ? "0" + Sec : Sec)
            + "." + ((MilliSec < 100) ? "0" + ((MilliSec < 10) ? "0" + MilliSec : MilliSec) : MilliSec);

}
function action(mode, type, selection) {
    if (mode == -1 || mode == 0)
        cm.dispose();
    else {
        if (status != 2)
            status++;

        if (status == 0) {
            cm.sendSimple(Header() + "請選擇模式:\r\n" + ConstructModeSelectionString())
        } else if (status == 1) {
            if (selection < 0 || selection > Modes.length) {
                cm.dispose();
                return;
            }
            ModeSelected = selection;
            InitializeBoard();
            cm.sendSimple(Header() + ConstructBoardString());
        } else if (status == 2) {
            if (StartTime == -1) {
                StartTime = (new Date()).getTime();
            }
            var SendStr = Header();
            var Move = GetPositionFromSelection(selection);
            if (!ValidPosition(Move[0], Move[1])) {
                cm.sendOk("PE Detected ...");
                return;
            }
            if (Revealed[Move[0]][Move[1]] == VALUE_REVEALED) {
                SendStr += "該空格已被打開啟 ...\r\n\r\n" + ConstructBoardString();
                cm.sendSimple(SendStr);
                return;
            }
            Revealed[Move[0]][Move[1]] = VALUE_REVEALED;
            LeftToBeRevealed--;
            SendStr += ConstructBoardString();
            if (Board[Move[0]][Move[1]] == MINE_ITEM) {
                cm.sendOk(Header() + ConstructEndBoardString() + "\r\n你輸了!! 遊戲時間: " + GetGameTime((new Date()).getTime()));
                cm.dispose();
            } else {
                if (IsGameOver()) {
                    cm.sendOk(Header() + ConstructEndBoardString() + "\r\n你贏了!! 遊戲時間: " + GetGameTime((new Date()).getTime()));
                    cm.worldMessage(6,"『踩地雷小遊戲』:恭喜玩家:" + cm.getPlayer().getName() + " 花費: " + GetGameTime((new Date()).getTime()) + " 成功完成了" + text + "的踩地雷!!!");
                    cm.getPlayer().modifyCSPoints(1, 200, true);
                    cm.gainItem(4031189,1);
                    cm.dispose();
                } else {
                    cm.sendSimple(SendStr);
                }
            }
        }
    }
}  

老虎機




這個本來也是下賭注的,但我一樣把它改成固定金額1000w

JS

/*老虎機*/

var status = 0;
var fee;
var winner;
var item=4021000;

var card1 = Math.floor(Math.random()*8+item);
var card2 = Math.floor(Math.random()*8+item);
var card3 = Math.floor(Math.random()*8+item);
var card4 = Math.floor(Math.random()*8+item);
var card5 = Math.floor(Math.random()*8+item);
var card6 = Math.floor(Math.random()*8+item);
var card7 = Math.floor(Math.random()*8+item);
var card8 = Math.floor(Math.random()*8+item);
var card9 = Math.floor(Math.random()*8+item);
/*這台老虎機是用各類水晶來遊戲的,從4021000(石榴石)-4021007(鑽石)*/

function start() {
status = -1;
action(1, 0, 0);
}

function action(mode, type, selection) {

if (mode == -1) {
cm.dispose();
} else {
if (mode == 0) {
cm.sendOk("你的損失。你或許可以贏得大錢。");
cm.dispose();
return;
}

if (mode == 1)
status++;
else
status--;

if (status == 0) {
cm.sendNext("你想玩#b老虎機#k嗎? 這個機台是六倍的賠率喔!!\r\n#v4021000##v4021001##v4021002##v4021003##v4021004##v4021005##v4021006##v4021007#寶石連線,就可獲勝");
} else if (status == 1) {
fee = 10000000;
cm.sendYesNo("你確定要下注 #r" + fee + "#k 楓幣嗎?... ");
} else if (status == 2) {
if (cm.getMeso() < fee) {
cm.sendOk("你沒有那麼多錢");
cm.dispose();
} else if (cm.getMeso() + fee * 6 > 2100000000) {
cm.sendOk("如果你贏了這一把,身上的錢會超過21億,請先將金錢存放至倉庫。");
cm.dispose();
} else { //這邊是判斷連線的部分
if (card1 == card2 && card2 == card3) {
winner = 1;
} else if (card1 == card5 && card5 == card9) {
winner = 1;
} else if (card4 == card5 && card5 == card6) {
winner = 1;
} else if (card7 == card8 && card8 == card9) {
winner = 1;
} else if (card7 == card5 && card5 == card3) {
winner = 1;
} else if (card1 == card4 && card4 == card7) {
winner = 1;
} else if (card2 == card5 && card5 == card8) {
winner = 1;
} else if (card3 == card6 && card6 == card9) {
winner = 1;
} else {
winner = 2;
}

if (winner == 1) {

cm.sendOk("老虎機: \r\n\r\n#v" +
card1 + "##v " + card2 + "##v " + card3 + "# \r\n#v" +
card4 + "##v " + card5 + "##v " + card6 + "# \r\n#v" +
card7 + "##v " + card8 + "##v " + card9 +
"#\r\n\r\n 恭喜!你贏了!");

cm.gainMeso(fee * 6); //這裡設定獎勵
cm.gainItem(4031189,1);
cm.dispose();

} else if (winner == 2) {

cm.sendOk("老虎機: \r\n\r\n#v" +
card1 + "##v " + card2 + "##v " + card3 + "# \r\n#v" +
card4 + "##v " + card5 + "##v " + card6 + "# \r\n#v" +
card7 + "##v " + card8 + "##v " + card9 +
"#\r\n\r\n 你輸了!再接再厲!");

cm.gainMeso(-fee);
cm.dispose();

} else {
cm.dispose();
}
}
}
}
}

Black Jack 精緻版的21點腳本

來源:Sharky

/**
*
* @author Sharky
* @info BlackJack NPC
*/
importPackage(java.lang);
var debug = false; // set to true for debugging checks to appear in your .bat files
var status = 0, bet, selected;
var whichFunction = {"HowToPlay" : false, "PlayGame" : false, "SpendChips" : false};
var playingAction = {"Hit" : false, "Stay" : false};
var CardsInDeck = [[], []], CardsInPlayerHand = [[], []], CardsInDealerHand = [[], []];
var prizes = [[4001008], [10]]; // Item 4001008 (Pass) costs 10 Chips
// var prizes = [[enter, item, ids, here, like, so], [enter, amount, of, chips, needed, for, corresponding, item, here, like, so]];

function start() {
cm.sendSimple("你好!我是#rBlackJack莊家#k.#b \r\n\t#L0#我該怎麼玩BlackJack?#l \r\n\t#L1#我想玩Black Jack!#l \r\n\t#L2#我想用我的Black Jack 籌碼換取獎品!#l");
}

function action(m,t,s) {
if(m == -1 || (m != 1 && whichFunction["PlayGame"])) {
cm.dispose();
return;
} else {
if(m == 1) {
status++;
} else {
status--;
}
if(!whichFunction["HowToPlay"] && !whichFunction["PlayGame"] && !whichFunction["SpendChips"]) {
whichFunction[s == 0 ? "HowToPlay" : s == 1 ? "PlayGame" : "SpendChips"] = true;
}
if(whichFunction["HowToPlay"]) {
HowToPlay();
} else if (whichFunction["PlayGame"]) {
PlayGame(s);
} else if (whichFunction["SpendChips"]) {
SpendChips(s);
}
}
}

function HowToPlay() {
if(status == 1) {
if(debug) {
System.out.println("HowToPlay() is progressing...");
}
cm.sendNext("好吧,我看到我們這裡有一個菜鳥!不用擔心,我會很樂意教您如何玩 #rBlackJack#k!");
} else if (status == 2) {
cm.sendNextPrev("系統會給您 #b籌碼#k玩遊戲。這些#b籌碼#k 是給您用來下注的!在發給您任何牌之前,您必須先下注。如果您贏得一輪,您的籌碼將增加一倍,如果您只抽兩張牌就達到#bBlack Jack#k(21點),您的籌碼將被返還2.5倍!");
} else if (status == 3) {
cm.sendNextPrev("在遊戲開始時,您將獲得2張卡。計算這些卡並加總值。 #b遊戲的目標是當您將手中的所有卡牌加在一起時獲得21點(或接近21點)。#k. 完成此操作後,您可以選擇#bHit#k (用來抽出另一張牌), 或 #bStay#k. 如果您選擇#bhit#k, 請記住,超過21點將導致您#r爆掉#k, 或將游戲輸給發牌人。如果您認為自己已經接近21,並且希望#bstay#k, 您將和發牌者將比較大小,最接近21者勝!");
} else if (status == 4) {
cm.sendPrev("請記住,如果輸了,您給發牌者的所有#b籌碼#k都會輸掉!祝好運!");
} else if (status == 5) {
cm.dispose();
}
}    

function PlayGame(s) {
if(status == 1) {
if(debug) {
System.out.println("PlayGame() is progressing...");
}
if(cm.getPlayer().getBlackJackChips() == 0) {
cm.getPlayer().gainBlackJackChips(5);
}
cm.sendGetNumber("您目前有 #b" + cm.getPlayer().getBlackJackChips() + " BlackJack 籌碼#k. 多少 #b籌碼#k 你想在本輪投注?", 1, 1, cm.getPlayer().getBlackJackChips());
} else if (status == 2) {
if(s > 0 && s <= cm.getPlayer().getBlackJackChips()) { // packet edits
bet = s;
if(debug) {
System.out.println("Deck Initializing...");
}
InitializeGame();
var totP = GetTotalCardValue("Player"), totD = GetTotalCardValue("Dealer");
if(totD == 21 && CardsInDealerHand[0].length == 2 && totP == 21 && CardsInPlayerHand[0].length == 2) {
Finish("Tie");
} else if (totP == 21 && CardsInPlayerHand[0].length == 2) {
Finish("Player21");
} else if (totD == 21 && CardsInDealerHand[0].length == 2) {
Finish("Dealer21");
} else {
DisplayHandWithProgression();
}
}
} else if (status > 2) {
playingAction[s == 0 ? "Hit" : "Stay"] = true;
var totP, totD;
if(playingAction["Stay"]) {
if(debug) {
System.out.println("玩家選擇 Stay.");
}
if(totD < 16) {
CompleteDealer();
if(debug) {
System.out.println("當玩家選擇Stay時,發牌者低於16,發牌者成功完成。");
}
}
totP = GetTotalCardValue("Player"), totD = GetTotalCardValue("Dealer");
if(totP > 21 && totD > 21) {
Finish("DoubleBust");
} else if (totP > 21) {
Finish("PlayerBust");
} else if (totD > 21) {
Finish("DealerBust");
} else if(totP == totD) {
Finish("Tie");
} else if (totP == 21 && CardsInPlayerHand[0].length == 2) {
Finish("Player21");
} else if (totD == 21 && CardsInDealerHand[0].length == 2) {
Finish("Dealer21");
} else if (totP > totD) {
Finish("Win");
} else if (totP < totD) {
Finish("Lose");
}
} else if(playingAction["Hit"]) {
AddCardToHand();
totP = GetTotalCardValue("Player"), totD = GetTotalCardValue("Dealer");
if(totD == 21 && CardsInDealerHand[0].length == 2 && totP == 21 && CardsInPlayerHand[0].length == 2) {
Finish("Tie");
} else if (totP == 21 && CardsInPlayerHand[0].length == 2) {
Finish("Player21");
} else if (totD == 21 && CardsInDealerHand[0].length == 2) {
Finish("Dealer21");
} else if (totP > 21) {
Finish("PlayerBust");
} else if (totD > 21) {
Finish("DealerBust");
} else {
DisplayHandWithProgression();
}
}
}
}

function InitializeGame() {
var cardNames = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace"];
var cardSuits = ["Hearts", "Spades", "Diamonds", "Clubs"];
for(var i = 0, a = 0; a < cardNames.length; i++) {
if(i == 4) {
a++;
i = 0;
}
CardsInDeck[0].push(cardNames[a]);
CardsInDeck[1].push(cardSuits[i]);
}
CardsInDeck[0].splice(-1);
CardsInDeck[1].splice(-1);
if(debug) {
for(var i = 0; i < CardsInDeck[0].length; i++) {
System.out.println(CardsInDeck[0][i] + " of " + CardsInDeck[1][i] + " pushed.");
}
}
AddCardToHand();
AddCardToHand();
}

function AddCardToHand() {
var random;
random = Math.floor(Math.random() * CardsInDeck[0].length);
CardsInPlayerHand[0].push(CardsInDeck[0][random]);
CardsInPlayerHand[1].push(CardsInDeck[1][random]);
if(debug) {
System.out.println("Card Added to Player Hand: " + CardsInDeck[0][random] + " of " + CardsInDeck[1][random]);
}
for(var i = 0; i < CardsInDeck[0].length; i++) {
if(CardsInPlayerHand[0][CardsInPlayerHand[0].length - 1] == CardsInDeck[0][i] && CardsInPlayerHand[1][CardsInPlayerHand[1].length - 1] == CardsInDeck[1][i]) {
if(debug) {
System.out.println("Card Spliced from Deck: " + CardsInDeck[0][i] + " of " + CardsInDeck[1][i]);
}
CardsInDeck[0].splice(i, 1);
CardsInDeck[1].splice(i, 1);
break;
}
}
if(GetTotalCardValue("Dealer") < 16) {
random = Math.floor(Math.random() * CardsInDeck[0].length);
CardsInDealerHand[0].push(CardsInDeck[0][random]);
CardsInDealerHand[1].push(CardsInDeck[1][random]);
if(debug) {
System.out.println("Card Added to Dealer Hand: " + CardsInDeck[0][random] + " of " + CardsInDeck[1][random]);
}
for(var i = 0; i < CardsInDeck[0].length; i++) {
if(CardsInDealerHand[0][CardsInDealerHand[0].length - 1] == CardsInDeck[0][i] && CardsInDealerHand[1][CardsInDealerHand[1].length - 1] == CardsInDeck[1][i]) {
if(debug) {
System.out.println("Card Spliced from Deck: " + CardsInDeck[0][i] + " of " + CardsInDeck[1][i]);
}
CardsInDeck[0].splice(i, 1);
CardsInDeck[1].splice(i, 1);
break;
}
}
}
}

function CompleteDealer() {
while (GetTotalCardValue("Dealer") < 16) {
var random = Math.floor(Math.random() * CardsInDeck[0].length);
CardsInDealerHand[0].push(CardsInDeck[0][random]);
CardsInDealerHand[1].push(CardsInDeck[1][random]);
if(debug) {
System.out.println("Card Added to Dealer Hand: " + CardsInDeck[0][random] + " of " + CardsInDeck[1][random]);
}
for(var i = 0; i < CardsInDeck[0].length; i++) {
if(CardsInDealerHand[0][CardsInDealerHand[0].length - 1] == CardsInDeck[0][i] && CardsInDealerHand[1][CardsInDealerHand.length - 1] == CardsInDeck[1][i]) {
if(debug) {
System.out.println("Card Spliced from Deck: " + CardsInDeck[0][i] + " of " + CardsInDeck[1][i]);
}
CardsInDeck[0].splice(i, 1);
CardsInDeck[1].splice(i, 1);
break;
}
}
}
}

function GetValueByName(name) {
var nums = [["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace"], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11]];
for(var i = 0; i < nums[0].length; i++) {
if(name == nums[0][i]) {
return nums[1][i];
}
}
}

function DisplayHandWithProgression() {
var text = "#d#n你手中的牌:#k#e"
if(CardsInPlayerHand[0].length > 1) {
text += "\r\n#e第一張牌:#n #d" + CardsInPlayerHand[0][0] + "#k of " + (CardsInPlayerHand[1][0].equals("Hearts") || CardsInPlayerHand[1][0].equals("Diamonds") ? ("#r" + CardsInPlayerHand[1][0] + "#k") : CardsInPlayerHand[1][0]) +
"\r\n#e第二張牌:#n #d" + CardsInPlayerHand[0][1] + "#k of " + (CardsInPlayerHand[1][1].equals("Hearts") || CardsInPlayerHand[1][1].equals("Diamonds") ? ("#r" + CardsInPlayerHand[1][1] + "#k") : CardsInPlayerHand[1][1]);
}
if (CardsInPlayerHand[0].length > 2) {
text += "\r\n#e第三張牌:#n #d" + CardsInPlayerHand[0][2] + "#k of " + (CardsInPlayerHand[1][2].equals("Hearts") || CardsInPlayerHand[1][2].equals("Diamonds") ? ("#r" + CardsInPlayerHand[1][2] + "#k") : CardsInPlayerHand[1][2]);
}
if (CardsInPlayerHand[0].length > 3) {
text += "\r\n#e第四張牌:#n #d" + CardsInPlayerHand[0][3] + "#k of " + (CardsInPlayerHand[1][3].equals("Hearts") || CardsInPlayerHand[1][3].equals("Diamonds") ? ("#r" + CardsInPlayerHand[1][3] + "#k") : CardsInPlayerHand[1][3]);
}
if (CardsInPlayerHand[0].length > 4) {
text += "\r\n#e第五張牌:#n #d" + CardsInPlayerHand[0][4] + "#k of " + (CardsInPlayerHand[1][4].equals("Hearts") || CardsInPlayerHand[1][4].equals("Diamonds") ? ("#r" + CardsInPlayerHand[1][4] + "#k") : CardsInPlayerHand[1][4]);
}
text += "\r\n\r\n#e總額: #b" + GetTotalCardValue("Player");
if(CardsInPlayerHand[0].length > 4) {
text += "\r\n看來您必須#bstay#k看看結果如何。#b \r\n\t#L1#Stay#l";
} else {
text += "\r\n你想選擇什麼?#b \r\n\t#L0#Hit#l \r\n\t#L1#Stay#l";
}
cm.sendSimple(text);
}

function GetTotalCardValue(name) {
var sum = 0;
if(name.equals("Player")) {
for(var i = 0; i < CardsInPlayerHand[0].length; i++) {
sum += GetValueByName(CardsInPlayerHand[0][i]);
}
} else if (name.equals("Dealer")) {
for(var i = 0; i < CardsInDealerHand[0].length; i++) {
sum += GetValueByName(CardsInDealerHand[0][i]);
}
}
return sum;
}

function Finish(action) {
if(action.equals("DoubleBust")) {
cm.sendOk("看起來我們倆都#r爆#k了! \r\n#b你手中的牌:#k \r\n\t" + DisplayCardsInHand("Player") + " \r\n#r我手中的牌:#k \r\n\t" + DisplayCardsInHand("Dealer") + " \r\n我想沒人勝利.");
} else if (action.equals("PlayerBust")) {
cm.sendOk("哈哈,你看起來 #r爆#k了! \r\n#b你手中的牌:#k \r\n\t" + DisplayCardsInHand("Player") + " \r\n#r我手中的牌:#k \r\n\t" + DisplayCardsInHand("Dealer") + " \r\n抱歉,但是我好像要把你的 #b籌碼#k拿走!");
cm.getPlayer().gainBlackJackChips(-bet);
} else if (action.equals("DealerBust")) {
cm.sendOk("我不能相信! 我 #r爆#k了! \r\n#b你手中的牌:#k \r\n\t" + DisplayCardsInHand("Player") + " \r\n#r我手中的牌:#k \r\n\t" + DisplayCardsInHand("Dealer") + " \r\n看來您已經贏得了一些#b籌碼#k!");
cm.getPlayer().gainBlackJackChips(bet);
} else if (action.equals("Tie")) {
cm.sendOk("We tied! \r\n#b你手中的牌:#k \r\n\t" + DisplayCardsInHand("Player") + "\r\n#r我手中的牌:#k \r\n\t" + DisplayCardsInHand("Dealer") + " \r\n看來我們倆都沒贏...");
} else if (action.equals("Player21")) {
cm.sendOk("Wow! 你有 #rBlackJack#k! 這代表你用兩張牌得到 #r21 #k! \r\n#b你手中的牌:#k \r\n\t" + DisplayCardsInHand("Player") + " \r\n你贏得了 #b2.5x 的籌碼#k");
cm.getPlayer().gainBlackJackChips(bet + (bet % 2 != 0 ? ((bet + 1) / 2) : (bet / 2)));
} else if (action.equals("Dealer21")) {
cm.sendOk("#rBLACKJACK!#k 哈哈,看來我以兩張牌贏了#r21#k! \r\n#r我手中的牌:#k \r\n\t" + DisplayCardsInHand("Dealer") + " \r\n抱歉,看來我必須帶走您的#b籌碼#k! 下次好運!");
cm.getPlayer().gainBlackJackChips(-bet);
} else if (action.equals("Win")) {
cm.sendOk("我不敢相信,你贏了! \r\n#b你手中的牌:#k \r\n\t" + DisplayCardsInHand("Player") + "\r\n#r我手中的牌:#k \r\n\t" + DisplayCardsInHand("Dealer") + " \r\n看來您贏了一些 #b籌碼#k!");
cm.getPlayer().gainBlackJackChips(bet);
} else if (action.equals("Lose")) {
cm.sendOk("哈哈,看起來你輸了! \r\n#b你手中的牌:#k \r\n\t" + DisplayCardsInHand("Player") + "\r\n#r我手中的牌:#k \r\n\t" + DisplayCardsInHand("Dealer") + " \r\n抱歉,看來我必須帶走您的#b籌碼#k! 下次好運!");
cm.getPlayer().gainBlackJackChips(-bet);
}
if(debug) {
System.out.println("Finish() carried out with a " + action);
}
cm.dispose();
}

function DisplayCardsInHand(name) {
var cards = "";
if(name.equals("Player")) {
for(var i = 0; i < CardsInPlayerHand[0].length; i++) {
cards += ("#d" + CardsInPlayerHand[0][i] + "#k of " + (CardsInPlayerHand[1][i].equals("Hearts") || CardsInPlayerHand[1][i].equals("Diamonds") ? ("#r" + CardsInPlayerHand[1][i] + "#k") : CardsInPlayerHand[1][i]) + (i != (CardsInPlayerHand[0].length - 1) ? ", " : "."));
}
} else if (name.equals("Dealer")) {
for(var i = 0; i < CardsInDealerHand[0].length; i++) {
cards += ("#d" + CardsInDealerHand[0][i] + "#k of " + (CardsInDealerHand[1][i].equals("Hearts") || CardsInDealerHand[1][i].equals("Diamonds") ? ("#r" + CardsInDealerHand[1][i] + "#k") : CardsInDealerHand[1][i]) + (i != (CardsInDealerHand[0].length - 1) ? ", " : "."));
}
}
return cards;
}

function SpendChips(s) {
if(status == 1) {
if(debug) {
System.out.println("SpendChips() progressing...");
}
var text = "你目前有 #b" + cm.getPlayer().getBlackJackChips() + " Black Jack 籌碼#k. 你想要換取什麼?";
for(var i = 0; i < prizes[0].length; text += "\r\n#L" + i + "##i" + prizes[0][i] + "##b ~ #t" + prizes[0][i] + "##k for #r" + prizes[1][i] + " Black Jack 籌碼#k#l", i++);
cm.sendSimple(text);
} else if (status == 2) {
selected = s;
cm.sendYesNo("您確定要購買 #i" + prizes[0][s] + "##b ~ #t" + prizes[0][s] + "##k 以 #r" + prizes[1][s] + " Black Jack 籌碼#k?");
} else if (status == 3) {
if(cm.getPlayer().getBlackJackChips() >= prizes[1][selected]) {
cm.gainItem(prizes[0][selected]);
cm.getPlayer().gainBlackJackChips(-prizes[1][selected]);
cm.sendOk("感謝參與!享受您的獎品,然後再來!");
cm.dispose();
} else {
cm.sendOk("你還需要 #r" + (prizes[1][selected] - cm.getPlayer().getBlackJackChips()) + "  Black Jack 籌碼#k 才能兌換這個獎品!");
cm.dispose();
}
cm.dispose();
}
}

GEMZ

來源:Emilyx3

/**
 * Gems Game NPC
 * Author: Emilyx3 of UMaple
 */

var Board;
var Score = 0;
var GameType = -1, BoardSize = -1, NumCols = -1, NumRows = -1,
NumGemTypes = -1, Difficulty = -1, NextComboMultiplier = 0,
GameTime = 180000 /*3 Minutes in Milliseconds*/, GameStart = -1;
var GameTypes = [
["普通模式", "玩一場常規遊戲"],
["時間攻擊模式", "3分鐘內盡可能獲取多的積分"]
//, ["Puzzle", "Solve puzzles"] // May add Puzzle mode later.
];
var BoardSizes = [
//Board Size Name, Number of Rows, Number of Cols
["Small", 6, 5],
["Medium", 7, 6],
["Large", 8, 7],
["Huge", 10, 7]
];
var Difficulties = [
//Difficulty Name, Number of Gem Types
["Very Easy", 4],
["Easy", 5],
["Medium", 6],
["Hard", 7]
];
var GameDropProbability = 0.01 / 100;
var GameDrops = [
//ItemID, Drop Probability (Should add Up to 1)
[5200000, 0.25],[5200001, 0.20],[5200002, 0.15],
[4031701, 0.05],[4001013, 0.10],[2340000, 0.25]
];
var Gems = [
//Ore, Gem
[4020000, 4021000], [4020001, 4021001], [4020002, 4021002], [4020003, 4021003],
[4020004, 4021004], [4020005, 4021005], [4020006, 4021006], [4020007, 4021007],
[4020008, 4021008]
];
var Neighbors4 = [[0,1],[0,-1],[-1,0],[1,0]];
var Neighbors8 = [[-1, -1],[-1, 0],[-1, 1],[0, -1],[0, 1],[1, -1],[1, 0], [1, 1]];
var status;

function Header() {
    return "#b============#kGEMZ#b============#k\r\n\r\n";
}
function MenuScreen() {
    return Header() +
    "請選擇:\r\n\r\n" +
    "#L0#開始遊戲#l\r\n" +
    "#L1#遊戲介紹#l";
}
function SendGameInstructions() {
    cm.sendNext(Header() +
        "#e遊戲介紹:#n\r\n" +
        "1. 通過單擊3塊連線或更多塊連線的礦石/寶石以獲得分數。\r\n" +
        "2. 您每破壞一組連線可獲得5點,如果消除高於3塊的連線可以+5%的分數。\r\n" +
        "3. 當您破壞礦石有機會(1次)將變成一個寶石。" +
        "如果寶石連線可得到30分。您也可以直接單擊寶石,但只能獲得20分。\r\n" +
        "4. 過程中可能出現特殊道具。它們有各自的功用:\r\n" +
        "    #v5021013# - 銷毀周圍的8格礦石/寶石(不影響特殊物品)。\r\n" +
        "    #v4031051# - 將周圍的8格變成寶石。\r\n" +
        "    #v4031311# - 將計時器增加2秒。(僅時間攻擊模式)\r\n" +
        "    #v3990021##v3990023# - 紅色(水平銷毀所有礦石/寶石),綠色(水平銷毀所有礦石為寶石)\r\n" +
        "    #v3991008##v3991034# - 紅色(垂直銷毀所有礦石/寶石),綠色(垂直銷毀所有礦石)\r\n" +
        "    #v3990020# - 垂直和水平存儲所有礦石/寶石\r\n" +
        "    每個被銷毀的礦石價值10分。被摧毀的寶石各值25分。特殊物品和掉落物品不會被銷毀。\r\n" +
        "5. 過程中可能會出現獎勵道具。單擊它們可以獲取它們:\r\n" +
        "    #v5200000##v5200001##v5200002##v4031701##v4001013##v2340000#\r\n" +
        "\r\nGood Luck ~"
        );
}
function SendGameTypeSelectionMenu() {
    var SendStr = Header();
    for (var i = 0;i < GameTypes.length;i++) {
        SendStr += "#L"+i+"#"+GameTypes[i][0]+" - "+GameTypes[i][1]+"#l\r\n";
    }
    cm.sendSimple(SendStr);
}
function SendBoardSizeSelectionMenu() {
    var SendStr = Header();
    for (var i = 0;i < BoardSizes.length;i++) {
        SendStr += "#L"+i+"#"+BoardSizes[i][0]+" - "+BoardSizes[i][1]+"x"+BoardSizes[i][2]+"#l\r\n";
    }
    cm.sendSimple(SendStr);
}
function SendDifficultySelectionMenu() {
    var SendStr = Header();
    for (var i = 0;i < Difficulties.length;i++) {
        SendStr += "#L"+i+"#"+Difficulties[i][0]+" - "+Difficulties[i][1]+" Gem Types#l\r\n";
    }
    cm.sendSimple(SendStr);
}
function InitializeBoard() {
    NumRows = BoardSizes[BoardSize][1];
    NumCols = BoardSizes[BoardSize][2];
    Board = new Array(NumRows);
    for (var i = 0;i < Board.length;i++) {
        Board[i] = new Array(NumCols);
    }
}
function InitializeGems() {
    NumGemTypes = Difficulties[Difficulty][1];
    Shuffle(Gems);
    for (var r = 0;r < Board.length;r++) {
        for (var c = 0;c < Board[r].length;c++) {
            Board[r][c] = GetRandomOre();
        }
    }
}
function GetRandomOre() {
    return Gems[Math.floor(Math.random() * NumGemTypes)][0];
}
function GetScoreString() {
    return "#b#e遊戲分數:#n#k " + AddCommas(Score.toFixed(2)) + "\r\n";
}
function GetGameSettingsDescriptionString() {
    return "#d#e遊戲設定:#n#k " + GameTypes[GameType][0]
    + " - 大小: " + BoardSizes[BoardSize][0] + "("+ BoardSizes[BoardSize][1]+"x" + BoardSizes[BoardSize][2]
    + ") - 難易度: " + Difficulties[Difficulty][0] + "\r\n";
}
function AddCommas(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}
function GetGameEndBoardString() {
    var SendStr = "";
    for (var r = 0;r < Board.length;r++) {
        for (var c = 0;c < Board[r].length;c++) {
            SendStr += "#v"+Board[r][c]+"#";
        }
        SendStr += "\r\n";
    }
    SendStr += "\r\n";
    return SendStr;
}
function GetBoardSelectionString() {
    var SendStr = "";
    var Count = 0;
    for (var r = 0;r < Board.length;r++) {
        for (var c = 0;c < Board[r].length;c++) {
            SendStr += "#L"+(Count++)+"##v"+Board[r][c]+"##l";
        }
        SendStr += "\r\n";
    }
    SendStr += "\r\n";
    return SendStr;
}
function ContainsGem(Combo, GemGroup) {
    for (var i = 0;i < Combo.length;i++) {
        if (Board[Combo[i][0]][Combo[i][1]] == GemGroup[1]) {
            return true;
        }
    }
    return false;
}
function DoMove(Move) {
    var ItemID = Board[Move[0]][Move[1]];
    var GemGroup = GetGemGroup(ItemID);
    var Combo = new Array();
    var IsSpecialItem = false;
    Combo.push([Move[0],Move[1]]);
    if (GemGroup != null) {
        //Normal Gem
        GetNeighborGems(Move[0],Move[1],GemGroup,Combo);
        if (Combo.length < 3) {
            if (!ContainsGem(Combo, GemGroup)) {
                return false;
            }
        }
        AddScoreForCombination(Combo, GemGroup);
    } else if (IsDropItem(ItemID)) {
        cm.gainItem(ItemID, 1);
    } else {
        //Special Item
        UseSpecialItem(ItemID, Move[0], Move[1], Combo);
        IsSpecialItem = true;
    }
    RemoveAndGenerateNewGems(Combo, Move[0], Move[1], GemGroup, IsSpecialItem);
    return true;
}

function RemoveGemAndShiftDown(r, c) {
    for (var i = r;i > 0;i--) {
        Board[i][c] = Board[i-1][c];
    }
    return [0, c];
}
function RemoveAndGenerateNewGems(Combo, r, c, GemGroup, IsSpecialItem) {
    var DropItemProb = (IsSpecialItem ? 0 : GameDropProbability + ((Combo.length > 5) ? (GameDropProbability / 10) * (Combo.length - 5) : 0));
    var SpecialItemProb = (IsSpecialItem ? 0 : 0.005 + (Combo.length > 3 ? 0.01 * (Combo.length - 3) : 0.0) + DropItemProb);
    for (var i = 0;i < Combo.length;i++) {
        var TurnToGemProb = 0.20 + ((Combo.length > 3) ? 0.2 * (Combo.length - 3) : 0.0);
        if (Combo[i][0] == r && Combo[i][1] == c && GemGroup != null
            && GemGroup[0] == Board[r][c] && Math.random() < TurnToGemProb) {
            Board[r][c] = GemGroup[1];
        } else {
            var NewGemLocation = RemoveGemAndShiftDown(Combo[i][0],Combo[i][1]);
            for (var j = i + 1; j < Combo.length;j++) {
                if (Combo[j][1] == Combo[i][1] && Combo[j][0] < Combo[i][0]) {
                    Combo[j][0]++;
                }
            }
            if (c == Combo[i][1] && r < Combo[i][0]) {
                r++;
            }
            var Ret = RandomOreGemDrop(NewGemLocation[0], NewGemLocation[1], DropItemProb, SpecialItemProb);
            //Only allow 1 item drop and 1 Special Item drop per combo.
            if (Ret == 1) {
                SpecialItemProb = 0;
            } else if (Ret == 2) {
                DropItemProb = 0; 
            }
        }
    }
}
function UseSpecialItem(ItemID, r, c, ToBeRemoved) {
    Score += 10;
    var Targets = new Array();
    switch (ItemID) {
        case 5021013:
        case 4031051:
            for (var i = 0;i < Neighbors8.length;i++) {
                var NewR = r + Neighbors8[i][0];
                var NewC = c + Neighbors8[i][1];
                Targets.push([NewR, NewC]);
            }
            break;
        case 3990021:
        case 3990023:
            for (i = 0;i < Board[r].length;i++) {
                if (i != c) {
                    Targets.push([r, i]);
                }
            }
            break;
        case 3991008:
        case 3991034:
            for (i = 0;i < Board.length;i++) {
                if (i != r) {
                    Targets.push([i, c]);
                }
            }
            break;
        case 3990020:
            for (i = 0;i < Board[r].length;i++) {
                if (i != c) {
                    Targets.push([r, i]);
                }
            }
            for (i = 0;i < Board.length;i++) {
                if (i != r) {
                    Targets.push([i, c]);
                }
            }
            break;
    }
    if (ItemID == 4031311) {
        GameTime += 2000;
    }
    switch (ItemID) {
        case 4031051:
        case 3990023:
        case 3991034:
            for (i = 0;i < Targets.length;i++) {
                if (ValidPosition(Targets[i][0], Targets[i][1])) {
                    var GemGroup = GetGemGroup(Board[Targets[i][0]][Targets[i][1]]);
                    if (GemGroup != null) {
                        if (GemGroup[0] == Board[Targets[i][0]][Targets[i][1]]) {
                            Board[Targets[i][0]][Targets[i][1]] = GemGroup[1];
                        }
                    }
                }
            }
            break;
        case 5021013:
        case 3990021:
        case 3991008:
        case 3990020:
            for (i = 0;i < Targets.length;i++) {
                if (ValidPosition(Targets[i][0], Targets[i][1])) {
                    GemGroup = GetGemGroup(Board[Targets[i][0]][Targets[i][1]]);
                    if (GemGroup != null) {
                        if (GemGroup[0] == Board[Targets[i][0]][Targets[i][1]]) {
                            Score += 10;
                        } else if (GemGroup[1] == Board[Targets[i][0]][Targets[i][1]]) {
                            Score += 25;
                        }
                        ToBeRemoved.push([Targets[i][0], Targets[i][1]]);
                    }
                }
            }
            break;
    }
}
function IsDropItem(ItemID) {
    var Len = GameDrops.length;
    while (Len--) {
        if (GameDrops[Len][0] == ItemID) {
            return true;
        }
    }
    return false;
}

function IsOreOrGem(ItemID) {
    for (var i = 0;i < Gems.length;i++) {
        for (var j = 0;j < Gems[i].length;i++) {
            if (Gems[i][j] == ItemID)
                return true;
        }
    }
    return false;
}

function GetDropItem() {
    var R = Math.random();
    var tot = 0;
    for (var i = 0;i < GameDrops.length;i++) {
        tot += GameDrops[i][1];
        if (R < tot) {
            return GameDrops[i][0];
        }
    }
    return 5200000; //Just in case.
}
function RandomOreGemDrop(r, c, DropItemProb, SpecialItemProb) {
    var R = Math.random();
    if (R < DropItemProb) {
        //Generate a Drop
        Board[r][c] = GetDropItem();
        return 2;
    } else if (R < SpecialItemProb) {
        //Generate Special Item
        Board[r][c] = GetRandomSpecialItem();
        return 1;
    } else {
        //Normal Ore
        Board[r][c] = GetRandomOre();
        return 0;
    }
}

/*
#v5021013# - Destroy surrounding 8 Ores/Gems (Does not affect special items). (25 points / destroyed item)\r\n" +
#v4031051# - Turns the surrounding 8 Ores into Gems.\r\n" +
#v4031311# - Add 2 seconds to timer. (Only Time Attack mode)\r\n" +
#v3990021##v3990023# - Red(Destroy all Ores/Gems Horizontally - 25 points / destroyed item), Green(Turn all Ores into Gems Horizontally)\r\n" +
#v3991008##v3991034# - Red(Destroy all Ores/Gems Vertically - 25 points / destroyed item), Green(Turn all Ores into Gems Vertically)\r\n" +
#v3990020# - Destory all Ores/Gems Vertically and Horizontally (25 points / destroyed item)\r\n" +
 */
function GetRandomSpecialItem() {
    var Prob = Math.random();
    if (GameType == 1 && Math.random() < 0.25) {
        return 4031311;
    }
    if (Prob < 0.10) {
        return 3990020;
    } else if (Prob < 0.25) {
        return 3991008;
    } else if (Prob < 0.35) {
        return 3991034;
    } else if (Prob < 0.50) {
        return 3990021;
    } else if (Prob < 0.60) {
        return 3990023;
    } else if (Prob < 0.70) {
        return 4031051;
    } else {
        return 5021013;
    }
}
function AddScoreForCombination(Combo, GemGroup) {
    var Multiplier = 1.0 + (Combo.length > 3 ? 0 : 0.05 * (Combo.length - 3))
    + NextComboMultiplier;
    if (Combo.length == 3) {
        NextComboMultiplier = 0;
    } else if (Combo.length == 4) {
        NextComboMultiplier += 0.01;
    } else if (Combo.length == 5) {
        NextComboMultiplier += 0.015;
    } else if (Combo.length > 5) {
        NextComboMultiplier += 0.02;
    }
    var Points = 0;
    for (var i = 0;i < Combo.length;i++) {
        var ItemID = Board[Combo[i][0]][Combo[i][1]];
        if (GemGroup[0] == ItemID) {
            Points += 5;
        } else if (GemGroup[1] == ItemID) {
            if (Combo.length >= 3) {
                Points += 30;
            } else {
                Points += 20;
            }
        }
    }
    Score += (Points * Multiplier);
}
function NoMoreMoves() {
    for (var i = 0;i < Board.length;i++) {
        for (var j = 0;j < Board[i].length;j++) {
            var GemGroup = GetGemGroup(Board[i][j]);
            if (GemGroup == null) { //Special Item
                return false;
            } else {
                var GetCount = new Array();
                GetCount.push([i,j]);
                GetNeighborGems(i, j, GemGroup, GetCount);
                if (GetCount.length > 2) {
                    return false;
                }
            }
        }
    }
    return true;
}
function GetNeighborGems(r, c, GemGroup, ToBeRemoved) {
    var CheckNeighbors = new Array();
    for (var i = 0;i < Neighbors4.length;i++) {
        var NewR = r + Neighbors4[i][0];
        var NewC = c + Neighbors4[i][1]
        if (ValidPosition(NewR, NewC) && Contains(Board[NewR][NewC], GemGroup)) {
            if (PushIfNotPresent([NewR, NewC], ToBeRemoved)) {
                CheckNeighbors.push([NewR, NewC]);
            }
        }
    }
    for (i = 0;i < CheckNeighbors.length;i++) {
        GetNeighborGems(CheckNeighbors[i][0], CheckNeighbors[i][1], GemGroup, ToBeRemoved);
    }
}
function ValidPosition(r, c) {
    return r >= 0 && r < NumRows && c >= 0 && c < NumCols;
}
function Contains(ItemID, GemGroup) {
    var i = GemGroup.length;
    while (i--) {
        if (GemGroup[i] == ItemID) {
            return true;
        }
    }
    return false;
}
function PushIfNotPresent(Move, Combo) {
    var i = Combo.length;
    while (i--) {
        var Comp = Combo[i];
        if (Comp[0] == Move[0] && Comp[1] == Move[1]) {
            return false;
        }
    }
    Combo.push(Move);
    return true;
}
function GetPositionFromSelection(sel) {
    return [(sel / NumCols) | 0, (sel % NumCols) | 0];
}
function GetGemGroup(ItemID) {
    for (var i = 0; i < Gems.length;i++) {
        for (var j = 0;j < Gems[i].length;j++) {
            if (Gems[i][j] == ItemID) {
                return Gems[i];
            }
        }
    }
    return null;
}
function Shuffle(arr) {
    var i = arr.length;
    if (i == 0)
        return;
    while (--i) {
        var j = Math.floor( Math.random() * ( i + 1 ) );
        var tempi = arr[i];
        var tempj = arr[j];
        arr[i] = tempj;
        arr[j] = tempi;
    }
}
function GetTimeLeftString() {
    var Ret = "Time Left: ";
    var Now = (new Date()).getTime();
    var Diff = GameTime + GameStart - Now;
    var MilliSec = (Diff % 1000) | 0;
    Diff /= 1000;
    var Min = (Diff / 60) | 0;
    var Sec = (Diff % 60) | 0;
    Ret += ((Min < 10) ? "0" + Min : Min) + ":" + ((Sec < 10) ? "0" + Sec : Sec)
    + "." + ((MilliSec < 100) ? "0" + ((MilliSec < 10) ? "0" + MilliSec : MilliSec) : MilliSec);
    Ret += " seconds\r\n";
    return Ret;
}
function GetGameTime(End) {
    var Diff = End - GameStart;
    var MilliSec = (Diff % 1000) | 0;
    Diff /= 1000;
    var Min = (Diff / 60) | 0;
    var Sec = (Diff % 60) | 0;
    return ((Min < 10) ? "0" + Min : Min) + ":" + ((Sec < 10) ? "0" + Sec : Sec)
    + "." + ((MilliSec < 100) ? "0" + ((MilliSec < 10) ? "0" + MilliSec : MilliSec) : MilliSec);

}
function start() {
    status = -1;
    action(1, 0, 0);
}
function CheckSelection(s, low, high) {
    return s < low && s > high;
}
function action(mode, type, selection) {
    if (mode == -1 || mode == 0)
        cm.dispose();
    else {

        if (mode == 1) {
            if (status != 6) {
                status++;
            }
        } else {
            status--;
        }

        if (status == 0) {
            cm.sendSimple(MenuScreen());
        } else if (status == 1) {
            if (selection == 0) {
                action(1, 0, 0); //Move to Next
            } else if (selection == 1) {
                SendGameInstructions();
            } else { //Packet Edits
                cm.dispose();
            }
        } else if (status == 2) {
            //Choose Game Type
            SendGameTypeSelectionMenu();
        } else if (status == 3) {
            if (CheckSelection(selection, 0, GameTypes.length - 1)) {
                cm.dispose();
                return;
            }
            GameType = selection;
            //Choose Board Size
            SendBoardSizeSelectionMenu();
        } else if (status == 4) {
            if (CheckSelection(selection, 0, BoardSizes.length - 1)) {
                cm.dispose();
                return;
            }
            BoardSize = selection;
            //Choose Difficulty
            SendDifficultySelectionMenu();
        } else if (status == 5) {
            if (CheckSelection(selection, 0, Difficulties.length - 1)) {
                cm.dispose();
                return;
            }
            Difficulty = selection;
            InitializeBoard();
            InitializeGems();
            //No Header while in game, it's just annoying
            cm.sendSimple(GetScoreString() + GetBoardSelectionString() + GetGameSettingsDescriptionString());
        } else if (status == 6) {
            if (CheckSelection(selection, 0, NumCols * NumRows - 1)) {
                cm.dispose();
                return;
            }
            if (GameStart == -1) {
                GameStart = (new Date()).getTime();
            }
            if (GameType == 1 && GameStart + GameTime < (new Date()).getTime()) {
                //Time Over
                status++;
                action(1, 0, 0);
                return;
            }
            var Move = GetPositionFromSelection(selection);
            var ValidMove = DoMove(Move);
            if (NoMoreMoves()) {
                status++;
                action(1, 0, 0);
            } else {
                cm.sendSimple(
                    (ValidMove ? "" : "無效的移動,您必須單擊一組3個或更多的礦石/寶石。\r\n")
                    + GetScoreString()+ (GameType == 1 ? GetTimeLeftString() : "")
                    + GetBoardSelectionString() + GetGameSettingsDescriptionString());
            }
        } else if (status == 8) {
            var SendStr = Header();
            SendStr += "#e#rGame Over#k#n\r\n";
            SendStr += GetScoreString();
            SendStr += GetGameSettingsDescriptionString();
            SendStr += "遊戲時間: " + GetGameTime((new Date()).getTime()) + "\r\n";
            SendStr += GetGameEndBoardString();
            cm.sendOk(SendStr);
        } else {
            cm.dispose();
        }
    }
} 

OX遊戲

來源:XxОsirisxX

status = -1;
playerFlag = 0;
computerFlag = 0;
var playerColor;
var computerColor;

function start() {
    cm.sendYesNo("嗨 #h #.\r\n想與無腦的電腦玩OX遊戲嗎?勝利的話可以贏得#b#t5220000##k1張");
}

function action (mode, type, selection) {
    if (mode != 1) {
        if (type == 1 && mode == 0) {
            cm.sendNext("膽小鬼。");
        }
        cm.dispose();
        return;
    }
    status++;
    if (status == 0) {
        cm.sendSimple("你想做?\r\n\r\n#b#L0#先手.\r\n#L1#後手.");
    } else if (status == 1) {
        playerColor = selection == 0 ? 3991040 : 3991049;
        computerColor = selection == 0 ? 3991023 : 3991014;
        if (selection == 1) {
            computerMoves();
        }
        play();
    } else {
        if ((playerFlag & (1 << selection)) == (1 << selection) || (computerFlag & (1 << selection)) == (1 << selection) || selection < 0 || selection > 9) {
            cm.sendNext("禁止作弊。");
            cm.dispose();
            return;
        }
        playerFlag |= 1 << selection;
        if (((playerFlag | computerFlag) ^ 511) == 0) {
            tie();
            return;
        }
        for (var i = 0; i < 3; ) {
            if (isWinner(playerFlag, i++)) {
                win();
                return;
            }
        }
        computerMoves();
        for (var i = 0; i < 3; ) {
            if (isWinner(computerFlag, i++)) {
                lose();
                return;
            }
        }
        play();
    }
}

function play() {
    cm.sendSimple(loadText(true));
}

function win() {
    if (cm.canHold(5220000)) {
        cm.gainItem(5220000, 1);
        cm.sendNext(loadText(false) + "\r\n\r\n哇!你做到了!恭喜你!您贏得了#b#t5220000##k.");
    } else {
        cm.sendNext("哇!你做到了!恭喜你!但很抱歉告訴您,我不能給您 #b#t5220000##k 因為您的背包似乎已滿。稍後再試。");
    }
    cm.dispose();
}

function isWinner(player, val) {
    return (player & (7 << (val * 3))) == 7 << (val * 3) || (player & (73 << val)) == (73 << val) || (((player & (1 << 4)) == 1 << 4) && (player & ((1 << 6) << (val * 2))) && ((player & (1 << 2) >> (val * 2))));
}

function lose() {
    cm.sendNext(loadText(false) + "\r\n\r\n您輕視了這台電腦。您應該再試一次,您可能只是累了。");
    cm.dispose();
}

function computerMoves() {
    if (playerFlag == 0) {
        var rand = Math.random() * 9 | 0;
        computerFlag |= 1 << (rand + 1 & 1 == 1 ? rand : 4);
    } else {
        if (computerFlag == 0) {
            for (var i = 0; i < 4; i++) {
                if (playerFlag & (2 << i) == 2 << i) {
                    computerFlag |= 1 << 4;
                    return;
                }
            }
            var rand = Math.random() * 9 | 0;
            if (playerFlag == 1 << 4) {
                computerFlag |= 1 << (rand + 1 & 1 == 1 ? rand : 0);
            } else {
                if ((playerFlag & 1) << (rand + 1 & 1 == 1 ? rand : 4) != 1 << (rand + 1 & 1 == 1 ? rand : 4)) {
                    computerFlag |= 1 << (rand + 1 & 1 == 1 ? rand : 4);
                } else {
                    computerFlag |= 1 << 4;
                }
            }
        } else {
            for (var i = 0; i < 9; i++) {
                if (((computerFlag | playerFlag) & (1 << i)) != 0) {
                    continue;
                }
                var nextMove = (computerFlag | (1 << i));
                for (var x = 0; x < 3; x++) {
                    if (isWinner(nextMove, x)) {
                        computerFlag |= 1 << i;
                        return;
                    }
                }
                var playerPossibleMove = (playerFlag | (1 << i));
                for (var x = 0; x < 3; x++) {
                    if (isWinner(playerPossibleMove, x)) {
                        computerFlag |= 1 << i;
                        return;
                    }
                }
            }
            for (var i = 0; i < 9; i++) {
                if (((computerFlag | playerFlag) & (1 << i)) != 0) {
                    continue;
                }
                computerFlag |= 1 << i;
                break;
            }
        }
    }
}

function loadText(sendSimple) {
    var text = (sendSimple ? "選擇你的位置." : "比賽結果.") + "\r\n\r\n";
    for (var i = 0; i < 9; i++) {
        text += ((playerFlag & (1 << i)) == (1 << i) ? "#i" + playerColor + "#" : (computerFlag & (1 << i)) == (1 << i) ? "#i" + computerColor + "#" : ((sendSimple ? "#L" + i + "#" : "") + "___")) + "\t\t" + (((i + 1) % 3 == 0 ? "\r\n" : ""));
    }
    return text;
}

function tie() {
    cm.sendNext(loadText(false) + "\r\n\r\n哦,看起來您與電腦平手了。你需要更加努力。");
    cm.dispose();
}

Mastermind

來源:Emilyx3

/**
 * Mastermind NPC
 * Author: Emilyx3 of UMaple
 */
var status;
var CorrectCombo;
var CurrentCombo;
var PreviousGuesses = new Array();
var NumSpaces, NumColors;
var SpaceDiffSelected, PieceDiffSelected;
var Pieces = [4030002,4030003,4030004,4030005,4030006,4030007,4030008];
var SpaceDifficulties = [["Beginner(3)", 3], ["Easy(4)", 4], ["Intermediate(5)", 5], ["Hard(6)", 6], ["Expert(7)", 7]];
var PieceDifficulties = [["Beginner", 3], ["Easy", 4], ["Intermediate", 5], ["Hard", 6], ["Expert", 7]];
var MaxGuesses = 25;
//var CorrectPiece = 4031140, CorrectPieceAndSpace = 4005004;
var CorrectPiece = 4001007, CorrectPieceAndSpace = 4001008, Blank = 4031325, DeletePrevious =3991002;
var mount = Math.random()*50; //獎勵獲得的數量

function Header() {
    return "#d============#k Mastermind #d============#k\r\n\r\n";
}
function SendMainMenu() {
    cm.sendSimple(
        Header() +
        "#L0#開始遊戲#l\r\n" +
        "#L1#遊戲介紹#l"
    );
}
function SendGameInstructions() {
    cm.sendNext(Header() +
        "#b#e歡迎來到 game Mastermind.#k#n\r\n" +
        "#e遊戲介紹:#n\r\n" +
        "1)遊戲目標是猜測正確的方塊組合。\r\n" +
        "2)每次猜測之後,您將收到反饋,以了解如何正確推論。\r\n" +
        "    #v"+CorrectPieceAndSpace+"# - 表示#b正確#k零件在#b正確#k位置\r\n" +
        "    #v"+CorrectPiece+"# - 表示#b正確#k零件在#b不正確#k位置\r\n\r\n" +
        "    Example: " + GetFeedback([1,2]) + " - 1個正確零件在正確位置,以及2個正確零件在錯誤位置。\r\n" +
        "3)您擁有最多#r" + MaxGuesses + "#k次機會來嘗試獲得正確的組合。\r\n"
    );
}
function SendNumSpacesSelectionMenu() {
    var SendStr = Header();
    SendStr += "#e請選擇您要遊戲的猜測數:#n\r\n"
    for (var i = 0;i < SpaceDifficulties.length;i++) {
        SendStr += "#L" + i + "#" + SpaceDifficulties[i][0] + " - 猜測數:" + SpaceDifficulties[i][1] + "\r\n";
    }
    cm.sendSimple(SendStr);
}
function SendNumPiecesSelectionMenu() {
    var SendStr = Header();
    SendStr += "#e請選擇您想玩的零件數:#n\r\n"
    for (var i = 0;i < PieceDifficulties.length;i++) {
        SendStr += "#L" + i + "#" + PieceDifficulties[i][0] + " - 零件數:" + PieceDifficulties[i][1] + "\r\n";
    }
    cm.sendSimple(SendStr);
}
function GetGameSettingsDescription() {
    return "\r\n#d#e遊戲設定:#n#k\r\n" +
        SpaceDifficulties[SpaceDiffSelected][0] + " - 猜測數:" + SpaceDifficulties[SpaceDiffSelected][0] + "\r\n" +
        PieceDifficulties[PieceDiffSelected][0] + " - 零件數:" +  PieceDifficulties[PieceDiffSelected][1] + "\r\n";
}
function InitializeCorrectSequence() {
    Shuffle(Pieces);
    CorrectCombo = new Array(NumSpaces);
    for (var i = 0;i < CorrectCombo.length;i++) {
        CorrectCombo[i] = Math.floor(Math.random() * NumColors);
    }
}
function GetSequenceString(Sequence) {
    var Ret = "";
    for (var i = 0;i < Sequence.length;i++) {
        Ret += "#v" + Pieces[Sequence[i]] + "#";
    }
    return Ret;
}
function GetCurrentCombo() {
    var Ret = "你目前的猜測: ";
    for (var i = 0;i < CurrentCombo.length;i++) {
        Ret += "#v" + Pieces[CurrentCombo[i]] + "#";
    }
    for (var j = 0;j < NumSpaces - CurrentCombo.length;j++) {
        Ret += "#v" + Blank + "#";
    }
    return Ret + "\r\n";
}
function GetPieceSelectionString() {
    var Ret = "請選擇一個方塊:\r\n";
    for (var i = 0;i < NumColors;i++) {
        Ret += "#L" + i + "##v" + Pieces[i] + "##l ";
    }
    if (CurrentCombo.length > 0) {
        Ret += "#L" + NumColors + "##v" + DeletePrevious + "##l";
    }
    return Ret + "\r\n";

}
function CalculateMatch() {
    var Correct = new Array();
    for (var i = 0;i < NumSpaces;i++) {
        if (CorrectCombo[i] == CurrentCombo[i]) {
            Correct.push(i);
        }
    }
    var Ret1 = Correct.length;
    for (var j = 0;j < NumSpaces;j++) {
        if (!Contains(j, Correct)) {
            for (var k = 0;k < NumSpaces;k++) {
                if (!Contains(k, Correct)) {
                    if (CurrentCombo[j] == CorrectCombo[k]) {
                        Correct.push(k);
                        break;
                    }
                }
            }
        }
    }
    return [Ret1, Correct.length - Ret1];
}
function Contains(i, arr) {
    for (var j = 0;j < arr.length;j++) {
        if (arr[j] == i) {
            return true;
        }
    }
    return false;
}
function GetFeedback(CorrectNumbers) {
    var Ret = "";
    for (var i = 0;i < CorrectNumbers[0];i++) {
        Ret += "#v" + CorrectPieceAndSpace + "#";
    }
    for (var j = 0;j < CorrectNumbers[1];j++) {
        Ret += "#v" + CorrectPiece + "#";
    }
    return Ret;
}
function GetPreviousCombos() {
    if (PreviousGuesses.length == 0) {
        return "";
    }
    var Ret = "\r\n=== #e上一輪猜測#n ===\r\n";
    for (var i = PreviousGuesses.length - 1;i >= 0;i--) {
        var PreviousGuess = PreviousGuesses[i];
        Ret += ((i + 1) + ". ") + GetSequenceString(PreviousGuess[0]) + "   " + GetFeedback(PreviousGuess[1]) + "\r\n";
    }
    return Ret + "\r\n";
}
function Shuffle(arr) {
    var i = arr.length;
    if (i == 0)
        return;
    while (--i) {
        var j = Math.floor( Math.random() * ( i + 1 ) );
        var tempi = arr[i];
        var tempj = arr[j];
        arr[i] = tempj;
        arr[j] = tempi;
    }
}
function CheckSelection(s, low, high) {
    return s < low && s > high;
}
function start() {
    status = -1;
    action(1, 0, 0);
}
function action(mode, type, selection) {
    if (mode == -1 || (mode == 0 && (status != 5 || CurrentCombo == null || CurrentCombo.length != NumSpaces))) {
        cm.dispose();
        return;
    }
    if (status != 5)
        status++;

    if (status == 0) {
        SendMainMenu();
    } else if (status == 1) {
        if (selection == 0) {
            action(1, 0, 0);
        } else if (selection == 1) {
            SendGameInstructions();
        } else {
            cm.dispose();
        }
    } else if (status == 2) {
        SendNumSpacesSelectionMenu();
    } else if (status == 3) {
        if (CheckSelection(selection, 0, SpaceDifficulties.length - 1)) {
            cm.dispose();
            return;
        }
        SpaceDiffSelected = selection;
        NumSpaces = SpaceDifficulties[selection][1];
        SendNumPiecesSelectionMenu();
    } else if (status == 4) {
        if (CheckSelection(selection, 0, PieceDifficulties.length - 1)) {
            cm.dispose();
            return;
        }
        PieceDiffSelected = selection;
        NumColors = PieceDifficulties[selection][1];
        InitializeCorrectSequence();
        CurrentCombo = new Array();
        cm.sendSimple(Header() + GetCurrentCombo() + GetPieceSelectionString()
            + GetPreviousCombos() + GetGameSettingsDescription());
    } else if (status == 5) {
        if (CurrentCombo.length == NumSpaces) {
            if (mode == 0) { //No
                CurrentCombo.pop();
                cm.sendSimple(Header() + GetCurrentCombo() + GetPieceSelectionString()
                    + GetPreviousCombos() + GetGameSettingsDescription());
            } else if (mode == 1) { //Yes
                var Match = CalculateMatch();
                if (Match[0] == NumSpaces) {
                    //Win
                    cm.sendOk(Header() + "#b#e恭喜你,你只花了 "+(PreviousGuesses.length + 1)+" 次猜測就贏了!#n#k\r\n"
                        + GetSequenceString(CurrentCombo) + "    " + GetFeedback(Match) + "\r\n"
                        + GetPreviousCombos() + GetGameSettingsDescription());
                    cm.gainItem(4001126,mount); //贏的獎勵
                    cm.dispose();
                } else if (PreviousGuesses.length + 1 == MaxGuesses) {
                    //Lose
                    PreviousGuesses.push([CurrentCombo, Match]);
                    cm.sendOk(Header() + "#b#e抱歉,你輸了!您超過了最大猜測數 ("+MaxGuesses+")!#n#k\r\n"
                        + "正確的組合是:" +  GetSequenceString(CorrectCombo) + "\r\n"
                        + GetPreviousCombos() + GetGameSettingsDescription());
                    cm.dispose();
                } else {
                    //Continue
                    PreviousGuesses.push([CurrentCombo, Match]);
                    CurrentCombo = new Array();
                    cm.sendSimple(Header() +
                        "#r抱歉,序列不正確。#k\r\n"
                        + GetCurrentCombo() + GetPieceSelectionString()
                        + GetPreviousCombos() + GetGameSettingsDescription());
                }
            }
        } else {
            if (CheckSelection(selection, 0, (CurrentCombo.length > 0 ? NumColors : NumColors - 1))) {
                cm.dispose();
                return;
            }
            if (selection == NumColors) {
                CurrentCombo.pop();
            } else {
                CurrentCombo.push(selection);
            }
            if (CurrentCombo.length == NumSpaces) {
                cm.sendYesNo(Header() + "#r請確認您的選擇:#k\r\n"
                    + GetCurrentCombo() + GetPreviousCombos() + GetGameSettingsDescription()
                );
            } else {
                cm.sendSimple(Header() + GetCurrentCombo() + GetPieceSelectionString()
                    + GetPreviousCombos() + GetGameSettingsDescription());
            }
        }
    } else {
        cm.dispose();
    }
} 

跳棋

來源:Lapje

數字猜猜猜




這個稍微複雜點,註解必看。
獎池物品隨便放的,可以自行修改。

/*數字猜猜猜

如果需要檢測背包容量功能,請在MapleCharacter加上

    public short getSpace(int type) {
        return getInventory(MapleInventoryType.getByType((byte) type)).getNumFreeSlot();
    }

    public boolean haveSpace(int type) {
        short slot = getInventory(MapleInventoryType.getByType((byte) type)).getNextFreeSlot();
        return (slot != -1);
    }

    public boolean haveSpaceForId(int itemid) {
        short slot = getInventory(GameConstants.getInventoryType(itemid)).getNextFreeSlot();
        return (slot != -1);
    }

PS.我的bosslog是getBossLog2和setBossLog2,看你自己的寫法,別照我的打。

*/

var a = 0;
var randomNumber = Array();
var n1;
var n2;
var n3;
var itemData = Array(
        1102275, 
        1042187, 
        1042174, 
        1042149, 
        1072437, 
        1072448, 
        1022005,
        1022006,
        1022007,
        1022009,
        1112414,
        1022097,
        1702256,
        1702257,
        1702258,
        1702259,
        1702260,
        1102040,
        1102041,
        1102042,
        1102043,
        1482073,
        1492073,
        1122075
        );
var pass = true;
var correct = 0
var NumberPosition = Array();


function start() {
    a = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) {
        cm.dispose();
    } else {
        if (mode == 1)
            a++;
        else
            cm.dispose();
        if (a == -1) {
            cm.dispose();
        } else if (a == 0) {
            /* 沒有檢測背包容量功能這邊就不需要,有就可以把注釋消掉。
            for (var i = 1; i < 5; i++) {
                if (cm.getSpace(i) < 5) {
                    pass = false;
                }
            }*/
            if (cm.getBossLog2("數字猜猜猜") >= 5) {
                cm.sendOk("對不起,數字猜猜猜活動一天只能進行五次。");
                cm.dispose();
            } else {
                cm.sendSimple("萬眾期待的HOTTIME時間又到了!親愛的冒險家,請問你要做什麼呢? \r\n#b#L0# 我要玩數字猜猜猜活動! \r\n#L1# 介紹一下此活動。");
            }
        } else if (a == 1) {
            if (selection == 0) {//我要玩數字猜猜猜活動!
                if (pass) {
                    cm.sendNextS("系統將隨機產生10個數字,請您做好準備記錄下這10個數字。 \r\n#r -- 點擊下一步開始產生。 \r\n #r-- 如果切斷對話,參加活動所需的物品不歸還。", 3);
                } else {
                    cm.sendOk("請讓你的所有背包欄空出5個格子。");
                    cm.dispose();
                }
            } else if (selection == 1) {//介紹一下此活動。
                a = -1;
                cm.sendNext("#e數字猜猜猜活動遊戲規則:#n#d\r\n\r\n1)系統會隨機給出10個數字,並且公示。 \r\n2)這10個數字將被打亂,且隱藏。 \r\n3)玩家會被隨機提問第N個數字是什麼\r\n如果回答正確即可得到獎勵! \r\n4)玩家一共有3次提問的機會。 #e\r\n\r\n5)獎池中有隨機5個道具 \r\n - 回答正確1次,隨機從裡面得到1個道具。 \r\n - 回答正確2次,隨機從裡面得到3個道具。 \r\n - 回答正確3次,獎池內所有道具都帶走! #n\r\n\r\n 參加活動的時候切記您的所有背包空格都有5格以上的空間。");
            }//selection
        } else if (a == 2) {
            var temp;
            var i = 0;
            while (i < 10) {
                temp = Math.floor(Math.random() * 40);
                if (checkid(temp)) {
                    randomNumber.push(temp);//隨機0~39
                    i++;
                }
            }
            var text = "這10個隨機數字依次為:\r\n #r- 請拿起您的筆記下這隨機的數字!\r\n\r\n#d";
            for (var i = 0; i < randomNumber.length; i++) {
                text += "第" + (i + 1) + "個數字為: - " + randomNumber[i] + "\r\n";
            }
            cm.sendNextS(text, 3);
        } else if (a == 3) {
            cm.sendNextS("正在打亂這10個數字,請點擊下一步……。", 3)
        } else if (a == 4) {
            randomNumber.sort(function() {
                return 0.5 - Math.random();
            })//隨機打亂
            var temp = Math.floor(Math.random() * 10) + 1;
            var i = 0;
            while (i < 3) {
                temp = Math.floor(Math.random() * 10) + 1;
                //cm.sendY(temp)
                if (checkNumberPosition(temp)) {
                    NumberPosition.push(temp);//隨機1~10
                    i++;
                }
            }//隨機位數的數字猜
            cm.sendGetNumber("現在請您輸入第" + NumberPosition[0] + "個數字:\r\n #r-- 如果切斷對話,參加活動所需的物品不歸還。\r\n", 0, 0, 999);
        } else if (a == 5) {
            n1 = selection; //記錄玩家第一次輸入
            cm.sendGetNumber("現在請您輸入第" + NumberPosition[1] + "個數字:\r\n #r-- 如果切斷對話,參加活動所需的物品不歸還。\r\n", 0, 0, 999);
        } else if (a == 6) {
            n2 = selection;
            cm.sendGetNumber("現在請您輸入第" + NumberPosition[2] + "個數字:\r\n #r-- 如果切斷對話,參加活動所需的物品不歸還。\r\n", 0, 0, 999);
        } else if (a == 7) {
            n3 = selection;
            cm.sendNextS("你所輸入的數字為:\r\n\r\n 第" + NumberPosition[0] + "個數字 -- " + n1 + "\r\n 第" + NumberPosition[1] + "個數字 -- " + n2 + "\r\n 第" + NumberPosition[2] + "個數字 -- " + n3 + ".", 3);
        } else if (a == 8) {
            var text = "現在我來公佈結果:\r\n 經過打亂後的10個數字為:\r\n\r\n#b";
            for (var i = 0; i < randomNumber.length; i++) {
                if (i == (NumberPosition[0] - 1)) {
                    text += "第" + (i + 1) + "個數字為: - " + randomNumber[i] + " #r( 您的答案為:" + n1 + ")#b\r\n";
                } else if (i == (NumberPosition[1] - 1)) {
                    text += "第" + (i + 1) + "個數字為: - " + randomNumber[i] + " #r( 您的答案為:" + n2 + ")#b\r\n";
                } else if (i == (NumberPosition[2] - 1)) {
                    text += "第" + (i + 1) + "個數字為: - " + randomNumber[i] + " #r( 您的答案為:" + n3 + ")#b\r\n";
                } else {
                    text += "第" + (i + 1) + "個數字為: - " + randomNumber[i] + "\r\n";
                }
            }
            cm.sendNextS(text, 3);
        } else if (a == 9) {//判斷是否答對部分
            if (randomNumber[NumberPosition[0] - 1] == n1) {
                correct += 1;
            }
            if (randomNumber[NumberPosition[1] - 1] == n2) {
                correct += 1;
            }
            if (randomNumber[NumberPosition[2] - 1] == n3) {
                correct += 1;
            }
            var text = "系統判斷您一共答對了" + correct + "次。\r\n\r\n現在獎池裡面有下列的道具(隨機5個):\r\n\r\n#b";

            itemData.sort(function(){return Math.random()>0.5?-1:1;});
            //隨機打亂獎池
            for (var i = 0; i < 5; i++) {//拿前5个
                text += "#i" + itemData[i] + "#   #z" + itemData[i] + "#\r\n\r\n";
            } 
            cm.sendNextS(text + "#d\r\n\r\n - 回答正確1次,隨機從裡面得到1個道具。 \r\n - 回答正確2次,隨機從裡面得到3個道具。 \r\n - 回答正確3次,獎池內所有道具都帶走!", 3);
        } else if (a == 10) {
            if (correct == 0) {//沒回答正確
                cm.sendOk("對不起,你沒有回答正確。 \r\n領取物品的必要條件是必須至少回答一個正確。");
                cm.dispose();
            } else if (correct == 3) {//全部回答正確
                var text = "恭喜你!回答3個全部正確!你將獲取獎池內的所有物品!\r\n\r\n#b";
                for (var i = 0; i < 5; i++) {//拿前5个
                    text += "#i" + itemData[i] + "#   #z" + itemData[i] + "#\r\n\r\n";
                }
                cm.sendNextS(text + "#d\r\n\r\n請妥善保管哦!", 3);
            } else if (correct == 1) {//正確1個
                cm.gainItem(itemData[0], 1);
                cm.sendOk("贈送成功!喜歡獎池裡面的道具嗎?");
                cm.dispose();
            } else if (correct == 2) {//2個正確
                var text = "恭喜你!回答正確" + correct + "次,按照規則,你將獲取獎池內的:\r\n\r\n#b";
                for (var i = 0; i < 3; i++) {
                    text += "#i" + itemData[i] + "#   #z" + itemData[i] + "#\r\n\r\n";
                }
                a = 11;
                cm.sendNextS(text + "#d\r\n\r\n請妥善保管哦!", 3);
            } else {
                cm.sendOk("錯誤!請和管理員聯繫。\r\n錯誤代碼:" + correct);
            }
            cm.setBossLog2("數字猜猜猜");
        } else if (a == 11) {//全部正確
            for (var i = 0; i < 5; i++) {//拿前5个
                cm.gainItem(itemData[i], 1);
            }
            cm.sendOk("贈送成功!喜歡獎池裡面的道具嗎?");
            cm.dispose();
        } else if (a == 12) {//2題
            for (var i = 0; i < 3; i++) {
                cm.gainItem(itemData[i], 1);
            }
            cm.sendOk("贈送成功!喜歡獎池裡面的道具嗎?");
            cm.dispose();
        }//a
    }//mode
}//f


function checkid(number) {//檢查是否重複
    var i = 0;
    while (randomNumber.length >= i) {
        if (randomNumber[i] == number) {
            return false;
        }
        i++;
    }
    return true;
}

function checkNumberPosition(number) {//檢查是否重複
    var i = 0;
    while (NumberPosition.length >= i) {
        if (NumberPosition[i] == number) {
            return false;
        }
        i++;
    }
    return true;
}

大概就是這樣,能隨意更改的部分我大多都有標上註解,當然,只要有創意怎麼改都行。