Ejemplo n.º 1
0
void chc_drawline(board_t board, int line) {
    int i, j;

    move(line, 0);
    clrtoeol();
    if(line == 0) {
        prints("\033[1;46m   象棋對奕   \033[45m%30s VS %-30s\033[m",
               cuser.userid, uin->userid);
    } else if(line >= 3 && line <= 21) {
        outs("   ");
        for(i = 0; i < 9; i++) {
            j = board[RTL(line)][i];
            if((line & 1) == 1 && j) {
                if(chc_selected &&
                   chc_select.r == RTL(line) && chc_select.c == i)
                    prints("%s%s\033[m",
                           CHE_O(j) == 0 ? BLACK_REVERSE : RED_REVERSE,
                           chess_str[CHE_O(j)][CHE_P(j)]);
                else
                    prints("%s%s\033[m",
                           CHE_O(j) == 0 ? BLACK_COLOR : RED_COLOR,
                           chess_str[CHE_O(j)][CHE_P(j)]);
            } else
                prints("%c%c", chess_brd[line - 3][i * 4],
                       chess_brd[line - 3][i * 4 + 1]);
            if(i != 8)
                prints("%c%c", chess_brd[line - 3][i * 4 + 2],
                       chess_brd[line - 3][i * 4 + 3]);
        }
        outs("        ");

        if(line >= 3 && line < 3 + dim(hint_str)) {
            outs(hint_str[line - 3]);
        } else if(line == SIDE_ROW) {
            prints("\033[1m你是%s%s\033[m",
                   chc_my == 0 ? BLACK_COLOR : RED_COLOR,
                   turn_str[chc_my]);
        } else if(line == TURN_ROW) {
            prints("%s%s\033[m",
                   TURN_COLOR,
                   chc_my == chc_turn ? "輪到你下棋了" : "等待對方下棋");
        } else if(line == STEP_ROW && !chc_firststep) {
            showstep(board);
        } else if(line == TIME_ROW) {
            prints("剩餘時間 %d:%02d", chc_lefttime / 60, chc_lefttime %60);
        } else if(line == WARN_ROW) {
            outs(chc_warnmsg);
        } else if(line == MYWIN_ROW) {
            prints("\033[1;33m%12.12s    "
                   "\033[1;31m%2d\033[37m勝 "
                   "\033[34m%2d\033[37m敗 "
                   "\033[36m%2d\033[37m和\033[m",
                   cuser.userid,
                   my.chc_win, my.chc_lose , my.chc_tie);
        } else if(line == HISWIN_ROW) {
            prints("\033[1;33m%12.12s    "
                   "\033[1;31m%2d\033[37m勝 "
                   "\033[34m%2d\033[37m敗 "
                   "\033[36m%2d\033[37m和\033[m",
                   uin->userid,
                   chc_hiswin, chc_hislose , chc_histie);
        }
    } else if(line == 2 || line == 22) {
        outs("   ");
        if(line == 2)
            for(i = 1; i <= 9; i++)
                prints("%s  ", num_str[i]);
        else
            for(i = 9; i >= 1; i--)
                prints("%s  ", num_str[i]);
    }
}
Ejemplo n.º 2
0
void UI::Keyboard(void)
{
  Common *cm = Common::GetInstance();

  bool is_acc_prev = cm->is_acc;
  bool is_dec_prev = cm->is_dec;
  GLdouble scale_prev = cm->scale;
  GLdouble radius_prev = cm->radius;
  GLdouble phi_prev = cm->phi;
  GLdouble theta_prev = cm->theta;
  //  GLdouble dx_prev = cm->dx;
  //  GLdouble dy_prev = cm->dy;
  //  GLdouble dd_prev = cm->dd;

  if (CAVEgetbutton(CAVE_HKEY)) {
    //		cm->runstate = 0;

    //	show_help();

  } else if (CAVEgetbutton(CAVE_AKEY)) {
    if(cm->inc <= 0&&cm->runstate==1){
      cm->inc = 1;
    }
    if (cm->runstate == 0 && !cm->is_acc) {
      cm->is_acc = true;
      cout << "is_acc: " << is_acc_prev << " -> " << cm->is_acc << endl;
    }
  } else if (CAVEgetbutton(CAVE_QKEY)) {
    if(cm->inc > 0&&cm->runstate==1){
      cm->inc = -1;
    }
    if (cm->runstate == 0 && !cm->is_dec) {
      cm->is_dec = true;
      cout << "is_dec: " << is_dec_prev << " -> " << cm->is_dec << endl;
    }
  } else if (CAVEgetbutton(CAVE_SKEY)) {
    if (CAVEgetbutton(CAVE_ZKEY)) {
      /* s */
      cm->scale *= SCALE_UNIT;
      cout << "scale: " << scale_prev << " -> " << cm->scale << endl;
    } else {
      /*z_s*/
      cm->scale /= SCALE_UNIT;
      cout << "scale: " << scale_prev << " -> " << cm->scale << endl;
    }
  } else if (CAVEgetbutton(CAVE_RKEY)) {
    if (!CAVEgetbutton(CAVE_ZKEY)) {
      /*z_r */
      cm->radius *= SCALE_UNIT;
      cout << "radius: " << radius_prev << " -> " << cm->radius << endl;
    } else {
      /* r */
      cm->radius /= SCALE_UNIT;
      cout << "radius: " << radius_prev << " -> " << cm->radius << endl;
    }
  } else if (CAVEgetbutton(CAVE_XKEY)) {
    if (CAVEgetbutton(CAVE_ZKEY)) {
      /*x*/
      cm->phi += 0.03;
      cm->phi += 3;
      cout << "phi: " << phi_prev << " -> " << cm->phi << endl;
    } else {
      /*z_x*/
      cm->phi -= 0.03;
      cm->phi -=3;
      cout << "phi: " << phi_prev << " -> " << cm->phi << endl;
    }
  } else if (CAVEgetbutton(CAVE_YKEY)) {
    if (CAVEgetbutton(CAVE_CTRLKEY)) {
      /* y */
      cm->theta += 0.03;
      cm->theta += 3;
      cout << "theta: " << theta_prev << " -> " << cm->theta << endl;
    } else {
      /*z_y */
      cm->theta -= 0.03;
      cm->theta -= 3;
      cout << "theta: " << theta_prev << " -> " << cm->theta << endl;
    }
    // 	} else if (CAVEgetbutton(CAVE_UKEY)) {
    // 		if (!CAVEgetbutton(CAVE_CTRLKEY)) {
    // 			/* U */
    //  			cm->dx += cm->dd;
    // 			cout << "dx: " << dx_prev << " -> " << cm->dx << endl;
    // 		} else {
    // 			/* u */
    // 			cm->dx -= cm->dd;
    // 			cout << "dx: " << dx_prev << " -> " << cm->dx << endl;
    // 	}
    // 	} else if (CAVEgetbutton(CAVE_NKEY)) {
    // 		if (!CAVEgetbutton(CAVE_CTRLKEY)) {
    // 			/* N */
    // 			cm->dy += cm->dd;
    // 			cout << "dy: " << dy_prev << " -> " << cm->dy << endl;
    // 		} else {
    // 			/* n */
    // 			cm->dy -= cm->dd;
    // 			cout << "dy: " << dy_prev << " -> " << cm->dy << endl;
    // 		}
    //	} else if (CAVEgetbutton(CAVE_TKEY)) {
    //		if (!CAVEgetbutton(CAVE_CTRLKEY)) {
    //			/* T */
    //			cm->dd *= 1.3;
    //			cout << "dd: " << dd_prev << " -> " << cm->dd << endl;
    //		} else {
    //			/* t */
    //			cm->dd /= 1.3;
    //			cout << "dd: " << dd_prev << " -> " << cm->dd << endl;
    //		}
  }else if(CAVEgetbutton(CAVE_CKEY)){

    cm->char_state = 1;
    if(CAVEgetbutton(CAVE_ZKEY))
      cm->char_state = 0;
  } else if (CAVEgetbutton(CAVE_PERIODKEY)) {
    /* . */
    showstep(1);
  } else if (CAVEgetbutton(CAVE_COMMAKEY)) {
    /* , */
    showstep(-1);
  }
}