這里是目錄
- 🌳 游戲介紹
- 🌳 效果圖
- 🌳 整個游戲代碼
- 各個模塊分解
- 🌳 猜數字模塊
- 🌳心形閃爍表白模塊
- 🌳關機整蠱模塊
?? :熱愛編程學習,期待一起交流!
🙏:博主水平有限,如有發現錯誤,求告知,多謝!
🌳 游戲介紹
- 此篇不涉及詳解,只是獻給有些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;
}
}
else
printf(" ");
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;
}
}
else
printf(" ");
}
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;
}
}
else
printf(" ");
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;
}
}
else
printf(" ");
}
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;
}
如果你覺得我的文章對你有幫助🎉歡迎關注🔎點贊👍收藏??留言📝,

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/349676.html
標籤:其他
上一篇:自適應控制
