双人接龙小游戏
双人接龙小游戏 C++ 重置版
只能使用 VC++23,GNU 用户请自行解析!
Update:
- 增加了脏话字库,请大家在接龙时文明用语!
本代码遵循 CC-BY-NC-ND (署名-非商业使用-禁止演绎)协议
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <format>
#include <print>
#include <cstring>
#include <string>
#include <fstream>
#include <unordered_set>
#include <windows.h>
#include <conio.h>
using namespace std;
string n1, n2, record;
unordered_set<string> dic;
vector<string> shit{ "傻逼", "煞笔", "沙比", "傻比", "我草", "我曹", "卧槽", "我操", "我艹", "艹", "草", "CCF", "西西弗", "€€£", "他妈", "特么", "特喵", "奶奶", "妈", "大爷", "生的", "shit", "SHIT", "Shit", "fuck", "FUCK", "Fuck", "滚", "gun", "sad", "SB", "sb", "Sb", "sB", "Bee", "bee", "Sad", "Some", "some", "body", "Body" }; // 仅用作脏话识别,请勿在现实中骂人!
void init() {
#ifdef UNICODE
SetConsoleTitleW(L"双人接龙小游戏 - 好渴鹅");
#else
SetConsoleTitleA("双人接龙小游戏 - 好渴鹅");
#endif
}
void readPlayer() {
print("你是 P1,请输入你的名字:");
cin >> n1;
print("你是 P2,请输入你的名字:");
cin >> n2;
system("cls");
}
bool find(string &s, string &c) {
return s.find(c) != string::npos;
}
bool isShit(string &s) {
for (string i : shit) {
if (find(s, i)) {
return 1;
}
}
return 0;
}
void play() {
string last;
for (size_t i = 1; i <= 11451419198105201314; i++) {
string name = (i & 1 ? n1 : n2);
print("{},", name);
if (last == "") {
println("你是第一个人,请随便输入一个词语开始");
} else {
println("上一个人输入的是{},请接上", last);
}
println("提示:如果想要结束了可以输入“我不会了”哟~");
record += format("当前玩家是{}", name);
string s = "";
while (s == "") {
getline(cin, s);
if (s == "我不会了") {
record += "ta 没有接出来!";
return;
}
}
if (last == "") {
if (isShit(s)) {
println("请你文明用语!!!");
return;
}
println("好的,{}~", name);
} else {
if (dic.count(s)) {
println("重复的单词!");
record += "ta 输入的是重复的单词!";
return;
}
if (s.front() == last.back()) {
println("恭喜你,单接上了!");
} else if (s.size() >= 2 && last.size() >= 2 && s.substr(0, 2) == last.substr(s.size() - 2, 2)) {
println("恭喜你,双接上了!");
} else if (isShit(s)) {
println("请你文明用语!!!");
return;
} else {
println("对接失败!");
record += "ta 对接失败了!";
return;
}
}
dic.insert(s), last = s;
record += format("ta 输入的是{}\n", s);
cout << endl;
system("cls");
}
}
void writeFile() {
ofstream fout("接龙记录.txt");
fout << record;
fout.close();
}
int main() {
init();
readPlayer();
play();
writeFile();
system("pause");
return 0;
}

浙公网安备 33010602011771号