EE308 LAB4

m0_51336275 2021-10-14 00:25:29
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.

...全文
266 点赞 收藏 回复
写回复
回复
切换为时间正序
请发表友善的回复…
发表回复

还没有回复,快来抢沙发~

相关推荐
发帖
福州大学-软件工程EE308-2021秋
创建于2021-09-10

185

社区成员

福州大学 梅努斯国际工程学院 软件工程 教学
帖子事件
编辑了帖子
2021-10-14 00:28
创建了帖子
2021-10-14 00:25
社区公告
暂无公告