game库(作者原创)

 个人主页

目录(感觉有目录很了不起的样子)

一、代码

二、每段分析

①、 头文件

②、函数

1、circle()函数

2、get_help()函数

3、Prime()函数

4、random()函数

5、star()函数

 6、tutrle_draw()函数

7、rinbow()函数

8、快读

③、其他

1、sound

2、tree

三、安装及其使用

①、安装

②、使用

注意事项

画五角星☆

画圆○

画彩虹

快读函数



 

一、代码

#pragma GCC optimize(2,3,"Ofast","inline")
#include<rturtle.h>
#include<utilapiset.h>
#include<conio.h>
#include<bits/stdc++.h>
#include<ctime>
#include<unordered_map>
#include<unordered_set>
#define Sleep(a) _sleep(a)
#define ll long long
#define reg register
using namespace std;
inline int int_read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-'){
			f=-1;
		}
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-48;
		ch=getchar();
	}
	return x*f;
}
inline string string_read(){
	string x="";
	char ch=getchar();
	x=x+ch;
	while(ch!=' '&&ch!='\n'){
		ch=getchar();
		x=x+ch;
	}
	return x;
}
inline char char_read(){
	return getchar();
}
inline double double_read(){
	int x=0,f=1;
	double y=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-'){
			f=-1;
		}
		ch=getchar();
	}
	while((ch>='0'&&ch<='9')||ch=='.'){
		if(ch>='0'&&ch<='9'){
			x=x*10+(ch-48);
		}else{
			break;
		}
		ch=getchar();
	}
	ch=getchar();
	while(ch>='0'&&ch<='9'){
		y=y*10+ch-48*1.0;
		ch=getchar();
	}
	while(y>1){
		y=y/10;
	}
	return (x+y)*f;
}
inline void circle(double a){
	arc(a,360);
}
inline void get_help(){
	system("start https://http://t.csdn.cn/HfXXZ/");
}
inline bool Prime(int num){
	if(num<=1){
		return false;
	}
	if(num==2||num==3){
		return true;
	}
	if(num%6!=1&&num%6!=5){
		return false;
	}else{
		return true;
	}
}
inline random(int left,int right){
	if(left>right){
		return 0;
	}
	return time(0)%(right-left+1)+left;
}
inline void star(double line=400,double size=5,double x=0,double y=0,bool tutrle=true){
	Color a[5]={RED,ORANGE,PURPLE,BLUE,GREEN};
	setPenColor(RED);
	if(tutrle==false){
		hide();	
	}
	penUp();
	setPenSize(size);
	setXY(x+(line*sin(18)/2),y-(line*cos(18))/2);
	penDown();
	setAngle(72);
	fd(line);
	for(int i=1;i<=4;i++){
		setPenColor(a[i]);
		rt(144);
		fd(line);
	}
	penUp();
}
inline void tutrle_draw(bool game=0){
	if(game==0){
		setPenSize(1);
	}
	show();
	penUp();
	for(int i=1;i<=180;i++){
		fd(200);
		penDown();
		drawPoint(getX(),getY());
		if(game==1){
			penUp();
		}
		rt(60);	
		fd(200);
		rt(60);
		fd(200);
		rt(60);
		fd(200);
		rt(60);
		fd(200);
		rt(60);
		fd(200);
		rt(178);
	}
}
inline void rainbow(double line=500,double x=getX(),double y=getY(),double size=40){
	Color a[7]={RED,ORANGE,YELLOW,GREEN,CYAN,BLUE,PURPLE};
	for(int i=0;i<=6;i++){
		setPenSize(size);
		setPenColor(a[i]);
		penUp();
		setX(x-size*i);
		penDown();
		arc(line,180);
		line=line-size;
		rt(180);
	}
}
typedef struct Z{//ai+b
	int a;
	int b;
}Z;
typedef struct sound{
	unsigned long s;
	double l;
}sound;
#define l1  CLITERAL(sound){262,500}
#define l2  CLITERAL(sound){294,500}
#define l3  CLITERAL(sound){330,500}
#define l4  CLITERAL(sound){349,500}
#define l5  CLITERAL(sound){392,500}
#define l6  CLITERAL(sound){440,500}
#define l7  CLITERAL(sound){498,500}

#define n1  CLITERAL(sound){532,500}
#define n2  CLITERAL(sound){588,500}
#define n3  CLITERAL(sound){660,500}
#define n4  CLITERAL(sound){698,500}
#define n5  CLITERAL(sound){784,500}
#define n6  CLITERAL(sound){880,500}
#define n7  CLITERAL(sound){998,500}

#define h1  CLITERAL(sound){1046,500}
#define h2  CLITERAL(sound){1175,500}
#define h3  CLITERAL(sound){1319,500}
#define h4  CLITERAL(sound){1397,500}
#define h5  CLITERAL(sound){1568,500}
#define h6  CLITERAL(sound){1760,500}
#define h7  CLITERAL(sound){1976,500}
inline void play(sound a){
	Beep(a.s,a.l);
}
template<class T>
	class tree{
		public:
			struct tree_node{
				T num;//存的值
				list<tree_node*>child;//子节点
				tree_node*father;//父节点
			};
			tree_node trunk;//根节点
			tree_node*find(T x){//查找
				if(x==trunk.num){
					return &x;
				}else{
					return dfs(trunk,x);
				}
			}
			inline void push(T nuum,tree_node*fatherr){//加入
				list<tree_node*>_;
				tree_node numm;
				numm.child=_;
				numm.num=nuum;
				numm.father=fatherr;
				fatherr->child.push_back(&numm);
			}
			inline void init(T key){
				list<tree_node*>_;
				trunk={key,_,NULL};
			}
		private:
			inline tree_node*dfs(tree_node*x,T y){
				if(x->child.empty()){
					return NULL;
				}
				if(x.num==y){
					return x;
				}
				else{
					for(int i=0;i<x.child.size();i++){
						if(dfs(x.child.front(),y)!=NULL){
							return dfs(x.child.front());
						}
						x.child.push_back(x.child.front());
						x.child.pop_front();
					}
					return NULL;
				}
			}
	};

二、每段分析

①、 头文件

#include<rturtle.h>//非C++自带
#include<utilapiset.h>
#include<conio.h>
#include<bits/stdc++.h>
#include<ctime>

②、函数

1、circle()函数

void circle(double a){
	arc(a,360);
}

2、get_help()函数

inline void get_help(){
	system("start https://http://t.csdn.cn/HfXXZ/");
}

3、Prime()函数

bool Prime(int x){
	if(x<=1){
		return false;
	}else{
		for(int i=2;i*i<=x;i++){
			if(x%i==0){
				return false;
			}
		}
		return true;
	}
}

4、random()函数

inline int random(int left,int right){
	if(left>right){
		return 0;
	}
	return time(0)%(right-left+1)+left;
}

5、star()函数

inline void star(double line=400,double size=5,double x=0,double y=0,bool tutrle=true){
	Color a[5]={RED,ORANGE,PURPLE,BLUE,GREEN};
	setPenColor(RED);
	if(tutrle==false){
		hide();	
	}
	penUp();
	setPenSize(size);
	setXY(x+(line*sin(18)/2),y-(line*cos(18))/2);
	penDown();
	setAngle(72);
	fd(line);
	for(int i=1;i<=4;i++){
		setPenColor(a[i]);
		rt(144);
		fd(line);
	}
	penUp();
}

 6、tutrle_draw()函数

inline void tutrle_draw(bool game=0){//无聊的小游戏
	if(game==0){
		setPenSize(1);
	}
	show();
	penUp();
	for(int i=1;i<=180;i++){
		fd(200);
		penDown();
		drawPoint(getX(),getY());
		if(game==1){
			penUp();
		}
		rt(60);	
		fd(200);
		rt(60);
		fd(200);
		rt(60);
		fd(200);
		rt(60);
		fd(200);
		rt(60);
		fd(200);
		rt(178);
	}
}

7、rinbow()函数

inline void rainbow(double line=500,double x=getX(),double y=getY(),double size=40){
	Color a[7]={RED,ORANGE,YELLOW,GREEN,CYAN,BLUE,PURPLE};
	for(int i=0;i<=6;i++){
		setPenSize(size);
		setPenColor(a[i]);
		penUp();
		setX(x-size*i);
		penDown();
		arc(line,180);
		line=line-size;
		rt(180);
	}
}

8、快读

inline int int_read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-'){
			f=-1;
		}
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-48;
		ch=getchar();
	}
	return x*f;
}
inline string string_read(){
	string x="";
	char ch=getchar();
	x=x+ch;
	while(ch!=' '&&ch!='\n'){
		ch=getchar();
		x=x+ch;
	}
	return x;
}
inline char char_read(){
	return getchar();
}

inline double double_read(){
	int x=0,f=1;
	double y=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-'){
			f=-1;
		}
		ch=getchar();
	}
	while((ch>='0'&&ch<='9')||ch=='.'){
		if(ch>='0'&&ch<='9'){
			x=x*10+(ch-48);
		}else{
			break;
		}
		ch=getchar();
	}
	ch=getchar();
	while(ch>='0'&&ch<='9'){
		y=y*10+ch-48*1.0;
		ch=getchar();
	}
	while(y>1){
		y=y/10;
	}
	return (x+y)*f;
}

③、其他

1、sound

typedef struct sound{
	unsigned long s;
	double l;
}sound;
#define l1  CLITERAL(sound){262,500}
#define l2  CLITERAL(sound){294,500}
#define l3  CLITERAL(sound){330,500}
#define l4  CLITERAL(sound){349,500}
#define l5  CLITERAL(sound){392,500}
#define l6  CLITERAL(sound){440,500}
#define l7  CLITERAL(sound){498,500}

#define n1  CLITERAL(sound){532,500}
#define n2  CLITERAL(sound){588,500}
#define n3  CLITERAL(sound){660,500}
#define n4  CLITERAL(sound){698,500}
#define n5  CLITERAL(sound){784,500}
#define n6  CLITERAL(sound){880,500}
#define n7  CLITERAL(sound){998,500}

#define h1  CLITERAL(sound){1046,500}
#define h2  CLITERAL(sound){1175,500}
#define h3  CLITERAL(sound){1319,500}
#define h4  CLITERAL(sound){1397,500}
#define h5  CLITERAL(sound){1568,500}
#define h6  CLITERAL(sound){1760,500}
#define h7  CLITERAL(sound){1976,500}
void play(sound a){
	Beep(a.s,a.l);
}

注意:该部分参考洛谷博客

2、tree

没文化的去这里

template<class T>
	class tree{
		public:
			struct tree_node{
				T num;//存的值
				list<tree_node*>child;//子节点
				tree_node*father;//父节点
			};
			tree_node trunk;//根节点
			tree_node*find(T x){//查找
				if(x==trunk.num){
					return &x;
				}else{
					return dfs(trunk,x);
				}
			}
			inline void push(T nuum,tree_node*fatherr){//加入
				list<tree_node*>_;
				tree_node numm;
				numm.child=_;
				numm.num=nuum;
				numm.father=fatherr;
				fatherr->child.push_back(&numm);
			}
			inline void init(T key){
				list<tree_node*>_;
				trunk={key,_,NULL};
			}
		private:
			inline tree_node*dfs(tree_node*x,T y){
				if(x->child.empty()){
					return NULL;
				}
				if(x.num==y){
					return x;
				}
				else{
					for(int i=0;i<x.child.size();i++){
						if(dfs(x.child.front(),y)!=NULL){
							return dfs(x.child.front());
						}
						x.child.push_back(x.child.front());
						x.child.pop_front();
					}
					return NULL;
				}
			}
	};

三、安装及其使用

①、安装

点立即下载并且打开

 

 全选后复制

打开你的编译器(我用的是小熊猫C++),找到文件夹,搜索include

 随便点一个(只要是叫include的都行)

按右键粘贴,然使用后无论如何一直点继续 

 最后就可以开始使用啦

②、使用

打开编译器,新建一个cpp文件

注意事项

如果编译时报错,需在工具-->编译选项-->编译时加入一下命令:插入代码    -std=c++14(我就没报错)

 

 如果还不行,请将代码中的

#pragma GCC optimize(2,3,"Ofast","inline")

删去,参考手动开上O2优化(c++) 和openwrt GCC 编译错误:error: #pragma GCC diagnostic not allowed inside functions

画五角星☆

#include<game.h>//引用这个库
using namespace std;
int main(){
	initWorld(1000,1000);//创建一个世界
	star();//调用
	waitClick();//等待按鼠标
	closeWorld();//关闭世界
	return 0;
}

运行结果:

画圆○

#include<game.h>//引用这个库
using namespace std;
int main(){
	initWorld(1000,1000);//创建一个世界
	setSpeed(1000);
	circle(200);//调用
	waitClick();//等待按鼠标
	closeWorld();//关闭世界
	return 0;
}

运行结果:

画彩虹

#include<game.h>//引用这个库
using namespace std;
int main(){
	initWorld(1000,1000);//创建一个世界
	setSpeed(1000);
	rainbow();//调用
	waitClick();//等待按鼠标
	closeWorld();//关闭世界
	return 0;
}

运行结果:

快读函数

#include<game.h>//引用这个库
using namespace std;
int main(){
	int a;
	a=int_read();//调用
	cout<<a;
	return 0;
}

运行结果:

#include<game.h>//引用这个库
using namespace std;
int main(){
	double a;
	a=double_read();//调用
	cout<<a;
	return 0;
}

 运行结果:

#include<game.h>//引用这个库
using namespace std;
int main(){
	char a;
	a=char_read();//调用
	cout<<a;
	return 0;
}

运行结果:

#include<game.h>//引用这个库
using namespace std;
int main(){
	string a;
	a=string_read();//调用
	cout<<a;
	return 0;
}

 运行结果:

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值