全部评论 3

  • 1

    2026-07-31 来自 浙江

    0
  • 1

    2026-07-31 来自 浙江

    0
  • #include <iostream>
    #include <string>
    #include <windows.h>
    #include <conio.h>
    
    using namespace std;
    
    // 棋盘尺寸
    const int BOARD_ROWS = 10;
    const int BOARD_COLS = 9;
    
    // 棋子类型枚举
    enum PieceType {
    EMPTY = 0,
    R_SHUAI = 1, R_SHI = 2, R_XIANG = 3, R_MA = 4,
    R_CHE = 5, R_PAO = 6, R_BING = 7,
    B_JIANG = -1, B_SHI = -2, B_XIANG = -3, B_MA = -4,
    B_CHE = -5, B_PAO = -6, B_ZU = -7
    };
    
    // 控制台颜色常量
    const int COLOR_RED = 12; // 红方棋子:亮红色
    const int COLOR_BLACK = 11; // 黑方棋子:亮青色
    const int COLOR_WHITE = 15; // 边框与坐标:亮白色
    const int COLOR_YELLOW = 14; // 标题与提示:亮黄色
    const int COLOR_GREEN = 10; // 楚河汉界:亮绿色
    
    // 游戏状态常量
    const int STATE_SELECT_PIECE = 0; // 选择棋子状态
    const int STATE_SELECT_TARGET = 1; // 选择目标状态
    
    // ==================== 控制台辅助函数【新增,解决闪烁】 ====================
    void GotoXY(int x, int y)
    {
    COORD pos;
    pos.X = x;
    pos.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
    }
    
    // ==================== 棋子类 ====================
    
    class Piece {
    public:
    int type, row, col;
    Piece(int t = EMPTY, int r = 0, int c = 0) : type(t), row(r), col(c) {}
    
    bool isRed() const { return type > 0; }
    bool isBlack() const { return type < 0; }
    bool isEmpty() const { return type == EMPTY; }
    
    const char* getChar() const {
        switch (type) {
        case R_SHUAI: return "\xCB\xA7"; // 帅
        case R_SHI:   return "\xCA\xCB"; // 仕
        case R_XIANG: return "\xCF\xE0"; // 相
        case R_MA:    return "\xC2\xED"; // 马
        case R_CHE:   return "\xB3\xB5"; // 车
        case R_PAO:   return "\xC5\xDA"; // 炮
        case R_BING:  return "\xB1\xF8"; // 兵
        case B_JIANG: return "\xBD\xAB"; // 将
        case B_SHI:   return "\xCA\xBF"; // 士
        case B_XIANG: return "\xCF\xF3"; // 象
        case B_MA:    return "\xC2\xED"; // 马
        case B_CHE:   return "\xB3\xB5"; // 车
        case B_PAO:   return "\xC5\xDA"; // 炮
        case B_ZU:    return "\xD7\xE4"; // 卒
        default:      return "  ";
        }
    }
    
    int getColor() const {
        if (isRed()) return COLOR_RED;
        if (isBlack()) return COLOR_BLACK;
        return COLOR_WHITE;
    }
    };
    
    // ==========
    

    2026-07-30 来自 浙江

    0

热门讨论