用鸿蒙HarmonyOS5实现国际象棋小游戏的过程

news2025/6/10 12:25:47

下面是一个基于鸿蒙OS (HarmonyOS) 的国际象棋小游戏的完整实现代码,使用Java语言和鸿蒙的Ability框架。

1. 项目结构

/src/main/java/com/example/chess/
    ├── MainAbilitySlice.java    // 主界面逻辑
    ├── ChessView.java          // 游戏视图和逻辑
    ├── ChessPiece.java         // 棋子类
    └── resources/
        ├── base/
        │   ├── layout/
        │   │   └── ability_main.xml  // 布局文件
        │   └── graphic/
        │       └── board_bg.xml      // 棋盘背景

2. 实现代码

ChessPiece.java (棋子类)

package com.example.chess;

public class ChessPiece {
    public static final int WHITE = 0;
    public static final int BLACK = 1;
    
    // 棋子类型常量
    public static final int KING = 0;      // 王
    public static final int QUEEN = 1;     // 后
    public static final int ROOK = 2;      // 车
    public static final int BISHOP = 3;    // 象
    public static final int KNIGHT = 4;    // 马
    public static final int PAWN = 5;      // 兵
    
    private int type;   // 棋子类型
    private int color;  // 棋子颜色
    private int row;    // 行
    private int col;    // 列
    private boolean hasMoved = false; // 是否移动过(用于王车易位和兵的初始移动)
    
    public ChessPiece(int type, int color, int row, int col) {
        this.type = type;
        this.color = color;
        this.row = row;
        this.col = col;
    }
    
    // getter和setter方法
    public int getType() {
        return type;
    }
    
    public int getColor() {
        return color;
    }
    
    public int getRow() {
        return row;
    }
    
    public void setRow(int row) {
        this.row = row;
    }
    
    public int getCol() {
        return col;
    }
    
    public void setCol(int col) {
        this.col = col;
    }
    
    public boolean hasMoved() {
        return hasMoved;
    }
    
    public void setMoved(boolean hasMoved) {
        this.hasMoved = hasMoved;
    }
    
    // 获取棋子Unicode字符
    public char getSymbol() {
        switch (type) {
            case KING: return color == WHITE ? '♔' : '♚';
            case QUEEN: return color == WHITE ? '♕' : '♛';
            case ROOK: return color == WHITE ? '♖' : '♜';
            case BISHOP: return color == WHITE ? '♗' : '♝';
            case KNIGHT: return color == WHITE ? '♘' : '♞';
            case PAWN: return color == WHITE ? '♙' : '♟';
            default: return ' ';
        }
    }
}

ChessView.java (游戏视图和逻辑)

package com.example.chess;

import ohos.agp.components.Component;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.agp.utils.RectFloat;
import ohos.app.Context;
import ohos.agp.components.AttrSet;
import ohos.multimodalinput.event.TouchEvent;

import java.util.ArrayList;
import java.util.List;

public class ChessView extends Component implements Component.DrawTask {
    private static final int ROWS = 8;     // 棋盘行数
    private static final int COLS = 8;     // 棋盘列数
    
    private Paint lightPaint;              // 浅色格子画笔
    private Paint darkPaint;               // 深色格子画笔
    private Paint textPaint;               // 文字画笔
    private Paint highlightPaint;          // 高亮画笔
    private Paint moveHintPaint;           // 移动提示画笔
    
    private List<ChessPiece> pieces;       // 棋子列表
    private ChessPiece selectedPiece;      // 当前选中的棋子
    private int currentPlayer = ChessPiece.WHITE; // 当前玩家
    private List<int[]> possibleMoves;     // 当前选中棋子的可能移动位置
    
    public ChessView(Context context) {
        super(context);
        init();
    }
    
    public ChessView(Context context, AttrSet attrSet) {
        super(context, attrSet);
        init();
    }
    
    private void init() {
        lightPaint = new Paint();
        lightPaint.setColor(new Color(0xFFF0D9B5));
        lightPaint.setStyle(Paint.Style.FILL_STYLE);
        
        darkPaint = new Paint();
        darkPaint.setColor(new Color(0xFFB58863));
        darkPaint.setStyle(Paint.Style.FILL_STYLE);
        
        textPaint = new Paint();
        textPaint.setColor(new Color(0xFF000000));
        textPaint.setTextSize(50);
        textPaint.setTextAlign(Paint.Align.CENTER);
        
        highlightPaint = new Paint();
        highlightPaint.setColor(new Color(0x6644FF44));
        highlightPaint.setStyle(Paint.Style.FILL_STYLE);
        
        moveHintPaint = new Paint();
        moveHintPaint.setColor(new Color(0x6644AAFF));
        moveHintPaint.setStyle(Paint.Style.FILL_STYLE);
        
        initPieces();
        possibleMoves = new ArrayList<>();
        addDrawTask(this);
        setTouchEventListener(this::onTouchEvent);
    }
    
    private void initPieces() {
        pieces = new ArrayList<>();
        
        // 初始化白方棋子
        pieces.add(new ChessPiece(ChessPiece.ROOK, ChessPiece.WHITE, 7, 0));
        pieces.add(new ChessPiece(ChessPiece.KNIGHT, ChessPiece.WHITE, 7, 1));
        pieces.add(new ChessPiece(ChessPiece.BISHOP, ChessPiece.WHITE, 7, 2));
        pieces.add(new ChessPiece(ChessPiece.QUEEN, ChessPiece.WHITE, 7, 3));
        pieces.add(new ChessPiece(ChessPiece.KING, ChessPiece.WHITE, 7, 4));
        pieces.add(new ChessPiece(ChessPiece.BISHOP, ChessPiece.WHITE, 7, 5));
        pieces.add(new ChessPiece(ChessPiece.KNIGHT, ChessPiece.WHITE, 7, 6));
        pieces.add(new ChessPiece(ChessPiece.ROOK, ChessPiece.WHITE, 7, 7));
        for (int i = 0; i < 8; i++) {
            pieces.add(new ChessPiece(ChessPiece.PAWN, ChessPiece.WHITE, 6, i));
        }
        
        // 初始化黑方棋子
        pieces.add(new ChessPiece(ChessPiece.ROOK, ChessPiece.BLACK, 0, 0));
        pieces.add(new ChessPiece(ChessPiece.KNIGHT, ChessPiece.BLACK, 0, 1));
        pieces.add(new ChessPiece(ChessPiece.BISHOP, ChessPiece.BLACK, 0, 2));
        pieces.add(new ChessPiece(ChessPiece.QUEEN, ChessPiece.BLACK, 0, 3));
        pieces.add(new ChessPiece(ChessPiece.KING, ChessPiece.BLACK, 0, 4));
        pieces.add(new ChessPiece(ChessPiece.BISHOP, ChessPiece.BLACK, 0, 5));
        pieces.add(new ChessPiece(ChessPiece.KNIGHT, ChessPiece.BLACK, 0, 6));
        pieces.add(new ChessPiece(ChessPiece.ROOK, ChessPiece.BLACK, 0, 7));
        for (int i = 0; i < 8; i++) {
            pieces.add(new ChessPiece(ChessPiece.PAWN, ChessPiece.BLACK, 1, i));
        }
    }
    
    @Override
    public void onDraw(Component component, Canvas canvas) {
        int width = getWidth();
        int height = getHeight();
        float cellWidth = width / (float) COLS;
        float cellHeight = height / (float) ROWS;
        
        // 绘制棋盘
        drawBoard(canvas, width, height, cellWidth, cellHeight);
        
        // 绘制高亮和移动提示
        drawHighlights(canvas, cellWidth, cellHeight);
        
        // 绘制棋子
        drawPieces(canvas, cellWidth, cellHeight);
    }
    
    private void drawBoard(Canvas canvas, int width, int height, float cellWidth, float cellHeight) {
        for (int i = 0; i < ROWS; i++) {
            for (int j = 0; j < COLS; j++) {
                float left = j * cellWidth;
                float top = i * cellHeight;
                float right = left + cellWidth;
                float bottom = top + cellHeight;
                
                Paint paint = (i + j) % 2 == 0 ? lightPaint : darkPaint;
                canvas.drawRect(new RectFloat(left, top, right, bottom), paint);
            }
        }
    }
    
    private void drawHighlights(Canvas canvas, float cellWidth, float cellHeight) {
        // 绘制选中的棋子高亮
        if (selectedPiece != null) {
            float left = selectedPiece.getCol() * cellWidth;
            float top = selectedPiece.getRow() * cellHeight;
            float right = left + cellWidth;
            float bottom = top + cellHeight;
            canvas.drawRect(new RectFloat(left, top, right, bottom), highlightPaint);
        }
        
        // 绘制可能的移动位置
        for (int[] move : possibleMoves) {
            int row = move[0];
            int col = move[1];
            float left = col * cellWidth;
            float top = row * cellHeight;
            float right = left + cellWidth;
            float bottom = top + cellHeight;
            canvas.drawRect(new RectFloat(left, top, right, bottom), moveHintPaint);
        }
    }
    
    private void drawPieces(Canvas canvas, float cellWidth, float cellHeight) {
        for (ChessPiece piece : pieces) {
            float centerX = (piece.getCol() + 0.5f) * cellWidth;
            float centerY = (piece.getRow() + 0.5f) * cellHeight;
            
            textPaint.setColor(piece.getColor() == ChessPiece.WHITE ? Color.WHITE : Color.BLACK);
            canvas.drawText(String.valueOf(piece.getSymbol()), centerX, centerY + 15, textPaint);
        }
    }
    
    private boolean onTouchEvent(Component component, TouchEvent event) {
        if (event.getAction() == TouchEvent.PRIMARY_POINT_DOWN) {
            int width = getWidth();
            int height = getHeight();
            float cellWidth = width / (float) COLS;
            float cellHeight = height / (float) ROWS;
            
            int col = (int) (event.getPointerPosition(0).getX() / cellWidth);
            int row = (int) (event.getPointerPosition(0).getY() / cellHeight);
            
            if (row >= 0 && row < ROWS && col >= 0 && col < COLS) {
                handleClick(row, col);
            }
        }
        return true;
    }
    
    private void handleClick(int row, int col) {
        ChessPiece clickedPiece = getPieceAt(row, col);
        
        if (selectedPiece == null) {
            // 没有选中棋子时,尝试选中一个棋子
            if (clickedPiece != null && clickedPiece.getColor() == currentPlayer) {
                selectedPiece = clickedPiece;
                calculatePossibleMoves();
                invalidate();
            }
        } else {
            // 已经选中了一个棋子
            if (clickedPiece != null && clickedPiece.getColor() == currentPlayer) {
                // 点击的是己方棋子,切换选中
                selectedPiece = clickedPiece;
                calculatePossibleMoves();
                invalidate();
            } else {
                // 检查是否是合法的移动
                for (int[] move : possibleMoves) {
                    if (move[0] == row && move[1] == col) {
                        // 执行移动
                        movePiece(selectedPiece, row, col);
                        return;
                    }
                }
            }
        }
    }
    
    private void calculatePossibleMoves() {
        possibleMoves.clear();
        
        if (selectedPiece == null) {
            return;
        }
        
        int fromRow = selectedPiece.getRow();
        int fromCol = selectedPiece.getCol();
        
        switch (selectedPiece.getType()) {
            case ChessPiece.KING:
                calculateKingMoves(fromRow, fromCol);
                break;
            case ChessPiece.QUEEN:
                calculateQueenMoves(fromRow, fromCol);
                break;
            case ChessPiece.ROOK:
                calculateRookMoves(fromRow, fromCol);
                break;
            case ChessPiece.BISHOP:
                calculateBishopMoves(fromRow, fromCol);
                break;
            case ChessPiece.KNIGHT:
                calculateKnightMoves(fromRow, fromCol);
                break;
            case ChessPiece.PAWN:
                calculatePawnMoves(fromRow, fromCol);
                break;
        }
    }
    
    private void calculateKingMoves(int fromRow, int fromCol) {
        // 国王可以移动到周围8个格子
        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                if (i == 0 && j == 0) continue;
                
                int toRow = fromRow + i;
                int toCol = fromCol + j;
                
                if (isValidPosition(toRow, toCol)) {
                    ChessPiece target = getPieceAt(toRow, toCol);
                    if (target == null || target.getColor() != currentPlayer) {
                        possibleMoves.add(new int[]{toRow, toCol});
                    }
                }
            }
        }
        
        // 王车易位(待实现)
    }
    
    private void calculateQueenMoves(int fromRow, int fromCol) {
        // 后可以沿直线和斜线移动任意距离
        calculateRookMoves(fromRow, fromCol);
        calculateBishopMoves(fromRow, fromCol);
    }
    
    private void calculateRookMoves(int fromRow, int fromCol) {
        // 车可以沿直线移动任意距离
        int[][] directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
        
        for (int[] dir : directions) {
            for (int step = 1; step < 8; step++) {
                int toRow = fromRow + dir[0] * step;
                int toCol = fromCol + dir[1] * step;
                
                if (!isValidPosition(toRow, toCol)) break;
                
                ChessPiece target = getPieceAt(toRow, toCol);
                if (target == null) {
                    possibleMoves.add(new int[]{toRow, toCol});
                } else {
                    if (target.getColor() != currentPlayer) {
                        possibleMoves.add(new int[]{toRow, toCol});
                    }
                    break;
                }
            }
        }
    }
    
    private void calculateBishopMoves(int fromRow, int fromCol) {
        // 象可以沿斜线移动任意距离
        int[][] directions = {{-1, -1}, {-1, 1}, {1, -1}, {1, 1}};
        
        for (int[] dir : directions) {
            for (int step = 1; step < 8; step++) {
                int toRow = fromRow + dir[0] * step;
                int toCol = fromCol + dir[1] * step;
                
                if (!isValidPosition(toRow, toCol)) break;
                
                ChessPiece target = getPieceAt(toRow, toCol);
                if (target == null) {
                    possibleMoves.add(new int[]{toRow, toCol});
                } else {
                    if (target.getColor() != currentPlayer) {
                        possibleMoves.add(new int[]{toRow, toCol});
                    }
                    break;
                }
            }
        }
    }
    
    private void calculateKnightMoves(int fromRow, int fromCol) {
        // 马走日字
        int[][] moves = {
            {-2, -1}, {-2, 1}, {-1, -2}, {-1, 2},
            {1, -2}, {1, 2}, {2, -1}, {2, 1}
        };
        
        for (int[] move : moves) {
            int toRow = fromRow + move[0];
            int toCol = fromCol + move[1];
            
            if (isValidPosition(toRow, toCol)) {
                ChessPiece target = getPieceAt(toRow, toCol);
                if (target == null || target.getColor() != currentPlayer) {
                    possibleMoves.add(new int[]{toRow, toCol});
                }
            }
        }
    }
    
    private void calculatePawnMoves(int fromRow, int fromCol) {
        int direction = (currentPlayer == ChessPiece.WHITE) ? -1 : 1;
        
        // 向前移动一格
        int toRow = fromRow + direction;
        if (isValidPosition(toRow, fromCol) && getPieceAt(toRow, fromCol) == null) {
            possibleMoves.add(new int[]{toRow, fromCol});
            
            // 初始位置可以移动两格
            if ((currentPlayer == ChessPiece.WHITE && fromRow == 6) || 
                (currentPlayer == ChessPiece.BLACK && fromRow == 1)) {
                toRow = fromRow + 2 * direction;
                if (getPieceAt(toRow, fromCol) == null) {
                    possibleMoves.add(new int[]{toRow, fromCol});
                }
            }
        }
        
        // 吃子(斜前方)
        int[] cols = {fromCol - 1, fromCol + 1};
        for (int toCol : cols) {
            toRow = fromRow + direction;
            if (isValidPosition(toRow, toCol)) {
                ChessPiece target = getPieceAt(toRow, toCol);
                if (target != null && target.getColor() != currentPlayer) {
                    possibleMoves.add(new int[]{toRow, toCol});
                }
            }
        }
        
        // 吃过路兵(待实现)
    }
    
    private boolean isValidPosition(int row, int col) {
        return row >= 0 && row < ROWS && col >= 0 && col < COLS;
    }
    
    private ChessPiece getPieceAt(int row, int col) {
        for (ChessPiece piece : pieces) {
            if (piece.getRow() == row && piece.getCol() == col) {
                return piece;
            }
        }
        return null;
    }
    
    private void movePiece(ChessPiece piece, int toRow, int toCol) {
        // 检查是否吃子
        ChessPiece target = getPieceAt(toRow, toCol);
        if (target != null) {
            pieces.remove(target);
            // 检查是否将死
            if (target.getType() == ChessPiece.KING) {
                gameOver(currentPlayer);
                return;
            }
        }
        
        // 移动棋子
        piece.setRow(toRow);
        piece.setCol(toCol);
        piece.setMoved(true);
        
        // 兵的升变(待实现)
        
        // 切换玩家
        currentPlayer = (currentPlayer == ChessPiece.WHITE) ? ChessPiece.BLACK : ChessPiece.WHITE;
        selectedPiece = null;
        possibleMoves.clear();
        invalidate();
        
        if (getContext() instanceof MainAbilitySlice) {
            String player = currentPlayer == ChessPiece.WHITE ? "白方" : "黑方";
            ((MainAbilitySlice) getContext()).updateStatusText("当前回合: " + player);
        }
    }
    
    private void gameOver(int winner) {
        String message = (winner == ChessPiece.WHITE) ? "白方胜利!" : "黑方胜利!";
        if (getContext() instanceof MainAbilitySlice) {
            ((MainAbilitySlice) getContext()).showGameOverDialog(message);
        }
        
        // 重置游戏
        initPieces();
        currentPlayer = ChessPiece.WHITE;
        selectedPiece = null;
        possibleMoves.clear();
        invalidate();
    }
    
    public void resetGame() {
        initPieces();
        currentPlayer = ChessPiece.WHITE;
        selectedPiece = null;
        possibleMoves.clear();
        invalidate();
        
        if (getContext() instanceof MainAbilitySlice) {
            ((MainAbilitySlice) getContext()).updateStatusText("当前回合: 白方");
        }
    }
}

MainAbilitySlice.java (主界面)

package com.example.chess;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.agp.window.dialog.ToastDialog;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Text;
import ohos.agp.components.Button;

public class MainAbilitySlice extends AbilitySlice {
    private ChessView chessView;
    private Text statusText;
    
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        
        DirectionalLayout layout = new DirectionalLayout(this);
        layout.setOrientation(DirectionalLayout.VERTICAL);
        
        // 状态文本
        statusText = new Text(this);
        statusText.setText("当前回合: 白方");
        statusText.setTextSize(50);
        statusText.setPadding(10, 10, 10, 10);
        
        // 象棋视图
        chessView = new ChessView(this);
        
        // 按钮布局
        DirectionalLayout buttonLayout = new DirectionalLayout(this);
        buttonLayout.setOrientation(DirectionalLayout.HORIZONTAL);
        buttonLayout.setPadding(10, 10, 10, 10);
        
        // 重新开始按钮
        Button resetButton = new Button(this);
        resetButton.setText("重新开始");
        resetButton.setClickedListener(component -> chessView.resetGame());
        
        // 悔棋按钮
        Button undoButton = new Button(this);
        undoButton.setText("悔棋");
        undoButton.setClickedListener(component -> {
            new ToastDialog(this).setText("悔棋功能待实现").show();
        });
        
        buttonLayout.addComponent(resetButton);
        buttonLayout.addComponent(undoButton);
        
        layout.addComponent(statusText);
        layout.addComponent(chessView);
        layout.addComponent(buttonLayout);
        
        super.setUIContent(layout);
    }
    
    public void showGameOverDialog(String message) {
        new ToastDialog(this)
            .setText(message)
            .show();
        statusText.setText("游戏结束 - " + message);
    }
    
    public void updateStatusText(String text) {
        statusText.setText(text);
    }
}

ability_main.xml (布局文件)

<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:width="match_parent"
    ohos:height="match_parent"
    ohos:orientation="vertical">
    
    <Text
        ohos:id="$+id:status_text"
        ohos:width="match_parent"
        ohos:height="50vp"
        ohos:text="当前回合: 白方"
        ohos:text_size="20fp"
        ohos:padding="10vp"/>
        
    <com.example.chess.ChessView
        ohos:id="$+id:chess_view"
        ohos:width="match_parent"
        ohos:height="0vp"
        ohos:weight="1"/>
        
    <DirectionalLayout
        ohos:id="$+id:button_layout"
        ohos:width="match_parent"
        ohos:height="wrap_content"
        ohos:orientation="horizontal"
        ohos:padding="10vp">
        
        <Button
            ohos:id="$+id:reset_button"
            ohos:width="0vp"
            ohos:height="50vp"
            ohos:weight="1"
            ohos:text="重新开始"
            ohos:margin="5vp"/>
            
        <Button
            ohos:id="$+id:undo_button"
            ohos:width="0vp"
            ohos:height="50vp"
            ohos:weight="1"
            ohos:text="悔棋"
            ohos:margin="5vp"/>
    </DirectionalLayout>
</DirectionalLayout>

3. 功能说明

  1. ​游戏规则​​:标准国际象棋规则
  2. ​棋子类型​​:
    • 王(King)、后(Queen)、车(Rook)、象(Bishop)、马(Knight)、兵(Pawn)
  3. ​界面元素​​:
    • 棋盘:8×8网格,交替颜色
    • 棋子:使用Unicode字符表示
    • 状态显示:当前回合信息
    • 操作按钮:重新开始、悔棋(待实现)
  4. ​交互​​:
    • 点击选中棋子,显示可移动位置
    • 再次点击目标位置移动棋子
    • 自动判断移动是否合法
    • 自动判断胜负

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2406615.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

ZYNQ学习记录FPGA(二)Verilog语言

一、Verilog简介 1.1 HDL&#xff08;Hardware Description language&#xff09; 在解释HDL之前&#xff0c;先来了解一下数字系统设计的流程&#xff1a;逻辑设计 -> 电路实现 -> 系统验证。 逻辑设计又称前端&#xff0c;在这个过程中就需要用到HDL&#xff0c;正文…

Java中HashMap底层原理深度解析:从数据结构到红黑树优化

一、HashMap概述与核心特性 HashMap作为Java集合框架中最常用的数据结构之一&#xff0c;是基于哈希表的Map接口非同步实现。它允许使用null键和null值&#xff08;但只能有一个null键&#xff09;&#xff0c;并且不保证映射顺序的恒久不变。与Hashtable相比&#xff0c;Hash…

【记录坑点问题】IDEA运行:maven-resources-production:XX: OOM: Java heap space

问题&#xff1a;IDEA出现maven-resources-production:operation-service: java.lang.OutOfMemoryError: Java heap space 解决方案&#xff1a;将编译的堆内存增加一点 位置&#xff1a;设置setting-》构建菜单build-》编译器Complier

【阅读笔记】MemOS: 大语言模型内存增强生成操作系统

核心速览 研究背景 ​​研究问题​​&#xff1a;这篇文章要解决的问题是当前大型语言模型&#xff08;LLMs&#xff09;在处理内存方面的局限性。LLMs虽然在语言感知和生成方面表现出色&#xff0c;但缺乏统一的、结构化的内存架构。现有的方法如检索增强生成&#xff08;RA…

【笔记】AI Agent 项目 SUNA 部署 之 Docker 构建记录

#工作记录 构建过程记录 Microsoft Windows [Version 10.0.27871.1000] (c) Microsoft Corporation. All rights reserved.(suna-py3.12) F:\PythonProjects\suna>python setup.py --admin███████╗██╗ ██╗███╗ ██╗ █████╗ ██╔════╝…

五、jmeter脚本参数化

目录 1、脚本参数化 1.1 用户定义的变量 1.1.1 添加及引用方式 1.1.2 测试得出用户定义变量的特点 1.2 用户参数 1.2.1 概念 1.2.2 位置不同效果不同 1.2.3、用户参数的勾选框 - 每次迭代更新一次 总结用户定义的变量、用户参数 1.3 csv数据文件参数化 1、脚本参数化 …

python基础语法Ⅰ

python基础语法Ⅰ 常量和表达式变量是什么变量的语法1.定义变量使用变量 变量的类型1.整数2.浮点数(小数)3.字符串4.布尔5.其他 动态类型特征注释注释是什么注释的语法1.行注释2.文档字符串 注释的规范 常量和表达式 我们可以把python当作一个计算器&#xff0c;来进行一些算术…

C++11 constexpr和字面类型:从入门到精通

文章目录 引言一、constexpr的基本概念与使用1.1 constexpr的定义与作用1.2 constexpr变量1.3 constexpr函数1.4 constexpr在类构造函数中的应用1.5 constexpr的优势 二、字面类型的基本概念与使用2.1 字面类型的定义与作用2.2 字面类型的应用场景2.2.1 常量定义2.2.2 模板参数…

EEG-fNIRS联合成像在跨频率耦合研究中的创新应用

摘要 神经影像技术对医学科学产生了深远的影响&#xff0c;推动了许多神经系统疾病研究的进展并改善了其诊断方法。在此背景下&#xff0c;基于神经血管耦合现象的多模态神经影像方法&#xff0c;通过融合各自优势来提供有关大脑皮层神经活动的互补信息。在这里&#xff0c;本研…

C++中vector类型的介绍和使用

文章目录 一、vector 类型的简介1.1 基本介绍1.2 常见用法示例1.3 常见成员函数简表 二、vector 数据的插入2.1 push_back() —— 在尾部插入一个元素2.2 emplace_back() —— 在尾部“就地”构造对象2.3 insert() —— 在任意位置插入一个或多个元素2.4 emplace() —— 在任意…

CVE-2023-25194源码分析与漏洞复现(Kafka JNDI注入)

漏洞概述 漏洞名称&#xff1a;Apache Kafka Connect JNDI注入导致的远程代码执行漏洞 CVE编号&#xff1a;CVE-2023-25194 CVSS评分&#xff1a;8.8 影响版本&#xff1a;Apache Kafka 2.3.0 - 3.3.2 修复版本&#xff1a;≥ 3.4.0 漏洞类型&#xff1a;反序列化导致的远程代…

Copilot for Xcode (iOS的 AI辅助编程)

Copilot for Xcode 简介Copilot下载与安装 体验环境要求下载最新的安装包安装登录系统权限设置 AI辅助编程生成注释代码补全简单需求代码生成辅助编程行间代码生成注释联想 代码生成 总结 简介 尝试使用了Copilot&#xff0c;它能根据上下文补全代码&#xff0c;快速生成常用…

Axure零基础跟我学:展开与收回

亲爱的小伙伴,如有帮助请订阅专栏!跟着老师每课一练,系统学习Axure交互设计课程! Axure产品经理精品视频课https://edu.csdn.net/course/detail/40420 课程主题:Axure菜单展开与收回 课程视频:

RabbitMQ 各类交换机

为什么要用交换机&#xff1f; 交换机用来路由消息。如果直发队列&#xff0c;这个消息就被处理消失了&#xff0c;那别的队列也需要这个消息怎么办&#xff1f;那就要用到交换机 交换机类型 1&#xff0c;fanout&#xff1a;广播 特点 广播所有消息​​&#xff1a;将消息…

高保真组件库:开关

一:制作关状态 拖入一个矩形作为关闭的底色:44 x 22,填充灰色CCCCCC,圆角23,边框宽度0,文本为”关“,右对齐,边距2,2,6,2,文本颜色白色FFFFFF。 拖拽一个椭圆,尺寸18 x 18,边框为0。3. 全选转为动态面板状态1命名为”关“。 二:制作开状态 复制关状态并命名为”开…

未授权访问事件频发,我们应当如何应对?

在当下&#xff0c;数据已成为企业和组织的核心资产&#xff0c;是推动业务发展、决策制定以及创新的关键驱动力。然而&#xff0c;未授权访问这一隐匿的安全威胁&#xff0c;正如同高悬的达摩克利斯之剑&#xff0c;时刻威胁着数据的安全&#xff0c;一旦触发&#xff0c;便可…

欢乐熊大话蓝牙知识17:多连接 BLE 怎么设计服务不会乱?分层思维来救场!

多连接 BLE 怎么设计服务不会乱&#xff1f;分层思维来救场&#xff01; 作者按&#xff1a; 你是不是也遇到过 BLE 多连接时&#xff0c;调试现场像网吧“掉线风暴”&#xff1f; 温度传感器连上了&#xff0c;心率带丢了&#xff1b;一边 OTA 更新&#xff0c;一边通知卡壳。…

Element-Plus:popconfirm与tooltip一起使用不生效?

你们好&#xff0c;我是金金金。 场景 我正在使用Element-plus组件库当中的el-popconfirm和el-tooltip&#xff0c;产品要求是两个需要结合一起使用&#xff0c;也就是鼠标悬浮上去有提示文字&#xff0c;并且点击之后需要出现气泡确认框 代码 <el-popconfirm title"是…

Selenium 查找页面元素的方式

Selenium 查找页面元素的方式 Selenium 提供了多种方法来查找网页中的元素&#xff0c;以下是主要的定位方式&#xff1a; 基本定位方式 通过ID定位 driver.find_element(By.ID, "element_id")通过Name定位 driver.find_element(By.NAME, "element_name"…

OPENCV图形计算面积、弧长API讲解(1)

一.OPENCV图形面积、弧长计算的API介绍 之前我们已经把图形轮廓的检测、画框等功能讲解了一遍。那今天我们主要结合轮廓检测的API去计算图形的面积&#xff0c;这些面积可以是矩形、圆形等等。图形面积计算和弧长计算常用于车辆识别、桥梁识别等重要功能&#xff0c;常用的API…