【Yuexingfei_qwq的原创游戏】
好的其实标题里的Yuexingfei_qwq指的是我。
不定时持续更新ing……
有bug及时回复或私信我哈……
本文同步发表在以下Blog:
洛谷:https://www.luogu.com.cn/article/a0nqm3my(看不到的话可以看https://www.luogu.me/article/a0nqm3my,记得每次点进去的时候都按一下“更新文章内容”按键)
CSDN:https://blog.csdn.net/yuexingfei_111/article/details/146573222?spm=1011.2415.3001.5331
博客园:https://www.cnblogs.com/yxf2013/p/18797025
“.h”文件(自编头文件)
game_1.h(常用游戏函数):
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <cmath>
#include <windows.h>
#include <algorithm>
#include <conio.h>
#include <math.h>
#define _cl system("cls")
#define _pa system("pause")
#define _sl(x) Sleep(x)
#define _PI 3.1415926535897932384626
#define _ge getch()
#define _Get(x) GetAsyncKeyState('x')
#define _KE(x) ((GetAsyncKeyState(x) & 0x8000) ? 1:0)
#define _sr srand(time(NULL))
#define _ra(a, b) (rand() % (b - a + 1)) + a
using namespace std;
typedef long long ll;
typedef string str;
using ull = unsigned long long;
inline ll x_y(ll x, ll y, ll p = (1LL << 60)) {//x的y次方模p
int ans_1 = 1;
while (y) {
if (y & 1) {
(ans_1 *= x) %= p;
}
(x *= x) %= p;
y >>= 1;
}
return ans_1;
}
inline void Sleep_write(const string &s, const int &y = 10, const string &t = "cout") {//逐字输出
for (auto i : s) {
if (t == "cin") {
cout << i;
} else {
putchar(i);
}
_sl(y);
}
}
inline void setcolor(int color) {//设置颜色
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, color);
}
inline void wait(int d = 100) {
_sl(d);
_ge;
}
inline char get(str s) {
char ch[114514];
int l = 0;
for (auto i : s) {
ch[++l] = i;
}
while (true) {
char x = getchar();
for (int i = 1; i <= l; i++) {
if (x == ch[i]) {
return x;
}
}
Sleep_write("Error:输入无效\n");
_sl(2000);
_pa;
}
}
抽奖
#include <bits/stdc++.h>
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <cmath>
#include <windows.h>
#include <cstdlib>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#include <conio.h>
#include <string>
#include <string.h>
#include <math.h>
#define w(x) while(x)
#define cl system("cls")
#define Sl(x) Sleep(x)
#define f(i, a, b) for (int i = a; i <= b; i++)
using namespace std;
int a[10][10], money = 20, h1, h2;
void init() {
srand(time(0));
f(i, 1, 3) {
f(j, 1, 3) {
a[i][j] = rand() % 10 + 1;
}
}
}
void start() {
puts("来抽奖吧!!!");
puts("yuexingfei出品,必属精品!");
puts("请按任意键开始游戏...");
getch();
cl;
puts ("Loading......");
Sl(2000);
cl;
}
void out() {
cl;
int r = rand() % 3 + 1, l = rand() % 3 + 1;
h1 = r, h2 = l;
f(i, 1, 3) {
f(j, 1, 3) {
if (i == r && j == l) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
} else {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
}
printf ("%d", a[i][j]);
if (j != 3) {
printf ("\t");
}
}
printf ("\n");
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
}
int main() {
init();
start();
w(1) {
cl;
if (money < 4) {
puts("你的钱不够抽了!");
break;
}
printf ("你现在有%d元,抽一次奖4元。\n请问本次你要旋转几次?(输入123456789重置转盘)\n", money);
int x;
scanf ("%d", &x);
if (x == 123456789) {
init();
} else {
for (int i = 1; i <= x; i++) {
out();
int t;
if (i == x) {
t = 3000;
} else {
if (i == x - 1) {
t = 2000;
} else {
if (i == x - 2) {
t = 1000;
} else {
if (i == x - 3) {
t = 500;
} else {
t = 10;
}
}
}
}
Sl(t);
}
money = money - 4 + a[h1][h2];
printf ("恭喜获得了%d元!\n", a[h1][h2]);
Sl(2500);
}
}
return 0;
}
躲避铁砧
#include <bits/stdc++.h>
#include <iostream>
#include <windows.h>
#include <cmath>
#include <stdlib.h>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <time.h>
using namespace std;
int r = -1, b = -1, rf = 3, bf = 3;
int n, m;
int a[10];
void init() {
memset(a, 0, sizeof(a));
}
void out() {
system ("cls");
printf ("地图 : \n*******************\n");
for (int i = 0; i < 10; i++) {
if (a[i] == 0) {
if (i == r) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
printf ("i ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
} else {
if (i == b) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
printf ("i ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
} else {
printf ("/ ");
}
}
} else {
if (a[i] == 1) {
if (i == r) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
printf ("* ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
rf--;
}
if (i == b) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
printf ("* ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
bf--;
}
if (i != b && i != r) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
printf ("# ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
}
}
}
}
printf ("\n*******************\n");
printf ("红生命 : %d\n蓝生命 : %d\n", rf, bf);
}//"#" : 有铁砧但没人; "*" : 有铁砧且有人; "/" : 空; "i" : 人 (对应颜色)
void ran() {
n = rand() % 5 + 1;
printf ("落下%d个铁砧\n", n);
for (int i = 1; i <= n; i++) {
while (a[m] != 0) {
m = rand() % 10;
}
a[m] = 1;
}
}
int main() {
srand(time(0));
init();
while (1) {
out();
printf ("红方选择位置(1~10) : \n");
scanf ("%d", &r);
r--;
printf ("蓝方选择位置(1~10) : \n");
scanf ("%d", &b);
b--;
out();
printf ("ran...\n");
Sleep(1000);
ran();
Sleep(1000);
out();
Sleep(2500);
init();
if (a[r] == 1)
rf--;
if (a[b] == 1)
bf--;
if (rf == 0 || bf == 0)
break;
}
if (rf > bf)
printf ("红赢了!\n");
if (rf < bf)
printf ("蓝赢了!\n");
if (rf == bf)
printf ("平局!\n");
return 0;
}
MC党福利
起床战争
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
#include<time.h>
char a[50][50] = {"OOOOOOOOOOOOOOOOOOOO",
"OA O",
"O H O O",
"O OOOOO O",
"O O R O",
"O WO",
"OOOOOOOOOOOOOOOOOOOO",
};
struct Player {
int shengming, gongji, fangyu;
};
Player P1, P2;
bool Aw = true, Ww = true;
int x = 2, y = 2, p = 4, q = 17, n = 1, m = 1, c = 5, b = 18, sx = 30, sy = 30, gx = 30, gy = 30, fx = 30, fy = 30;
void out() {
system("cls");
for (int i = 0; i <= 7; i++) {
for (int j = 0; j <= 20; j++) {
printf ("%c", a[i][j]);
}
switch (i) {
case 0:
printf (" H:玩家1(WASD移动)");
break;
case 1:
printf (" A:H的床");
break;
case 2:
printf (" R:玩家2(IJKL移动)");
break;
case 3:
printf (" W:R的床");
break;
case 4:
printf (" O:墙壁");
break;
case 5:
printf (" N:增加攻击");
break;
case 6:
printf (" F:增加防御");
break;
case 7:
printf (" S:增加生命");
break;
}
printf ("\n");
}
printf ("H:\n生命:%d\n攻击:%d\n防御:%d\n\n", P1.shengming, P1.gongji, P1.fangyu);
printf ("R:\n生命:%d\n攻击:%d\n防御:%d\n\n", P2.shengming, P2.gongji, P2.fangyu);
if (Aw) {
printf ("H水晶:YES\n");
} else {
printf ("H水晶:NO\n");
}
if (Ww) {
printf ("R水晶:YES\n");
} else {
printf ("R水晶:NO\n");
}
}
void SetFont(int size) {
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof cfi;
cfi.nFont = 0;
cfi.dwFontSize.X = 0;
cfi.dwFontSize.Y = size;//设置字体大小
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL; //字体粗细
wcscpy_s(cfi.FaceName, L"宋体");//设置字体
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFO consoleCurrentFont;
GetCurrentConsoleFont(handle, FALSE, &consoleCurrentFont);
}
void xuan() {
for (int i = 1; i <= 2; i++) {
if (i == 1) {
printf ("请H选择!(输入前面的序号)\n");
} else {
printf ("请R选择!(输入前面的序号)\n");
}
printf ("1.战士\n生命:200\n攻击:50\n防御:50\n");
printf ("2.铠甲人\n生命:150\n攻击:40\n防御:80\n");
printf ("3.X原型机\n生命:250\n攻击:40\n防御:40\n");
printf ("4.H原型机\n生命:130\n攻击:45\n防御:85\n");
printf ("5.X束光机\n生命:135\n攻击:65\n防御:40\n");
int d;
scanf ("%d", &d);
switch (d) {
case 1:
if (i == 1) {
P1.shengming = 200;
P1.gongji = 50;
P1.fangyu = 50;
} else {
P2.shengming = 200;
P2.gongji = 50;
P2.fangyu = 50;
}
break;
case 2:
if (i == 1) {
P1.shengming = 150;
P1.gongji = 40;
P1.fangyu = 80;
} else {
P2.shengming = 150;
P2.gongji = 40;
P2.fangyu = 80;
}
break;
case 3:
if (i == 1) {
P1.shengming = 250;
P1.gongji = 40;
P1.fangyu = 40;
} else {
P2.shengming = 250;
P2.gongji = 40;
P2.fangyu = 40;
}
break;
case 4:
if (i == 1) {
P1.shengming = 130;
P1.gongji = 45;
P1.fangyu = 85;
} else {
P2.shengming = 130;
P2.gongji = 45;
P2.fangyu = 85;
}
break;
case 5:
if (i == 1) {
P1.shengming = 135;
P1.gongji = 65;
P1.fangyu = 40;
} else {
P2.shengming = 135;
P2.gongji = 65;
P2.fangyu = 40;
}
break;
}
system("cls");
}
}
int zhan() {
system("cls");
printf ("交战中......\n");
Sleep(2500);
int P1s = P1.shengming, P1g = P1.gongji, P1f = P1.fangyu, P2s = P2.shengming, P2g = P2.gongji, P2f = P2.fangyu;
while (1) {
if (P2g - P1f > 0) {
P1s = P1s - (P2g - P1f);
}
if (P1g - P2f > 0) {
P2s = P2s - (P1g - P2f);
}
if (P1.gongji <= P2.fangyu && P1.fangyu >= P2.gongji) {
printf ("无法交战!\n");
Sleep(1000);
a[p][q] = ' ';
p = 4, q = 17;
a[p][q] = 'R';
a[x][y] = ' ';
x = 2, y = 2;
a[x][y] = 'H';
return 100;
}
if (P1s <= 0 && P2s > 0) {
printf ("H狗带了!\n");
Sleep(5000);
if (Aw) {
a[x][y] = ' ';
x = 2, y = 2;
a[x][y] = 'H';
if (p == x && q == y) {
p = 5, q = 9;
a[p][q] = 'R';
}
return 99;
} else {
return 1;
}
}
if (P2s <= 0 && P1s > 0) {
printf ("R狗带了!\n");
Sleep(5000);
if (Ww) {
a[p][q] = ' ';
p = 4, q = 17;
a[p][q] = 'R';
if (p == x && q == y) {
x = 1, y = 9;
a[x][y] = 'H';
}
return 99;
} else {
return 2;
}
}
if (P2s <= 0 && P1s <= 0) {
printf ("都狗带了!\n");
Sleep(5000);
if (Ww && Aw) {
a[p][q] = ' ';
p = 4, q = 17;
a[p][q] = 'R';
a[x][y] = ' ';
x = 2, y = 2;
a[x][y] = 'H';
return 99;
}
if (Ww && !Aw) {
return 2;
}
if (!Ww && Aw) {
return 1;
}
if (!Ww && !Aw) {
return 3;
}
}
}
}
void win(int g) {
if (g == 1) {
printf("\'R\' 赢了!\n");
Sleep(5000);
system("pause");
} else {
if (g == 2) {
printf("\'H\' 赢了!\n");
Sleep(5000);
system("pause");
} else {
printf("平局!\n");
Sleep(5000);
system("pause");
}
}
}
void rans(char cha) {
int f = rand() % 2;
a[sx][sy] = cha;
sx = 35, sy = 35;
switch (f) {
case 0:
sx = 5, sy = 1;
break;
case 1:
sx = 1, sy = 18;
break;
}
a[sx][sy] = 'S';
}
void rang(char cha) {
int ff = rand() % 3;
a[gx][gy] = cha;
gx = 35, gy = 35;
switch (ff) {
case 0:
gx = 2, gy = 15;
break;
case 1:
gx = 2, gy = 8;
break;
case 2:
gx = 4, gy = 10;
break;
}
a[gx][gy] = 'N';
}
void ranf(char cha) {
int fff = rand() % 3;
a[fx][fy] = cha;
fx = 35, fy = 35;
switch (fff) {
case 0:
fx = 2, fy = 10;
break;
case 1:
fx = 4, fy = 4;
break;
case 2:
fx = 4, fy = 8;
break;
}
a[fx][fy] = 'F';
}
int main() {
system("title 起床战争");
SetFont(25);
srand(time(NULL));
system("color 0a");
xuan();
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);//获取控制台光标信息
CursorInfo.bVisible = false; //隐藏控制台光标
SetConsoleCursorInfo(handle, &CursorInfo);//设置控制台光标状态
out();
ranf(' ');
rang(' ');
rans(' ');
while (1) {
if (GetAsyncKeyState('S')) {
if (a[x + 1][y] != 'O') {
a[x][y] = ' ';
x++;
a[x][y] = 'H';
}
}
if (GetAsyncKeyState('D')) {
if (a[x][y + 1] != 'O') {
a[x][y] = ' ';
y++;
a[x][y] = 'H';
}
}
if (GetAsyncKeyState('A')) {
if (a[x][y - 1] != 'O') {
a[x][y] = ' ';
y--;
a[x][y] = 'H';
}
}
if (GetAsyncKeyState('W')) {
if (a[x - 1][y] != 'O') {
a[x][y] = ' ';
x--;
a[x][y] = 'H';
}
}
if (GetAsyncKeyState('K')) {
if (a[p + 1][q] != 'O') {
a[p][q] = ' ';
p++;
a[p][q] = 'R';
}
}
if (GetAsyncKeyState('L')) {
if (a[p][q + 1] != 'O') {
a[p][q] = ' ';
q++;
a[p][q] = 'R';
}
}
if (GetAsyncKeyState('J')) {
if (a[p][q - 1] != 'O') {
a[p][q] = ' ';
q--;
a[p][q] = 'R';
}
}
if (GetAsyncKeyState('I')) {
if (a[p - 1][q] != 'O') {
a[p][q] = ' ';
p--;
a[p][q] = 'R';
}
}
if (x == p && y == q) {
int jie = zhan();
if (jie == 1) {
win(1);
break;
} else {
if (jie == 2) {
win(2);
break;
} else {
if (jie < 99) {
win(3);
break;
}
}
}
}
if (x == c && y == b) {
a[c][b] = ' ';
c = 48, b = 49;
Ww = false;
}
if (p == n && q == m) {
a[n][m] = ' ';
n = 39, m = 35;
Aw = false;
}
if (c == p && b == q && Ww) {
a[c][b] = 'R';
while (1) {
if (!(c == p && b == q))
a[c][b] = 'W';
break;
}
} else {
a[c][b] = 'W';
}
if (n == x && m == y && Aw) {
a[n][m] = 'H';
while (1) {
if (!(n == x && m == y))
a[n][m] = 'A';
break;
}
} else {
a[n][m] = 'A';
}
if (sx == x && sy == y) {
P1.shengming += 5;
Sleep(10);
rans('H');
}
if (sx == p && sy == q) {
P2.shengming += 5;
Sleep(10);
rans('R');
}
if (gx == x && gy == y) {
P1.gongji += 5;
rang('H');
}
if (gx == p && gy == q) {
P2.gongji += 5;
rang('R');
}
if (fx == x && fy == y) {
P1.fangyu += 5;
ranf('H');
}
if (fx == p && fy == q) {
P2.fangyu += 5;
ranf('R');
}
out();
}
return 0;
}
水晶战争
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
#include<time.h>
char a[50][50] = {"OOOOOOOOOOOOOOOOOOOO",
"OA O",
"O H O O",
"O OOOOO O",
"O O R O",
"O WO",
"OOOOOOOOOOOOOOOOOOOO",
};
struct Player {
int shengming, gongji, fangyu;
};
Player P1, P2;
bool Aw = true, Ww = true, Z = false;
int x = 2, y = 2, p = 4, q = 17, n = 1, m = 1, c = 5, b = 18, sx = 30, sy = 30, gx = 30, gy = 30, fx = 30, fy = 30, A = 1000, W = 1000;
void out() {
system("cls");
for (int i = 0; i <= 7; i++) {
for (int j = 0; j <= 20; j++) {
printf ("%c", a[i][j]);
}
switch (i) {
case 0:
printf (" H:玩家1(WASD移动)");
break;
case 1:
printf (" A:H的水晶");
break;
case 2:
printf (" R:玩家2(IJKL移动)");
break;
case 3:
printf (" W:R的水晶");
break;
case 4:
printf (" O:墙壁");
break;
case 5:
printf (" N:增加攻击");
break;
case 6:
printf (" F:增加防御");
break;
case 7:
printf (" S:增加生命");
break;
}
printf ("\n");
}
printf ("H:\n生命:%d\n攻击:%d\n防御:%d\n\n", P1.shengming, P1.gongji, P1.fangyu);
printf ("R:\n生命:%d\n攻击:%d\n防御:%d\n\n", P2.shengming, P2.gongji, P2.fangyu);
if (Aw) {
printf ("H水晶:YES 血量:%d\n", A);
} else {
printf ("H水晶:NO\n");
}
if (Ww) {
printf ("R水晶:YES 血量:%d\n", W);
} else {
printf ("R水晶:NO\n");
}
}
void SetFont(int size) {
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof cfi;
cfi.nFont = 0;
cfi.dwFontSize.X = 0;
cfi.dwFontSize.Y = size;//设置字体大小
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL; //字体粗细
wcscpy_s(cfi.FaceName, L"宋体");//设置字体
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFO consoleCurrentFont;
GetCurrentConsoleFont(handle, FALSE, &consoleCurrentFont);
}
void xuan() {
for (int i = 1; i <= 2; i++) {
if (i == 1) {
printf ("请H选择你的职业!(输入前面的序号)\n");
} else {
printf ("请R选择你的职业!(输入前面的序号)\n");
}
printf ("1.战士\n生命:200\n攻击:50\n防御:50\n");
printf ("2.铠甲人\n生命:150\n攻击:40\n防御:80\n");
printf ("3.X原型机\n生命:250\n攻击:40\n防御:40\n");
printf ("4.H原型机\n生命:130\n攻击:45\n防御:85\n");
printf ("5.X束光机\n生命:135\n攻击:65\n防御:40\n");
int d;
scanf ("%d", &d);
switch (d) {
case 1:
if (i == 1) {
P1.shengming = 200;
P1.gongji = 50;
P1.fangyu = 50;
} else {
P2.shengming = 200;
P2.gongji = 50;
P2.fangyu = 50;
}
break;
case 2:
if (i == 1) {
P1.shengming = 150;
P1.gongji = 40;
P1.fangyu = 80;
} else {
P2.shengming = 150;
P2.gongji = 40;
P2.fangyu = 80;
}
break;
case 3:
if (i == 1) {
P1.shengming = 250;
P1.gongji = 40;
P1.fangyu = 40;
} else {
P2.shengming = 250;
P2.gongji = 40;
P2.fangyu = 40;
}
break;
case 4:
if (i == 1) {
P1.shengming = 130;
P1.gongji = 45;
P1.fangyu = 85;
} else {
P2.shengming = 130;
P2.gongji = 45;
P2.fangyu = 85;
}
break;
case 5:
if (i == 1) {
P1.shengming = 135;
P1.gongji = 65;
P1.fangyu = 40;
} else {
P2.shengming = 135;
P2.gongji = 65;
P2.fangyu = 40;
}
break;
}
system("cls");
}
}
int zhan() {//这个函数我现在再倒回来看都觉得不是我的实力能写得出来的
Z = true;
system("cls");
printf ("交战中......\n");
Sleep(2500);
int P1s = P1.shengming, P1g = P1.gongji, P1f = P1.fangyu, P2s = P2.shengming, P2g = P2.gongji, P2f = P2.fangyu;
while (1) {
if (P2g - P1f > 0) {
P1s = P1s - (P2g - P1f);
}
if (P1g - P2f > 0) {
P2s = P2s - (P1g - P2f);
}
if (P1.gongji <= P2.fangyu && P1.fangyu >= P2.gongji) {
printf ("无法交战!\n");
Sleep(1000);
a[p][q] = ' ';
p = 4, q = 17;
a[p][q] = 'R';
a[x][y] = ' ';
x = 2, y = 2;
a[x][y] = 'H';
Z = false;
return 100;
}
if (P1s <= 0 && P2s > 0) {
printf ("H狗带了!\n");
Sleep(5000);
if (Aw) {
a[x][y] = ' ';
x = 2, y = 2;
a[x][y] = 'H';
if (p == x && q == y) {
p = 5, q = 9;
a[p][q] = 'R';
}
Z = false;
return 99;
} else {
Z = false;
return 1;
}
}
if (P2s <= 0 && P1s > 0) {
printf ("R狗带了!\n");
Sleep(5000);
if (Ww) {
a[p][q] = ' ';
p = 4, q = 17;
a[p][q] = 'R';
if (p == x && q == y) {
x = 1, y = 9;
a[x][y] = 'H';
}
Z = false;
return 99;
} else {
Z = false;
return 2;
}
}
if (P2s <= 0 && P1s <= 0) {
printf ("都狗带了!\n");
Sleep(5000);
if (Ww && Aw) {
a[p][q] = ' ';
p = 4, q = 17;
a[p][q] = 'R';
a[x][y] = ' ';
x = 2, y = 2;
a[x][y] = 'H';
Z = false;
return 99;
}
if (Ww && !Aw) {
Z = false;
return 2;
}
if (!Ww && Aw) {
Z = false;
return 1;
}
if (!Ww && !Aw) {
Z = false;
return 3;
}
}
}
}
void win(int g) {
if (g == 1) {
printf("\'R\' 赢了!\n");
Sleep(5000);
system("pause");
} else {
if (g == 2) {
printf("\'H\' 赢了!\n");
Sleep(5000);
system("pause");
} else {
printf("平局!\n");
Sleep(5000);
system("pause");
}
}
}
void rans(char cha) {
int f = rand() % 2;
a[sx][sy] = cha;
sx = 35, sy = 35;
switch (f) {
case 0:
sx = 5, sy = 1;
break;
case 1:
sx = 1, sy = 18;
break;
}
a[sx][sy] = 'S';
}
void rang(char cha) {
int ff = rand() % 3;
a[gx][gy] = cha;
gx = 35, gy = 35;
switch (ff) {
case 0:
gx = 2, gy = 15;
break;
case 1:
gx = 2, gy = 8;
break;
case 2:
gx = 4, gy = 10;
break;
}
a[gx][gy] = 'N';
}
void ranf(char cha) {
int fff = rand() % 3;
a[fx][fy] = cha;
fx = 35, fy = 35;
switch (fff) {
case 0:
fx = 2, fy = 10;
break;
case 1:
fx = 4, fy = 4;
break;
case 2:
fx = 4, fy = 8;
break;
}
a[fx][fy] = 'F';
}
int main() {
system("title 水晶战争");
SetFont(25);
srand(time(NULL));
system("color 0a");
xuan();
out();
ranf(' ');
rang(' ');
rans(' ');
while (1) {
if (GetAsyncKeyState('S')) {
if (a[x + 1][y] != 'O') {
a[x][y] = ' ';
x++;
a[x][y] = 'H';
}
}
if (GetAsyncKeyState('D')) {
if (a[x][y + 1] != 'O') {
a[x][y] = ' ';
y++;
a[x][y] = 'H';
}
}
if (GetAsyncKeyState('A')) {
if (a[x][y - 1] != 'O') {
a[x][y] = ' ';
y--;
a[x][y] = 'H';
}
}
if (GetAsyncKeyState('W')) {
if (a[x - 1][y] != 'O') {
a[x][y] = ' ';
x--;
a[x][y] = 'H';
}
}
if (GetAsyncKeyState('K')) {
if (a[p + 1][q] != 'O') {
a[p][q] = ' ';
p++;
a[p][q] = 'R';
}
}
if (GetAsyncKeyState('L')) {
if (a[p][q + 1] != 'O') {
a[p][q] = ' ';
q++;
a[p][q] = 'R';
}
}
if (GetAsyncKeyState('J')) {
if (a[p][q - 1] != 'O') {
a[p][q] = ' ';
q--;
a[p][q] = 'R';
}
}
if (GetAsyncKeyState('I')) {
if (a[p - 1][q] != 'O') {
a[p][q] = ' ';
p--;
a[p][q] = 'R';
}
}
if (x == p && y == q) {
int jie = zhan();
if (jie == 1) {
win(1);
break;
} else {
if (jie == 2) {
win(2);
break;
} else {
if (jie < 99) {
win(3);
break;
}
}
}
}
if (x == c && y == b && !Z) {
W -= P1.gongji;
Sleep(500);
if (W <= 0) {
a[c][b] = ' ';
c = 48, b = 49;
Ww = false;
}
}
if (p == n && q == m && !Z) {
A -= P2.gongji;
Sleep(500);
if (A <= 0) {
a[n][m] = ' ';
n = 48, m = 49;
Aw = false;
}
}
if (c == p && b == q && Ww) {
a[c][b] = 'R';
while (1) {
if (!(c == p && b == q))
a[c][b] = 'W';
break;
}
} else {
a[c][b] = 'W';
}
if (n == x && m == y && Aw) {
a[n][m] = 'H';
while (1) {
if (!(n == x && m == y))
a[n][m] = 'A';
break;
}
} else {
a[n][m] = 'A';
}
if (sx == x && sy == y) {
P1.shengming += 5;
A += 2;
Sleep(10);
rans('H');
}
if (sx == p && sy == q) {
P2.shengming += 5;
W += 2;
Sleep(10);
rans('R');
}
if (gx == x && gy == y) {
P1.gongji += 5;
rang('H');
}
if (gx == p && gy == q) {
P2.gongji += 5;
rang('R');
}
if (fx == x && fy == y) {
P1.fangyu += 5;
ranf('H');
}
if (fx == p && fy == q) {
P2.fangyu += 5;
ranf('R');
}
out();
}
return 0;
}
攻守战
#include <bits/stdc++.h>
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <cmath>
#include <windows.h>
#include <cstdlib>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#include <conio.h>
#include <string>
#include <string.h>
#include <math.h>
#define w(x) while(x)
#define cl system("cls")
#define Sl(x) Sleep(x)
using namespace std;
char a[50][50] = {"OOOOOOOOOOOOOOOOOOOOOOOOO",
"O WO",
"O O O",
"OH OOOOO R WO",
"O O O",
"O WO",
"OOOOOOOOOOOOOOOOOOOOOOOOO",
};
struct Player {
int shengming, gongji, fangyu;
};
Player P1, P2;
bool W1 = true, W2 = true, W3 = true;
int x = 3, y = 1, p = 3, q = 21, n = 1, m = 23, c = 3, b = 23, f = 5, j = 23, sx = 30, sy = 30, gx = 30, gy = 30, fx = 30, fy = 30;
int ttt;
int t = 100000;
void out() {
cl;
for (int i = 0; i <= 7; i++) {
for (int j = 0; j <= 24; j++) {
printf ("%c", a[i][j]);
}
printf (" ");
switch (i) {
case 0:
printf ("H:玩家1(WASD移动)");
break;
case 1:
printf ("R:玩家2(IJKL移动)");
break;
case 2:
printf ("W:R的床");
break;
case 3:
printf ("O:墙壁");
break;
case 4:
printf ("N:增加攻击");
break;
case 5:
printf ("F:增加防御");
break;
case 6:
printf ("S:增加生命");
break;
}
printf ("\n");
}
printf ("H:\n生命:%d\n攻击:%d\n防御:%d\n\n", P1.shengming, P1.gongji, P1.fangyu);
printf ("R:\n生命:%d\n攻击:%d\n防御:%d\n\n", P2.shengming, P2.gongji, P2.fangyu);
if (W1) {
printf ("床W1:YES\n");
} else {
printf ("床W1:NO\n");
}
if (W2) {
printf ("床W2:YES\n");
} else {
printf ("床W2:NO\n");
}
if (W3) {
printf ("床W3:YES\n");
} else {
printf ("床W3:NO\n");
}
printf ("剩余时间:%dms\n", t - (int)clock() + ttt);
}
void SetFont(int size) {
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof cfi;
cfi.nFont = 0;
cfi.dwFontSize.X = 0;
cfi.dwFontSize.Y = size;//设置字体大小
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL; //字体粗细
wcscpy_s(cfi.FaceName, L"宋体");//设置字体
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFO consoleCurrentFont;
GetCurrentConsoleFont(handle, FALSE, &consoleCurrentFont);
}
void xuan() {
for (int i = 1; i <= 2; i++) {
if (i == 1) {
printf ("请H选择职业!(输入前面的序号)\n");
} else {
printf ("请R选择职业!(输入前面的序号)\n");
}
printf ("1.战士\n生命:200\n攻击:50\n防御:50\n");
printf ("2.铠甲人\n生命:150\n攻击:40\n防御:80\n");
printf ("3.X原型机\n生命:250\n攻击:40\n防御:40\n");
printf ("4.H原型机\n生命:130\n攻击:45\n防御:85\n");
printf ("5.X束光机\n生命:135\n攻击:65\n防御:40\n");
int d;
scanf ("%d", &d);
switch (d) {
case 1:
if (i == 1) {
P1.shengming = 200;
P1.gongji = 50;
P1.fangyu = 50;
} else {
P2.shengming = 200;
P2.gongji = 50;
P2.fangyu = 50;
}
break;
case 2:
if (i == 1) {
P1.shengming = 150;
P1.gongji = 40;
P1.fangyu = 80;
} else {
P2.shengming = 150;
P2.gongji = 40;
P2.fangyu = 80;
}
break;
case 3:
if (i == 1) {
P1.shengming = 250;
P1.gongji = 40;
P1.fangyu = 40;
} else {
P2.shengming = 250;
P2.gongji = 40;
P2.fangyu = 40;
}
break;
case 4:
if (i == 1) {
P1.shengming = 130;
P1.gongji = 45;
P1.fangyu = 85;
} else {
P2.shengming = 130;
P2.gongji = 45;
P2.fangyu = 85;
}
break;
case 5:
if (i == 1) {
P1.shengming = 135;
P1.gongji = 65;
P1.fangyu = 40;
} else {
P2.shengming = 135;
P2.gongji = 65;
P2.fangyu = 40;
}
break;
}
system("cls");
}
}
int zhan() {
system("cls");
printf ("交战中......\n");
Sleep(2500);
int P1s = P1.shengming, P1g = P1.gongji, P1f = P1.fangyu, P2s = P2.shengming, P2g = P2.gongji, P2f = P2.fangyu;
while (1) {
if (P2g - P1f > 0) {
P1s = P1s - (P2g - P1f);
}
if (P1g - P2f > 0) {
P2s = P2s - (P1g - P2f);
}
if (P1.gongji <= P2.fangyu && P1.fangyu >= P2.gongji) {
printf ("无法交战!\n");
Sl(1000);
a[p][q] = ' ';
p = 3, q = 21;
a[p][q] = 'R';
a[x][y] = ' ';
x = 3, y = 1;
a[x][y] = 'H';
return 100;
}
if (P1s <= 0 && P2s > 0) {
printf ("H狗带了!\n");
Sl(3000);
a[x][y] = ' ';
x = 3, y = 1;
a[x][y] = 'H';
}
if (P2s <= 0 && P1s > 0) {
printf ("R狗带了!\n");
Sl(3000);
if (W1 || W2 || W3) {
a[p][q] = ' ';
p = 4, q = 17;
a[p][q] = 'R';
if (p == x && q == y) {
x = 3, y = 9;
a[x][y] = 'H';
}
return 99;
} else {
return 2;
}
}
if (P2s <= 0 && P1s <= 0) {
printf ("都狗带了!\n");
Sl(3000);
if (W1 || W2 || W3) {
a[x][y] = ' ';
x = 3, y = 1;
a[x][y] = 'H';
a[p][q] = ' ';
p = 4, q = 17;
a[p][q] = 'R';
if (p == x && q == y) {
a[x][y] = ' ';
x = 3, y = 9;
a[x][y] = 'H';
}
return 99;
} else {
return 2;
}
}
}
}
void win(int g) {
if (g == 1) {
printf("R赢了!\n");
Sl(3000);
system("pause");
} else {
printf("H赢了!\n");
Sl(3000);
system("pause");
}
}
void rans(char cha) {
int f = rand() % 2;
a[sx][sy] = cha;
sx = 35, sy = 35;
switch (f) {
case 0:
sx = 5, sy = 1;
break;
case 1:
sx = 1, sy = 18;
break;
}
a[sx][sy] = 'S';
}
void rang(char cha) {
int ff = rand() % 3;
a[gx][gy] = cha;
gx = 35, gy = 35;
switch (ff) {
case 0:
gx = 2, gy = 15;
break;
case 1:
gx = 2, gy = 8;
break;
case 2:
gx = 4, gy = 10;
break;
}
a[gx][gy] = 'N';
}
void ranf(char cha) {
int fff = rand() % 3;
a[fx][fy] = cha;
fx = 35, fy = 35;
switch (fff) {
case 0:
fx = 2, fy = 10;
break;
case 1:
fx = 4, fy = 4;
break;
case 2:
fx = 4, fy = 8;
break;
}
a[fx][fy] = 'F';
}
void Start() {
puts("欢迎来玩攻守战!!!");
Sl(1000);
puts("yuexingfei出品,必属精品!");
Sl(1000);
puts("请按任意键开始游戏...");
getch();
cl;
puts ("Loading......");
Sl(2000);
cl;
int o = 0;
for (int i = 1; i <= 200; i++) {
printf ("已加载%d个文件,进度%d", i, o);
cout << "%\n";
if (i % 2 == 0) {
o++;
}
Sl(1);
if (rand() % 15 == 9) {
Sl(4);
}
cl;
}
}
void SetConsoleWindowSize( SHORT width, SHORT height ) {
HANDLE hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SMALL_RECT wrt = { 0, 0, width - 1, height - 1 };
SetConsoleWindowInfo( hStdOutput, TRUE, &wrt );
COORD coord = { width, height };
SetConsoleScreenBufferSize( hStdOutput, coord );
}
int main() {
system("title 攻守战");
SetFont(25);
SetConsoleWindowSize(53, 25);
srand(time(NULL));
system("color 0a");
Start();
cl;
printf ("规则:\n1.有时间限制(100s)\n2.攻方在规定时间内破坏守方的三个床就算赢\n3.守方要在规定时间内守住三个床,只要规定时间结束后还有床没有被攻方破坏就算赢\n");
system("pause");
cl;
xuan();
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);//获取控制台光标信息
CursorInfo.bVisible = false; //隐藏控制台光标
SetConsoleCursorInfo(handle, &CursorInfo);//设置控制台光标状态
ttt = clock();
out();
ranf(' ');
rang(' ');
rans(' ');
w(1) {
if (GetAsyncKeyState('S')) {
if (a[x + 1][y] != 'O') {
a[x][y] = ' ';
x++;
a[x][y] = 'H';
}
}
if (GetAsyncKeyState('D')) {
if (a[x][y + 1] != 'O') {
a[x][y] = ' ';
y++;
a[x][y] = 'H';
}
}
if (GetAsyncKeyState('A')) {
if (a[x][y - 1] != 'O') {
a[x][y] = ' ';
y--;
a[x][y] = 'H';
}
}
if (GetAsyncKeyState('W')) {
if (a[x - 1][y] != 'O') {
a[x][y] = ' ';
x--;
a[x][y] = 'H';
}
}
if (GetAsyncKeyState('K')) {
if (a[p + 1][q] != 'O') {
a[p][q] = ' ';
p++;
a[p][q] = 'R';
}
}
if (GetAsyncKeyState('L')) {
if (a[p][q + 1] != 'O') {
a[p][q] = ' ';
q++;
a[p][q] = 'R';
}
}
if (GetAsyncKeyState('J')) {
if (a[p][q - 1] != 'O') {
a[p][q] = ' ';
q--;
a[p][q] = 'R';
}
}
if (GetAsyncKeyState('I')) {
if (a[p - 1][q] != 'O') {
a[p][q] = ' ';
p--;
a[p][q] = 'R';
}
}
if (clock() - ttt >= 100000) {
if (W1 || W2 || W3) {
win(2);
} else {
win(1);
}
break;
}
if (x == p && y == q) {
int jie = zhan();
if (jie == 2) {
win(2);
break;
}
}
if (x == n && y == m) {
W1 = false;
n = 48, m = 49;
}
if (x == c && y == b) {
W2 = false;
c = 48, b = 49;
}
if (x == f && y == j) {
W3 = false;
f = 48, j = 49;
}
if (p == n && q == m && W1) {
a[n][m] = 'R';
while (1) {
if (!(p == n && q == m))
a[n][m] = 'W';
break;
}
} else {
a[n][m] = 'W';
}
if (p == c && q == b && W2) {
a[c][b] = 'R';
while (1) {
if (!(p == c && q == b))
a[c][b] = 'W';
break;
}
} else {
a[c][b] = 'W';
}
if (p == f && q == j && W3) {
a[f][j] = 'R';
while (1) {
if (!(p == f && q == j))
a[f][j] = 'W';
break;
}
} else {
a[f][j] = 'W';
}
if (sx == x && sy == y) {
P1.shengming += 5;
Sleep(10);
rans('H');
}
if (sx == p && sy == q) {
P2.shengming += 5;
Sleep(10);
rans('R');
}
if (gx == x && gy == y) {
P1.gongji += 5;
rang('H');
}
if (gx == p && gy == q) {
P2.gongji += 5;
rang('R');
}
if (fx == x && fy == y) {
P1.fangyu += 5;
ranf('H');
}
if (fx == p && fy == q) {
P2.fangyu += 5;
ranf('R');
}
out();
}
return 0;
}
画图
turtle版
#include <turtle.h>
#include <conio.h>
#include <iostream>
#include <windows.h>
#define _cl system("cls")
#define _pa system("pause")
#define Get(x) GetAsyncKeyState(x)
#define inf 1e9
using namespace std;
typedef long long ll;
typedef string str;
inline void Sleep_write(const string &x, const int &y = 10) {
for (int i = 0; i < (int)x.length(); i++) {
putchar(x[i]);
ege::api_sleep(y);
}
}
inline void wait(const int &d = 100) {
ege::api_sleep(d);
getchar();
}
inline void welcome(void) {
Sleep_write("画图turtle版\n");
wait();
Sleep_write("作者:Yuexingfei_qwq\n");
wait();
Sleep_write("版权归Yuexingfei_qwq所有,恶意搬运者将会受到惩罚\n");
wait();
Sleep_write("开发者联系方式(洛谷):https://luogu.com.cn/user/1125939,用户名Yuexingfei_qwq||https://luogu.com.cn/user/1423517,用户名Mengchen_Yxf2013_qwq(Yuexingfei_qwq小号)\n");
wait();
Sleep_write("操控turtle时请使用英文输入法\n");
wait();
Sleep_write("出现bug时,请按下P键解除\n");
wait();
Sleep_write("使用教程在代码和代码末尾里的注释中都有,请自行查看\n");
wait();
_pa;
_cl;
}
inline char get(str s) {
char ch[114514];
int l = 0;
for (auto i : s) {
ch[++l] = i;
}
while (true) {
str t;
cin >> t;
for (int i = 1; i <= l; i++) {
if (t[0] == ch[i]) {
return t[0];
}
}
Sleep_write("Error:输入无效\n");
ege::api_sleep(1000);
_pa;
}
}
inline void init(void) {
char ch;
Sleep_write("是否设置画板大小?(Y/N)\n");
ch = tolower(get("YyNn"));
int n, m;
if (ch == 'y') {
Sleep_write("请输入画板的长和宽\n");
cin >> n >> m;
} else {
n = 800, m = 600;
}
_cl;
Sleep_write("是否设置turtle初始坐标?(Y/N)\n");
ch = tolower(get("YyNn"));
int x = inf, y = -inf;
if (ch == 'y') {
Sleep_write("请输入turtle初始坐标\n");
cin >> x >> y;
}
_cl;
Sleep_write("是否设置画布标题?(Y/N)\n");
ch = tolower(get("YyNn"));
char s[1919810];
int f = 0;
if (ch == 'y') {
f = 1;
Sleep_write("请输入画布标题\n");
cin >> s;
}
_cl;
initWorld(n, m);
if (x != inf && y != -inf) {
setOrigin(x, y);
}
if (f) {
setCaption(s);
}
}
int fo = 10, an = 30, ps = 1;//fo:步数 an:角度 ps:画笔粗细
int panc = 0, bakc = 15;//笔颜色和背景颜色
int isjisu = 0, sudu = 100;//1急速 0非
inline void SetPen(void) {
if (panc == 0) {
setPenColor(ege::BLACK);
}
if (panc == 1) {
setPenColor(ege::BLUE);
}
if (panc == 2) {
setPenColor(ege::GREEN);
}
if (panc == 3) {
setPenColor(ege::CYAN);
}
if (panc == 4) {
setPenColor(ege::RED);
}
if (panc == 5) {
setPenColor(ege::MAGENTA);
}
if (panc == 6) {
setPenColor(ege::BROWN);
}
if (panc == 7) {
setPenColor(ege::LIGHTGRAY);
}
if (panc == 8) {
setPenColor(ege::DARKGRAY);
}
if (panc == 9) {
setPenColor(ege::LIGHTBLUE);
}
if (panc == 10) {
setPenColor(ege::LIGHTGREEN);
}
if (panc == 11) {
setPenColor(ege::LIGHTCYAN);
}
if (panc == 12) {
setPenColor(ege::LIGHTRED);
}
if (panc == 13) {
setPenColor(ege::LIGHTMAGENTA);
}
if (panc == 14) {
setPenColor(ege::YELLOW);
}
if (panc == 15) {
setPenColor(ege::WHITE);
}
}
inline void SetBack(void) {
if (bakc == 0) {
setBackgroundColor(ege::BLACK);
}
if (bakc == 1) {
setBackgroundColor(ege::BLUE);
}
if (bakc == 2) {
setBackgroundColor(ege::GREEN);
}
if (bakc == 3) {
setBackgroundColor(ege::CYAN);
}
if (bakc == 4) {
setBackgroundColor(ege::RED);
}
if (bakc == 5) {
setBackgroundColor(ege::MAGENTA);
}
if (bakc == 6) {
setBackgroundColor(ege::BROWN);
}
if (bakc == 7) {
setBackgroundColor(ege::LIGHTGRAY);
}
if (bakc == 8) {
setBackgroundColor(ege::DARKGRAY);
}
if (bakc == 9) {
setBackgroundColor(ege::LIGHTBLUE);
}
if (bakc == 10) {
setBackgroundColor(ege::LIGHTGREEN);
}
if (bakc == 11) {
setBackgroundColor(ege::LIGHTCYAN);
}
if (bakc == 12) {
setBackgroundColor(ege::LIGHTRED);
}
if (bakc == 13) {
setBackgroundColor(ege::LIGHTMAGENTA);
}
if (bakc == 14) {
setBackgroundColor(ege::YELLOW);
}
if (bakc == 15) {
setBackgroundColor(ege::WHITE);
}
}
signed main(void) {
welcome();
init();
while (ege::is_run()) {
if (Get('P')) {//debug
setImmediate(1);
lt(360);
setImmediate(0);
setSpeed(sudu);
}
if (Get('W')) {//前进
fd(fo);
}
if (Get('S')) {//后退
bk(fo);
}
if (Get('A')) {//左转
lt(an);
}
if (Get('D')) {//右转
rt(an);
}
if (Get('Q')) {//落笔
pd();
}
if (Get('E')) {//抬笔
pu();
}
if (Get('R')) {//重置
clear();
}
if (Get('F')) {//回到起始点
home();
}
if (Get('Z')) {//画笔粗细+1
ps += 1;
setPenSize(ps);
}
if (Get('X')) {//画笔粗细-1
ps -= 1;
ps = std::max(1, ps);
setPenSize(ps);
}
if (Get('T')) {//速度+1
sudu += 1;
setSpeed(sudu);
}
if (Get('G')) {//速度-1
sudu -= 1;
sudu = std::max(1, sudu);
setSpeed(sudu);
}
if (Get('V')) {//隐藏
hide();
}
if (Get('Y')) {//显示
show();
}
if (Get('U')) {//旋转角度+1
an += 1;
an = std::min(an, 360);
}
if (Get('J')) {//旋转角度-1
an -= 1;
an = std::max(an, 0);
}
if (Get('N')) {//步数+1
fo += 10;
}
if (Get('M')) {//步数-1
fo -= 10;
fo = std::max(fo, 1);
}
if (Get('C')) {//将画笔颜色改为下一个
(panc += 1) %= 16;
SetPen();
}
if (Get('H')) {//将背景颜色改为下一个
(bakc += 1) %= 16;
SetBack();
}
if (Get('B')) {//设置是否急速
isjisu = 1 - isjisu;
if (isjisu) {
setImmediate(isjisu);
} else {
setSpeed(sudu);
}
}
}
pause();
return 0;
}
/*
操作指令
initWorld(int width, int height, double scale = 1.0):生成画布,设置画布大小(第三个参数为放大倍数,前两个参数均会乘上它;没填时默认为1.0)
setOrigin(int x, int y):设置乌龟起始点
setCaption(const char* title):改变画布标题(参数为一个string,需用双引号,而不是char)
W:fd(double step):前进step步
S:bk(double step):后退step步
A:lt(double step):左转step°
D:rt(double step):右转step°
Q:pd():落笔
E:pu():抬笔
R:clear():重置
F:home():乌龟移到起始点
Z+X-:setPenSize(int size):设置画笔粗细(默认值为1)(在参数较大时画出来的斜线可能会出现不均匀的情况) √
C:setPenColor(ege::color_t color):改变画笔颜色
ege::BLACK:黑色(默认颜色)
ege::BLUE:蓝色
ege::GREEN:绿色
ege::CYAN:青色
ege::RED:红色
ege::MAGENTA:紫色
ege::BROWN:棕色
ege::YELLOW:黄色
ege::WHITE:白色
ege::DARKGRAY:深灰色
ege::LIGHTGRAY:浅灰色
ege::LIGHTBLUE:浅蓝色
ege::LIGHTGREEN:浅绿色
ege::LIGHTCYAN:浅青色(类似天蓝色或淡蓝色)
ege::LIGHTRED:淡红色
ege::LIGHTMAGENTA:淡紫色(类似粉色)
注意事项:传参时参数应当为"ege::"+对应颜色的英文,颜色英文需全用大写
T+G-:setSpeed(int speed):调速度(默认100)
V:hide():隐藏乌龟
Y:show():显示乌龟
H:setBackgroundColor(ege::color_t color):改变背景颜色(详见setPenColor函数)
B:setImmediate(int isImmediate):参数为0时普通速度,否则为超快速度
U+J-:调节乌龟旋转角度(默认30°)
N+M-:调节乌龟走路步数(默认10步)
pause():等待直到画布被关闭
(由于输入输出、兼容性等问题,仅使用turtle.h中的部分操作指令)
*/
字符版
#include <bits/stdc++.h>
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <cmath>
#include <windows.h>
#include <cstdlib>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#include <conio.h>
#include <string>
#include <string.h>
#include <math.h>
using namespace std;
int x = 1, y = 1;
int pen = 1;
string s[102][102];
string color = "white";
string ch = "@";
string dfs_color = " ", dfs_ch = " ";
bool f = 0, b[102][102], yd = 0;
string a[102][102];
int l, h;
inline void color1(string g) {
if (g == "white") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
} else {
if (g == "red") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
} else {
if (g == "yellow") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
} else {
if (g == "green") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
} else {
if (g == "indego") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN);
} else {
if (g == "pink") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED);
} else {
if (g == "blue") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
} else {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
}
}
}
}
}
}
}
}
inline void out() {
system("cls");
for (int i = 0; i < l; i++) {
for (int j = 0; j < h; j++) {
if (a[i][j] == "+") {
if (f == 1) {
color1(dfs_color);
printf ("%s", dfs_ch.c_str());
} else {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
printf ("+");
}
} else {
color1(s[i][j]);
printf ("%s", a[i][j].c_str());
}
}
printf ("\n");
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
printf ("X:%d Y:%d\n", x, y);
}
inline void SetConsoleWindowSize(SHORT width, SHORT height) {
HANDLE hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SMALL_RECT wrt = {0, 0, width - 1, height - 1};
SetConsoleWindowInfo(hStdOutput, TRUE, &wrt);
COORD coord = {width, height};
SetConsoleScreenBufferSize(hStdOutput, coord);
}
inline void q() {
for (int i = 1; i < l - 1; i++) {
for (int j = 1; j < h - 1; j++) {
a[i][j] = " ";
}
}
a[x][y] = "+";
}
inline void init() {
for (int i = 0; i < l; i++) {
for (int j = 0; j < h; j++) {
b[i][j] = 0;
}
}
}
inline void dfs(const int &x, const int &y) {
b[x][y] = 1;
s[x][y] = color, a[x][y] = ch;
if (a[x - 1][y] == dfs_ch && s[x - 1][y] == dfs_color && !b[x - 1][y]) {
dfs(x - 1, y);
}
if (a[x + 1][y] == dfs_ch && s[x + 1][y] == dfs_color && !b[x + 1][y]) {
dfs(x + 1, y);
}
if (a[x][y - 1] == dfs_ch && s[x][y - 1] == dfs_color && !b[x][y - 1]) {
dfs(x, y - 1);
}
if (a[x][y + 1] == dfs_ch && s[x][y + 1] == dfs_color && !b[x][y + 1]) {
dfs(x, y + 1);
}
}
int main() {
cout << "教程在代码末尾的注释里\n";
system("pause");
system("cls");
h = 32, l = 12;
for (int i = 0; i < l; i++) {
for (int j = 0; j < h; j++) {
if (i == 0 || j == 0 || i == l - 1 || j == h - 1) {
a[i][j] = "O";
} else {
a[i][j] = " ";
}
s[i][j] = "white";
}
}
a[x][y] = "+";
CONSOLE_CURSOR_INFO cursorInfo;
GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo);
cursorInfo.bVisible = FALSE;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo);
SetConsoleWindowSize(32, 14);
system("title 画图");
while (1) {
out();
if (GetAsyncKeyState('S')) {
if (a[x + 1][y] != "O" && !f) {
if (!yd) {
if (pen) {
a[x][y] = ch;
} else {
a[x][y] = " ";
}
s[x][y] = color;
}
if (yd) {
a[x][y] = dfs_ch;
s[x][y] = dfs_color;
}
dfs_ch = a[x + 1][y];
dfs_color = s[x + 1][y];
x++;
a[x][y] = "+";
}
}
if (GetAsyncKeyState('D')) {
if (a[x][y + 1] != "O" && !f) {
if (!yd) {
if (pen) {
a[x][y] = ch;
} else {
a[x][y] = " ";
}
s[x][y] = color;
}
if (yd) {
a[x][y] = dfs_ch;
s[x][y] = dfs_color;
}
dfs_ch = a[x][y + 1];
dfs_color = s[x][y + 1];
y++;
a[x][y] = "+";
}
}
if (GetAsyncKeyState('A')) {
if (a[x][y - 1] != "O" && !f) {
if (!yd) {
if (pen) {
a[x][y] = ch;
} else {
a[x][y] = " ";
}
s[x][y] = color;
}
if (yd) {
a[x][y] = dfs_ch;
s[x][y] = dfs_color;
}
dfs_ch = a[x][y - 1];
dfs_color = s[x][y - 1];
y--;
a[x][y] = "+";
}
}
if (GetAsyncKeyState('W')) {
if (a[x - 1][y] != "O" && !f) {
if (!yd) {
if (pen) {
a[x][y] = ch;
} else {
a[x][y] = " ";
}
s[x][y] = color;
}
if (yd) {
a[x][y] = dfs_ch;
s[x][y] = dfs_color;
}
dfs_ch = a[x - 1][y];
dfs_color = s[x - 1][y];
x--;
a[x][y] = "+";
}
}
if (GetAsyncKeyState('1')) {
pen = 1;
}
if (GetAsyncKeyState('2')) {
pen = 0;
}
if (GetAsyncKeyState('3')) {
color = "white";
}
if (GetAsyncKeyState('4')) {
color = "red";
}
if (GetAsyncKeyState('5')) {
color = "yellow";
}
if (GetAsyncKeyState('6')) {
color = "green";
}
if (GetAsyncKeyState('7')) {
color = "indego";
}
if (GetAsyncKeyState('8')) {
color = "pink";
}
if (GetAsyncKeyState('9')) {
color = "blue";
}
if (GetAsyncKeyState('0')) {
color = "grey";
}
if (GetAsyncKeyState('Y')) {
ch = "@";
}
if (GetAsyncKeyState('U')) {
ch = "#";
}
if (GetAsyncKeyState('I')) {
ch = "%";
}
if (GetAsyncKeyState('O')) {
ch = "^";
}
if (GetAsyncKeyState('P')) {
ch = "&";
}
if (GetAsyncKeyState('H')) {
ch = "*";
}
if (GetAsyncKeyState('J')) {
ch = "/";
}
if (GetAsyncKeyState('K')) {
ch = "-";
}
if (GetAsyncKeyState('L')) {
ch = ".";
}
if (GetAsyncKeyState('M')) {
q();
}
if (GetAsyncKeyState('N')) {
f = 1;
}
if (GetAsyncKeyState('B')) {
f = 0;
}
if (GetAsyncKeyState('Z')) {
for (int i = 0; i < l; i++) {
for (int j = 0; j < h; j++) {
if (a[i][j] != "O") {
s[i][j] = color, a[i][j] = ch;
}
}
}
dfs_ch = ch;
dfs_color = color;
a[x][y] = "+";
}
if (GetAsyncKeyState('X')) {
init();
dfs(x, y);
dfs_ch = ch;
dfs_color = color;
a[x][y] = "+";
}
if (GetAsyncKeyState('Q')) {
yd = 1;
}
if (GetAsyncKeyState('E')) {
yd = 0;
}
}
return 0;
}
/*
操作方法如下:(按下键盘上的按钮操作;O代表边缘,画笔移动时碰到O就不能继续移动了;+代表鼠标)
w:鼠标向上移动
a:鼠标向左移动
s:鼠标向下移动
d:鼠标向右移动
1:鼠标设成画笔
2:鼠标设成橡皮
3:画笔颜色设为白色
4:画笔颜色设为红色
5:画笔颜色设为黄色
6:画笔颜色设为绿色
7:画笔颜色设为靛青
8:画笔颜色设为粉色
9:画笔颜色设为蓝色
0:画笔颜色设为灰色
y:画出图案设为@
u:画出图案设为#
i:画出图案设为%
o:画出图案设为^
p:画出图案设为&
h:画出图案设为*
j:画出图案设为/
k:画出图案设为-
l:画出图案设为.
m:清屏
n:开启观察者模式(见文末)
b:关闭观察者模式(见文末)
q:抬笔
e:落笔
特殊规则:
1.开始时,鼠标默认为画笔,画出图案为@
2.在画笔模式下,鼠标每移动一次,它原所在的格子为画出的图案
3.在橡皮模式下,鼠标每移动一次,它原所在的格子为空格
观察者模式:在该模式下,鼠标不会被显示,也不能移动,但可以改变颜色、图案、鼠标模式等。
*/
【Yuexingfei_qwq的原创游戏】的更多相关文章
- 原创游戏,金庸群侠传X 0.5公布
首先说一下背景,我个人从小特别爱玩游戏,对小时候一款游戏<金庸群侠传>DOS版更是情有独钟,自己工作以后,利用业余时间自己整了一个原创的改编版丢网上(找图片.音乐.写剧情更是虐心之极,耗时 ...
- H5实现的可自定义贪吃蛇游戏
原创游戏,使用lufylegend.js开发 用canvas实现的贪吃蛇游戏,与一般的贪吃蛇游戏不同,图片经过美工设计,代码设计支持扩展和自定义. 游戏元素丰富,包括障碍物(仙人掌),金币(奖励),苹 ...
- cocos2d 高仿doodle jump 无源代码
1. 游戏视频 主角眼熟吗?没错,上次跑酷游戏中的"30"来Jump了,有三种道具.主角光环,竹蜻蜓.翅膀: 有两种怪物,螃蟹和鸟: 有5种板子.点击屏幕,30会把它的嘴巴3给发射 ...
- JavaScript是如何工作的:与WebAssembly比较及其使用场景
摘要: WebAssembly未来可期. 原文:JavaScript是如何工作的:与WebAssembly比较及其使用场景 作者:前端小智 Fundebug经授权转载,版权归原作者所有. 这是专门探索 ...
- [转][darkbaby]任天堂传——失落的泰坦王朝(上)
前言: 曾经一再的询问自我;是否真的完全了解任天堂这个游戏老铺的真实本质?或许从来就没有人能够了解,世间已经有太多的真相被埋没在谎言和臆测之中.作为 一个十多年游龄的老玩家,亲眼目睹了任天堂从如日 ...
- 优化VR体验的7个建议
本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接: http://blog.csdn.net/cartzhang/article/details/50392607 作者:ca ...
- 苹果宣布 2022 年 Apple 设计大奖得主
Apple 今日举办了年度 Apple 设计大奖颁奖仪式,表彰 12 款出类拔萃的 app 与游戏佳作.今年的获奖者包括来自全球各地的开发者.他们通过 app 呈现锐意创新.别出心裁的优美设计体验,以 ...
- cocos2d-x游戏开发实战原创视频讲座系列1之2048游戏开发
cocos2d-x游戏开发实战原创视频讲座系列1之2048游戏开发 的产生 视持续更新中.... 视频存放地址例如以下:http://ipd.pps.tv/user/1058663622 ...
- 原创教程“ActionScript3.0游戏中的图像编程”開始连载啦!
经过近两年的不懈努力,笔者的原创教程"ActionScript3游戏中的图像编程"最终在今日划上了完美的句号!这其中记录着笔者多年来在游戏制作,尤其是其中图像处理方 ...
- 【微信小程序项目实践总结】30分钟从陌生到熟悉 web app 、native app、hybrid app比较 30分钟ES6从陌生到熟悉 【原创】浅谈内存泄露 HTML5 五子棋 - JS/Canvas 游戏 meta 详解,html5 meta 标签日常设置 C#中回滚TransactionScope的使用方法和原理
[微信小程序项目实践总结]30分钟从陌生到熟悉 前言 我们之前对小程序做了基本学习: 1. 微信小程序开发07-列表页面怎么做 2. 微信小程序开发06-一个业务页面的完成 3. 微信小程序开发05- ...
随机推荐
- document.querySelector 有多个类 的情况
document.querySelector 有多个类 document.querySelector 方法用于返回文档中匹配指定 CSS 选择器的第一个元素.如果要查询具有多个类的元素,可以将它们作为 ...
- C#钩子(Hook) 捕获键盘鼠标所有事件 - 5分钟没有操作,自动关闭 Form 窗体
C# 钩子 捕获键盘鼠标所有事件,可用于:判断鼠标键盘无操作时,关闭 Winform 窗体 5分钟没有操作,自动关闭 Form 窗体 钩子(Hook)的作用主要体现在监视和拦截系统或进程中的各种事件消 ...
- 第三章 (Nginx+Lua)Redis/SSDB安装与使用
目前对于互联网公司不使用Redis的很少,Redis不仅仅可以作为key-value缓存,而且提供了丰富的数据结果如set.list.map等,可以实现很多复杂的功能:但是Redis本身主要用作内存缓 ...
- G1原理—9.如何优化G1中的MGC
大纲 1.大对象导致频繁Mixed GC的案例 2.Mixed GC到底是在优化什么(从避免到提速) 3.Mixed GC相关参数详解之堆内存分配参数 4.Mixed GC其他相关的参数详解及优化 1 ...
- VueRouter案列
案列内容,包含,模板,路由传参,路由重定向,路由嵌套,能够复习路由基本使用,成果如图: 完整代码: 1 <!DOCTYPE html> 2 <html lang="en&q ...
- Collection子接口:Set接口(实现类:HashSet、LinkedHashSet、TreeSet)
/** * 1. Set接口的框架: * * |----Collection接口:单列集合,用来存储一个一个的对象 * |----Set接口:存储无序的.不可重复的数据 -->高中讲的" ...
- Object类中toString()的使用
/* * Object类中toString()的使用: * * 1. 当我们输出一个对象的引用时,实际上就是调用当前对象的toString() * * 2. Object类中toString()的定义 ...
- unicode编码 asis_2019_unicorn_shop
这题就是让我们购买第四个商品 当我们输入price为1337.0的时候他会报错,显示要我们只输入一个字符 那么我们就要想怎样用一个字符来表示一个比1337还要大的数字 答案是unicode 编码 (题 ...
- Nessus 扫描Web服务
Nessus 扫描Web服务 1.点击 New Scan,选择 Web Application Tests 2.填写扫描名称和扫描目标 3.点击 Discovery ,选择 Scan Type 为全端 ...
- 概率学习(Genshin中)
目前待补充:停时定理的部分例题. 定义 首先定义样本空间 \(\Omega\),是所有样本点(结果)的集合. 随机事件 \(A\) 是样本空间的子集. 定义事件和为事件并,积为事件交. 事件域 \(\ ...