首页 > C++ > C++小猫钓鱼小游戏源码免费下载

C++小猫钓鱼小游戏源码免费下载

上一篇 下一篇
用c语言写的console小游戏
#include <stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<time.h>
#include <conio.h>
 
void hidden_cursor();
void face();
void create_fish();
void gotoxy(int x,int y);
void move_fish(int x, int y);
 
int isok = 0;
int Ty = 10;
int islive = 1;
int score = 0;
int Time = 60;
int isover = 0;
int goal = 100;
DWORD WINAPI thread(LPVOID lpParameter);
DWORD WINAPI timeout(LPVOID lpParameter);
 
HANDLE h1;
HANDLE h2;
int main()
{
int num = 0;
Time = 60;
score = 0;
isover = 0;
TerminateThread(h1, 0);
system("cls");
printf("tttt小猫钓鱼nnnn1.PLAY GAMEn2.GAME HELPn3.QUIT GAMEnnnnnnPlease input number(1,2,3):"); 
scanf("%d", &num);
if(num == 1){
h1 = CreateThread(NULL,0,thread,NULL,0,NULL);
h2 = CreateThread(NULL,0,timeout,NULL,0,NULL);
system("cls");
system("title CatFishing");
system("mode con cols=80 lines=40");
srand(time(NULL));
hidden_cursor();
face();
create_fish();
}else if(num == 2){
system("cls");
printf("按空格键发射鱼钩,在规定时间内完成得分!");
system("pause");
main();
}else if(num == 3){
exit(0);
}else{
system("cls");
printf("请输入正确的选项!");
system("pause");
main();
}
main();
}
void hidden_cursor() {
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hOut,&cci);
cci.bVisible=0;
SetConsoleCursorInfo(hOut,&cci);
}
 
void face(){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED); 
printf("SCORE:ttttttTIME:nnn");
printf("t                              M     M   n");
printf("t                            /`````````\ n");
printf("t                            | &     & | n");
printf("t                            \~___O___~/ n");
printf("t                     ---------(     )、 n");
printf("t                      |       (_____)  n");
printf("t                      |       .I. .I.~~   n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~n");
printf("t                      |n");
 
 
 
}
 
void create_fish(){
int x = 70;
while(!isover){
move_fish(x, rand() % 15 + 15);
}
if(score >= goal)
{
printf("恭喜通关!");
system("pause");
return;
}
printf("GAME OVER");
system("pause");
return;
}
void gotoxy(int x,int y) {
COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
}
 
void move_fish(int x, int y){
 
int i = 0;
 
while(1){
if(isover || score >= goal) return;
isok = 1;
gotoxy(x, y);
printf(" ____n");
gotoxy(x+5, y);
printf(" ");
 
gotoxy(x, y+1);
printf("/*   \/|n");
gotoxy(x+8, y+1);
printf(" ");
 
gotoxy(x, y+2);
printf("\____/\|n");
gotoxy(x+8, y+2);
printf(" ");
 
gotoxy(10, 0);
printf("%d/%d", score, goal);
 
gotoxy(55, 0);
printf("%d", Time);
 
isok = 0;
 
Sleep(100);
x--;
if (Ty >= y && Ty <= y+2 && x <= 30 && x+8 >= 30){
for (i = 1; i < 9; i++)
{
isok = 1;
gotoxy(x+i, y);
printf(" ");
gotoxy(x+i, y+1);
printf(" ");
gotoxy(x+i, y+2);
printf(" ");
}
score+=20;
islive = 0;
isok = 0;
break;
}
if(x == 0) {
for (i = 1; i < 9; i++)
{
isok = 1;
gotoxy(x+i, y);
printf(" ");
gotoxy(x+i, y+1);
printf(" ");
gotoxy(x+i, y+2);
printf(" ");
}
isok = 0;
break;
}
}
}
DWORD WINAPI thread(LPVOID lpParameter) {
 
while(1){
if(getch() == 32)
{
while(Ty < 35){
if(isover) return;
if(isok == 0){
if (islive == 0)
break;
gotoxy(30, Ty++);
printf("|");
Sleep(100);
}
}
while(Ty > 10){
if(isover) return;
if(isok == 0){
gotoxy(30, Ty--);
printf(" ");
Sleep(100);
}
}
 
islive = 1;
}
}
}
 
DWORD WINAPI timeout(LPVOID lpParameter) {
while(--Time){
Sleep(1000);
}
if(Time == 0){
system("cls");
isover = 1;
}
}
 

模板简介:该模板名称为【C++小猫钓鱼小游戏源码免费下载】,大小是,文档格式为.,推荐使用打开,作品中的图片,文字等数据均可修改,图片请在作品中选中图片替换即可,文字修改直接点击文字修改即可,您也可以新增或修改作品中的内容,该模板来自用户分享,如有侵权行为请联系网站客服处理。欢迎来懒人模板【C++】栏目查找您需要的精美模板。

  • 下载密码 lanrenmb
  • 下载次数 15,262次
  • 使用软件
  • 文件格式
  • 文件大小
  • 上传时间 08-07
  • 作者 网友投稿
  • 肖像权 人物画像及字体仅供参考
栏目分类 更多 >
热门推荐 更多 >
自适应 单页式简历模板 微信公众平台 微信文章 微信模板 微信图片 响应式 html5 微信素材 企业网站
您可能会喜欢的其他模板