当前位置:网站首页>Wechat applet project example - renju for two

Wechat applet project example - renju for two

2022-06-12 02:48:00 Long lost brother

Wechat applet project example —— Double Gobang

See the bottom of the text for the project code , Praise, focus and surprise


One 、 Project presentation

Wechat applet project example —— Double Gobang
Gobang for two is a small game program
Two players can play in 15x15 On the chessboard
Play Gobang
At the same time, the applet has set the repentance function

 Insert picture description here


Two 、 Project core code


Click to drop

step: function(event)
  {
    var pos=event.currentTarget.dataset.pos;
    wx.setStorageSync('vak', this.data.vak);
    
    if(this.data.vak[pos]=="white"||this.data.vak[pos]=="black")return;
    this.count++;
    if(this.count%2)
    {
      this.data.vak[pos]="black";
    }
    else
    {
      this.data.vak[pos]="white";
    }
    this.setData({
      vak : this.data.vak
    })
    this.judge(pos);
  }

Judge the outcome

  judge: function(pos)
  {
    var color=this.data.vak[pos];
    var x0=parseInt(pos/15),y0=pos%15,x,y,round;
    for(var i=0;i<4;i++)
    {
      var five=0;
      round=0;
      for(x=x0,y=y0;round<5;x+=this.vec[i][0],y+=this.vec[i][1],round++)
      {
        if(this.data.vak[15*x+y]==color)
        {
          five++;
        }
        else
        {
          break;
        }
      }
      round=0;
      for(x=x0,y=y0;round<5;x-=this.vec[i][0],y-=this.vec[i][1],round++)
      {
        if(this.data.vak[15*x+y]==color)
        {
          five++;
        }
        else
        {
          break;
        }
      }
      var rstr=color+"win";
      if(five>=6)
      {
        this.setData({
          result : rstr
        });
        wx.showModal({
        title: color+' win victory ',
        content: ' Another round ',
        success: function(res) {
          if (res.confirm) {
         wx.redirectTo({
           url:"./index"
         });
          }
        }
        })
      }
    }
  },

3、 ... and 、 Effect display


Victory effect

 Insert picture description here

restart

 Insert picture description here

Repentance

 Insert picture description here


At the end of the article

That's all for the specific introduction
Interested students can continue to study
The code is in the link below

Click to download Applet

 Insert picture description here

原网站

版权声明
本文为[Long lost brother]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120245137161.html