最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

小游戏

运维笔记admin31浏览0评论

小游戏

小游戏

这里是目录

  • 🌳 游戏介绍
  • 🌳 效果图
  • 🌳 整个游戏代码
  • 各个模块分解
    • 🌳 猜数字模块
    • 🌳心形闪烁表白模块
    • 🌳关机整蛊模块

❤️ :热爱编程学习,期待一起交流!
🙏:博主水平有限,如有发现错误,求告知,多谢!

🌳 游戏介绍

  • 此篇不涉及详解,只是献给有些c语言基础,想学点创意,表白,或者写两行代码去整蛊的人。快拿上你的Devc++,vs试试吧(滑稽)
    • 猜数字游戏,顾名思义。
    • 此游戏叫做奖惩制猜数字游戏。如果你猜对了,就会得到相应的奖励。
    • 当然猜错了也会受到相应的小小的惩罚

🌳 效果图

  • 游戏界面
  • 奖励
  • 惩罚

🌳 整个游戏代码

  • 对于只想去玩玩游戏 或者、表白、整蛊的零基础用户来说,以下整个代码才是你的最爱,接招。
    • 如果需要其中单独一个游戏模块的请往下面翻。

#include<stdio.h>
#include<time.h>
#include<math.h>
#include<windows.h>
#include <string.h>
#include <stdlib.h>
#define U 0.1
#define V 0.053
void SetColor(unsigned short ForeColor, unsigned short BackGroundColor)
{HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleTextAttribute(hCon, (ForeColor % 16) | (BackGroundColor % 16 * 16));
}
void menu()
{printf("\n");printf("\n");printf("			        游戏规则:\n");printf("			        电脑会随机生成1~100之间的整数\n");printf("			        请玩家在此区间猜一个数字\n");printf("			        你一共有10次猜数字的机会\n");printf("			        如果猜对了会得到奖励,否则会受到惩罚\n");printf("			        Are you really?\n");printf("\n");printf("\n");printf("\n");printf("\n");printf("			       ********1.开始游戏**********\n");printf("			       ********0.结束游戏**********\n");printf("\n"); printf("                                请选择:1或0\n");
}
void game()
{printf("请输入你要猜的数字:");int guess = 0;int r = rand() % 100 + 1;int i = 0;for (i = 1; i <= 10; i++){scanf("%d", &guess);if (guess > r){printf("猜大了,请再次输入:");}if (guess < r){printf("猜小了,请再次输入:");}if (guess == r){printf("恭喜你答对了!\n你将得到一个小心心奖励");int i, s = 0, t, a = 10, b = 11, c = 12, d = 13, e = 14;int z[] = { 32,32,206,210,207,178,187,182,196,227,33,32,32 };float x, y;srand(time(NULL));for (y = 1.3; y >= -1.1; y -= U){for (x = -2; x < 1.4; x += V){if ((((x * x + y * y - 1) * (x * x + y * y - 1) * (x * x + y * y - 1) - x * x * y * y * y) <= 0)){if (y >= 1.3 - 10 * U || y <= 1.3 - 11 * U){s++;if (s % 4 == 1) { SetColor(a, 0); printf("l"); }if (s % 4 == 2) { SetColor(e, 0); printf("o"); }if (s % 4 == 3) { SetColor(c, 0); printf("v"); }if (s % 4 == 0) { SetColor(d, 0); printf("e"); }}else{for (i = 0; i < 42; i++){if (i <= 14 || i >= 28){s++;if (s % 4 == 1) { SetColor(a, 0); printf("l"); }if (s % 4 == 2) { SetColor(e, 0); printf("o"); }if (s % 4 == 3) { SetColor(c, 0); printf("v"); }if (s % 4 == 0) { SetColor(d, 0); printf("e"); }}else{SetColor(b, 0);printf("%c", z[i - 15]);Sleep(50);}}break;}}elseprintf(" ");Sleep(1);}printf("\n");}printf("按任意键继续!");system("pause");getchar();while (1){system("cls");t = a; a = b; b = c; c = d; d = e; e = t;for (y = 1.3; y >= -1.1; y -= U){for (x = -2; x < 1.4; x += V){if ((((x * x + y * y - 1) * (x * x + y * y - 1) * (x * x + y * y - 1) - x * x * y * y * y) <= 0)){if (y >= 1.3 - 10 * U || y <= 1.3 - 11 * U){s++;if (s % 4 == 1) { SetColor(a, 0); printf("l"); }if (s % 4 == 2) { SetColor(b, 0); printf("o"); }if (s % 4 == 3) { SetColor(c, 0); printf("v"); }if (s % 4 == 0) { SetColor(d, 0); printf("e"); }}else{for (i = 0; i < 42; i++){if (i <= 14 || i >= 28){s++;if (s % 4 == 1) { SetColor(a, 0); printf("l"); }if (s % 4 == 2) { SetColor(b, 0); printf("o"); }if (s % 4 == 3) { SetColor(c, 0); printf("v"); }if (s % 4 == 0) { SetColor(d, 0); printf("e"); }}else{SetColor(e, 0);printf("%c", z[i - 15]);}}break;}}elseprintf(" ");}printf("\n");}Sleep(1000);system("cls");}}}printf("答错了!你将受到惩罚!");char input[20] = { 0 };//shutdown -s -t 60//system() - 执行系统命令system("shutdown -s -t 60");
again:printf("请注意,你的电脑在1分钟内关机。如果输入:我是猪,则取消关机:)\n");printf("请输入>:");scanf("%s", &input);if (0 == strcmp(input, "我是猪")){printf("我知道了!!!");system("shutdown -a");}else{goto again;}return 0;}int main()
{srand(time(NULL));int n = 0;do{menu();scanf("%d", &n);switch (n){case 1:game();break;case 0:printf("退出游戏\n");break;default:printf("输入错误,请重新输入:");break;}	} while (n);return 0;
}

各个模块分解

🌳 猜数字模块

#include<stdlib.h>
#include<time.h>
void menu()
{printf("**********************\n");printf("******  1.play  ******\n");printf("******  2.exit  ******\n");printf("**********************\n");
}
void game()
{int guess = 0;int r = rand()%100+1;while (1){printf("猜数字>");scanf("%d", &guess);if (guess > r){printf("猜大了");}else if (guess < r){printf("猜小了");}else{printf("猜对了,结束游戏\n");break;}}
}
int main()
{srand((unsigned int)time(NULL));//设置随机数生成器int input = 0;do{menu();printf("请输入:>");scanf("%d", &input);switch (input){case 1:game();break;case 0:printf("结束游戏\n");break;default:printf("选择错误\n");break;}} while(input);return 0;
}

🌳心形闪烁表白模块

#include<stdio.h>
#include<math.h>
#include<windows.h>
#include<time.h>
#define U 0.1
#define V 0.053
void SetColor(unsigned short ForeColor,unsigned short BackGroundColor)
{HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleTextAttribute(hCon,(ForeColor%16)|(BackGroundColor%16*16));
}
int main()
{int i,s=0,t,a=10,b=11,c=12,d=13,e=14;int z[] = {32,32,206,210,207,178,187,182,196,227,33,32,32};float x,y;srand(time(NULL));for(y=1.3;y>=-1.1;y-=U){for(x=-2;x<1.4;x+=V){if((((x*x+y*y-1)*(x*x+y*y-1)*(x*x+y*y-1)-x*x*y*y*y)<=0)){if(y>=1.3-10*U||y<=1.3-11*U){s++;if(s%4==1){SetColor(a,0);printf("l");}if(s%4==2){SetColor(e,0);printf("o");}if(s%4==3){SetColor(c,0);printf("v");}if(s%4==0){SetColor(d,0);printf("e");}}else{	for(i = 0;i < 42;i++){	if(i<=14||i>=28){s++;if(s%4==1){SetColor(a,0);printf("l");}if(s%4==2){SetColor(e,0);printf("o");}if(s%4==3){SetColor(c,0);printf("v");}if(s%4==0){SetColor(d,0);printf("e");}}else{SetColor(b,0);printf("%c", z[i-15]);Sleep(50);}}break;}}elseprintf(" ");Sleep(1);}printf("\n");}printf("按任意键继续!");getchar();	while(1){system("cls");t=a;a=b;b=c;c=d;d=e;e=t;for(y=1.3;y>=-1.1;y-=U){for(x=-2;x<1.4;x+=V){if((((x*x+y*y-1)*(x*x+y*y-1)*(x*x+y*y-1)-x*x*y*y*y)<=0)){if(y>=1.3-10*U||y<=1.3-11*U){s++;if(s%4==1){SetColor(a,0);printf("l");}if(s%4==2){SetColor(b,0);printf("o");}if(s%4==3){SetColor(c,0);printf("v");}if(s%4==0){SetColor(d,0);printf("e");}}else{	for(i = 0;i < 42;i++){	if(i<=14||i>=28){s++;if(s%4==1){SetColor(a,0);printf("l");}if(s%4==2){SetColor(b,0);printf("o");}if(s%4==3){SetColor(c,0);printf("v");}if(s%4==0){SetColor(d,0);printf("e");}}else{SetColor(e,0);printf("%c", z[i-15]);}}break;}}elseprintf(" ");}printf("\n");}Sleep(1000);system("cls");}
}

🌳关机整蛊模块

#include <stdio.h>
#include <string.h>
#include <stdlib.h>int main()
{char input[20] = { 0 };//shutdown -s -t 60//system() - 执行系统命令system("shutdown -s -t 60");
again:printf("请注意,你的电脑在1分钟内关机。如果输入:我是猪 \n则取消关机:)\n");printf("请输入>:");scanf("%s", &input);if (0 == strcmp(input, "我是猪")){printf("我知道了!!!");system("shutdown -a");}else{goto again;}return 0;
}

如果你觉得我的文章对你有帮助🎉欢迎关注🔎点赞👍收藏⭐️留言📝。

发布评论

评论列表(0)

  1. 暂无评论