⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 everyman.cpp

📁 一个麻将程序。我的。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    int x2=x+zuhand.getcount()*25;
    if(mousex<x2&&mousex>=x&&mousey<=497&&mousey>=462)
        return (mousex-x)/25;

    if(mousex<=x2+24+5&&mousex>=x2+5&&mousey<=497&&mousey>=462)
        return  50;

    if(mousex<564&&mousex>=500&&mousey<=538&&mousey>=520)
        return (mousex-500)/16+101;

    return 100;
}
void player::resetbegin()
{
    int c=zushowed.getkuaicount();

    int s=0;int i;
    for(i=0;i<c;i++)
    {
        if(zushowed.iske(i)||zushowed.isshun(i)||zushowed.isgang(i))
            s+=3*25;
        else
            s+=25;

        s+=5;
    }

    s+=zuhand.getcount()*25;

    beginx=153+(495-30-s)/2;
}

void computerright::resetbegin()
{
    int c=zushowed.getkuaicount();

    int s=0;int i;
    for(i=0;i<c;i++)
    {
        if(zushowed.iske(i)||zushowed.isshun(i)||zushowed.isgang(i))
            s+=3*25;
        else
            s+=25;

        s+=5;
    }

    s+=zuhand.getcount()*25;

    beginy=507-(495-30-s)/2;

}
void computerleft::resetbegin()
{
    int c=zushowed.getkuaicount();

    int s=0;int i;
    for(i=0;i<c;i++)
    {
        if(zushowed.iske(i)||zushowed.isshun(i)||zushowed.isgang(i))
            s+=3*25;
        else
            s+=25;

        s+=5;
    }

    s+=zuhand.getcount()*25;

    beginy=33+(495-30-s)/2;

}

void computerup::resetbegin()
{
    int c=zushowed.getkuaicount();

    int s=0;int i;
    for(i=0;i<c;i++)
    {
        if(zushowed.iske(i)||zushowed.isshun(i)||zushowed.isgang(i))
            s+=3*25;
        else
            s+=25;

        s+=5;
    }

    s+=zuhand.getcount()*25;

    beginx=602-(495-30-s)/2;

}

mjpai mjontable::takeone(bool fromhead) //取一张,变量代表从头还是尾
{
    if(fromhead)
    {
        takenfromhead++;
        return takemj(0);
    }
    else
    {
        takenfromtail++;
        return takemj(mjpaizu::getcount()-1);
    }
}

//---------------------------------------

void mjontableshowed::clear()
{
    int i,j;

    for(i=0;i<10;i++)
        for(j=0;j<8;j++)
        {
            posmj1[i][j]=char(0);
            if(i<2) newestmj[i]=100;
            if(i<8&&j<5)
                  posmj2[i][j]=char(0);
        }

    flag_firstlayerused=false;

    showedinhand.clear();

    count=0;
}
mjontableshowed::mjontableshowed():showedinhand(80)//初始化vector的capacity为80张
{
    clear();
}
void mjontableshowed::insertmjup(mjpai mj)
{
    assert(count<120);

    sound(Form1,mj);

    int i,j;

    if(!flag_firstlayerused)
        for(j=0;j<8;j++)
            for(i=9;i>=0;i--)
                if(posmj1[i][j]==char(0))
                {
                     posmj1[i][j]=char(mj);
                     count++;
                     newestmj[0]=i;
                     newestmj[1]=j;
                     return;
                }
     assert(0);//现行120张麻将不可能执行到这
     flag_firstlayerused=true;

     for(j=0;j<5;j++)
        for(i=7;i>=0;i--)
            if(posmj2[i][j]==char(0))
            {
                posmj2[i][j]=char(mj);
                count++;
                newestmj[0]=i;
                newestmj[1]=j;
                return;
            }

}
void mjontableshowed::sound(TForm1 *Form1,mjpai mj)const
{
    if(!Form1->m_sound)return;

        if (mj.iswan())
         {
            Form1->sound->FileName="wav\\wfn0"+AnsiString(mj-10)+".wav";
         }
         if(mj.istiao())
         {
            Form1->sound->FileName="wav\\wfn1"+AnsiString(mj-30)+".wav";
         }
         if(mj.isbing())
         {
            Form1->sound->FileName="wav\\wfn2"+AnsiString(mj-50)+".wav";
         }
         if(mj.iszi())
         {
            Form1->sound->FileName="wav\\wfn3"+AnsiString((mj-71)/10+5)+".wav";
         }
         Form1->sound->Open();
         Form1->sound->Play();
}
void mjontableshowed::insertmjdown(mjpai mj)
{
    assert(count<120);

    sound(Form1,mj);

    int i,j;

    if(!flag_firstlayerused)
        for(j=7;j>=0;j--)
            for(i=0;i<10;i++)
                if(posmj1[i][j]==char(0))
                {
                     posmj1[i][j]=char(mj);
                     count++;
                     newestmj[0]=i;
                     newestmj[1]=j;
                     return;
                }

     assert(0);//现行120张麻将不可能执行到这
     flag_firstlayerused=true;

     for(j=4;j>=0;j--)
        for(i=0;i<8;i++)
            if(posmj2[i][j]==char(0))
            {
                posmj2[i][j]=char(mj);
                count++;
                newestmj[0]=i;
                newestmj[1]=j;
                return;
            }

}

void mjontableshowed::insertmjleft(mjpai mj)
{
    assert(count<120);

    sound(Form1,mj);

    int i,j;

    if(!flag_firstlayerused)
        for(i=0;i<10;i++)
            for(j=0;j<8;j++)
                if(posmj1[i][j]==char(0))
                {
                     posmj1[i][j]=char(mj);
                     count++;
                     newestmj[0]=i;
                     newestmj[1]=j;
                     return;
                }

     assert(0);//现行120张麻将不可能执行到这
     flag_firstlayerused=true;

     for(i=0;i<8;i++)
        for(j=0;j<5;j++)
            if(posmj2[i][j]==char(0))
            {
                posmj2[i][j]=char(mj);
                count++;
                newestmj[0]=i;
                newestmj[1]=j;
                return;
            }

}

void mjontableshowed::insertmjright(mjpai mj)
{
    assert(count<120);

    sound(Form1,mj);

    int i,j;

    if(!flag_firstlayerused)
        for(i=9;i>=0;i--)
            for(j=7;j>=0;j--)
                if(posmj1[i][j]==char(0))
                {
                     posmj1[i][j]=char(mj);
                     count++;
                     newestmj[0]=i;
                     newestmj[1]=j;
                     return;
                }

     assert(0);//现行120张麻将不可能执行到这
     flag_firstlayerused=true;

     for(i=7;i>=0;i--)
         for(j=4;j>=0;j--)
            if(posmj2[i][j]==char(0))
            {
                posmj2[i][j]=char(mj);
                count++;
                newestmj[0]=i;
                newestmj[1]=j;
                return;
            }

}

void mjontableshowed::insertshowedinhand(mjpai mj)
{
     showedinhand.insertmj(mj);
}

int mjontableshowed::find(mjpai mj)const
{
    int c=0;

    int cc=showedinhand.getcount( );

    for(int i=0;i<cc;i++)
        if(showedinhand.getmj(i)==mj)
            c++;



    if(flag_firstlayerused)
    {
        for(int i=0;i<10;i++)
            for(int j=0;j<8;j++)
            {
                if(posmj1[i][j]==char(mj))
                    c++;
                if(i<8&&j<5)
                    if(posmj2[i][j]==char(mj))
                        c++;
            }
    }
    else
    {
        for(int i=0;i<10;i++)
            for(int j=0;j<8;j++)
                if(posmj1[i][j]==char(mj))
                    c++;
    }

    assert(c<=4);

    return c;
}

TRect mjontableshowed::picrect(mjpai mj) const
{      
    if(mj>=11&&mj<=19)
        return Rect((mj-11)*25,0,25+(mj-11)*25,35);
    else if(mj>=31&&mj<=39)
        return Rect((mj-31)*25,35,25+(mj-31)*25,70);
    else if(mj>=51&&mj<=59)
        return Rect((mj-51)*25,70,25+(mj-51)*25,105);
    else if(mj==91)
        return Rect(0,105,24,139);
    else if(mj==81)
        return Rect(25,105,49,139);
    else if(mj==71)
        return Rect(50,105,74,139);
    else if(mj==100)
        return Rect(175,105,200,140);


    return Rect(0,0,0,0);
}
void mjontableshowed::draw(int image)const
{
    if(count==0)return;
    
    int i,j;
    //player *pp;

    TImage *im=image==1?Form1->imdownming1o:Form1->imdownming2o;

    for(i=0;i<10;i++)
        for(j=0;j<8;j++)
            if(posmj1[i][j]!=char(0))
                 Form1->PaintBox1->Canvas->CopyRect(Rect(278+i*25,120+j*35,278+i*25+24,120+j*35+34),
                    im->Canvas, picrect(mjpai(posmj1[i][j])));

    if(flag_firstlayerused) {

        for(i=0;i<8;i++)
          for(j=0;j<5;j++)
            if(posmj2[i][j]!=char(0))
                 Form1->PaintBox1->Canvas->CopyRect(Rect(278+25+3+i*25,120+70-16+j*35,278+25+3+i*25+24,120+70-16+j*35+34),
                    im->Canvas, picrect(mjpai(posmj1[i][j])));
     }

    //画最新一张边框
    if(newestmj[0]==100||newestmj[1]==100)return;
    
    if(!flag_firstlayerused){
        Form1->PaintBox1->Canvas->CopyRect(Rect(278+newestmj[0]*25,120+newestmj[1]*35,278+newestmj[0]*25+2,120+newestmj[1]*35+34),
            Form1->imbiankuang->Canvas, Rect(0,0,2,35));
        Form1->PaintBox1->Canvas->CopyRect(Rect(278+newestmj[0]*25,120+newestmj[1]*35,278+newestmj[0]*25+24,120+newestmj[1]*35+2),
            Form1->imbiankuang->Canvas, Rect(0,0,25,2));
        Form1->PaintBox1->Canvas->CopyRect(Rect(278+newestmj[0]*25+23,120+newestmj[1]*35,278+newestmj[0]*25+24,120+newestmj[1]*35+34),
            Form1->imbiankuang->Canvas, Rect(23,0,25,35));
        Form1->PaintBox1->Canvas->CopyRect(Rect(278+newestmj[0]*25,120+newestmj[1]*35+33,278+newestmj[0]*25+24,120+newestmj[1]*35+34),
            Form1->imbiankuang->Canvas, Rect(0,33,25,35));
    }
    else {
        Form1->PaintBox1->Canvas->CopyRect(Rect(278+25+3+newestmj[0]*25,120+70-16+newestmj[1]*35,278+25+3+newestmj[0]*25+2,120+70-16+newestmj[1]*35+34),
            Form1->imbiankuang->Canvas, Rect(0,0,2,35));
        Form1->PaintBox1->Canvas->CopyRect(Rect(278+25+3+newestmj[0]*25,120+70-16+newestmj[1]*35,278+25+3+newestmj[0]*25+24,120+70-16+newestmj[1]*35+2),
            Form1->imbiankuang->Canvas, Rect(0,0,25,2));
        Form1->PaintBox1->Canvas->CopyRect(Rect(278+25+3+newestmj[0]*25+23,120+70-16+newestmj[1]*35,278+25+3+newestmj[0]*25+24,120+70-16+newestmj[1]*35+34),
            Form1->imbiankuang->Canvas, Rect(23,0,25,35));
        Form1->PaintBox1->Canvas->CopyRect(Rect(278+25+3+newestmj[0]*25,120+70-16+newestmj[1]*35+33,278+25+3+newestmj[0]*25+24,120+70-16+newestmj[1]*35+34),
            Form1->imbiankuang->Canvas, Rect(0,33,25,35));
    }


}

mjpai mjontableshowed::takenewest()
{
    assert(newestmj[0]!=100&&newestmj[1]!=100);
     int mj;
     if(!flag_firstlayerused){
         mj=(int)posmj1[newestmj[0]][newestmj[1]];
         posmj1[newestmj[0]][newestmj[1]]=char(0);
     }
     else{
         mj=(int)posmj2[newestmj[0]][newestmj[1]];
         posmj2[newestmj[0]][newestmj[1]]=char(0);
     }
     newestmj[0]=newestmj[1]=100;


     count--;
     if(count<80)
        flag_firstlayerused=false;



     assert(mj>=mjpai::wan1&&mj<=mjpai::bai);
     return mj;
}

mjpai mjontableshowed::getnewest()const
{
    assert(newestmj[0]!=100&&newestmj[1]!=100);

     if(!flag_firstlayerused){
         return (int)posmj1[newestmj[0]][newestmj[1]];
     }
     else{
         return (int)posmj2[newestmj[0]][newestmj[1]];
     }
}








⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -