新手天翼
#include<bits/stdc++.h>
#include<windows.h>
#include <pthread.h>
#include<conio.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME)&0x8000)?1:0)
/******************\
本题思路:
LvC LvB LvA LvS LvSS
LvSSS LvS+ Lv神 LvV LvV+
金 木 水 火 土 雷 风
6 2 9 4 14 13 7
0=黑色 1=蓝色 2=绿色 3=湖蓝色
4=红色 5=紫色 6=** 7=白色
8=灰色 9=淡蓝色A=淡绿色B=淡浅绿色
C=淡红色D=淡紫色E=淡黄 F=亮白色
\*******************/
using namespace std;
int bag[31][8],Lv,jb,X=505,Y=505,XU=200,XI=200;
map<int,string>i_s;
map<string,int>s_i;
map<int,int>i_c;
class boss{
public:
int x,y,xu,xi;
boss(){
x=405,y=404,xu=505,xi=505;
}
};
vector<boss>bosses;
struct Men{
int id,lv;
};
class Kuang{
public:
int x,y,n;
Kuang(){
x=rand()%300+200,y=rand()%300+200,n=1;
}
};
vector<Kuang>kuangs;
vector<Men>men;
int blocks[1000][10][10] = {
{
//8:air(空气)
{15, 15, 15, 15, 15, 15, 15, 15, 15, 15},
{15, 15, 15, 15, 15, 15, 15, 15, 15, 15},
{15, 15, 15, 15, 15, 15, 15, 15, 15, 15},
{15, 15, 15, 15, 15, 15, 15, 15, 15, 15},
{15, 15, 15, 15, 15, 15, 15, 15, 15, 15},
{15, 15, 15, 15, 15, 15, 15, 15, 15, 15},
{15, 15, 15, 15, 15, 15, 15, 15, 15, 15},
{15, 15, 15, 15, 15, 15, 15, 15, 15, 15},
{15, 15, 15, 15, 15, 15, 15, 15, 15, 15},
{15, 15, 15, 15, 15, 15, 15, 15, 15, 15},
}, {
//3:stone(石头)
{8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
}
};
namespace{
void nofastedit() { //关闭快速编辑
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hStdin, &mode);
mode &= ~ENABLE_QUICK_EDIT_MODE;
mode &= ~ENABLE_INSERT_MODE;
mode &= ~ENABLE_MOUSE_INPUT;
SetConsoleMode(hStdin, mode);
}HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE), hsout;
void cursor(bool visible) { //控制光标函数
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(hout, &CursorInfo);
CursorInfo.bVisible = visible;
SetConsoleCursorInfo(hout, &CursorInfo);
}
HWND hwnd = GetConsoleWindow();
int setfontsize(int x, int y) { //设置字体大小
CONSOLE_FONT_INFOEX cfi;
GetCurrentConsoleFontEx(hout, FALSE, &cfi);
cfi.cbSize = sizeof(cfi);
cfi.nFont = 0;
cfi.dwFontSize.X = x;
cfi.dwFontSize.Y = y;
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = 400;
wcscpy(cfi.FaceName, L"NSimSun");
return SetCurrentConsoleFontEx(hout, TRUE, &cfi);
}
void swrite(string str) { //输出到设置缓冲区
WriteConsoleA(hsout, str.c_str(), str.size(), NULL, NULL);
}
WORD get_font(int ForgC, int BackC) { //获取字体颜色参数
return ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
}
COORD home_coord = {0, 0};
DWORD written;
int WDOUBLE;
int world[101][101];
POINT GetMouse() {
/* HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFO font;
GetCurrentConsoleFont(handle, FALSE, &font);
int DPI = GetDeviceCaps(GetDC(NULL), LOGPIXELSX);
double Zoom = DPI * 1.0 / 24 * 25.0 / 100.0;
p.x /= font.dwFontSize.X * Zoom;
p.y /= font.dwFontSize.Y * Zoom;*/
POINT p;
GetCursorPos(&p);
ScreenToClient(hwnd, &p);
return p;
}
void hello() { //首次运行设置
SetConsoleActiveScreenBuffer(hsout);
swrite("你好,欢迎使用SUPERCRAFT。\n");
swrite("在开始之前,我们需要进行一些设置。\n");
swrite("[按任意键继续]");
getch();
system("cls");
swrite("在显示的两个正方形中,选择较为规整的一个\n");
swrite("[按任意键继续]");
getch();
system("cls");
SetConsoleActiveScreenBuffer(hout);
setfontsize(4, 4);
for (int i = 1; i <= 10; i++) {
WORD w[1005];
int pos = 0;
COORD coord = {1, i};
for (int j = 1; j <= 10; j++) {
w[pos++] = get_font(4, 4);
}
WriteConsoleOutputAttribute(hout, w, pos, coord, &written);
}
for (int i = 1; i <= 10; i++) {
WORD w[1005];
int pos = 0;
COORD coord = {13, i};
for (int j = 1; j <= 10; j++) {
w[pos++] = get_font(4, 4);
w[pos++] = get_font(4, 4);
}
WriteConsoleOutputAttribute(hout, w, pos, coord, &written);
}
getch();
system("cls");
SetConsoleActiveScreenBuffer(hsout);
swrite("哪一个正方形是最规整的?\n");
swrite("1.左边的 2.右边的");
reinput:
int ipt = getch();
if (ipt == '1') {
WDOUBLE = 0;
} else if (ipt == '2') {
WDOUBLE = 1;
} else {
goto reinput;
}
system("cls");
swrite("按+/-调整窗口大小,F键确定\n");
swrite("请保持白色方块为正方形\n[按任意键继续]");
getch();
SetConsoleActiveScreenBuffer(hout);
if (WDOUBLE == 0) {
system("mode con:cols=200 lines=100");
} else {
system("mode con:cols=400 lines=100");
}
if (WDOUBLE == 0) {
for (int i = 1; i <= 10; i++) {
WORD w[1005];
int pos = 0;
COORD coord = {1, i};
for (int j = 1; j <= 10; j++) {
w[pos++] = get_font(4, 4);
}
WriteConsoleOutputAttribute(hout, w, pos, coord, &written);
}
} else {
for (int i = 1; i <= 10; i++) {
WORD w[1005];
int pos = 0;
COORD coord = {1, i};
for (int j = 1; j <= 10; j++) {
w[pos++] = get_font(4,4);
w[pos++] = get_font(4, 4);
}
WriteConsoleOutputAttribute(hout, w, pos, coord, &written);
}
}
int sizes = 4;
while (1) {
int ipt = getch();
if (ipt == '+' || ipt == '=') {
sizes++;
setfontsize(sizes, sizes);
if (WDOUBLE == 0) {
system("mode con:cols=200 lines=100");
} else {
system("mode con:cols=400 lines=100");
}
}
if (ipt == '-' || ipt == '_') {
sizes--;
if (sizes < 1) {
sizes = 1;
}
setfontsize(sizes, sizes);
if (WDOUBLE == 0) {
system("mode con:cols=200 lines=100");
} else {
system("mode con:cols=400 lines=100");
}
}
if (WDOUBLE == 0) {
for (int i = 1; i <= 10; i++) {
WORD w[1005];
int pos = 0;
COORD coord = {1, i};
for (int j = 1; j <= 10; j++) {
w[pos++] = get_font(4,4);
}
WriteConsoleOutputAttribute(hout, w, pos, coord, &written);
}
} else {
for (int i = 1; i <= 10; i++) {
WORD w[1005];
int pos = 0;
COORD coord = {1, i};
for (int j = 1; j <= 10; j++) {
w[pos++] = get_font(4, 4);
w[pos++] = get_font(4, 4);
}
WriteConsoleOutputAttribute(hout, w, pos, coord, &written);
}
}
if (ipt == 'f' || ipt == 'F') {
break;
}
}
SetConsoleActiveScreenBuffer(hsout);
system("cls");
ofstream sout("sets");
sout << WDOUBLE << " " << sizes;
sout.close();
swrite("谢谢!\n设置已保存,以后将不会出现此窗口。\n");
swrite("如果对此次设定不满意,可以删除sets文件以重新设置\n[按任意键继续]");
getch();
SetConsoleActiveScreenBuffer(hout);
}
void init(){
i_s[1]="C";s_i["C"]=1; i_s[2]="B";s_i["B"]=2;
i_s[3]="A";s_i["A"]=3; i_s[4]="S";s_i["S"]=4;
i_s[5]="SS";s_i["SS"]=5; i_s[6]="SSS";s_i["SSS"]=6;
i_s[7]="S+";s_i["S+"]=7; i_s[8]="神";s_i["神"]=8;
i_s[9]="V";s_i["V"]=9; i_s[10]="V+";s_i["V+"]=10;
i_c[1]=6;i_c[2]=2;i_c[3]=9;i_c[4]=12;
i_c[5]=14; i_c[6]=13; i_c[7]=7;
ifstream IFS;
cursor(0);
nofastedit();
IFS.open("碎片");
for(int i=1;i<=7;i++){
for(int j=1;j<=10;j++){
IFS>>bag[j][i];
}
}
IFS.open("jb");
IFS>>jb;
IFS.close();
IFS.open("lv");
IFS>>Lv;
/*
IFS.open("属**大作战存档\\人物");
int K,LV;
while(IFS>>K>>LV){
men.push_back({K,LV});
}
*/
}
int output[201][121]; //输出缓存
void writefont(const WORD *font, int fsize) { //快速渲染颜色信息
WriteConsoleOutputAttribute(hout, font, fsize, home_coord, &written);
}
void sendprint() { //绘制控制台
WORD col[24005] = {};
int pos = 0;
//将二维数组存储到一维内
for (int i = 1; i <= 120; i++) {
for (int j = 1; j <= 100; j++) {
col[pos] = get_font(output[j][i], output[j][i]);
pos++;
}
}
writefont(col, 24000);
}
void sendprint_double() { //绘制控制台
WORD col[48005] = {};
int pos = 0;
//将二维数组存储到一维内
for (int i = 1; i <= 120; i++) {
for (int j = 1; j <= 100; j++) {
col[pos] = get_font(output[j][i], output[j][i]);
pos++;
col[pos] = get_font(output[j][i], output[j][i]);
pos++;
}
}
writefont(col, 48000);
}
bool access(string name) { //判断文件是否存在
ifstream f(name.c_str());
return f.good();
}
void c_olor(int corcorcor){ //颜色函数(效率比cmd高一些)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),corcorcor);
}
void console() { //设置控制台
system("title 属**大作战");
system("chcp 936");
system("cls");
hsout = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 1, NULL);
if (!access("sets")) { //不存在
hello();
}
ifstream sin("sets");
int sizes;
sin >> WDOUBLE >> sizes; //读入设置
sin.close();
setfontsize(sizes, sizes);
if (WDOUBLE == 0) {
system("mode con:cols=100 lines=120");
} else {
system("mode con:cols=200 lines=120");
}
}
void render() { //软件渲染器
if(1){
int x_left = X / 10 - 5,
x_right = (X % 10 == 0) ? (X / 10 + 5) :
(X / 10 + 6); //计算需要渲染的左边线和右边线
int y_left = (Y % 10 == 0) ? (Y / 10 - 5) :
(Y / 10 - 6), y_right = Y / 10 + 5; //计算需要渲染的上边线和下边线
int x_more = X % 10, y_more = Y % 10; //计算多出的部分
int x_pos = 1, y_pos = 1; //渲染位置计算
//渲染世界
for (int i = x_left; i <= x_right; i++) {
y_pos = 1;
for (int j = y_right; j >= y_left; j--) {
for (int p_i = 0; p_i < 10; p_i++) {
for (int p_j = 0; p_j < 10; p_j++) {
if (x_pos + p_i - x_more < 0 ||
x_pos + p_i - x_more > 100 ||
y_pos - p_j + y_more < 0 ||
y_pos - p_j + y_more > 100) {
continue; //如果越界则跳过
}
output[x_pos + p_i - x_more][y_pos - p_j
+ y_more] = blocks[world[i][j]][9 - p_j
][p_i];
}
}
y_pos += 10;
}
x_pos += 10;
}
//渲染boss和矿物
for(int i=0;i<bosses.size();i++){
boss n=bosses[i];
n.x+=46;
n.y-=55;
for (int p_i = 0; p_i < 10; p_i++) {
for (int p_j = 0; p_j < 10; p_j++) {
if (n.x -X+ p_i < 0 ||
n.x -X+ p_i > 100 ||
Y-n.y- p_j < 0 ||
Y-n.y - p_j > 100) {
continue; //如果越界则跳过
}
output[n.x-X+p_i][Y-n.y-p_j]=12;
}
}
}
for(int i=0;i<kuangs.size();i++){
Kuang n=kuangs[i];
n.x+=50;
n.y-=50;
if(n.x-X<0||n.x-X>100||Y-n.y<0||Y-n.y>100){
continue; //如果越界则跳过
}
output[n.x-X][Y-n.y]=i_c[kuangs[i].n];
}
//渲染玩家
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
output[46 + i][46 + j] = 14;
}
}
//渲染血量
int m=XI*100/XU;
for(int i=0;i<m;i++){
for(int j=0;j<10;j++){
output[i+1][j+101]=((XI<30)?4:10);
}
}
for(int i=m;i<100;i++){
for(int j=0;j<10;j++){
output[i+1][j+101]=0;
}
}
}
}
bool FLAG;
void *printmain(void *arg) {
clock_t st, tmp;
int sum = 0, fps = -1;
char t[1005];
st = clock();
while (FLAG) {
render(); //软件渲染
if (WDOUBLE == 0) { //发送渲染
sendprint();
} else {
sendprint_double();
}
sum++; //记录渲染个数
sprintf(t, "属**大作战 (X:%.1f,Y:%.1f,FPS:%d)", X * 1.0 / 10.0, Y * 1.0 / 10.0, fps); //输出FPS,坐标
tmp = clock();
if (tmp - st >= 1000) { //计算FPS
fps = sum / ((tmp - st) / 1000.0);
sum = 0;
st = tmp;
}
SetConsoleTitleA(t); //输出FPS
}
}
POINT ptorp(POINT P){
return {P.x/4+X-50,Y+50-P.y/4};
}
POINT ptob(POINT P){
P=ptorp(P);
return {P.x/10,P.y/10};
}
}
void craft(){
}
void buy(){
}
void beat(){
}
void about_mine(){
}
void study(){
}
int DFSCHECK(int x,int y){
return (world[x][y]==0)+
(world[x+1][y]==0)+(world[x][y+1]==0)
+(world[x][y-1]==0)+(world[x-1][y]==0);
}
bool dfs(int x,int y){
if(x==40&&y==40){
world[x][y]=0;
return 1;
}
if(x<15||y<15||x>50||y>50||DFSCHECK(x,y)>1||rand()%50==1){
return 0;
}
world[x][y]=0;
int cnt=0;
bool fl=0;
do{
++cnt;
int f=rand()%4;
if(f==0){fl=dfs(x+1,y);}
else if(f==1){fl=dfs(x,y+1);}
else if(f==2){fl=dfs(x-1,y);}
else{fl=dfs(x,y-1);}
}while(fl==0&&cnt<4);
return cnt<=3;
}
void set_map(int i){
switch(i){
case 1:{
for(int i=1;i<=100;i++){
Kuang ku;
kuangs.push_back(ku);
}
X=205,Y=204;
for(int i=1;i<=100;i++){
for(int j=1;j<=100;j++){
world[i][j]=1;
}
}
srand(time(0));
dfs(20,20);
break;
}
}
}
bool _canin(int x){
return x==0;
}
bool checkP(int x,int y){
return _canin(world[x/10][y/10]);
}
bool check_(int x=X,int y=Y){
return checkP(x+4,y+5)&&checkP(x+4,y-4)&&
checkP(x-5,y+5)&&checkP(x-5,y-4);
}
void do_mine(){
set_map(1);
FLAG=1;
console();
pthread_create(NULL, NULL, printmain, NULL);
int T=time(0);
while(1){
bool mouse=0;
POINT P;
if(KEY_DOWN(VK_LBUTTON)){
mouse=1;
P=GetMouse();
}
bool Kb=kbhit();
char ch=Kb?getch():-123;
if(ch==27||XI==0){
break;
}else if(ch=='w'||ch=='W'){
Y++;
if(ch<'a'){
++ ++Y;
}
while(!check_()){
Y--;
}
}else if(ch=='s'||ch=='S'){
Y--;
if(ch<'a'){
-- --Y;
}
while(!check_()){
Y++;
}
}else if(ch=='a'||ch=='A'){
X--;
if(ch<'a'){
-- --X;
}
while(!check_()){
X++;
}
}else if(ch=='d'||ch=='D'){
X++;
if(ch<'a'){
++ ++X;
}
while(!check_()){
X--;
}
}
if(time(0)-T>1){
XI--;
T++;
}
if(mouse){
POINT p;
p=ptorp(P);
ofstream OFS("ts");
OFS<<p.x<<" "<<p.y;
for(int i=0;i<kuangs.size();i++){
if(abs(kuangs[i].x-p.x)<2&&abs(kuangs[i].y-p.y)<2){
bag[1][kuangs[i].n]++;
swap(kuangs[i],kuangs[kuangs.size()-1]);
kuangs.pop_back();
i--;
}
}
}
}
FLAG=0;
}
void CONSOLE(){
system("cls");
setfontsize(8, 16);
c_olor(240);
system("mode con:cols=120 lines=30");
}
int main(){
init();
do_mine();
CONSOLE();
cout<<bag[1][1];
return 0;
}
//WASD移动,大写移动三像素,小写移动1像素
陈俊霖在2022-10-28 09:12:15追加了内容
注意——本游戏是从SUPERCFRAFT改的,也是属**大作战的前身,有的字没改,请谅解!