101
3.cpp
Normal file
101
3.cpp
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// 遊戲設定
|
||||||
|
const int NUM_COLORS = 7;
|
||||||
|
const int INITIAL_HAND_SIZE = 1;
|
||||||
|
|
||||||
|
// 顏色定義
|
||||||
|
enum Color {
|
||||||
|
RED,
|
||||||
|
GREEN,
|
||||||
|
BLUE,
|
||||||
|
YELLOW,
|
||||||
|
ORANGE,
|
||||||
|
PURPLE,
|
||||||
|
PINK
|
||||||
|
};
|
||||||
|
|
||||||
|
// 玩家類別
|
||||||
|
enum PlayerType {
|
||||||
|
HUMAN,
|
||||||
|
COMPUTER
|
||||||
|
};
|
||||||
|
|
||||||
|
// 玩家結構
|
||||||
|
struct Player {
|
||||||
|
int id;
|
||||||
|
vector<Color> hand;
|
||||||
|
int score;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 遊戲初始化
|
||||||
|
void initializeGame(vector<Player>& players) {
|
||||||
|
// 初始化玩家
|
||||||
|
for (int i = 0; i < players.size(); ++i) {
|
||||||
|
players[i].id = i;
|
||||||
|
players[i].hand.resize(INITIAL_HAND_SIZE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 遊戲流程 (簡化版)
|
||||||
|
void playGame() {
|
||||||
|
vector<Player> players;
|
||||||
|
initializeGame(players);
|
||||||
|
|
||||||
|
// 遊戲回合
|
||||||
|
for (int i = 0; i < 10; ++i) { // 假設遊戲回合數為 10
|
||||||
|
cout << "回合 " << i + 1 << endl;
|
||||||
|
|
||||||
|
// 人類玩家回合
|
||||||
|
if (players[0].id == HUMAN) {
|
||||||
|
// 玩家行動選擇
|
||||||
|
cout << "請選擇行動 (1. 抽牌, 2. 拿走區域卡)" << endl;
|
||||||
|
int choice;
|
||||||
|
cin >> choice;
|
||||||
|
|
||||||
|
if (choice == 1) {
|
||||||
|
// 抽牌
|
||||||
|
cout << "已抽牌" << endl;
|
||||||
|
} else if (choice == 2) {
|
||||||
|
// 拿走區域卡
|
||||||
|
cout << "已拿走區域卡" << endl;
|
||||||
|
} else {
|
||||||
|
cout << "無效的選擇,請重新輸入" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 程式隨機模擬電腦玩家的行動
|
||||||
|
if (players[0].id == HUMAN) {
|
||||||
|
// 电脑玩家随机选择行动
|
||||||
|
if (rand() % 2 == 0) {
|
||||||
|
cout << "電腦玩家選擇: 抽牌" << endl;
|
||||||
|
} else {
|
||||||
|
cout << "電腦玩家選擇: 拿走區域卡" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 結束回合
|
||||||
|
}
|
||||||
|
|
||||||
|
// 結算分數
|
||||||
|
cout << "結算分數" << endl;
|
||||||
|
// 顯示每個玩家的分數
|
||||||
|
for (int i = 0; i < players.size(); ++i) {
|
||||||
|
cout << "玩家 " << i << " 分數: " << players[i].score << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 詢問是否再來一次或離開程式
|
||||||
|
char choice;
|
||||||
|
cout << "是否再來一次 (y/n)? ";
|
||||||
|
cin >> choice;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
playGame();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user