本人在小学编的游戏,内容分为两个cpp文件,可以把两个文件合到一起,因为代码写得太烂了
就不进行代码解释了,注:还需要添加一个name.txt文件加入两个玩家的名称
直接免费下载网址:【免费】C++控制台射击小游戏(双人版)_c++小游戏代码资源-优快云文库
tool.cpp
#include<iostream>
#include<string>
#include<windows.h>
#include <vector>
#include <algorithm>
#include<cstdlib>
#include<cstdio>
using namespace std;
void ycgb(void)
{
HANDLE hOut;
CONSOLE_CURSOR_INFO curInfo;
hOut=GetStdHandle(STD_OUTPUT_HANDLE);
curInfo.dwSize=1;
curInfo.bVisible=0;
SetConsoleCursorInfo(hOut,&curInfo);
}
//************************************
void opengame(void)
{
system("color 0E");
system("mode con cols=55 lines=25");
cout<<endl;
cout<<"╔";
for(int i=1;i<=25;i++)
{
cout<<"═";
}
cout<<"╗"<<endl;
for(int a=1;a<=20;a++)
{
cout<<"║";
if(a!=5&&a!=10&&a!=15)
{
for(int b=1;b<=25*2;b++)
{
cout<<" ";
}
}
if(a==5)
{
cout<<" 1.开始游戏"<<" ";
}
if(a==10)
{
cout<<" 2.游戏设置"<<" ";
}
if(a==15)
{
cout<<" 3.积分商店"<<" ";
}
cout<<"║"<<endl;
}
cout<<"╚";
for(int i=1;i<=25;i++)
{
cout<<"═";
}
cout<<"╝"<<endl;
}
//选择模式
void drawchose(void)
{
system("color 0E");
system("mode con cols=55 lines=25");
cout<<endl;
cout<<"╔";
for(int i=1;i<=25;i++)
{
cout<<"═";
}
cout<<"╗"<<endl;
for(int a=1;a<=20;a++)
{
cout<<"║";
if(a!=5&&a!=10&&a!=15)
{
for(int b=1;b<=25*2;b++)
{
cout<<" ";
}
}
if(a==5)
{
cout<<" 1.双人游戏"<<" ";
}
if(a==10)
{
cout<<" 2.人机对战"<<" ";
}
if(a==15)
{
cout<<" 3.赏金模式"<<" ";
}
cout<<"║"<<endl;
}
cout<<"╚";
for(int i=1;i<=25;i++)
{
cout<<"═";
}
cout<<"╝"<<endl;
}
//重复打印字符串
void pen1(int a,string b)
{
int i=0;
while(true)
{
cout<<b;
i++;
if(a<=i)
{
break;
}
}
}
void a(HANDLE hout,int x,int y){
//COORD是WindowsAPI中定义的一种结构,表示一个字符在控制台屏幕上的坐标
COORD pos;
pos.X=x;
pos.Y=y;
//SetConsoleCursorPosition是API中定位光标位置的函数。
SetConsoleCursorPosition(hout,pos);
}
//文字颜色
void color(WORD A)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), A);
}
void zb(short x, short y) { //定位光标
COORD coord = { x, y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
,main.cpp