C++游戏编程之模拟实现键盘打字程序

程序演示:

程序代码:

#include<graphics.h>
#include<iostream>
#include<conio.h>
#include<time.h>
using namespace std;

class KeyBoard
{
public:
	KeyBoard();
	~KeyBoard();
	int randomKeys();//产生1~26的随机值
	void showBoard();//画键盘
	void showText();//显示键值
	void acceptAction();//获取响应
private:
	int randomKey;//随机值
	int Struct;//支撑体
	int keySize;//键块大小
	int x1, y1;//第一行的第一个键块左上角坐标
	int x2, y2;//第二行的第一个键块左上角坐标
	int x3, y3;//第三行的第一个键块左上角坐标
};

KeyBoard::KeyBoard()
{
	Struct = 10;
	keySize = 50;
	x1 = 50, y1 = 50;
	x2 = 70, y2 = 110;
	x3 = 90, y3 = 170;
	initgraph(1000, 400);
	showBoard();
	_getch();
}

KeyBoard::~KeyBoard()
{

}

void KeyBoard::showText()
{
	settextcolor(WHITE);
	TCHAR firstRowKeys[100] = _T("Q     W     E     R     T     Y     U     I     O     P");//定义字符数组
	settextstyle(20, 0, _T("楷体"));
	outtextxy(65, 60, firstRowKeys);
	TCHAR secondRowKeys[100] = _T("A     S     D     F     G     H     J     K     L");//定义字符数组
	settextstyle(20, 0, _T("楷体"));
	outtextxy(85, 125, secondRowKeys);
	TCHAR thirdRowKeys[100] = _T("Z     X     C     V     B     N     M");//定义字符数组
	settextstyle(20, 0, _T("楷体"));
	outtextxy(105, 190, thirdRowKeys);
}

void KeyBoard::showBoard()
{
	int tx1 = x1,tx2 = x2,tx3 = x3;
	showText();
	for (int i = 0; i < 10; i++)
	{
		rectangle(x1, y1, x1 + keySize, y1 + keySize);
		x1 = x1 + keySize + Struct;
	}
	x1 = tx1;
	for (int i = 0; i < 9; i++)
	{
		rectangle(x2, y2, x2 + keySize, y2 + keySize);
		x2 = x2 + keySize + Struct;
	}
	x2 = tx2;
	for (int i = 0; i < 7; i++)
	{
		rectangle(x3, y3, x3 + keySize, y3 + keySize);
		x3 = x3 + keySize + Struct;
	}
	x3 = tx3;
}

int KeyBoard::randomKeys()
{
	srand((unsigned)time(NULL));
	randomKey = rand() % 26 + 1;//1到26
	return randomKey;
}

void KeyBoard::acceptAction()
{
	int tx1 = x1, tx2 = x2, tx3 = x3;
	int flag = randomKeys();
	char input;
	switch (flag)
	{
	case 1:
		setlinecolor(GREEN);
		rectangle(x1, y1, x1 + keySize, y1 + keySize);
		input = _getch();
		if (input == 'Q' || input == 'q')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x1, y1, x1 + keySize, y1 + keySize);
				input = _getch();
				if (input == 'Q' || input == 'q')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		break;
	case 2:
		setlinecolor(GREEN);
		x1 = x1 + keySize + Struct;
		rectangle(x1, y1, x1 + keySize, y1 + keySize);
		input = _getch();
		if (input == 'W' || input == 'w')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x1, y1, x1 + keySize, y1 + keySize);
				input = _getch();
				if (input == 'W' || input == 'w')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x1 = tx1;
		break;
	case 3:
		setlinecolor(GREEN);
		x1 = x1 + 2 * (keySize + Struct);
		rectangle(x1, y1, x1 + keySize, y1 + keySize);
		input = _getch();
		if (input == 'E' || input == 'e')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x1, y1, x1 + keySize, y1 + keySize);
				input = _getch();
				if (input == 'E' || input == 'e')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x1 = tx1;
		break;
	case 4:
		setlinecolor(GREEN);
		x1 = x1 + 3 * (keySize + Struct);
		rectangle(x1, y1, x1 + keySize, y1 + keySize);
		input = _getch();
		if (input == 'R' || input == 'r')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x1, y1, x1 + keySize, y1 + keySize);
				input = _getch();
				if (input == 'R' || input == 'r')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x1 = tx1;
		break;
	case 5:
		setlinecolor(GREEN);
		x1 = x1 + 4 * (keySize + Struct);
		rectangle(x1, y1, x1 + keySize, y1 + keySize);
		input = _getch();
		if (input == 'T' || input == 't')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x1, y1, x1 + keySize, y1 + keySize);
				input = _getch();
				if (input == 'T' || input == 't')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x1 = tx1;
		break;
	case 6:
		setlinecolor(GREEN);
		x1 = x1 + 5 * (keySize + Struct);
		rectangle(x1, y1, x1 + keySize, y1 + keySize);
		input = _getch();
		if (input == 'Y' || input == 'y')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x1, y1, x1 + keySize, y1 + keySize);
				input = _getch();
				if (input == 'Y' || input == 'y')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x1 = tx1;
		break;
	case 7:
		setlinecolor(GREEN);
		x1 = x1 + 6 * (keySize + Struct);
		rectangle(x1, y1, x1 + keySize, y1 + keySize);
		input = _getch();
		if (input == 'U' || input == 'u')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x1, y1, x1 + keySize, y1 + keySize);
				input = _getch();
				if (input == 'U' || input == 'u')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x1 = tx1;
		break;
	case 8:
		setlinecolor(GREEN);
		x1 = x1 + 7 * (keySize + Struct);
		rectangle(x1, y1, x1 + keySize, y1 + keySize);
		input = _getch();
		if (input == 'I' || input == 'i')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x1, y1, x1 + keySize, y1 + keySize);
				input = _getch();
				if (input == 'I' || input == 'i')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x1 = tx1;
		break;
	case 9:
		setlinecolor(GREEN);
		x1 = x1 + 8 * (keySize + Struct);
		rectangle(x1, y1, x1 + keySize, y1 + keySize);
		input = _getch();
		if (input == 'O' || input == 'o')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x1, y1, x1 + keySize, y1 + keySize);
				input = _getch();
				if (input == 'O' || input == 'o')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x1 = tx1;
		break;
	case 10:
		setlinecolor(GREEN);
		x1 = x1 + 9 * (keySize + Struct);
		rectangle(x1, y1, x1 + keySize, y1 + keySize);
		input = _getch();
		if (input == 'P' || input == 'p')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x1, y1, x1 + keySize, y1 + keySize);
				input = _getch();
				if (input == 'P' || input == 'p')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x1 = tx1;
		break;
	case 11:
		setlinecolor(GREEN);
		rectangle(x2, y2, x2 + keySize, y2 + keySize);
		input = _getch();
		if (input == 'A' || input == 'a')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x2, y2, x2 + keySize, y2 + keySize);
				input = _getch();
				if (input == 'A' || input == 'a')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x2 = tx2;
		break;
	case 12:
		setlinecolor(GREEN);
		x2 = x2 + keySize + Struct;
		rectangle(x2, y2, x2 + keySize, y2 + keySize);
		input = _getch();
		if (input == 'S' || input == 's')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x2, y2, x2 + keySize, y2 + keySize);
				input = _getch();
				if (input == 'S' || input == 's')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x2 = tx2;
		break;
	case 13:
		setlinecolor(GREEN);
		x2 = x2 + 2 * (keySize + Struct);
		rectangle(x2, y2, x2 + keySize, y2 + keySize);
		input = _getch();
		if (input == 'D' || input == 'd')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x2, y2, x2 + keySize, y2 + keySize);
				input = _getch();
				if (input == 'D' || input == 'd')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x2 = tx2;
		break;
	case 14:
		setlinecolor(GREEN);
		x2 = x2 + 3 * (keySize + Struct);
		rectangle(x2, y2, x2 + keySize, y2 + keySize);
		input = _getch();
		if (input == 'F' || input == 'f')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x2, y2, x2 + keySize, y2 + keySize);
				input = _getch();
				if (input == 'F' || input == 'f')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x2 = tx2;
		break;
	case 15:
		setlinecolor(GREEN);
		x2 = x2 + 4 * (keySize + Struct);
		rectangle(x2, y2, x2 + keySize, y2 + keySize);
		input = _getch();
		if (input == 'G' || input == 'g')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x2, y2, x2 + keySize, y2 + keySize);
				input = _getch();
				if (input == 'G' || input == 'g')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x2 = tx2;
		break;
	case 16:
		setlinecolor(GREEN);
		x2 = x2 + 5 * (keySize + Struct);
		rectangle(x2, y2, x2 + keySize, y2 + keySize);
		input = _getch();
		if (input == 'H' || input == 'h')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x2, y2, x2 + keySize, y2 + keySize);
				input = _getch();
				if (input == 'H' || input == 'h')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x2 = tx2;
		break;
	case 17:
		setlinecolor(GREEN);
		x2 = x2 + 6 * (keySize + Struct);
		rectangle(x2, y2, x2 + keySize, y2 + keySize);
		input = _getch();
		if (input == 'J' || input == 'j')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x2, y2, x2 + keySize, y2 + keySize);
				input = _getch();
				if (input == 'J' || input == 'j')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x2 = tx2;
		break;
	case 18:
		setlinecolor(GREEN);
		x2 = x2 + 7 * (keySize + Struct);
		rectangle(x2, y2, x2 + keySize, y2 + keySize);
		input = _getch();
		if (input == 'K' || input == 'k')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x2, y2, x2 + keySize, y2 + keySize);
				input = _getch();
				if (input == 'K' || input == 'k')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x2 = tx2;
		break;
	case 19:
		setlinecolor(GREEN);
		x2 = x2 + 8 * (keySize + Struct);
		rectangle(x2, y2, x2 + keySize, y2 + keySize);
		input = _getch();
		if (input == 'L' || input == 'l')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x2, y2, x2 + keySize, y2 + keySize);
				input = _getch();
				if (input == 'L' || input == 'l')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x2 = tx2;
		break;
	case 20:
		setlinecolor(GREEN);
		rectangle(x3, y3, x3 + keySize, y3 + keySize);
		input = _getch();
		if (input == 'Z' || input == 'z')
		{
			setlinecolor(WHITE);
		}
		else
		{
			rectangle(x3, y3, x3 + keySize, y3 + keySize);
			input = _getch();
			if (input == 'Z' || input == 'z')
			{
				setlinecolor(WHITE);
				break;
			}
		}
		x3 = tx3;
		break;
	case 21:
		setlinecolor(GREEN);
		x3 = x3 + keySize + Struct;
		rectangle(x3, y3, x3 + keySize, y3 + keySize);
		input = _getch();
		if (input == 'X' || input == 'x')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x3, y3, x3 + keySize, y3 + keySize);
				input = _getch();
				if (input == 'X' || input == 'x')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x3 = tx3;
		break;
	case 22:
		setlinecolor(GREEN);
		x3 = x3 + 2 * (keySize + Struct);
		rectangle(x3, y3, x3 + keySize, y3 + keySize);
		input = _getch();
		if (input == 'C' || input == 'c')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x3, y3, x3 + keySize, y3 + keySize);
				input = _getch();
				if (input == 'C' || input == 'c')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x3 = tx3;
		break;
	case 23:
		setlinecolor(GREEN);
		x3 = x3 + 3 * (keySize + Struct);
		rectangle(x3, y3, x3 + keySize, y3 + keySize);
		input = _getch();
		if (input == 'V' || input == 'v')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x3, y3, x3 + keySize, y3 + keySize);
				input = _getch();
				if (input == 'V' || input == 'v')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x3 = tx3;
		break;
	case 24:
		setlinecolor(GREEN);
		x3 = x3 + 4 * (keySize + Struct);
		rectangle(x3, y3, x3 + keySize, y3 + keySize);
		input = _getch();
		if (input == 'B' || input == 'b')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x3, y3, x3 + keySize, y3 + keySize);
				input = _getch();
				if (input == 'B' || input == 'b')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x3 = tx3;
		break;
	case 25:
		setlinecolor(GREEN);
		x3 = x3 + 5 * (keySize + Struct);
		rectangle(x3, y3, x3 + keySize, y3 + keySize);
		input = _getch();
		if (input == 'N' || input == 'n')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x3, y3, x3 + keySize, y3 + keySize);
				input = _getch();
				if (input == 'N' || input == 'n')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x3 = tx3;
		break;
	case 26:
		setlinecolor(GREEN);
		x3 = x3 + 6 * (keySize + Struct);
		rectangle(x3, y3, x3 + keySize, y3 + keySize);
		input = _getch();
		if (input == 'M' || input == 'm')
		{
			setlinecolor(WHITE);
		}
		else
		{
			while (1)
			{
				rectangle(x3, y3, x3 + keySize, y3 + keySize);
				input = _getch();
				if (input == 'M' || input == 'm')
				{
					setlinecolor(WHITE);
					break;
				}
			}
		}
		x3 = tx3;
		break;
	}
}

int main()
{
	KeyBoard KB;
	while (1)
	{
		KB.showBoard();
		KB.acceptAction();
	}

	return 0;
}

以上就是C++游戏编程之模拟实现键盘打字程序的详细内容,更多关于C++模拟键盘打字的资料请关注我们其它相关文章!

(0)

相关推荐

  • c++调用windows键盘代码详情

    目录 1.何为windows键盘 2.如何调用这些windows键盘 3.巨(wei)硬(ruan)搞事情 4.具体代码 1.何为windows键盘 windows管这个长得有点儿丑的叫屏幕键盘 windows管这个长得好看的叫触摸键盘 当然上面的截图是win10的键盘效果,在win7上是有一些差别的,这里就不截图放出来了 2.如何调用这些windows键盘 似乎很简单,我们用Spy++抓下窗口,找到窗口句柄所关联的进程句柄,再查看下是哪个进程以及命令行信息,然后我们就可以愉快地执行命令调用进程

  • C++模拟键盘按键的实例

    这个与模拟鼠标点击的函数差不多,直接上函数 keybd_event(VK_RETURN,0,0,0); keybd_event(VK_RETURN,0,KEYEVENTF_KEYUP,0); 这是模拟按下.抬起回车键 我直接上一个我曾经用它与一些函数写的一个刷屏程序 我用自己的小号试过,如果对方用的是手机,效果很显著 #include<iostream> #include<windows.h> using namespace std; int b[11000],top=0; cha

  • C++键盘记录程序代码

    本文实例讲述了C++键盘记录程序.分享给大家供大家参考.具体分析如下: 主程序如下: 就是基于对话框的框架,加个个OnHookKey函数, 复制代码 代码如下: long CMainDialog::OnHookKey(WPARAM wParam, LPARAM lParam)   //处理自定义消息  {      char szKey[80]={0};      GetKeyNameText(lParam, szKey, 80);      CString strItem;      strI

  • 浅谈C++的几种从键盘输入方式

    我们都知道,C++可以从键盘来读取输入,读取输入的方式也有好多种,下面我们来介绍常见的几种方式 和他们的不同之处 1.cin 使用cin输入时,程序将输入视为一系列字节.每个字节都被解释为字符编码.不管数据类型是什么,输入一开始都是字符数据,然后cin对象负责将数据转换成其他类型 例如 string name; std::cin>>name; std::cout<<name; 当你输入Michael Jackon时,通运行程序你会发现name只存储了Michael,这是为什么呢?

  • C++处理键盘输入的方法

    本文实例讲述了C++处理键盘输入的方法,可实现简单处理键盘输入,分享给大家供大家参考.具体实现方法如下: 需要响应WM_CHAR消息: 复制代码 代码如下: #include <string> static std::string str; 在wm_char中: 复制代码 代码如下: str = str + char(wParam);  ::InvalidateRect(hWnd, NULL, 0);  return 0; 在wm_paint中: 复制代码 代码如下: case WM_PAIN

  • C++检测键盘某键是否按下的方法

    检测键盘与鼠标差不多,但是它比较好记 但是比较奇怪,比如你想要检测字母,必须是它的大写 具体的就参照虚拟键盘值表,上百度可以查到 为了能更清楚地表达,我编了个小程序 #include<iostream> #include<windows.h> #define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) //必要的,我是背下来的 using namespace std; void col

  • C/C++获取键盘事件的方法

    在vs中可以使用_kbhit()函数来获取键盘事件,使用时需要加入conio.h头文件,例: #include <conio.h> #include <iostream> using namespace std; int main() { int ch; while (1){ if (_kbhit()){//如果有按键按下,则_kbhit()函数返回真 ch = _getch();//使用_getch()函数获取按下的键值 cout << ch; if (ch == 2

  • C++游戏编程之模拟实现键盘打字程序

    程序演示: 程序代码: #include<graphics.h> #include<iostream> #include<conio.h> #include<time.h> using namespace std; class KeyBoard { public: KeyBoard(); ~KeyBoard(); int randomKeys();//产生1~26的随机值 void showBoard();//画键盘 void showText();//显示

  • JavaScript模拟实现键盘打字效果

    $(function () { var input_type = { init:function ($obj) { this.name = $obj.html().split("") this.length = this.name.length; this.i = 0; }, pri:function () { var $this = this //在此处只能使用闭包,因为windown.settimeout使函数的this指向object windown,而非原型链的this对象.而

  • JS模拟键盘打字效果的方法

    本文实例讲述了JS模拟键盘打字效果的方法.分享给大家供大家参考.具体如下: 这里使用JS模拟实现软键盘及打字效果,点击软键盘年的字母键,文本框中即可显示文字,像是键盘打字的效果,美工不太好,没怎么美化,CSS高手可美化一下按钮,看上去还挺不错吧,我觉得. 先来看看运行效果图: 具体代码如下: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb23

  • python之模拟鼠标键盘动作具体实现

    上个月就打算开发个还算好玩的项目,但是一直没时间.这篇是此项目用到的一部分, 处理好此部分基本还差通信等方面的了.首先模拟鼠标键盘按下释放的动作,本人利用X11 这个库,所以要了解X11编程;其次,本身用c或者c++就可以实现了,但是由于本人是py 粉,所以总想把代码搬进python,所以本人就要实现python模块,本篇用的ctypes,以后会 把python的c扩展模块附上来的. 1.X11编程 首先简单的介绍一下X11吧,网上有介绍,本人就不重复了.我们知道X是以server与client

  • Python外星人入侵游戏编程完整版

    PYTHON游戏编程外星人入侵的完整实现思路,具体内容如下 准备工作:下载python,比如Anaconda3(64 bit),导入pygame游戏包 1.外星人设置,alien.py,代码: import pygame from pygame.sprite import Sprite class Alien(Sprite): """表示单个外星人的类""" def __init__(self,ai_settings,screen): "

  • python儿童学游戏编程知识点总结

    python爬虫基本告一段落,琢磨搞点其他的,正好在网上看到一个帖子,一个外国13岁小朋友用python写的下棋程序,内容详细,也有意思,拿来练手. 13岁啊.. 我这年纪还在敲 dir啥的吧 想到原先玩跑跑卡丁车时看到欧酷有个4岁熊孩子玩的完美漂移录像,深受打击,从此退出车坛... 废话不多说,记录一下这几天的游戏编程折腾史 游戏规则:6*6的方格棋盘,两个人轮流点击棋盘画横线或竖线,谁成功围成一个格子,这个格子算作此人的积分. 游戏架构:客户端和服务端. 先来看下游戏准备工作,需要用到pyg

  • python PyAutoGUI 模拟鼠标键盘操作和截屏功能

    简介 一款跨平台/无依赖的自动化测试工具,目测只能控制鼠标/键盘/获取屏幕尺寸/弹出消息框/截屏. 安装 pip install pyautogui 鼠标键盘控制 >>> import pyautogui >>> screenWidth, screenHeight = pyautogui.size() >>> currentMouseX, currentMouseY = pyautogui.position() >>> pyautog

  • Java实现鼠标模拟与键盘映射

    本文实例为大家分享了Java实现鼠标模拟与键盘映射的具体代码,供大家参考,具体内容如下 关键字: java 鼠标模拟 键盘映射 Java SDK 1.3以后实现了Robot类.此类用于为测试自动化.自运行演示程序和其他需要控制鼠标和键盘的应用程序生成本机系统输入事件.Robot 的主要目的是便于 Java 平台实现自动测试. 使用该类生成输入事件与将事件发送到 AWT 事件队列或 AWT 组件的区别在于:事件是在平台的本机输入队列中生成的.例如,Robot.mouseMove 将实际移动鼠标光标

  • Python模拟钢琴键盘实现演奏数鸭子歌曲

    目录 前言 winsound模块 keyboard模块 源代码 运行结果 前言 前几天上课老师给我们讲了两个模块,然后利用这两个模块来模拟钢琴键盘去简单地演奏<数鸭子>今天来分享给大家. 模块1:winsound 模块2:keyboard winsound模块 winsound模块提供对windows平台的基本声音播放功能的访问,他还包含函数和一些常量. 1.安装winsound模块 在cmd窗口下输入 pip install winsound 2.导入模块 import winsound 3

  • JavaScript面向对象编程实现模拟

    目录 前言 1. 构造函数 2. new的过程 2.1 基础使用 2.2 new.target 3. 手动实现一个构造函数 前言 每个对象都是一个功能中心,具有明确分工,可以处理信息,处理信息,发出信息.面向对象编程具有灵活性.可复用性.模块化等好处,适合更多合作完成的大型项目. 1. 构造函数 构造函数的功能是生成对象,生成具有相同结构对象的函数.Java语言通过类实现面向对象,对象是类的实例,而Javascript则是通过构造函数作为对象的模板,使用prototype实现继承. 构造函数的几

随机推荐