wendagames.h

· · 个人记录

//wenda generic super function header file v1.0.0
//this is created by 2023/5/19
// Standard objects -*- C++ -*-

//for codingwenda games
//made with c++11

//no"codingtang.h"in it

//  Name: "wendagames.h"
//  Copyright: --
//  Author: --
//  Last update time: 20/05/23 21:39
//  Description: a header file for codingwenda

//包含函数:
//-------------------------------------------------
//console()                       --包含在游戏里 
//color()                         --包含在游戏里 
//lin()                           --包含在游戏里 
//clearScreen()                   --包含在游戏里 
//getTime()                       --包含在游戏里 
//GetTime()                       --包含在游戏里 
//nian()                          ----------原创 
//Line()                          --包含在游戏里 
//Line2()                         ----------原创 
//to_year_month_days()            --包含在游戏里 
//to_month_days()                 --包含在游戏里 
//rightLine()                     --包含在游戏里 
//rightLine2()                    ----------原创 
//sbLine()                        ----------原创 
//leftprint()                     ----------原创 
//rightPrint()                    --包含在游戏里 
//outfloat()                      ----------原创 
//outnum()                        ----------原创 
//outstring()                     ----------原创 
//wait()                          ----------原创 
//wait_sec()                      ----------原创 
//wait_min()                      ----------原创 
//rechange()                      --包含在游戏里 
//all_color()                     ----------原创 
//open_web()                      ----------原创 
//open()                          ----------原创 
//cls()                           --包含在游戏里 
//fast_cls()                      --包含在游戏里 
//HideCursor()                    --包含在游戏里 
//slowout()                       --包含在游戏里 
//quicklyout()                    --包含在游戏里 
//Slowsay()                       --包含在游戏里 
//Slowsay1()                      --包含在游戏里 
//wohide_cursor()                 --包含在游戏里 
//woshow_cursor()                 --包含在游戏里 
//full_screen()                   --包含在游戏里 
//setfontsize()                   --包含在游戏里 
//set_no_exit()                   ----------原创 
//ert()                           ----------原创 
//warn_noise()                    ----------原创 
//cur_left()                      ----------原创 
//cur_right()                     ----------原创 

/*----------------------start----------------------*/

#include <iostream>
#include <bits/stdc++.h>
#include <conio.h>
#include <string>
#include <map>
#include<stdlib.h>
#include <cmath>//数学 
#include<fstream> //文件操作 
#include<windows.h>//系 统操作 
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<conio.h>//大部分用于游戏里的getch() 
#include<sstream>
#include<time.h>//时间 
#include<vector> 
#include<stdio.h>
#include<stdlib.h>
#include <windows.h>
#include <time.h> 
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
void console(string consolename)//基础窗口操作,可以不加 
{
    if(!consolename.size()){
        consolename="问答游戏项目 - 未命名1";
    }
    char consolename1[1000005];
    strcpy(consolename1, consolename.c_str()); 
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);  
    CONSOLE_SCREEN_BUFFER_INFO bInfo; 
    GetConsoleScreenBufferInfo(hOut, &bInfo );  
    SetConsoleTitle(consolename1); // 设置窗口的标题
}
void color(int corcorcor){//设置字体颜色 
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),corcorcor);

/*  1   深蓝色
    2   深绿色
    3   深青色 
    4   深红色
    5   深粉色
    i   黄色
    7   深白色
    8   灰色
    9   浅蓝色
    10  浅绿色 
    11  浅青色 
    12  浅红色 
    13  浅粉色 
    14  浅黄色 
    15  浅白色 
    背景
    1~15        黑色 
    16~31       深蓝色 
    32~47       深绿色
    48~63       深青色
    64~79       深红色
    'S'~95      深粉色
    96~111      深黄色
    112~127     深白色
    128~143     灰色
    144~159     浅蓝色
    160~1'A'    浅绿色
    176~191     浅青色
    192~207     浅红色
    208~223     浅粉色
    224~239     浅黄色
    240~255     浅白色
*/

}
void lin(string str){//没有换行的居中输出 
    int i,l,w;
    w=80;
    l=str.length();
    for(i=0;i<(w-l)/2;i++)
    cout<<" ";
    cout<<str;
    return ;
}
void clearScreen(){    //快速清屏 
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coordScreen = { 0, 0 };    // home for the cursor
    SetConsoleCursorPosition( hConsole, coordScreen );
}

string getTime(){//月和日 
    time_t timep;
    time (&timep);
    char tmp[64];
    strftime(tmp, sizeof(tmp), "%m%d",localtime(&timep) );
    return tmp;
}
string GetTime(){//该函数如需借鉴请先联系沙兴安 
    time_t timep;
    time (&timep);
    char tmp[64];
    strftime(tmp, sizeof(tmp), "%Y%m%d",localtime(&timep) );//年,月和日 
    return tmp;
}

string nian(){//年 
    time_t timep;
    time (&timep);
    char tmp[64];
    strftime(tmp, sizeof(tmp), "%Y",localtime(&timep) );
    return tmp;
}
void Line(string str){//经典居中 
    int i,l,w;
    w=80;
    l=str.length();
    for(i=0;i<(w-l)/2;i++)
    cout<<" ";
    cout<<str<<endl;
    return ;
}

void Line2(string str){// 经典居中改版,只输出空格 
    int i,l,w;
    w=80;
    l=str.length();
    for(i=0;i<(w-l)/2;i++)
    cout<<" ";
    cout<<str;
    for(i=0;i<(w-l)/2;i++)
    cout<<" ";
    return ;
}
bool to_year_month_days(string end){//统计是否是目标年月日 
    string tmp=GetTime(),temp=end;
    if(tmp>=temp) return 1;
    else return 0;
}
bool to_month_days(string end){//统计是否是目标月日 
    string tmp=getTime();
    if(tmp==end) return 1;
    else return 0;
}
void rightLine(string str){//右侧输出加换行 
    int i,l,w;
    w=80;
    l=str.length();
    for(i=1;i<80-l;i++)
    cout<<" ";
    cout<<str<<endl;
    return ;
}

void rightLine2(string str){//右侧输出
    int i,l,w;
    w=80;
    l=str.length();
    for(i=1;i<80-l;i++)
    cout<<" ";
    cout<<str;
    return ;
}
void sbLine(string str){//80空格+字+换行 
    int i,l,w;
    w=80;
    l=str.length();
    for(i=1;i<80;i++)
    cout<<" ";
    cout<<str<<endl;
    return ;
}
void leftprint(string pr){//打印 
    cout<<pr;
}
void rightPrint(string str){//右侧打印
    int i,l,w;
    w=80;
    l=str.length();
    for(i=1;i<80-l;i++)
    cout<<" ";
    cout<<str<<endl;
    return ;
}
void outfloat(double a){//实数打印 
    cout<<a;
}
void outnum(long long a){//整数打印 (极限long long) 
    cout<<a;
}
void outstring(string s){//打印字符串 
    cout<<s;
}
void wait(int a){//等待(毫秒) 
    Sleep(a);
}
void wait_sec(int a){//这是很方便的, 调用 wait_sec(秒数) 就可以等待秒数 
    Sleep(a*1000);
} 
void wait_min(int a){//这也是很方便, 调用 wait_min(分钟) 就可以等待分钟
    Sleep(a*1000*60);
} 
void rechange(){//打印时间年-月-日 
    time_t timep;
    time(&timep);
    char tmp[64];
    strftime(tmp, sizeof(tmp), "%Y-%m-%d",localtime(&timep) );
}
//cmd系列: 
void all_color(string as){//全屏渲染颜色,同“system("color XX")” 
    as="color "+as;
    char sa[100005];
    strcpy(sa, as.c_str()); 
    system(sa);
}
void open_web(string as){//打开网站 
    as="start https://"+as;
    char sa[100005];
    strcpy(sa, as.c_str()); 
    system(sa);
}
void open(string as){//打开 
    as="start "+as;
    char sa[100005];
    strcpy(sa, as.c_str()); 
    system(sa);
}
void cls(){//清屏,同"system("cls")" ,这个更好记。 
    system("cls");
}
//cmd系列结束 
void fast_cls(){//快速清屏,同"clearscreen()" ,这个更好记。 
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coordScreen = { 0, 0 };
    SetConsoleCursorPosition( hConsole, coordScreen );
}
void HideCursor(){//隐藏光标 
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_CURSOR_INFO CursorInfo;
    GetConsoleCursorInfo(handle, &CursorInfo);
    CursorInfo.bVisible = false;
    SetConsoleCursorInfo(handle, &CursorInfo);
}
void slowout(string s){//慢速打印 
    for(int i=0;i<s.size();i++){
        cout<<s[i];
        Sleep(25);
    }
    cout<<"\n"; 
}
void quicklyout(string s){//快速打印 
    for(int i=0;i<s.size();i++){
        cout<<s[i];
        Sleep(20);
    }
    cout<<"\n";
}

void Slowsay(string s) {//慢慢吐字 
    for (int i = 0; s[i]; i++) {
        cout << s[i];
        Sleep(10);
    }
}
void Slowsay1(string s) {//超慢说 
    for (int i = 0; s[i]; i++) {
        cout << s[i];
    }
    Sleep(400);
}

//小结:
//吐字速度排行: 
//1.Slowsay()     10毫秒 
//2.quicklyout()  20毫秒 
//3.out()         25毫秒 
//4.Slowsay1()   400毫秒 
void wohide_cursor()//隐藏光标
{
HANDLE h_GAME =GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursor_info;
GetConsoleCursorInfo(h_GAME,&cursor_info);
cursor_info.bVisible=false;
SetConsoleCursorInfo(h_GAME,&cursor_info);
}
void woshow_cursor()//显示光标
{
HANDLE h_GAME =GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursor_info;
GetConsoleCursorInfo(h_GAME,&cursor_info);
cursor_info.bVisible=true;
SetConsoleCursorInfo(h_GAME,&cursor_info);
}
void full_screen()//全屏 
{   
    HWND hwnd = GetForegroundWindow();
    int cx = GetSystemMetrics(SM_CXSCREEN);           
    int cy = GetSystemMetrics(SM_CYSCREEN);            

    LONG l_WinStyle = GetWindowLong(hwnd,GWL_STYLE);   

    SetWindowLong(hwnd,GWL_STYLE,(l_WinStyle | WS_POPUP | WS_MAXIMIZE) & ~WS_CAPTION & ~WS_THICKFRAME & ~WS_BORDER);

    SetWindowPos(hwnd, HWND_TOP, 0, 0, cx, cy, 0);
}

int setfontsize(int x, int y) { //设置字体大小
    CONSOLE_FONT_INFOEX 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");
}
void set_no_exit() {//窗口设置 
    int cx = GetSystemMetrics(SM_CXSCREEN);           
    int cy = GetSystemMetrics(SM_CYSCREEN);   
    SetWindowPos(GetConsoleWindow(), HWND_TOPMOST, 0, 0, cx, cy, SWP_NOSIZE);
    DWORD mode;
    GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode);
    mode &= ~ENABLE_QUICK_EDIT_MODE;
    SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), mode);
    SetWindowLong(GetConsoleWindow(), GWL_STYLE, GetWindowLong(GetConsoleWindow(), GWL_STYLE) & ~WS_CAPTION);
}

void ert(){//警告 
    MessageBeep(MB_ICONERROR);
}

void warn_noise(){//发声 
    MessageBeep(MB_ICONWARNING);
}
void cur_left(){//左键点击 
    mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
}
void cur_right(){//右键点击 
    mouse_event(MOUSEEVENTF_RIGHTUP | MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
}

/*-----------------------end-----------------------*/