耗时2天自制电子桌游
2026-11-08 18:06:10
发布于:浙江
代码先放这
后续可能会有更新
这里不会变
会把最新版本放在团队里
建议加团
(申请可能会晚点通过)
/*By/SRA.刺胞动物*/
///DEMO
#include<bits/stdc++.h>
#include<Windows.h>
#include<conio.h>
#include<winable.h>
using namespace std;
#define sy system
void col(int a){
if(a==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
if(a==7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
}
void say(string s,int ms){
for(int i=0;i<s.size();i++){
cout<<s[i];
Sleep(ms);
}
Sleep(ms);
}
void tab(int n){
for(int i=1;i<=n;i++)col(0),cout<<'\t';
}
void cls(){
sy("cls");
}
char type(){
return _getch();
}
struct nodeplayer{
int oc;
int hp,maxhp,hurt,money;
vector<int> card;
vector<int> weapon;
}player[10];///max>>>8 player
struct nodecard{
string name,intr;
int level,pay;
}card[1005];
void loadcard(){
card[1]={"再生药水","+1HP",0,15};
card[2]={"再生药水","+1HP",0,15};
card[3]={"再生药水","+1HP",0,15};
card[4]={"再生药水","+1HP",0,15};
card[5]={"盐水","50%+2HP\n50%-1HP",1,20};
card[6]={"盐水","50%+2HP\n50%-1HP",1,20};
card[7]={"盐水","50%+2HP\n50%-1HP",1,20};
card[8]={"哑铃","+1默认伤害",0,20};
card[9]={"哑铃","+1默认伤害",0,20};
card[10]={"哑铃","+1默认伤害",0,20};
card[11]={"哑铃","+1默认伤害",0,20};
card[12]={"维他命","回合结束后+1HP\n-5HP",3,60};
}
struct nodeweapon{
string name,intr;
int level,hurt,pay;
}weapon[1005];
void loadweapon(){
weapon[1]={"小刀","1伤害",0,1,10};
weapon[2]={"小刀","1伤害",0,1,10};
weapon[3]={"小刀","1伤害",0,1,10};
weapon[4]={"小刀","1伤害",0,1,10};
weapon[5]={"刺棍","2伤害",0,2,15};
weapon[6]={"刺棍","2伤害",0,2,15};
weapon[7]={"刺棍","2伤害",0,2,15};
weapon[8]={"左轮手枪","3伤害",1,3,20};
weapon[8]={"左轮手枪","3伤害",1,3,20};
weapon[9]={"斩首刀","3伤害\n有1%概率秒杀",3,3,45};
weapon[10]={"铁板","2伤害\n+1HP",2,2,25};
weapon[11]={"铁板","2伤害\n+1HP",2,2,25};
weapon[12]={"斩首刀Plus","3伤害\n有2%概率秒杀",4,3,60};
}
struct nodeoc{
string name,intr;
}oc[1005];
void loadoc(){
oc[1]={"全能者","+2HP上限\n+1默认伤害"};
oc[2]={"企业家","回合开始时+$30\n-1默认伤害"};
oc[3]={"病人","回合开始时+1HP上限,-1HP"};
}
const int ocnum=3;//////////////////////////////////////////////////
const int cardnum=12;//////////////////////////////////////////////////
const int weaponnum=12;//////////////////////////////////////////////////
bool per(int persent){
int x=(rand()%100+1);
if(x<=persent)return 1;
return 0;
}
struct nodegetM{
int money,persent;
}getM[1005];
void loadgetM(){
getM[1]={20,100};
getM[2]={30,90};
getM[3]={40,85};
getM[4]={50,75};
getM[5]={55,75};
getM[6]={70,60};
getM[7]={75,50};
getM[8]={80,45};
getM[9]={90,30};
getM[10]={95,20};
getM[11]={100,15};
getM[12]={105,10};
getM[13]={120,5};
getM[14]={115,5};
getM[15]={125,3};
}
void load(){
loadcard();
loadweapon();
loadoc();
loadgetM();
}
void game(){
cls();
load();
Sleep(1000);
col(0),cout<<"How many players?(2~8)\n";
lendin:
char oplend=type();
int players=(oplend-'0');
if(players<2 || players>8){
cout<<'\r';
goto lendin;
}
cls();
Sleep(1000);
for(int i=1;i<=players;i++){
int lineoc=1;
character:
cls();
col(0),cout<<"PLAYER"<<i<<"\nChoose your character\n";
for(int j=1;j<=ocnum;j++){
if(j==lineoc)col(5),cout<<'>'<<oc[j].name<<'<'<<'\n'<<oc[j].intr<<"\n\n";
else col(0),cout<<'<'<<oc[j].name<<'>'<<'\n'<<oc[j].intr<<"\n\n";
}
col(0),cout<<"\nw/s>>>change\nSPACE>>>choose";
char opoc=type();
if(opoc=='w')lineoc--;
if(opoc=='s')lineoc++;
if(lineoc<1)lineoc=ocnum;
if(lineoc>ocnum)lineoc=1;
if(opoc==' '){
player[i].oc=lineoc;
player[i].maxhp=15;
player[i].hp=player[i].maxhp;
player[i].hurt=0;
player[i].money=0;
switch(lineoc){
case 1:
player[i].hp+=2;
player[i].maxhp+=2;
player[i].hurt++;
break;
case 2:
player[i].hurt--;
}
}else{
goto character;
}
}
cls();
Sleep(1000);
say("GAME START\n",30);
col(0),cout<<"press a letter\n";
type();
int alive=players;
cls();
int fvitamin[10]={};
while(alive>1){
for(int i=1;i<=players;i++){
cls();
if(player[i].hp<=0)continue;
switch(player[i].oc){
case 2:
player[i].money+=30;
break;
case 3:
player[i].maxhp++;
player[i].hp--;
}
col(0),cout<<"PLAYER"<<i<<'\n';
Sleep(1000);
type();
cls();
say("Part1\n",50);
Sleep(1000);
type();
int x1=(rand()%15+1),x2=(rand()%15+1),x3=(rand()%15+1);
int linegM=1;
getM:
cls();
col(0),cout<<"make some money\n";
if(linegM==1)col(5),cout<<">$"<<getM[x1].money<<'('<<getM[x1].persent<<"%)<\n";
else col(0),cout<<"<$"<<getM[x1].money<<'('<<getM[x1].persent<<"%)>\n";
if(linegM==2)col(5),cout<<">$"<<getM[x2].money<<'('<<getM[x2].persent<<"%)<\n";
else col(0),cout<<"<$"<<getM[x2].money<<'('<<getM[x2].persent<<"%)>\n";
if(linegM==3)col(5),cout<<">$"<<getM[x3].money<<'('<<getM[x3].persent<<"%)<\n";
else col(0),cout<<"<$"<<getM[x3].money<<'('<<getM[x3].persent<<"%)>\n";
col(0),cout<<"\nw/s>>>change\nSPACE>>>choose";
char opgM=type();
if(opgM=='w')linegM--;
if(opgM=='s')linegM++;
if(linegM<1)linegM=3;
if(linegM>3)linegM=1;
if(opgM==' '){
int gM;
if(linegM==1)gM=x1;
if(linegM==2)gM=x2;
if(linegM==3)gM=x3;
cls();
if(per(getM[gM].persent)){
col(0),cout<<"Congratulations!\nYou got $"<<getM[gM].money<<"!\n";
player[i].money+=getM[gM].persent;
type();
}else{
col(0),cout<<"Sorry~'^'\n";
type();
}
}else{
goto getM;
}
}
cls();
Sleep(1000);
for(int i=1;i<=players;i++){
cls();
if(player[i].hp<=0)continue;
col(0),cout<<"PLAYER"<<i<<'\n';
type();
cls();
Sleep(1000);
say("Part2\n",50);
type();
while(1){
cls();
shop:
cls();
int shop[6],linesp=1;
for(int j=1;j<=2;j++)shop[j]=(rand()%weaponnum+1);
for(int j=3;j<=5;j++)shop[j]=(rand()%cardnum+1);
buy:
cls();
col(0),cout<<"Hi,I'm the shop assistent\nBuy some items and weapons'v'\n";
col(0),cout<<"weapons:\n";
for(int j=1;j<=2;j++){
if(j==linesp)col(5),cout<<'>'<<weapon[shop[j]].name<<"<\n$"<<weapon[shop[j]].pay<<'\n'<<weapon[shop[j]].intr<<"\n\n";
else col(weapon[shop[j]].level),cout<<'<'<<weapon[shop[j]].name<<">\n$"<<weapon[shop[j]].pay<<'\n'<<weapon[shop[j]].intr<<"\n\n";
}
col(0),cout<<"items:\n";
for(int j=3;j<=5;j++){
if(j==linesp)col(5),cout<<'>'<<card[shop[j]].name<<"<\n$"<<card[shop[j]].pay<<'\n'<<card[shop[j]].intr<<"\n\n";
else col(card[shop[j]].level),cout<<'<'<<card[shop[j]].name<<">\n$"<<card[shop[j]].pay<<'\n'<<card[shop[j]].intr<<"\n\n";
}
col(0),cout<<"HP:"<<player[i].hp<<'/'<<player[i].maxhp;
col(0),cout<<"\nYou have $"<<player[i].money<<"\nw/s>>>change\nSPACE>>>choose\ny>>>refresh($5)\nf>>>OK";
char opsp=type();
if(opsp=='w')linesp--;
if(opsp=='s')linesp++;
if(linesp>5)linesp=1;
if(linesp<1)linesp=5;
if(opsp=='y'){
if(player[i].money>=5){
player[i].money-=5;
goto shop;
}else{
cls();
say("You haven't got enough money!\n",25);
type();
goto buy;
}
}
if(opsp=='f')break;
if(opsp==' '){
int num=shop[linesp];
if(linesp<=2){
if(player[i].money<weapon[num].pay){
cls();
say("You haven't got enough money!\n",25);
type();
goto buy;
}else{
player[i].money-=weapon[num].pay;
player[i].weapon.push_back(num);
goto buy;
}
}else{
if(player[i].money<card[num].pay){
cls();
say("You haven't got enough money!\n",25);
type();
goto buy;
}else{
player[i].money-=card[num].pay;
player[i].card.push_back(num);
goto buy;
}
}
}else{
goto buy;
}
}
}
cls();
Sleep(1000);
for(int i=1;i<=players;i++){
cls();
if(player[i].hp<=0)continue;
col(0),cout<<"PLAYER"<<i<<'\n';
type();
cls();
Sleep(1000);
say("Part3\n",50);
type();
cls();
int lineuw=1;
usew:
cls();
col(0),cout<<"Use your weapon\n";
for(int j=0;j<player[i].weapon.size();j++){
if(j==(lineuw-1))col(5),cout<<'>'<<weapon[player[i].weapon[j]].name<<"<\n"<<weapon[player[i].weapon[j]].intr<<'\n';
else col(weapon[player[i].weapon[j]].level),cout<<'<'<<weapon[player[i].weapon[j]].name<<">\n"<<weapon[player[i].weapon[j]].intr<<'\n';
}
col(0),cout<<"HP:"<<player[i].hp<<'/'<<player[i].maxhp<<"\n(+"<<player[i].hurt<<"hurt)\n";
col(0),cout<<"\nw/s>>>change\nSAPCE>>>use\nf>>>OK\n";
char opuw=type();
if(opuw=='w')lineuw--;
if(opuw=='s')lineuw++;
if(lineuw<1)lineuw=player[i].weapon.size();
if(lineuw>player[i].weapon.size())lineuw=1;
if(opuw=='f')continue;
if(opuw==' '){
usewt:
cls();
col(0),cout<<weapon[player[i].weapon[lineuw-1]].name<<"\nUse it to whom?";
char _type_=type();
int wto=(_type_-'0');
if(wto<1 || wto>players || player[wto].hp<=0){
cout<<'\r';
goto usewt;
}
player[wto].hp-=(weapon[player[i].weapon[lineuw-1]].hurt+player[i].hurt);
switch(player[i].weapon[lineuw-1]){
case 9:
if(per(1))player[wto].hp=0;
break;
case 10:
case 11:
player[i].hp++;
player[i].hp=min(player[i].hp,player[i].maxhp);
break;
case 12:
if(per(2))player[wto].hp=0;
}
player[i].weapon.erase(player[i].weapon.begin()+lineuw-1);
if(player[wto].hp<=0)alive--;
continue;
}else{
goto usew;
}
}
cls();
Sleep(1000);
for(int i=1;i<=players;i++){
cls();
if(player[i].hp<=0)continue;
col(0),cout<<"PLAYER"<<i<<'\n';
type();
cls();
Sleep(1000);
say("Part4\n",50);
type();
cls();
int lineuc=1;
usec:
cls();
col(0),cout<<"Use your cards\n";
for(int j=0;j<player[i].card.size();j++){
if(j==lineuc-1)col(5),cout<<'>'<<card[player[i].card[j]].name<<"<\n"<<card[player[i].card[j]].intr<<'\n';
else col(card[player[i].card[j]].level),cout<<'<'<<card[player[i].card[j]].name<<">\n"<<card[player[i].card[j]].intr<<'\n';
}
col(0),cout<<"HP:"<<player[i].hp<<'/'<<player[i].maxhp<<"\n(+"<<player[i].hurt<<"hurt)\n";
col(0),cout<<"\nw/s>>>change\nSAPCE>>>use\nf>>>OK\n";
char opuc=type();
if(opuc=='w')lineuc--;
if(opuc=='s')lineuc++;
if(lineuc<1)lineuc=player[i].card.size();
if(lineuc>player[i].card.size())lineuc=1;
if(opuc=='f'){
for(int j=1;j<=fvitamin[i];j++)player[i].hp=min(player[i].hp+1,player[i].maxhp);
continue;
}
if(opuc==' '){
switch(player[i].card[lineuc-1]){
case 1:
case 2:
case 3:
case 4:
player[i].hp++;
player[i].hp=min(player[i].hp,player[i].maxhp);
break;
case 5:
case 6:
case 7:
if(per(50))player[i].hp=min(player[i].hp+2,player[i].maxhp);
else player[i].hp--;
break;
case 8:
case 9:
case 10:
case 11:
player[i].hurt++;
break;
case 12:
fvitamin[i]++;
player[i].hp-=5;
if(player[i].hp<=0)alive--;
}
}
goto usec;
}
}
}
string notice="The game is just a demo,we'll finish it in a week\n";
void start(){
tab(9);
say("DEATH INK\n",35);
Sleep(1000);
tab(8);
cout<<"press a letter to play\n";
type();
int linest=1;
start:
cls();
tab(8);
col(0),cout<<"DEATH INK\n";
tab(8);
if(linest==1)col(5),cout<<">play<\n";
else col(0),cout<<"<play>\n";
tab(8);
if(linest==2)col(5),cout<<">notices<\n";
else col(0),cout<<"<notices>\n";
tab(8);
if(linest==3)col(5),cout<<">close<\n";
else col(0),cout<<"<close>\n";
col(0),cout<<"\nw/s>>>change\nSPACE>>>choose";
char opst=type();
if(opst=='w')linest--;
if(opst=='s')linest++;
if(linest<1)linest=3;
if(linest>3)linest=1;
if(opst==' '){
switch(linest){
case 1:
game();
break;
case 2:
notice:{
cls();
col(0),say(notice,20);
Sleep(1000);
col(0),cout<<"SPACE>>>return\n";
char opnotice=type();
if(opnotice==' ')goto start;
goto notice;
break;
}
case 3:
cls();
col(0),cout<<"close the game now?\nSPACE>>>yes\n";
char close=type();
if(close==' '){
cls();
return;
}
goto start;
}
}
goto start;
}
int main(){
srand(static_cast<unsigned>(time(0)));
start();
}
全部评论 1
感谢
2天前 来自 浙江
0乐
2天前 来自 浙江
0凯 旋 乐 ④ 了
2天前 来自 浙江
0上课请认真听课
2天前 来自 浙江
0





















有帮助,赞一个