- void HelloWorld::ccTouchesBegan( CCSet *pTouches, CCEvent *pEvent )
- {
- CCSetIterator it = pTouches->begin();
- CCTouch* touch = (CCTouch*)(*it);
- CCPoint location = touch->locationInView();
- CCPoint convertedLocation = CCDirector::sharedDirector()->convertToGL(location);
- int x=convertedLocation.x;
- int y=convertedLocation.y;
- //帖子---------------------------------------------------------------
- if (x>=62&&x<492 && y>=21&&y<451)
- {
- if(k!=1){
- MessageBoxA(
- NULL,
- "游戏未开始,请登录",
- "五子棋",
- MB_OKCANCEL);
- }
- if (k==1)
- {
- s++;
- c++;
- i=((x-73)%30)<=15?((x-73)/30):(((x-73)/30)+1);
- j=((y-31)%30)<=15?((y-31)/30):(((y-31)/30)+1);
- weix[s]=i;
- weiy[s]=j;
- if (chess[i][j]==0)
- {
- if (c%2==0)
- {
- CCSprite* pSprite = CCSprite::create("黑子副本.png");
- pSprite->setPosition(ccp(i*30+73,j*30+31));
- this->addChild(pSprite, 1,1);
- chess[i][j]=1;
- }
- if (c%2==1)
- {
- CCSprite* pSprite = CCSprite::create("白子副本.png");
- pSprite->setPosition(ccp(i*30+73,j*30+31));
- this->addChild(pSprite, 1,1);
- chess[i][j]=2;
- }
- }
- for(i=0;i<15;i++)
- for(j=0;j<15;j++)
- {
- if(chess[i][j]==1&&chess[i][j+1]==1&&chess[i][j+2]==1&&chess[i][j+3]==1&&chess[i][j+4]==1)
- {
- bangming(dup3());
- gamer();
- for(i=0;i<15;i++)
- for(j=0;j<15;j++)
- chess[i][j]=0;
- }
- if(chess[i][j]==2&&chess[i][j+1]==2&&chess[i][j+2]==2&&chess[i][j+3]==2&&chess[i][j+4]==2)
- {
- bangming(dup4());
- gamer();
- for(i=0;i<15;i++)
- for(j=0;j<15;j++)
- chess[i][j]=0;
- }
- }
- for(j=0;j<15;j++)//判断横着的5个是否都相等
- for(i=0;i<15;i++)
- {
- if(chess[i][j]==1&&chess[i+1][j]==1&&chess[i+2][j]==1&&chess[i+3][j]==1&&chess[i+4][j]==1)
- // MessageBoxA(
- // NULL,
- // "d",
- //"s",
- // NULL);
- {
- bangming(dup3());
- gamer();
- for(i=0;i<15;i++)
- for(j=0;j<15;j++)
- chess[i][j]=0;
- }
- if(chess[i][j]==2&&chess[i+1][j]==2&&chess[i+2][j]==2&&chess[i+3][j]==2&&chess[i+4][j]==2)
- {
- bangming(dup4());
- gamer();
- for(i=0;i<15;i++)
- for(j=0;j<15;j++)
- chess[i][j]=0;
- }
- }
- for(i=0;i<15;i++)//判断左斜5个
- for(j=0;j<15;j++)
- {
- if(chess[i][j]==1&&chess[i+1][j+1]==1&&chess[i+2][j+2]==1&&chess[i+3][j+3]==1&&chess[i+4][j+4]==1)
- {
- bangming(dup3());
- gamer();
- for(i=0;i<15;i++)
- for(j=0;j<15;j++)
- chess[i][j]=0;
- }
- if(chess[i][j]==2&&chess[i+1][j+1]==2&&chess[i+2][j+2]==2&&chess[i+3][j+3]==2&&chess[i+4][j+4]==2)
- {
- bangming(dup4());
- gamer();
- for(i=0;i<15;i++)
- for(j=0;j<15;j++)
- chess[i][j]=0;
- }
- }
- //return 1;
- for(i=0;i<15;i++)//右斜5个
- for(j=0;j<15;j++)
- {
- if(chess[i][j]==1&&chess[i+1][j-1]==1&&chess[i+2][j-2]==1&&chess[i+3][j-3]==1&&chess[i+4][j-4]==1)
- {
- bangming(dup3());
- gamer();
- for(i=0;i<15;i++)
- for(j=0;j<15;j++)
- chess[i][j]=0;
- }
- if(chess[i][j]==2&&chess[i+1][j-1]==2&&chess[i+2][j-2]==2&&chess[i+3][j-3]==2&&chess[i+4][j-4]==2)
- {
- bangming(dup4());
- gamer();
- for(i=0;i<15;i++)
- for(j=0;j<15;j++)
- chess[i][j]=0;
- }
- }
- }
- }
- if (x>=0&&x<50&&y>=0&&y<50)
- {
- if(yx0>=0)
- {
- p5=fopen("hero.txt","w");
- fprintf(p5,"%d",yx0);
- for(yx=0;yx<=yx0;yx++)
- fprintf(p5,"%s %d\\n",xingming[yx].c_str(),cishu[yx]);
- fprintf(p5,"%s %d\\n",xingming1.c_str(),cishu1);
- fprintf(p5,"%s %d\\n",xingming2.c_str(),cishu2);
- fprintf(p5,"%s %d\\n",xingming3.c_str(),cishu3);
- fclose(p5);
- }
- }
- //结束--------------------------------------------------------------
- if(x>=750&&x<800&&y>=0&&y<50)
- {
- jilu();
- }
- //kaishi-------------------------------------------------------------
- if (x>=500&&x<650&&y>=271&&y<344)
- {
- k=1;
- for(i=0;i<15;i++)
- for(j=0;j<15;j++)
- {
- chess[i][j]=0;
- }
- //MessageBoxA(
- //NULL,
- //"游戏已开始",
- //"五子棋",
- //NULL);
- kaishi();
- }
- //复盘-------------------------
- if (x>=610&&x<=700&&y>=180&&y<=220)
- {
- MessageBoxA(
- NULL,
- "11",
- "22",
- NULL);
- p2=fopen("fupan.txt","r");
- if(!p2)
- {
- MessageBoxA(
- NULL,
- "复盘",
- "无子可悔!",
- NULL);
- return;
- }
- for (i=0;i<15;i++)
- for (j=0;j<15;j++)
- {
- fscanf(p2," %d",&chess[i][j]);
- }
- fclose(p2);
- ondraw2();
- }
- //---------------------------悔棋--------------
- if (x>=710&&x<800&&y>=180&&y<225)
- {
- chess[weix[s]][weiy[s]]=0;
- s--;
- MessageBoxA(
- NULL,
- "是否悔棋!",
- "五子棋",
- NULL);
- ondraw();
- }
- //英雄榜---------------------------------------------------------------------
- if (x>=520&&x<780&&y>=42&&y<160)
- {
- CCScene *pscene = hero::scene();
- CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1.5, pscene));
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/091220137827.html
来源: http://www.codesnippet.cn/detail/091220137827.html