Example #1
0
void
FieldView::ToggleBox(const IntPoint &pt)
{
	switch (fField->GetState(pt))
	{
		case BOX_MARKED:
		{
			fField->SetState(pt,BOX_QUESTION);
			fFlagCount--;
			Window()->PostMessage(M_UPDATE_COUNT);
			break;
		}
		case BOX_QUESTION:
		{
			fField->SetState(pt,BOX_UNMARKED);
			break;
		}
		case BOX_UNMARKED:
		{
			if (fFlagCount == fField->MineCount())
			{
				BAlert *alert = new BAlert(B_TRANSLATE_SYSTEM_NAME("BeMines"),B_TRANSLATE("You have already set as many "
									"flags as there are mines. Unflag a tile "
									"before trying to flag another one."),B_TRANSLATE("OK"));
				alert->Go();
				break;
			}

			fField->SetState(pt,BOX_MARKED);
			fFlagCount++;
			Window()->PostMessage(M_UPDATE_COUNT);

			if (CheckWin())
			{
				DoWin();
				break;
			}
			break;
		}
		default:
		{
			break;
		}
	}
	Invalidate(gGameStyle->TileRect(pt.x,pt.y));
}
Example #2
0
void
FieldView::OpenBox(const IntPoint &pt)
{
	if (pt.x >= fField->Width() || pt.y >= fField->Height() )
		return;

	if (fField->GetState(pt) == BOX_UNMARKED)
	{
		if (fField->IsMine(pt))
		{
			fField->SetState(pt,BOX_HIT);
			DoLose();
		}
		else
		{
			fField->SetState(pt,BOX_REVEALED);
			if (CheckWin())
				DoWin();
		}
	}
	Invalidate(gGameStyle->TileRect(pt.x,pt.y));
}
Example #3
0
/*主函数*/
void main()
{
  int press;
  int bOutWhile=0;/*退出循环标志*/

  int a=DETECT,b;     /*切换到图形模式*/
  initgraph(&a,&b,"d:\\tc");
  gotoxy(28,5);printf ("****WELCOME TO WU ZI Qi****");
  gotoxy(33,8);printf("xi  tong  ben\n");
  gotoxy(33,11);printf ("shao wang quan\n");
  gotoxy(33,12);printf("zhou  rui fei\n ");
  gotoxy(33,13);printf ("wu   guo  xu\n");
  gotoxy(33,14);printf ("yang      wu");
  gotoxy(28,20);printf("Please press any key  start.....");
  getch();
  closegraph();    /*切换到字符模式*/
  Init();/*初始化图象,数据*/
  while(1)
  {
     press=GetKey();/*获取用户的按键值*/
     switch(CheckKey(press))/*判断按键类别*/
        {
          /*是退出键*/
         case KEY_EXIT:
           clrscr();/*清屏*/
           bOutWhile = 1;
         break;
        /*是落子键*/
         case KEY_FALLCHESS:
              /*走棋*/
            if(ChessGo(gPlayOrder,gCursor)==0)/*判断当前是否有子并提示*/
             {
              textcolor(RED+BLINK);
              gotoxy(2,21);
              cputs("Point for chessman,Please enter again!");
              gotoxy(gCursor.x+MAPX_O,gCursor.y+MAPY_O);
             }
            else
             {
                gotoxy(2,21);
                cputs("                                      ");
              /*如果当前行棋方赢棋*/
              if(JudgeWin(gPlayOrder,gCursor)==1)
                {
                   DoWin(gPlayOrder);
                   bOutWhile = 1;/*退出循环标志置为真*/
                }
              else
               /*交换行棋方*/
               ChangeOrder();
            }
        break;
      /*是光标移动键*/
      case KEY_MOVECURSOR:
        MoveCursor(gPlayOrder,press);
      break;
    /*是无效键*/
      case KEY_INVALID:
      break;
    }
    if(bOutWhile==1)
      break;
  }
  /*游戏结束*/
  EndGame();
}