隱形天堂 一個原汁原味的天堂


    [技術文]真正的樂透系統寫法

    分享

    Admin
    Admin

    文章數 : 134
    注冊日期 : 2010-09-27

    [技術文]真正的樂透系統寫法

    發表  Admin 于 周一 9月 27, 2010 7:48 am

    先聲明
    本程式碼原始碼由eric0826大大所編寫
    (也就是紀錄最後登入時間的作者)
    他寫出普通的樂透程式
    我只是改成l1j核心可以用的程式碼而已

    沒有eric0826大大
    沒有這個大樂透
    所以要感謝是感謝eric0826大大

    之前我和eric0826大大聊MSN
    由於他是個程式工程師
    剛好今天的工作已經做完
    於是向他請教了樂透系統
    才發現我們的寫法根本叫幼稚XD

    以下的程式碼是個獨立的程式
    跟天堂的java無關
    String sNum = "", pNum = "";
    //系統數字
    while(sNum.split(",").length < 5){
    int sk = 1 + (int) (Math.random() * 46);
    if(sNum.indexOf(sk + ",") < 0)
    sNum += String.valueOf(sk) + ",";
    }
    //玩家數字
    while(pNum.split(",").length < 5){
    int pk = 1 + (int) (Math.random() * 46);
    if(pNum.indexOf(pk + ",") < 0)
    pNum += String.valueOf(pk) + ",";
    }
    int ch = 0;
    for(int i=0; i<sNum.split(",").length;i++) {
    String pk[] = pNum.split(",");
    if((","+sNum).indexOf(","+pk[ i ]+",") >= 0)
    ch++;
    }
    System.out.println(sNum);
    System.out.println(pNum);
    System.out.println("**********************你對中了" + ch + "個號碼!");

    ok看的懂人就看的懂
    看不懂也別問我[/size]

    [size=3]以下是我用cmd執行的結果

    Microsoft Windows XP [版本 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\\Documents and Settings\\Administrator>cd..

    C:\\Documents and Settings>cd..

    C:\\>java Test
    26,25,21,31,43,
    25,13,30,46,41,
    **********************你對中了1個號碼!
    26,42,44,30,34,
    42,13,20,44,21,
    **********************你對中了2個號碼!
    17,27,34,29,18,
    41,8,36,44,32,
    **********************你對中了0個號碼!
    44,28,34,46,2,
    31,32,33,18,46,
    **********************你對中了1個號碼!
    41,2,43,37,19,
    19,6,46,44,23,
    **********************你對中了1個號碼!
    43,18,11,36,40,
    8,38,42,22,35,
    **********************你對中了0個號碼!
    42,43,6,46,20,
    45,4,27,30,8,
    **********************你對中了0個號碼!
    22,32,12,25,44,
    19,25,36,7,18,
    **********************你對中了1個號碼!
    3,14,24,30,28,
    20,17,30,32,37,
    **********************你對中了1個號碼!
    24,45,27,28,29,
    7,46,14,38,12,
    **********************你對中了0個號碼!

    C:\\>

    其實魔法骰子漂亮的寫法就應該是寫成這樣
    用一堆if是不能看的XD


    以下是我做點加工改成天堂的樂透系統

    if (k == 40787){
    //獎品
    int itemId1 = 40308; //-----------金幣
    int itemId2 = 40733; //-----------1億代幣,請自己設定
    int itemId3 = 40734; //-----------5億代幣,請自己設定
    int itemId4 = 40735; //----------10億代幣,請自己設定
    int itemId5 = 40736; //---------500萬代幣,請自己設定

    // TODO Auto-generated method stub
    String sNum = "", pNum = "";
    //系統數字
    while(sNum.split(",").length < 6){
    int sk = 1 + (int) (Math.random() * 49);
    if(sNum.indexOf(sk + ",") < 0)
    sNum += String.valueOf(sk) + ",";
    }
    //玩家數字
    while(pNum.split(",").length < 6){
    int pk = 1 + (int) (Math.random() * 49);
    if(pNum.indexOf(pk + ",") < 0)
    pNum += String.valueOf(pk) + ",";
    }
    int ch = 0;
    int iloop = sNum.split(",").length;
    String pk[] = pNum.split(",");
    for(int a=0; a<sNum.split(",").length;a++) {
    if((","+sNum).indexOf(","+pk[a]+",") >= 0)
    ch++;
    }
    l1pcinstance.sendPackets(new S_SystemMessage(sNum));
    l1pcinstance.sendPackets(new S_SystemMessage(pNum));
    l1pcinstance.sendPackets(new S_SystemMessage("對中了" + ch + "個號碼!"));
    l1pcinstance.getInventory().removeItem(l1iteminstance,1);

    switch(ch)
    {

    case 3:
    l1pcinstance.sendPackets(new S_SystemMessage("您中了普獎!! "));
    L1ItemInstance item = l1pcinstance.getInventory().storeItem(itemId5, 2); //----1千萬
    l1pcinstance.sendPackets(new S_SkillSound(j, 2011));
    l1pcinstance.broadcastPacket(new S_SkillSound(j, 2011));
    break;
    case 4:
    l1pcinstance.sendPackets(new S_SystemMessage("您中了参獎!! "));
    L1ItemInstance item1 = l1pcinstance.getInventory().storeItem(itemId3, 2); //-----10億
    l1pcinstance.sendPackets(new S_SkillSound(j, 2011));
    l1pcinstance.broadcastPacket(new S_SkillSound(j, 2011));
    break;
    case 5:
    l1pcinstance.sendPackets(new S_SystemMessage("您中了貳獎!! "));
    L1ItemInstance item2 = l1pcinstance.getInventory().storeItem(itemId4, 10); //----100億
    l1pcinstance.sendPackets(new S_SkillSound(j, 2020));
    l1pcinstance.broadcastPacket(new S_SkillSound(j, 2020));
    break;
    case 6:
    l1pcinstance.sendPackets(new S_SystemMessage("您中了頭獎!! "));
    L1ItemInstance item3 = l1pcinstance.getInventory().storeItem(itemId4, 50); //---500億
    l1pcinstance.sendPackets(new S_SkillSound(j, 2047));
    l1pcinstance.broadcastPacket(new S_SkillSound(j, 2047));
    break;
    default:
    l1pcinstance.sendPackets(new S_SystemMessage("您槓龜了!! "));
    break;
    }
    } else

    轉檔問題別問我
    因為一定不是這段程式碼的問題..

      現在的時間是 周二 10月 16, 2018 5:42 am