EE308_LAB2-2

只影清欢 2022-11-18 23:46:51
The Link Your Classhttps://bbs.csdn.net/forums/MUEE308FZU202201
The Link of Requirement of This Assignmenthttps://bbs.csdn.net/topics/608859318
MU STU ID and FZU STU ID20124147_832001108
GitHub Linkhttps://github.com/Ryan-pq/EE308-lab2-2
Video demo linkhttps://www.bilibili.com/video/BV12P4y117Vq/?share_source=copy_web

1.PSP form

Personal Software Process StagesEstimated time (minutes)real time (minutes)
Planning2040
- Estimate230270
Development3040
- Analysis4060
- Design Spec2030
- Design80120
- Coding110180
- Code Review2030
- Test2030
Reporting3060
Total620830

2.The key or difficult functions

This assignment shows the game in the form of small program. The production tool is wechat developer tool and the code is JavaScript.

1. Six dice produce random numbers

Due to the lack of knowledge of this language, I gradually understood it after consulting a series of materials and learning, and used for reference and modified part of the code. The final result is as follows:

const app = getApp()

Page({
    data: {
      txt:'点击摇一摇开始进行博饼',
      one_img:'https://img-blog.csdnimg.cn/20181116192114783.png',
      two_img: 'https://img-blog.csdnimg.cn/20181116192223207.png',
      three_img: 'https://img-blog.csdnimg.cn/20181116192249314.png',
      four_img: 'https://img-blog.csdnimg.cn/20181116192305231.png',
      five_img: 'https://img-blog.csdnimg.cn/20181116192320187.png',
      six_img: 'https://img-blog.csdnimg.cn/20181116192332897.png',
      flag:true,
      timer:null,
      msg:'摇一摇',
      total:0,


      arr:[
        'https://img-blog.csdnimg.cn/20181116192114783.png',
        'https://img-blog.csdnimg.cn/20181116192223207.png',
        'https://img-blog.csdnimg.cn/20181116192249314.png',
        'https://img-blog.csdnimg.cn/20181116192305231.png',
        'https://img-blog.csdnimg.cn/20181116192320187.png',
        'https://img-blog.csdnimg.cn/20181116192332897.png',
      ]
    },
    enter:function(event){
      let obj = this;
    var idx=0;
    var that=this;
    
     if(obj.data.flag==true){
         obj.data.timer = setInterval(function () {
     
          var one = that.randomNum(1, 6);
          var two = that.randomNum(1, 6);
          var three = that.randomNum(1, 6);
          var four = that.randomNum(1, 6);
          var five =that.randomNum(1, 6);
          var six = that.randomNum(1, 6);
  idx++;
  var tmp1=one;var tmp2=two;var tmp3=three; var tmp4=four ;var tmp5=five; var tmp6=six;         
  
  obj.setData({
            one_img:  one + ".png",
            two_img: two + ".png",
            three_img: three + ".png",
            four_img: four+ ".png",
            five_img:five+".png",
            six_img:six+".png",
            flag:false,
            msg:'等待中...',
  
           // total:18,
          })
  if(idx>20){
         

    
          clearInterval(obj.data.timer);
          obj.setData({
        txt:'',
               msg:'摇一摇',
               flag:true,
          })
    var NumberArr = [];
    NumberArr.push(tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);
    var level = {
      one: '状元插金花',
      two: '满堂红', // 六子
      two1: '遍地锦',
      two2: '六勃黑',
      three: '五王', // 五子
      three1:'五子',
      four: '状元',
      five: '对堂',
      six: '三红',
      seven: '四进',
      eight: '二举',
      nine: '一秀',
      ten: '太遗憾啦'
   },
   this_level; 
  
    NumberArr.sort();
    var isfour = 0;
    for (var i = 0; i < NumberArr.length; i++) {
      if (NumberArr[i] == 4) {
          isfour = isfour + 1;
      }
  } 
  switch (isfour) {
    case 1:
        for (var i = 0; i < NumberArr.length; i++) {
            //存储当前相同的数量,判断是否为四进
            var ContrastArr = [];
            for (var j = 0; j < NumberArr.length; j++) {
                if (NumberArr[i] == NumberArr[j]) {
                    ContrastArr.push(NumberArr[j]);
                }
            }
        }
        // 等到上面遍历执行完再进行判断属于哪个级别
        if (ContrastArr.length === 4) {
            this_level = level.seven; //四进

            break;
        } else if (ContrastArr.length === 5) {
            this_level = level.three; //五王
            
            break;
        } else if (ContrastArr.length === 6) {
            this_level = level.two; //满堂红
           
            break;
        } else {
            // 判断一下,是 "对堂"" or ”一秀“,对堂就是顺子,123456,一秀就是一个只有4;
            var isContinuityArray = false;
            var array = NumberArr;
            var arrayCount = array.length;
            for (var i = 0; i < arrayCount; i++) {
                var currentArr = Number(array[i]) + 1;
                var nestArr = Number(array[i + 1]);
                if (i + 1 == arrayCount) {
                    currentArr = Number(array[i]);
                    nestArr = Number(array[i]);
                }
                if (currentArr != nestArr) {
                    isContinuityArray = false;
                    break;
                } else {
                    isContinuityArray = true;
                }
            }
            if (isContinuityArray) {
                this_level = level.five;
                
                break;
            } else {
                this_level = level.nine;
                
                
                break;
            }
        };
        break;
    case 2:
        for (var i = 0; i < NumberArr.length; i++) {
            var ContrastArr = [];
            for (var j = 0; j < NumberArr.length; j++) {
                if (NumberArr[i] == NumberArr[j]) {
                    ContrastArr.push(NumberArr[j]);
                }
            }
            // 判断是 4进 or 二举
            if (ContrastArr.length === 4) {
                this_level = level.seven;
               
                break;
            } else {
                this_level = level.eight;
                
            }
        };
        break;
    case 3:
        this_level = level.six;   
        break;
    case 4:
        // 判断是 "普通状元" or "状元插金花",普通就是4个四,插金花就是  4个四 + 2个1 ;
        var one = 0;
        for (var i = 0; i < NumberArr.length; i++) {
            if (NumberArr[i] === 1) {
                one = one + 1;
            }
        }
        if (one == 2) {
            this_level = level.one; // 插金花
            
        } else {
            this_level = level.four; //状元
           
        }
        break;
    case 5:
        this_level = level.three; // 五王
        
        break;
    case 6:
        this_level = level.two; //满堂红
        
        break;
    default:
        // 就是页面都没有四,来判断是否属于 “五子” 和 “六子” 和 “四进” 中的哪一种;
        for (var i = 0; i < NumberArr.length; i++) {
            var ContrastArr = [];
            for (var j = 0; j < NumberArr.length; j++) {
                if (NumberArr[i] == NumberArr[j]) {
                    ContrastArr.push(NumberArr[j]);
                }
            }
            if (ContrastArr.length === 4) {
                this_level = level.seven; //四进
               
                break;
            } else if (ContrastArr.length === 5) {
                this_level = level.three1; //五子
                
                break;
            } else if (ContrastArr.length === 6 && NumberArr[0] === 1) {
                this_level = level.two1; //遍地锦
                
                break;
            } else if (ContrastArr.length === 6 && NumberArr[0] === 2) {
                this_level = level.two2; //六勃黑
                
                break;
            } else {
                this_level = level.ten;
            }
        };
        break;  }


        that.setData({
          l:this_level,
          });
        }

        }, 50);}
      
    },
 

  randomNum: function (minNum, maxNum) {
    switch (arguments.length) {
      case 1:
        return parseInt(Math.random() * minNum + 1, 10);
        break;
      case 2:
        return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
        break;
      default:
        return 0;
    }
  } 

})

2. Judge the result of the dice roll

After a series of studies, I got a simple idea: When rolling dice, an array is used to store the number of the top points of each die, and it is judged in the switch(isfour) structure. The classification is based on the number of dice with 4 in the array. Then, under the current classification, if-elseif-else statements are used to list all possible results of the current number of 4. When comparing the options, a ContrastArr array was set to store dice with the same number of points. The array length was used to determine the number of dice with the same number of points in the set of dice.

3. Small program pop-up Settings

When we first contacted wechat developer tools, it took us a lot of time to click the button to pop up the popover and realize the mask effect. After referring to various popover operations of wechat mini program, we finally got the concrete realization

img

3.Experience and harvest in experiment

1.At the beginning of the project, I did not know the relevant knowledge of wechat small program development and did not know the programming language used. Therefore, to learn unfamiliar knowledge and write programs, at least more than half of the time was spent on learning new knowledge. This kind of time is short and the task is tight, and the situation of constantly learning new things is beneficial.
2.In the process of the experiment, we find that there are always mistakes between reality and imagination. We need to realize the final effect according to the actual situation and our own level.
3.This is the second pair assignment. Compared with the last assignment, this assignment is obviously much more difficult to realize. At the beginning of this assignment, I first agreed with my teammates on the core functions to be completed, and then I beautified and optimized the interface together. In the process of working in pairs, in line with the principle of being responsible for teammates and homework, I also avoided the phenomenon of being lazy and improved the efficiency of completion.

4.Summary

In this experiment, we not only need to complete more difficult tasks than before, but also need to learn the new language and software. The whole process is very difficult. At the same time, we also need to recognize the gap between the ideal and the reality, and some needs are very difficult to achieve and have to give up. There is something wrong with this experiment. At the same time, I understand the importance of cooperation. Only through mutual encouragement, help and learning can we complete this project.

...全文
133 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

285

社区成员

发帖
与我相关
我的任务
社区描述
福州大学 梅努斯国际工程学院 软件工程(2022秋) 教学
软件工程 高校
社区管理员
  • LinQF39
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧