EE308 LAB4

m0_51336275 m0_51336275 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
The Link Your Class https://bbs.csdn.net/forums/MUEE308FZ?category=0
The Link of Requirement of This Assignment https://bbs.csdn.net/topics/601188617
The Aim of This AssignmentBase on Lab3 develop a small Wechat program
MU STU ID and FZU STU ID19103603_831902107
Teammate's MU STU ID and FZU STU ID19104359_831902113
Link of Teammate's BLOG

PSP Form

PSPEstimated Time/minutesCompleted Time/minutes
Planning2020
Estimate1530
Development--
Analysis80100
Design4040
Coding Standard4040
Coding12001500
Test6090
Reporting--
Test Report6060
Size Measurement3030
Postmortem&Process Improvement12080
Total15861990

Environment

http://8.135.15.73:2333/

Github

https://github.com/kawiil/EE308_Lab4

Detail

The game is a website placing on a server so there is no need to install it.

You can open it with a browser and play it anywhere.

We use JavaScript to implement to logic of Bobing game.

The result of each dice is random by using Math.random() function.

    init: async function(){
        var container = document.getElementById('dicebox');
        $('.redpacket').remove();
        var dices = this.randomFun();
        for (var i = 0 ; i < 6; i++) {
            container.appendChild(this.createDice(dices[i]+1,i));
        }
        var result = this.getResult(dices);
        await sleep(2333);
        alert(result);
    },
    randomFun:function(){
        var arr = [];
        for (var i = 0 ; i < 6; i++ ) {
            arr.push(Math.floor(Math.random()*6));
        }
        return arr;
    },
    createDice:function(num,i){
        var image = document.createElement('img');
                 image.setAttribute("class","redpacket");
                 image.id = "redpacket" + i;
              image.src = 'img/' + num +'.jpg';
              return image;
    },

The result will be display when the game is finished

    getResult:function(dices) {
        if (dices.count(4) == 4 && dices.count(1) == 2)
            result = "状元插金花";
        else if (dices.count(4) == 6)
            result = "满堂红";
        else if (dices.count(1) == 6)
            result = "遍地锦";
        else if (dices.count(2) == 6)
            result = "六勃黑";
        else if (dices.count(4) >= 5)
            result = "五王";
        else if (dices.count(2) >= 5)
            result = "五子";
        else if (dices.count(4) >= 4)
            result = "状元";
        else if (dices.count(1) == 1 && dices.count(2) == 1 && dices.count(3) == 1 && dices.count(4) == 1 && dices.count(5) == 1 && dices.count(6) == 1)
            result = "对堂";
        else if (dices.count(4) >= 3)
            result = "三红";
        else if (dices.count(2) >= 4)
            result = "四进";
        else if (dices.count(4) >= 2)
            result = "二举";
        else if (dices.count(4) >= 1)
            result = "一秀";
        else
            result = "未中奖";
        return result;
    }

By the way, there is no count function for array in JavaScript, so we modify its prototype.

Object.defineProperties(Array.prototype, {
    count: {
        value: function(value) {
            return this.filter(x => x==value).length;
        }
    }
});

Summary

There are still a lot of gains from this homework. For example, in order to meet the requirements of the commit information specification, I learned how to develop a webpage using html/css/javascript, learned simple javascipt program performance analysis and optimization. in addition
The only downside is that I am a little tired after finishing this homework.

...全文
评论
收藏 已收藏
分享
返回顶部