• 个人简介

    你好,陌生人,很高兴你能进我的主页,作为主页本人,必须给你整一点好玩的!!!!

    //围棋
    #include <iostream>
    #include <vector>
    #include <string>
    #include <algorithm>
    #include <utility>
    
    using namespace std;
    
    const int BOARD_SIZE = 19;
    const char EMPTY = '.';
    const char BLACK = 'B';
    const char WHITE = 'W';
    
    class GoGame {
    private:
        vector<vector<char>> board;
        char currentPlayer;
        pair<int, int> lastMove;
        bool gameOver;
        int blackCaptures;
        int whiteCaptures;
        
        // 检查坐标是否在棋盘内
        bool isValid(int x, int y) const {
            return x >= 0 && x < BOARD_SIZE && y >= 0 && y < BOARD_SIZE;
        }
        
        // 检查是否有气( liberties)
        bool hasLiberty(int x, int y, vector<vector<bool>>& visited) const {
            if (!isValid(x, y)) return false;
            if (visited[x][y]) return false;
            visited[x][y] = true;
            
            char stone = board[x][y];
            if (stone == EMPTY) return true;
            
            // 检查相邻位置
            bool libertyFound = false;
            const int dx[] = {-1, 1, 0, 0};
            const int dy[] = {0, 0, -1, 1};
            
            for (int i = 0; i < 4; ++i) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if (isValid(nx, ny) && !visited[nx][ny]) {
                    if (board[nx][ny] == EMPTY || 
                        (board[nx][ny] == stone && hasLiberty(nx, ny, visited))) {
                        libertyFound = true;
                        break;
                    }
                }
            }
            
            return libertyFound;
        }
        
        // 移除没有气的棋子
        void removeDeadStones(int x, int y, char player) {
            if (!isValid(x, y) || board[x][y] != player) return;
            
            vector<vector<bool>> visited(BOARD_SIZE, vector<bool>(BOARD_SIZE, false));
            if (!hasLiberty(x, y, visited)) {
                for (int i = 0; i < BOARD_SIZE; ++i) {
                    for (int j = 0; j < BOARD_SIZE; ++j) {
                        if (visited[i][j] && board[i][j] == player) {
                            board[i][j] = EMPTY;
                            if (player == BLACK) whiteCaptures++;
                            else blackCaptures++;
                        }
                    }
                }
            }
        }
        
        // 检查自杀规则
        bool isSuicide(int x, int y, char player) const {
            if (board[x][y] != EMPTY) return true;
            
            // 临时放置棋子
            board[x][y] = player;
            
            vector<vector<bool>> visited(BOARD_SIZE, vector<bool>(BOARD_SIZE, false));
            bool hasLib = hasLiberty(x, y, visited);
            
            // 检查是否能吃子
            const int dx[] = {-1, 1, 0, 0};
            const int dy[] = {0, 0, -1, 1};
            bool canCapture = false;
            
            for (int i = 0; i < 4; ++i) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if (isValid(nx, ny) && board[nx][ny] != EMPTY && board[nx][ny] != player) {
                    vector<vector<bool>> enemyVisited(BOARD_SIZE, vector<bool>(BOARD_SIZE, false));
                    if (!hasLiberty(nx, ny, enemyVisited)) {
                        canCapture = true;
                        break;
                    }
                }
            }
            
            // 恢复棋盘
            board[x][y] = EMPTY;
            
            return !hasLib && !canCapture;
        }
        
    public:
        GoGame() : board(BOARD_SIZE, vector<char>(BOARD_SIZE, EMPTY)), 
                   currentPlayer(BLACK), 
                   gameOver(false), 
                   blackCaptures(0), 
                   whiteCaptures(0) {
            lastMove = make_pair(-1, -1);
        }
        
        // 打印棋盘
        void printBoard() const {
            cout << "  ";
            for (int i = 0; i < BOARD_SIZE; ++i) {
                cout << (i < 10 ? " " : "") << i << " ";
            }
            cout << endl;
            
            for (int i = 0; i < BOARD_SIZE; ++i) {
                cout << (i < 10 ? " " : "") << i << " ";
                for (int j = 0; j < BOARD_SIZE; ++j) {
                    cout << board[i][j] << "  ";
                }
                cout << endl;
            }
            
            cout << "Current player: " << currentPlayer << endl;
            cout << "Captures - Black: " << blackCaptures << " White: " << whiteCaptures << endl;
        }
        
        // 落子
        bool makeMove(int x, int y) {
            if (gameOver || !isValid(x, y) || isSuicide(x, y, currentPlayer)) {
                return false;
            }
            
            board[x][y] = currentPlayer;
            lastMove = make_pair(x, y);
            
            // 检查并移除被吃的子
            const int dx[] = {-1, 1, 0, 0};
            const int dy[] = {0, 0, -1, 1};
            
            for (int i = 0; i < 4; ++i) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if (isValid(nx, ny) && board[nx][ny] != EMPTY && board[nx][ny] != currentPlayer) {
                    removeDeadStones(nx, ny, board[nx][ny]);
                }
            }
            
            // 切换玩家
            currentPlayer = (currentPlayer == BLACK) ? WHITE : BLACK;
            return true;
        }
        
        // 跳过回合
        void passTurn() {
            currentPlayer = (currentPlayer == BLACK) ? WHITE : BLACK;
            // 连续两次跳过表示游戏结束
            static bool lastWasPass = false;
            if (lastWasPass) {
                gameOver = true;
            }
            lastWasPass = true;
        }
        
        // 计算胜负(简单版)
        void calculateScore() {
            if (!gameOver) return;
            
            int blackScore = 0;
            int whiteScore = 0;
            
            for (int i = 0; i < BOARD_SIZE; ++i) {
                for (int j = 0; j < BOARD_SIZE; ++j) {
                    if (board[i][j] == BLACK) blackScore++;
                    else if (board[i][j] == WHITE) whiteScore++;
                }
            }
            
            // 简单计算,不考虑地域
            whiteScore += blackCaptures;
            blackScore += whiteCaptures;
            
            cout << "Game Over!" << endl;
            cout << "Black score: " << blackScore << endl;
            cout << "White score: " << whiteScore << endl;
            cout << "Winner: " << (blackScore > whiteScore ? "Black" : "White") << endl;
        }
        
        bool isGameOver() const {
            return gameOver;
        }
    };
    
    int main() {
        GoGame game;
        
        cout << "Welcome to Simple Go Game!" << endl;
        cout << "Commands: " << endl;
        cout << "  move x y - Place a stone at (x,y)" << endl;
        cout << "  pass     - Pass your turn" << endl;
        cout << "  exit     - End the game" << endl;
        
        while (!game.isGameOver()) {
            game.printBoard();
            
            string command;
            cout << "> ";
            getline(cin, command);
            
            if (command.substr(0, 4) == "move") {
                int x, y;
                if (sscanf(command.c_str(), "move %d %d", &x, &y) == 2) {
                    if (!game.makeMove(x, y)) {
                        cout << "Invalid move!" << endl;
                    }
                } else {
                    cout << "Invalid command format. Use: move x y" << endl;
                }
            } else if (command == "pass") {
                game.passTurn();
            } else if (command == "exit") {
                break;
            } else {
                cout << "Unknown command" << endl;
            }
        }
        
        game.calculateScore();
        
        return 0;
    }
    
    //五子棋
    #include <iostream>
    #include <vector>
    #include <iomanip>
    
    using namespace std;
    
    const int BOARD_SIZE = 15; // 棋盘大小 15x15
    const char EMPTY = '.';
    const char BLACK = 'X';
    const char WHITE = 'O';
    
    class Gomoku {
    private:
        vector<vector<char>> board;
        char currentPlayer;
        bool gameOver;
        int moveCount;
    
    public:
        Gomoku() : board(BOARD_SIZE, vector<char>(BOARD_SIZE, EMPTY)), 
                   currentPlayer(BLACK), gameOver(false), moveCount(0) {}
    
        void printBoard() {
            // 打印列号
            cout << "   ";
            for (int i = 0; i < BOARD_SIZE; ++i) {
                cout << setw(2) << i << " ";
            }
            cout << endl;
    
            for (int i = 0; i < BOARD_SIZE; ++i) {
                // 打印行号
                cout << setw(2) << i << " ";
                
                for (int j = 0; j < BOARD_SIZE; ++j) {
                    cout << " " << board[i][j] << " ";
                }
                cout << endl;
            }
        }
    
        bool makeMove(int row, int col) {
            if (row < 0 || row >= BOARD_SIZE || col < 0 || col >= BOARD_SIZE || board[row][col] != EMPTY) {
                return false;
            }
    
            board[row][col] = currentPlayer;
            moveCount++;
            
            if (checkWin(row, col)) {
                gameOver = true;
                cout << "玩家 " << currentPlayer << " 获胜!" << endl;
            } else if (moveCount == BOARD_SIZE * BOARD_SIZE) {
                gameOver = true;
                cout << "平局!" << endl;
            }
    
            currentPlayer = (currentPlayer == BLACK) ? WHITE : BLACK;
            return true;
        }
    
        bool isGameOver() const {
            return gameOver;
        }
    
        char getCurrentPlayer() const {
            return currentPlayer;
        }
    
    private:
        bool checkWin(int row, int col) {
            // 检查水平方向
            if (countInDirection(row, col, 0, 1) >= 5) return true;
            // 检查垂直方向
            if (countInDirection(row, col, 1, 0) >= 5) return true;
            // 检查主对角线方向
            if (countInDirection(row, col, 1, 1) >= 5) return true;
            // 检查副对角线方向
            if (countInDirection(row, col, 1, -1) >= 5) return true;
            
            return false;
        }
    
        int countInDirection(int row, int col, int dRow, int dCol) {
            char player = board[row][col];
            int count = 1; // 当前位置已经有一个棋子
            
            // 正向检查
            for (int i = 1; i < 5; ++i) {
                int newRow = row + i * dRow;
                int newCol = col + i * dCol;
                if (newRow < 0 || newRow >= BOARD_SIZE || newCol < 0 || newCol >= BOARD_SIZE || 
                    board[newRow][newCol] != player) {
                    break;
                }
                count++;
            }
            
            // 反向检查
            for (int i = 1; i < 5; ++i) {
                int newRow = row - i * dRow;
                int newCol = col - i * dCol;
                if (newRow < 0 || newRow >= BOARD_SIZE || newCol < 0 || newCol >= BOARD_SIZE || 
                    board[newRow][newCol] != player) {
                    break;
                }
                count++;
            }
            
            return count;
        }
    };
    
    int main() {
        Gomoku game;
        int row, col;
    
        cout << "欢迎来到五子棋游戏!" << endl;
        cout << "黑棋: X, 白棋: O" << endl;
        cout << "输入行号和列号来下棋 (例如: 7 7)" << endl;
    
        while (!game.isGameOver()) {
            game.printBoard();
            cout << "当前玩家: " << game.getCurrentPlayer() << endl;
            
            cout << "请输入你的下棋位置 (行 列): ";
            cin >> row >> col;
            
            if (!game.makeMove(row, col)) {
                cout << "无效的移动,请重试!" << endl;
            }
        }
        
        game.printBoard();
        cout << "游戏结束!" << endl;
        
        return 0;
    }
    
    //扫雷
    #include <iostream>
    #include <vector>
    #include <ctime>
    #include <cstdlib>
    #include <iomanip>
    #include <limits>
    
    using namespace std;
    
    class Minesweeper {
    private:
        int rows;
        int cols;
        int totalMines;
        vector<vector<char>> board;      // 玩家看到的棋盘
        vector<vector<char>> realBoard;  // 实际有地雷的棋盘
        vector<vector<bool>> visited;    // 记录是否访问过
    
    public:
        Minesweeper(int r = 9, int c = 9, int mines = 10) : rows(r), cols(c), totalMines(mines) {
            // 初始化棋盘
            board.resize(rows, vector<char>(cols, '-'));
            realBoard.resize(rows, vector<char>(cols, '0'));
            visited.resize(rows, vector<bool>(cols, false));
            
            // 放置地雷
            placeMines();
            
            // 计算周围地雷数
            calculateNumbers();
        }
    
        void placeMines() {
            srand(time(0));
            int minesPlaced = 0;
            
            while (minesPlaced < totalMines) {
                int x = rand() % rows;
                int y = rand() % cols;
                
                if (realBoard[x][y] != '*') {
                    realBoard[x][y] = '*';
                    minesPlaced++;
                }
            }
        }
    
        void calculateNumbers() {
            // 八个方向
            int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
            int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
            
            for (int i = 0; i < rows; i++) {
                for (int j = 0; j < cols; j++) {
                    if (realBoard[i][j] == '*') continue;
                    
                    int count = 0;
                    for (int k = 0; k < 8; k++) {
                        int ni = i + dx[k];
                        int nj = j + dy[k];
                        
                        if (ni >= 0 && ni < rows && nj >= 0 && nj < cols && realBoard[ni][nj] == '*') {
                            count++;
                        }
                    }
                    
                    if (count > 0) {
                        realBoard[i][j] = '0' + count;
                    }
                }
            }
        }
    
        void printBoard(bool showMines = false) {
            cout << "   ";
            for (int j = 0; j < cols; j++) {
                cout << setw(2) << j << " ";
            }
            cout << "\n";
            
            for (int i = 0; i < rows; i++) {
                cout << setw(2) << i << " ";
                for (int j = 0; j < cols; j++) {
                    if (showMines) {
                        cout << setw(2) << realBoard[i][j] << " ";
                    } else {
                        cout << setw(2) << board[i][j] << " ";
                    }
                }
                cout << "\n";
            }
        }
    
        bool isValid(int x, int y) {
            return x >= 0 && x < rows && y >= 0 && y < cols;
        }
    
        void reveal(int x, int y) {
            if (!isValid(x, y) || visited[x][y] || board[x][y] != '-') {
                return;
            }
            
            visited[x][y] = true;
            
            if (realBoard[x][y] == '*') {
                board[x][y] = '*';
                return;
            }
            
            if (realBoard[x][y] != '0') {
                board[x][y] = realBoard[x][y];
                return;
            }
            
            // 如果是0,递归揭示周围的格子
            board[x][y] = '0';
            
            // 八个方向
            int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
            int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
            
            for (int k = 0; k < 8; k++) {
                int ni = x + dx[k];
                int nj = y + dy[k];
                reveal(ni, nj);
            }
        }
    
        bool isGameWon() {
            int unrevealed = 0;
            for (int i = 0; i < rows; i++) {
                for (int j = 0; j < cols; j++) {
                    if (board[i][j] == '-' && realBoard[i][j] != '*') {
                        unrevealed++;
                    }
                }
            }
            return unrevealed == 0;
        }
    
        void play() {
            cout << "欢迎来到扫雷游戏!\n";
            cout << "输入坐标来揭开方块(例如: 2 3)\n";
            cout << "游戏开始!\n\n";
            
            while (true) {
                printBoard();
                
                int x, y;
                cout << "输入坐标 (行 列): ";
                while (!(cin >> x >> y) || !isValid(x, y)) {
                    cin.clear();
                    cin.ignore(numeric_limits<streamsize>::max(), '\n');
                    cout << "无效输入,请重新输入 (行 列): ";
                }
                
                if (realBoard[x][y] == '*') {
                    cout << "游戏结束! 你踩到地雷了!\n";
                    printBoard(true);
                    break;
                }
                
                reveal(x, y);
                
                if (isGameWon()) {
                    cout << "恭喜! 你赢了!\n";
                    printBoard(true);
                    break;
                }
            }
        }
    };
    
    int main() {
        int rows, cols, mines;
        cout << "输入棋盘大小和地雷数 (行 列 地雷数), 默认9x9有10个地雷: ";
        
        if (cin >> rows >> cols >> mines) {
            Minesweeper game(rows, cols, mines);
            game.play();
        } else {
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max(), '\n');
            Minesweeper game;
            game.play();
        }
        
        return 0;
    }
    
    

    以上都是c++游戏代码,如果大家觉得不好玩,试试搜以下网站:

    1.poki.cn

    2.crazygames.com

    3.yoyogames.com

    4.kbhgames.com(记得是games不是game不然你就进了黄色网站,别问我怎么知道的)

    5.itch.io

    6.www.miniclip.com

    7.www.retrogames.cc

    8.classicreload.com

    多人联机游戏网站:

    1.krunker.io

    2.skribbl.io

    许多游戏网站有广告,这也不怪我

    喜欢的话给我点个赞吧 再告诉你们一个秘密 6=5+2+0+1+3-1-4 也就是说6=5201314 所以别人(异性)给你发6大概率是跟你表白

  • 最近活动

  • Stat

  • Rating