问题标题: c++编程投稿,一等奖300豆 二等奖100 三等50

0
0

0
于逸杋
于逸杋
新手天翼
新手天翼

我来凑个热闹(一万年前打的,比较菜,请见谅)

/*
规则:猜对x次,对方就扣x*10滴血
*/
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#define random(x) (rand()%x)
using namespace std;
int p1,p2,p1a,p2a,p1cnt,p2cnt;
int p1hp=100,p2hp=100;
int main(){
    cout<<"欢迎来到猜数大作战1.0\n"<<"p1血量:"<<100<<' '<<"p2血量:"<<100<<endl;
    for(int i=1;i<=10000;i++){
        int cnt=0;
        cout<<"p1玩家猜\n";
            while(1){
            if(cnt==1){
                cout<<"猜对了,请继续猜\n";
            }
            cout<<"请输入0,1,2,3(否则会有BUG)\n";
            cin>>p1;
            if(p1>3){
                cout<<"输入错误,自动结束本局\n";
                cout<<"游戏结束! 制作不易,点个赞吧\n";
                cout<<"制作人:于逸杋,李文耀(我同学)";
                return 0;
            }
            p1a=random(3);
            if(p1==p1a){
                p1cnt++;
                cnt=1;
            }else{
                cout<<"猜错了\n";
                break;
            }
        }
        p2hp-=p1cnt*10;
        p1cnt=0;
        cnt=0;
        cout<<"p2玩家猜\n";
        while(1){
            if(cnt==1){
                cout<<"猜对了,请继续猜\n";
            }
            cout<<"请输入0,1,2,3(否则会有BUG)\n";
            if(p2>3){
                cout<<"输入错误,自动结束本局\n";
                cout<<"游戏结束! 制作不易,点个赞吧\n";
                cout<<"制作人:于逸杋,李文耀(我同学)";
                return 0;
            }
            cin>>p2;
            p2a=random(3);
            if(p2==p2a){
                p2cnt++;
                cnt=1;
            }else{
                cout<<"猜错了\n";
                break;
            }
        }
        p1hp-=p2cnt*10;
        p2cnt=0;
        if(p1hp<=0||p2hp<=0){
            cout<<"p1血量:"<<p1hp<<' '<<"p2血量:"<<p2hp<<endl;
            if(p1hp<=0&&p2hp<=0){
                cout<<"平局";

            }else if(p2hp<=0){
                cout<<"p1 is winner!";
            }else{
                cout<<"p2 is winner!";
            }
            cout<<endl<<"游戏结束! 制作不易,点个赞吧\n";
            cout<<"制作人:于逸杋,李文耀(我同学)";
            break;
        }
        cout<<"p1血量:"<<p1hp<<' '<<"p2血量:"<<p2hp<<endl;
    }
    return 0;
}
 

0
胡子靖
胡子靖
资深守护
资深守护


#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <limits>
#include <string>

using namespace std;
const int ROWS = 9;
const int COLS = 9;
const int MINES = 10;
enum CellState {
    HIDDEN = 0,
    REVEALED = 1,
    FLAGGED = 2 
};
struct Cell {
    bool isMine;
    int neighborMines;
    CellState state;

    Cell() : isMine(false), neighborMines(0), state(HIDDEN) {}
};

class Minesweeper {
private:
    vector<vector<Cell>> board;
    bool gameOver;
    bool gameWon;
    int flagsPlaced;

public:
    Minesweeper() : gameOver(false), gameWon(false), flagsPlaced(0) {
        initializeBoard();
        placeMines();
        calculateNeighborMines();
    }
    void initializeBoard() {
        board.resize(ROWS, vector<Cell>(COLS));
    }
    void placeMines() {
        srand(time(nullptr));
        int minesPlaced = 0;
        while (minesPlaced < MINES) {
            int r = rand() % ROWS;
            int c = rand() % COLS;
            if (!board[r][c].isMine) {
                board[r][c].isMine = true;
                minesPlaced++;
            }
        }
    }
    void calculateNeighborMines() {
        for (int r = 0; r < ROWS; ++r) {
            for (int c = 0; c < COLS; ++c) {
                if (board[r][c].isMine) continue;
                int count = 0;
                for (int dr = -1; dr <= 1; ++dr) {
                    for (int dc = -1; dc <= 1; ++dc) {
                        int nr = r + dr;
                        int nc = c + dc;
                        if (nr >= 0 && nr < ROWS && nc >= 0 && nc < COLS) {
                            if (board[nr][nc].isMine) count++;
                        }
                    }
                }
                board[r][c].neighborMines = count;
            }
        }
    }
    void revealCell(int r, int c) {
        if (r < 0 || r >= ROWS || c < 0 || c >= COLS) return;
        if (board[r][c].state != HIDDEN) return;

        board[r][c].state = REVEALED;

        if (board[r][c].isMine) {
            gameOver = true;
            return;
        }

        if (board[r][c].neighborMines == 0) {
            for (int dr = -1; dr <= 1; ++dr) {
                for (int dc = -1; dc <= 1; ++dc) {
                    revealCell(r + dr, c + dc);
                }
            }
        }
    }
    void clickCell(int r, int c) {
        if (gameOver || gameWon) return;
        if (r < 0 || r >= ROWS || c < 0 || c >= COLS) return;
        if (board[r][c].state == FLAGGED) return;

        revealCell(r, c);
        checkWinCondition();
    }
    void toggleFlag(int r, int c) {
        if (gameOver || gameWon) return;
        if (r < 0 || r >= ROWS || c < 0 || c >= COLS) return;
        if (board[r][c].state == REVEALED) return;

        if (board[r][c].state == HIDDEN) {
            board[r][c].state = FLAGGED;
            flagsPlaced++;
        } else if (board[r][c].state == FLAGGED) {
            board[r][c].state = HIDDEN;
            flagsPlaced--;
        }
    }
    void checkWinCondition() {
        int revealedCount = 0;
        for (int r = 0; r < ROWS; ++r) {
            for (int c = 0; c < COLS; ++c) {
                if (board[r][c].state == REVEALED) {
                    revealedCount++;
                }
            }
        }
        if (revealedCount == (ROWS * COLS - MINES)) {
            gameWon = true;
        }
    }
    void printBoard() const {
        cout << "\n   ";
        for (int c = 0; c < COLS; ++c) {
            cout << setw(3) << c;
        }
        cout << endl;

        for (int r = 0; r < ROWS; ++r) {
            cout << setw(2) << r << " ";
            for (int c = 0; c < COLS; ++c) {
                const Cell& cell = board[r][c];
                if (cell.state == HIDDEN) {
                    cout << " [?]";
                } else if (cell.state == FLAGGED) {
                    cout << " [F]";
                } else if (cell.state == REVEALED) {
                    if (cell.isMine) {
                        cout << " [*]";
                    } else if (cell.neighborMines > 0) {
                        cout << " [" << cell.neighborMines << "]";
                    } else {
                        cout << " [ ]";
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    void revealAllMines() const {
        cout << "\n   ";
        for (int c = 0; c < COLS; ++c) {
            cout << setw(3) << c;
        }
        cout << endl;

        for (int r = 0; r < ROWS; ++r) {
            cout << setw(2) << r << " ";
            for (int c = 0; c < COLS; ++c) {
                const Cell& cell = board[r][c];
                if (cell.isMine) {
                    cout << " [*]";
                } else if (cell.state == FLAGGED) {
                    cout << " [F]";
                } else if (cell.state == REVEALED) {
                     if (cell.neighborMines > 0) {
                        cout << " [" << cell.neighborMines << "]";
                    } else {
                        cout << " [ ]";
                    }
                } else {
                    cout << " [?]";
                }
            }
            cout << endl;
        }
        cout << endl;
    }

    bool isGameOver() const { return gameOver; }
    bool isGameWon() const { return gameWon; }
};

void showHelp() {
    cout << "\n--- Minesweeper Help ---" << endl;
    cout << "Command Format: <action> <row> <col>" << endl;
    cout << "Actions:" << endl;
    cout << "  r <row> <col> : Reveal a cell" << endl;
    cout << "  f <row> <col> : Flag/Unflag a mine" << endl;
    cout << "  h             : Show this help message" << endl;
    cout << "  q             : Quit the game" << endl;
    cout << "Example: r 0 0 (Reveals the cell at row 0, column 0)" << endl;
    cout << "----------------------\n" << endl;
}

int main() {
    cout << "========================================" << endl;
    cout << "   Welcome to C++ Console Minesweeper   " << endl;
    cout << "========================================" << endl;
    cout << "Board Size: " << ROWS << "x" << COLS << ", Mines: " << MINES << endl;
    showHelp();

    Minesweeper game;
    string command;

    while (!game.isGameOver() && !game.isGameWon()) {
        game.printBoard();
        cout << "Enter command: ";

        if (!(cin >> command)) {
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max(), '\n');
            cout << "Invalid input, please try again." << endl;
            continue;
        }

        if (command == "q" || command == "Q") {
            cout << "Thanks for playing, goodbye!" << endl;
            return 0;
        }

        if (command == "h" || command == "H") {
            showHelp();
            continue;
        }

        if (command == "r" || command == "R") {
            int r, c;
            if (cin >> r >> c) {
                game.clickCell(r, c);
                if (game.isGameOver()) {
                    cout << "\no Boom! You hit a mine! Game Over! 💥" << endl;
                    game.revealAllMines();
                }
            } else {
                cin.clear();
                cin.ignore(numeric_limits<streamsize>::max(), '\n');
                cout << "Invalid format. Use: r <row> <col>" << endl;
            }
        } else if (command == "f" || command == "F") {
            int r, c;
            if (cin >> r >> c) {
                game.toggleFlag(r, c);
            } else {
                cin.clear();
                cin.ignore(numeric_limits<streamsize>::max(), '\n');
                cout << "Invalid format. Use: f <row> <col>" << endl;
            }
        } else {
            cout << "Unknown command. Type 'h' for help." << endl;
            cin.ignore(numeric_limits<streamsize>::max(), '\n');
        }
    }

    if (game.isGameWon()) {
        game.printBoard();
        cout << "\n Congratulations! You cleared all mines! " << endl;
    }

    return 0;
}
/*
----------- 扫雷游戏帮助 -----------
命令格式: <操作> <行> <列>
操作:
r <行> <列> : 翻开格子 (Reveal)
f <行> <列> : 标记/取消标记地雷 (Flag)
h           : 显示帮助
q           : 退出游戏
示例: r 0 0 (翻开第0行第0列的格子)
--------------------------------------
*/

 

0
于行衍
于行衍
高级天翼
高级天翼

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
void size(int fontSize, const wchar_t* fontName = L"Consolas") {
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_FONT_INFOEX cfi;
    cfi.cbSize = sizeof(cfi);
    cfi.nFont = 0;
    cfi.dwFontSize.Y = fontSize;
    cfi.dwFontSize.X = fontSize / 2;
    cfi.FontFamily = FF_DONTCARE;
    cfi.FontWeight = FW_NORMAL;
    wcsncpy(cfi.FaceName, fontName, LF_FACESIZE - 1);
    cfi.FaceName[LF_FACESIZE - 1] = L'\0';
    SetCurrentConsoleFontEx(hConsole, FALSE, &cfi);
}
void cl() {
#ifdef _WIN32
    system("cls"); 
#else
    system("clear"); 
#endif
}
int sum,m,s,j,t;
int main(){
    ShowWindow(GetForegroundWindow(),SW_MAXIMIZE);
    size(25);
    cout<<"                                            欢迎使用计时器\n";
    Sleep(1000);
    cout<<"                                          请问想要哪种背景颜色\n";
    cout<<"                                        0 = 黑色       8 = 灰色\n";
    cout<<"                                        1 = 蓝色       9 = 淡蓝色\n";
    cout<<"                                        2 = 绿色       10 = 淡绿色\n";
    cout<<"                                        3 = 浅绿色     11 = 淡浅绿色\n";
    cout<<"                                        4 = 红色       13 = 淡红色\n";
    cout<<"                                        5 = 紫色       13 = 淡紫色\n";
    cout<<"                                        6 = **       14 = 淡**\n";
    cout<<"                                        7 = 白色       15 = 亮白色\n";
    int color;
    Sleep(1500);
    cl();
    cout<<"是否浏览所有颜色?是请输入1,不是请输入0\n";
    int ll;
    cin>>ll;
    if(ll==1){
        
        cout<<"请输入几秒变换一次?(建议1秒)\n";
        double jm;
        cin>>jm;
        cout<<"开始浏览\n";
        jm*=1000; 
        Sleep(jm);
        system("COLOR 00");
        Sleep(jm);
        system("COLOR 10");
        Sleep(jm);
        system("COLOR 20");
        Sleep(jm);
        system("COLOR 30");
        Sleep(jm);
        system("COLOR 40");
        Sleep(jm);
        system("COLOR 50");
        Sleep(jm);
        system("COLOR 60");
        Sleep(jm);
        system("COLOR 70");
        Sleep(jm);
        system("COLOR 80");
        Sleep(jm);
        system("COLOR 90");
        Sleep(jm);
        system("COLOR A0");
        Sleep(jm);
        system("COLOR B0");
        Sleep(jm);
        system("COLOR C0");
        Sleep(jm);
        system("COLOR D0");
        Sleep(jm);
        system("COLOR E0");
        Sleep(jm);
        system("COLOR F0");
        Sleep(jm);
        system("COLOR 00");
        Sleep(jm);
    } 
    cl();
    cout<<"                                          请问想要哪种背景颜色\n";
    cout<<"                                        0 = 黑色       8 = 灰色\n";
    cout<<"                                        1 = 蓝色       9 = 淡蓝色\n";
    cout<<"                                        2 = 绿色       10 = 淡绿色\n";
    cout<<"                                        3 = 浅绿色     11 = 淡浅绿色\n";
    cout<<"                                        4 = 红色       13 = 淡红色\n";
    cout<<"                                        5 = 紫色       13 = 淡紫色\n";
    cout<<"                                        6 = **       14 = 淡**\n";
    cout<<"                                        7 = 白色       15 = 亮白色\n\n\n\n";
    cout<<"                                           请问想要哪种背景颜色\n";
    while(1){
        cin>>color;
        if(color==0){
            system("COLOR 00");
        }    
        if(color==1){
            system("COLOR 10");
        }    
        if(color==2){
            system("COLOR 20");
        }    
        if(color==3){
            system("COLOR 30");
        }    
        if(color==4){
            system("COLOR 40");
        }    
        if(color==5){
            system("COLOR 50");
        }    
        if(color==6){
            system("COLOR 60");
        }    
        if(color==7){
            system("COLOR 70");
        }    
        if(color==8){
            system("COLOR 80");
        }    
        if(color==9){
            system("COLOR 90");
        }    
        if(color==10){
            system("COLOR A0");
        }    
        if(color==11){
            system("COLOR B0");
        }    
        if(color==12){
            system("COLOR C0");
        }    
        if(color==13){
            system("COLOR D0");
        }    
        if(color==14){
            system("COLOR E0");
        }    
        if(color==15){
            system("COLOR F0");
        }    
        cout<<"\n是否满意?满意请输入1,不满意输入0\n"; 
        int my;
        cin>>my;
        if(my)    break;
        cout<<"请再次选择\n"; 
    } 
    system("pause");
    while(1){
        sum=m=s=j=t=0;
           cout<<"请输入分 秒   请以分 秒的形式输入\n      ";
        cin>>m>>s;
        cout<<"请输入多少秒提醒一次\n";
        cin>>t;
        sum=m*60+s;
        for(int i=sum;i>=1;i--){
            cl();
            size(100);
            cout<<"\n\n\n    还剩下:"<<i/60<<"分"<<i%60<<"秒";
            j++;
            Sleep(1000);
            if(j%t==0)
                cout<<char(7);
        }
        cl();
        cout<<"时间到了!!!\n";
        system("powershell -Command \"Add-Type -AssemblyName System.Speech; $speak =New-object System.Speech.Synthesis.SpeechSynthesizer; $speak.Speak('break')\"");
        for(int i=1;i<=15;i++){
            Sleep(2000);
            if(i%5==0){
                system("powershell -Command \"Add-Type -AssemblyName System.Speech; $speak =New-object System.Speech.Synthesis.SpeechSynthesizer; $speak.Speak('break')\"");
            }
            cout<<char(7);
        }
        system("pause");
        cout<<"是否需要再来一次,是请输入1,不是请输入0\n";
        cin>>sum;
        if(!sum){ 
            break;
        }
    }
    cout<<"欢迎再次使用";
    return 0;
}

0
0
我要回答