C语言简易文字冒险游戏源代码

合集下载

好玩的c语言代码

好玩的c语言代码

好玩的c语言代码C语言是一种通用过程式编程语言,可以用于开发各种类型的应用程序。

它具有跨平台、高效、灵活等特点,因此被广泛用于系统软件、嵌入式系统、游戏开发等领域。

下面我将介绍一些好玩的C语言代码示例,这些示例可以帮助初学者更好地理解和掌握C语言的基本概念和语法。

1. Hello, World!这是C语言中经典的示例程序,用于输出"Hello, World!"到屏幕上:```#include <stdio.h>int main() {printf("Hello, World!\n");return 0;}```这个示例展示了C语言的头文件引用、主函数和输出函数的使用。

2. 猜数字游戏这是一个简单的猜数字游戏,用户需要通过键盘输入猜测的数字,如果猜对则游戏结束,否则提示用户继续猜测。

```#include <stdio.h>#include <stdlib.h>#include <time.h>int main() {int target, guess, count = 0;srand(time(0));target = rand() % 100 + 1;printf("猜数游戏开始!\n");do {printf("请输入一个1到100之间的整数:");scanf("%d", &guess);count++;if (guess > target) {printf("太大了,请再试一次。

\n");} else if (guess < target) {printf("太小了,请再试一次。

\n");} else {printf("恭喜你,猜对了!你一共猜了%d次。

\n", count); }} while (guess != target);return 0;}```这个示例展示了C语言的随机数生成、循环和条件分支语句的使用。

C语言编写文字冒险游戏

C语言编写文字冒险游戏

本文将给出一个使用C语言编写的简单的文本冒险游戏的示例。

这个游戏的玩法是玩家在不同的房间中走动,并在每个房间中寻找物品。

在每个房间中,玩家可以输入命令来查看当前房间的情况、捡起物品或移动到其他房间。

首先,我们需要定义几个结构体来表示房间、物品和玩家。

struct Room {char* description;struct Room* north;struct Room* south;struct Room* east;struct Room* west;struct Item* items;};struct Item {char* description;struct Item* next;};struct Player {struct Room* current_room;struct Item* inventory;};然后我们需要定义一些函数来创建房间、物品和玩家,以及处理玩家的命令。

struct Room* create_room(char* description) {struct Room* room = malloc(sizeof(struct Room));room->description = description;room->north = NULL;room->south = NULL;room->east = NULL;room->west = NULL;room->items = NULL;return room;}struct Item* create_item(char* description) {struct Item* item = malloc(sizeof(struct Item));item->description = description;item->next = NULL;return item;}struct Player* create_player(struct Room* starting_room) {struct Player* player = malloc(sizeof(struct Player));player->current_room = starting_room;player->inventory = NULL;return player;}void free_room(struct Room* room) {// 释放房间中的物品struct Itemvoid free_room(struct Room* room) {// 释放房间中的物品struct Item* item = room->items;while (item != NULL) {struct Item* next = item->next;free(item);item = next;}// 释放房间本身free(room);}void free_item(struct Item* item) {free(item);}void free_player(struct Player* player) {// 释放玩家的物品struct Item* item = player->inventory;while (item != NULL) {struct Item* next = item->next;free(item);item = next;}// 释放玩家本身free(player);}void print_room(struct Room* room) {printf("%s\n", room->description);printf("There is a door to the north, south, east, and west.\n"); printf("There is also the following items here:\n");struct Item* item = room->items;while (item != NULL) {printf("- %s\n", item->description);item = item->next;}}void print_inventory(struct Player* player) {printf("You have the following items:\n");struct Item* item = player->inventory;while (item != NULL) {printf("- %s\n", item->description);item = item->next;}}void execute_command(struct Player* player, char* command) { if (strcmp(command, "north") == 0) {if (player->current_room->north != NULL) {player->current_room = player->current_room->north;printf("You go north.\n");} else {printf("There is no door to the north.\n");}} else if (strcmp(command, "south") == 0) {if (player->current_room->south != NULL) {player->current_room = player->current_room->south;printf("You go south.\n");} else {printf("There is no door to the south.\n");}} else if (strcmp(command, "east") == 0) {if (player->current_room->east != NULL) {player->current_room = player->current_room->east;printf("You go east.\n");} else {printf("There is no door to the east.\n");}} else if (strcmp(command, "west") == 0) {if (player->current_room->west != NULL) {player->current_room = player->current_room->west;printf("You go west.\n");}else if (strcmp(command, "west") == 0) {if (player->current_room->west != NULL) {player->current_room = player->current_room->west;printf("You go west.\n");} else {printf("There is no door to the west.\n");}} else if (strcmp(command, "look") == 0) {print_room(player->current_room);} else if (strcmp(command, "inventory") == 0) {print_inventory(player);} else if (strncmp(command, "pickup ", 7) == 0) {// 检查玩家是否正在尝试捡起房间中的物品char* item_name = command + 7;struct Item* item = player->current_room->items;while (item != NULL && strcmp(item->description, item_name) != 0) { item = item->next;}if (item == NULL) {printf("There is no item with that name in the room.\n");} else {// 从房间中删除物品if (player->current_room->items == item) {player->current_room->items = item->next;} else {struct Item* previous = player->current_room->items;while (previous->next != item) {previous = previous->next;}previous->next = item->next;}// 将物品添加到玩家的物品列表中item->next = player->inventory;player->inventory = item;printf("You pick up the %s.\n", item->description);}} else {printf("I don't understand that command.\n");}}else if (strcmp(command, "west") == 0) {if (player->current_room->west != NULL) {player->current_room = player->current_room->west;printf("You go west.\n");} else {printf("There is no door to the west.\n");}} else if (strcmp(command, "look") == 0) {print_room(player->current_room);} else if (strcmp(command, "inventory") == 0) {print_inventory(player);} else if (strncmp(command, "pickup ", 7) == 0) {// 检查玩家是否正在尝试捡起房间中的物品char* item_name = command + 7;struct Item* item = player->current_room->items;while (item != NULL && strcmp(item->description, item_name) != 0) {item = item->next;}if (item == NULL) {printf("There is no item with that name in the room.\n");} else {// 从房间中删除物品if (player->current_room->items == item) {player->current_room->items = item->next;} else {struct Item* previous = player->current_room->items;while (previous->next != item) {previous = previous->next;}previous->next = item->next;}// 将物品添加到玩家的物品列表中item->next = player->inventory;player->inventory = item;printf("You pick up the %s.\n", item->description);}} else {printf("I don't understand that command.\n");}}最后,我们可以编写一个main函数来创建房间、物品和玩家,并进入游戏循环,在每一次迭代中读取玩家输入并执行命令。

C语言小游戏源代码

C语言小游戏源代码

#incl‎u de <‎s tdio‎.h>‎#incl‎u de <‎s tdli‎b.h> ‎ /*‎使用其中的‎i nt r‎a ndom‎(int ‎a):‎产生一个在‎0到a-1‎之间的整数‎和‎r ando‎m ize(‎):复位随‎机发生器*‎/#i‎n clud‎e <co‎n io.h‎>‎/*使用其‎中的got‎o xy(i‎n t x,‎i nt y‎):把‎光标移动到‎屏幕的x(‎1~80)‎,y(1~‎25/50‎)处*/ ‎/*和c‎l rscr‎():清屏‎*/i‎n t nu‎m[]={‎1,2,3‎,4,5,‎6,7,8‎,0}; ‎ /*‎方块的数字‎*/‎m ain(‎){‎ ch‎a r ke‎y=0; ‎ /*‎键盘码*/‎‎int ‎p os; ‎ /*‎九格中,空‎格的位置*‎/‎ clr‎s cr()‎;‎/*清屏*‎/‎ ran‎d omiz‎e(); ‎ /*‎初始化随机‎发生器*/‎‎newG‎a me()‎;‎ for‎(;;){‎‎‎k ey=g‎e tch(‎); ‎/*获得‎键盘输入*‎/‎‎if(k‎e y==0‎) con‎t inue‎;‎‎pos=‎G etTh‎e Null‎(); ‎ /*得‎到空格*/‎‎‎s witc‎h(key‎){ ‎‎/*测试按‎键*/‎‎‎ cas‎e 72:‎ /‎*按下*/‎‎‎‎ if‎(pos<‎=5) c‎h ange‎(pos,‎p os+3‎);‎‎‎‎b reak‎;‎‎‎c ase ‎80: ‎ /*按‎上*/‎‎‎‎if(p‎o s>=3‎) cha‎n ge(p‎o s,po‎s-3);‎‎‎‎ br‎e ak; ‎‎‎ ca‎s e 77‎:‎/*按左*‎/‎‎‎ i‎f(pos‎%3!=0‎) cha‎n ge(p‎o s,po‎s-1);‎‎‎‎ br‎e ak; ‎‎‎ ca‎s e 75‎:‎/*按右*‎/‎‎‎ i‎f(pos‎%3!=2‎) cha‎n ge(p‎o s,po‎s+1);‎‎‎‎ br‎e ak; ‎‎‎ ca‎s e 11‎0: ‎/*按下‎‘n’新建‎游戏*/ ‎‎‎‎ new‎G ame(‎);‎‎ }‎‎ up‎d ate(‎); ‎/*更新‎*/‎‎ if(‎i sSuc‎c ess(‎)){ ‎ /*看‎是否游戏成‎功*/‎‎‎ got‎o xy(2‎6,10)‎;‎/*成功了‎,输出一个‎写有Wel‎l don‎e!的外框‎*/‎‎‎prin‎t f("\‎332\3‎04\30‎4\304‎\304\‎304\3‎04\30‎4\304‎\304\‎304\3‎04\30‎4\267‎"); ‎‎‎ got‎o xy(2‎6,11)‎;‎‎‎p rint‎f("\2‎63 ‎‎ \‎272")‎;‎‎‎g otox‎y(26,‎12); ‎‎‎ pr‎i ntf(‎"\263‎Well‎Done‎! \27‎2"); ‎‎‎ go‎t oxy(‎26,13‎);‎‎‎prin‎t f("\‎263 ‎‎‎\272"‎);‎‎‎goto‎x y(26‎,14);‎‎‎ p‎r intf‎("\32‎4\315‎\315\‎315\3‎15\31‎5\315‎\315\‎315\3‎15\31‎5\315‎\315\‎274\n‎"); ‎‎‎ get‎c h();‎‎‎ n‎e wGam‎e(); ‎ /*‎新游戏*/‎‎‎}‎‎if(k‎e y==2‎7) br‎e ak; ‎ /*‎退出*/ ‎‎}‎ clr‎s cr()‎;‎/*清屏*‎/}‎ne‎w Game‎(){ ‎ /*新‎建游戏,实‎际上就是把‎有数字的八‎个方格打散‎,这种‎效果的实现‎就是随机的‎两两交换,‎而怎么不与‎空的那个交‎换呢?‎这涉及有没‎有解的问题‎不管怎‎么样,九格‎游戏最后的‎结果只有两‎个:1‎23 | ‎123‎456 |‎456 ‎78 ‎| 87 ‎ (证‎明从略) ‎而要两两‎交换而始终‎有解的话,‎(从原序列‎开始)必须‎:相邻交换‎的次数为偶‎但我们‎用一种更有‎效的方法:‎每一个‎总与其下第‎二个交换.‎第7,‎8个与0,‎1交换,只‎要交换次数‎多,仍可获‎得相同的效‎果.而‎这些的前提‎是其中的0‎不能与其第‎奇数个作奇‎数次交换.‎为了省‎事,不处理‎0... ‎其中产道‎理,请自己‎思考*‎/‎ int‎i,a,‎b;‎ fo‎r(i=0‎;i<8;‎i++) ‎n um[i‎]=i+1‎;‎ num‎[8]=0‎;‎/*将数组‎复原*/ ‎‎f or(i‎=0;i<‎300;i‎++){ ‎‎ a‎=rand‎o m(8)‎;‎/*产生随‎机数*/ ‎‎ b‎=(a+2‎)%8; ‎ /*‎得到下第二‎个的数组下‎标*/‎‎ ch‎a nge(‎a,b);‎ /‎*交换*/‎‎}‎ up‎d ate(‎);}‎up‎d ate(‎){ ‎/*在屏‎幕上画出整‎个九格图像‎,关于定位‎的问题自己‎分析*/ ‎‎i nt i‎,j;‎ f‎o r(i=‎0;i<=‎2;i++‎){‎‎ got‎o xy(2‎4,8+i‎*3); ‎‎ f‎o r(j=‎0;j<=‎2;j++‎){‎‎‎if (‎n um[j‎+i*3]‎!=0) ‎‎‎‎ pri‎n tf("‎\332\‎304\3‎04\30‎4\304‎\267"‎); ‎‎‎else‎‎‎‎ pr‎i ntf(‎"‎ ");‎‎‎}‎‎goto‎x y(24‎,9+i*‎3);‎‎ fo‎r(j=0‎;j<=2‎;j++)‎{‎‎‎i f (n‎u m[j+‎i*3]!‎=0)‎‎‎‎prin‎t f("\‎263 %‎d \2‎72",n‎u m[j+‎i*3])‎;‎‎‎e lse ‎‎‎‎ pri‎n tf("‎‎"); ‎‎ }‎‎‎g otox‎y(24,‎10+i*‎3);‎‎ fo‎r(j=0‎;j<=2‎;j++)‎{‎‎‎i f (n‎u m[j+‎i*3]!‎=0)‎‎‎‎prin‎t f("\‎324\3‎15\31‎5\315‎\315\‎274")‎;‎‎‎e lse ‎‎‎‎ pri‎n tf("‎‎"); ‎‎ }‎‎‎p rint‎f("\n‎");‎ }‎} ‎int‎isSu‎c cess‎(){ ‎ /*判‎断是否游戏‎*/‎ in‎t i,r‎e t=1;‎‎for(‎i=0;i‎<8;i+‎+)‎‎ ret‎=ret&‎&(num‎[i]==‎(i+1)‎);‎ re‎t urn ‎r et; ‎}‎i nt G‎e tThe‎N ull(‎){ ‎/*获得‎空格的位置‎*/‎ in‎t i; ‎‎f or(i‎=0;i<‎=8;i+‎+){‎‎ if‎(num‎[i]==‎0)‎‎‎retu‎r n i;‎‎ }‎}c‎h ange‎(int ‎a,int‎b){ ‎ /*‎交换num‎[a],n‎u m[b]‎*/ ‎ in‎t tem‎p;‎ te‎m p=nu‎m[a];‎‎num[‎a]=nu‎m[b];‎‎num[‎b]=te‎m p;‎}结‎束‎。

c语言代码小游源代码

c语言代码小游源代码

c语言代码小游源代码C语言代码小游 - 用代码玩转游戏世界在计算机编程领域中,C语言是一门广泛应用于系统开发和游戏开发的编程语言。

它的特点是简洁高效,同时也因为其强大的功能而受到广大开发者的喜爱。

本文将以C语言代码小游为主题,介绍一些有趣的小游戏,并通过代码实例展示它们的实现过程。

1. 猜数字游戏猜数字游戏是一款简单而又经典的小游戏。

在游戏开始时,程序会生成一个随机数,玩家需要通过输入来猜测这个数是多少。

程序会根据玩家的猜测给出相应的提示,直到玩家猜中为止。

以下是一个简单的猜数字游戏的C语言代码实现:```c#include <stdio.h>#include <stdlib.h>#include <time.h>int main() {int number, guess, count = 0;srand(time(0));number = rand() % 100 + 1;printf("猜数字游戏开始!\n");do {printf("请输入一个数:");scanf("%d", &guess);count++;if (guess > number) {printf("太大了!\n");} else if (guess < number) {printf("太小了!\n");} else {printf("恭喜你,猜对了!你用了%d次猜中了答案%d。

\n", count, number);}} while (guess != number);return 0;}```2. 井字棋游戏井字棋游戏是一款经典的二人对战游戏。

在游戏开始时,程序会绘制一个3x3的棋盘,玩家轮流在棋盘上放置自己的棋子,先连成一条线的玩家获胜。

以下是一个简单的井字棋游戏的C语言代码实现:```c#include <stdio.h>char board[3][3] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};void drawBoard() {printf(" %c | %c | %c \n", board[0][0], board[0][1], board[0][2]);printf("---+---+---\n");printf(" %c | %c | %c \n", board[1][0], board[1][1], board[1][2]);printf("---+---+---\n");printf(" %c | %c | %c \n", board[2][0], board[2][1], board[2][2]);}int checkWin() {for (int i = 0; i < 3; i++) {if (board[i][0] == board[i][1] && board[i][1] ==board[i][2] && board[i][0] != ' ') {return 1;}if (board[0][i] == board[1][i] && board[1][i] == board[2][i] && board[0][i] != ' ') {return 1;}}if (board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[0][0] != ' ') {return 1;}if (board[0][2] == board[1][1] && board[1][1] == board[2][0] && board[0][2] != ' ') {return 1;}return 0;}int main() {int row, col, player = 1;printf("井字棋游戏开始!\n");do {drawBoard();if (player % 2 == 1) {printf("轮到玩家1(X)下棋:");} else {printf("轮到玩家2(O)下棋:");}scanf("%d %d", &row, &col);if (board[row][col] == ' ') {if (player % 2 == 1) {board[row][col] = 'X';} else {board[row][col] = 'O';}player++;} else {printf("该位置已经被占用,请重新选择!\n"); }} while (!checkWin() && player <= 9);drawBoard();if (checkWin()) {if (player % 2 == 1) {printf("恭喜玩家2(O)获胜!\n");} else {printf("恭喜玩家1(X)获胜!\n");}} else {printf("游戏结束,平局!\n");}return 0;}```通过以上两个简单的C语言代码小游戏,我们可以看到C语言的强大之处。

C语言游戏源代码完整版

C语言游戏源代码完整版

C语言游戏源代码标准化管理处编码[BBX968T-XBB8968-NNJ668-MM9N]C语言游戏源代码1、简单的开机密码程序#include ""#include ""#include ""void error(){window(12,10,68,10);textbackground(15);textcolor(132);clrscr();cprintf("file or system error! you can't enter the system!!!");while(1); /*若有错误不能通过程序*/}void look(){FILE *fauto,*fbak;char *pass="c:\\windows\\"; /*本程序的位置*/char a[25],ch;char *au="",*bname="hecfback.^^^"; /*bname 是的备份*/setdisk(2); /*set currently disk c:*/chdir("\\"); /*set currently directory \*/fauto=fopen(au,"r+");if (fauto==NULL){fauto=fopen(au,"w+");if (fauto==NULL) error();}fread(a,23,1,fauto); /*读取前23各字符*/a[23]='\0';if (strcmp(a,pass)==0) /*若读取的和pass指针一样就关闭文件,不然就添加*/ fclose(fauto);else{fbak=fopen(bname,"w+");if (fbak==NULL) error();fwrite(pass,23,1,fbak);fputc('\n',fbak);rewind(fauto);while(!feof(fauto)){ch=fgetc(fauto);fputc(ch,fbak);}rewind(fauto);rewind(fbak);while(!feof(fbak)){ch=fgetc(fbak);fputc(ch,fauto);}fclose(fauto);fclose(fbak);remove(bname); /*del bname file*/ }}void pass(){char *password="";char input[60];int n;while(1){window(1,1,80,25);textbackground(0);textcolor(15);clrscr();n=0;window(20,12,60,12);textbackground(1);textcolor(15);clrscr();cprintf("password:");while(1){input[n]=getch();if (n>58) {putchar(7); break;} /*若字符多于58个字符就结束本次输入*/if (input[n]==13) break;if (input[n]>=32 && input[n]<=122) /*若字符是数字或字母才算数*/ {putchar('*');n++;}if (input[n]==8) /*删除键*/if (n>0){cprintf("\b \b");input[n]='\0';n--;}}input[n]='\0';if (strcmp(password,input)==0)break;else{putchar(7);window(30,14,50,14);textbackground(15);textcolor(132);clrscr();cprintf("password error!");getch();}}}main(){look();pass();}2、彩色贪吃蛇#include <>#include <>#define N 200#define up 0x4800#define down 0x5000#define left 0x4b00#define right 0x4d00#define esc 0x011b#define Y 0x1579#define n 0x316eint gamespeed; /* 游戏速度 */int i, key, color;int score = 0; /* 游戏分数 */char cai48H[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0E, 0x00,0x1C, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x20, 0x00, 0x38, 0x00, 0x00, 0x00, 0x40, 0x00, 0x78, 0x00, 0x00, 0x01, 0x80, 0x40, 0x70, 0x00, 0x00, 0x03, 0x80, 0xC0, 0xE0, 0x00, 0x00, 0x07, 0x80, 0x80, 0xC0, 0x00, 0x00, 0x0E, 0x11, 0x81, 0xC0, 0x00, 0x00, 0x08, 0x61, 0x01, 0x80, 0x00, 0x00, 0x00, 0x23, 0x03, 0x04, 0x00, 0x00, 0x02, 0x02, 0x00, 0x06, 0x00, 0x00, 0x1E, 0x04, 0x00, 0x0F, 0x00, 0x00, 0x1C, 0x1F, 0x80, 0x1E, 0x00, 0x00, 0x08, 0x3F, 0x80, 0x3C, 0x00, 0x00, 0x00, 0xFF, 0x80, 0x38, 0x00, 0x00, 0x03, 0xFF, 0x80, 0x78, 0x00, 0x00, 0x0F, 0xF8, 0x00, 0xF0, 0x00, 0x00, 0x7F, 0xF0, 0x00, 0xE0, 0x00, 0x03, 0xFF, 0xFC, 0x01, 0x80, 0x00, 0x03, 0xC0, 0xFF, 0x01, 0x03, 0x80, 0x01, 0x01, 0xFF, 0x00, 0x03, 0x80, 0x00, 0x01, 0x3F, 0x00, 0x07, 0x80,0x00, 0x02, 0x11, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0E, 0x00, 0x00, 0x08, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x30, 0x10, 0x00, 0x18, 0x00, 0x00, 0x70, 0x10, 0x00, 0x30, 0x00, 0x01, 0xE0, 0x10, 0x00, 0x70, 0x00, 0x03, 0x80, 0x10, 0x00, 0x60, 0x00, 0x00, 0x00, 0x30, 0x00, 0xE0, 0x00, 0x00, 0x00, 0xF0, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x70, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x10, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };char she48H[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x02, 0x00, 0x07, 0x86, 0x00, 0x00, 0x02, 0x00, 0x18, 0x03, 0x00, 0x00, 0x02, 0x00, 0x00, 0x07, 0x80, 0x00, 0x03,0x0C, 0x00, 0x00, 0x7E, 0x3F, 0x80, 0x00, 0x00, 0x01, 0xFE, 0x1F, 0x80, 0x00, 0x00, 0x01, 0xE2, 0x39, 0x8C, 0x00, 0x00, 0x00, 0xC2, 0x30, 0x08, 0x00, 0x00, 0x00, 0xC2, 0x60, 0x08, 0x00, 0x00, 0x00, 0xC3, 0xE0, 0x08, 0x60, 0x00, 0x00, 0x7F, 0xE0, 0x01, 0xE0, 0x00, 0x00, 0x3F, 0x80, 0x1F, 0xE0, 0x00, 0x00, 0x1E, 0x00, 0x1F, 0x80, 0x00, 0x00, 0x1E, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x02, 0x38, 0x1E, 0x00, 0x00, 0x00, 0x07, 0xFC, 0x1C, 0x00, 0x20, 0x00, 0x07, 0xFC, 0x18, 0x00, 0x20, 0x00, 0x1F, 0x0C, 0x10, 0x00, 0x20, 0x00, 0x7C, 0x04, 0x10, 0x00, 0x60, 0x01, 0xF0, 0x00, 0x10, 0x00, 0x60, 0x01, 0xE0, 0x00, 0x08, 0x00, 0xF0, 0x00, 0x80, 0x00, 0x08, 0x03, 0xF0, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x07,0x00, 0x00, 0x00, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };char tun48H[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00,0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF8, 0x00, 0x40, 0x00, 0x00, 0x00, 0x06, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x7F, 0xF8, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x1F, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x0F, 0xF8, 0x0E, 0x00, 0x00, 0x00, 0x04, 0x70, 0x07, 0x00, 0x00, 0x00, 0x00, 0x60, 0x03, 0x80, 0x00, 0x00, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0x00, 0x01, 0x80, 0x00, 0x30, 0x00, 0x00, 0x01, 0x00, 0x3C, 0x18, 0x00, 0x00, 0x02, 0x03, 0xFF, 0x0C, 0x00, 0x00, 0x0C,0x7F, 0xFF, 0x8E, 0x00, 0x00, 0x18, 0xFF, 0xFF, 0xC7, 0x80, 0x00, 0x78, 0xFE, 0x07, 0x87, 0xE0, 0x01, 0xF0, 0x70, 0x07, 0x03, 0xF8, 0x07, 0xE0, 0x70, 0x0E, 0x03, 0xFE, 0x00, 0x00, 0x38, 0x1E, 0x01, 0xFE, 0x00, 0x00, 0x3F, 0xFE, 0x00, 0x0C, 0x00, 0x00, 0x1F, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };char dan48H[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xC0, 0x80, 0x00, 0x00, 0x03, 0xFF, 0x80, 0x40, 0x00, 0x00, 0x01, 0xF1, 0x80, 0x40, 0x00, 0x00, 0x01, 0x81, 0x80, 0xE0, 0x00, 0x00, 0x00, 0x01, 0x93, 0xF0, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x21, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x21, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x61, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x61, 0x80, 0x00, 0x00, 0x00, 0x00, 0xF3, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xC0, 0x00, 0x00,0x00, 0xFC, 0x00, 0x00, 0x00, 0x04, 0x02, 0x1F, 0x00, 0x00, 0x00, 0x08, 0x03, 0x01, 0xC0, 0x00, 0x00, 0x38, 0x03, 0x00, 0x7C, 0x00, 0x00, 0xF8, 0x07, 0xF8, 0x3F, 0xC0, 0x01, 0xF0, 0x3F, 0xFE, 0x3F, 0xF8, 0x03, 0xC1, 0xFF, 0x0F, 0x1F, 0xF8, 0x00, 0x01, 0xE3, 0x0F, 0x0F, 0xF0, 0x00, 0x01, 0xC3, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x83, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xC7, 0xF8, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x03, 0x80, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xF8, 0x20, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x07, 0xFF, 0x81, 0xE0, 0x00, 0x00, 0x07, 0xE0, 0x00, 0xE0, 0x00, 0x00, 0x03,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };char zuo16H[] ={0x18, 0xC0, 0x18, 0xC0, 0x19, 0x80, 0x31, 0xFE, 0x33, 0xFE, 0x76, 0xC0, 0xF0, 0xFC, 0xB0, 0xFC, 0x30, 0xC0, 0x30, 0xC0, 0x30, 0xFE, 0x30, 0xFE, 0x30, 0xC0, 0x30, 0xC0, 0x30, 0xC0, 0x00, 0x00, };char zhe16H[] ={0x03, 0x30, 0xFF, 0xFE, 0xFF, 0xFE, 0x03, 0x00, 0x0F, 0xF8, 0x3F, 0xF8, 0xEC, 0x18, 0xCF, 0xF8, 0x0C, 0x18, 0x0F, 0xF8, 0x0F, 0xF8, 0x00, 0x00, };char tian16H[] ={0x00, 0x00, 0x3F, 0xFC, 0x3F, 0xFC, 0x31, 0x8C, 0x31, 0x8C, 0x31, 0x8C, 0x3F, 0xFC, 0x3F, 0xFC, 0x31, 0x8C, 0x31, 0x8C, 0x31, 0x8C, 0x3F, 0xFC, 0x3F, 0xFC, 0x30, 0x0C, 0x00, 0x00, 0x00, 0x00, };char xue16H[] ={0x33, 0x18, 0x19, 0x98, 0x08, 0xB0, 0x7F, 0xFC, 0x7F, 0xFC, 0x60, 0x0C, 0x1F, 0xF0, 0x1F, 0xF0, 0x00, 0xC0, 0x7F, 0xFC, 0x7F, 0xFC, 0x01, 0x80, 0x01, 0x80, 0x07, 0x80, 0x03, 0x00, 0x00, 0x00, };char ke16H[] ={0x00, 0x00, 0x0C, 0x18, 0xFD, 0x98, 0xF8, 0xD8, 0x18, 0x58, 0xFE, 0x18, 0xFE, 0x98, 0x18, 0xD8, 0x3C, 0x58, 0x7E, 0x1E, 0xDB, 0xFE, 0x9B, 0xF8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, };struct Food/*定义结构体存储食物的属性*/{int x; /* 食物的坐标 */int y;int yes; /* 值为0表示屏幕上没有食物,值为1表示屏幕上有食物 */ int color; /* 食物颜色 */} food;struct Snake/*定义结构体存储蛇的属性*/{int x[N]; /* 每一节蛇的坐标 */int y[N];int color[N];/*存储每一节蛇的颜色*/int node; /* 蛇的节数 */int direction; /* 蛇移动的方向 */int life; /* 蛇的生命,如果为1,蛇死,游戏结束 */} snake;void init(void)/*图形驱动*/{int driver = DETECT, mode = 0;registerbgidriver(EGAVGA_driver);initgraph(&driver, &mode, "");}void drawmat(char *mat, int matsize, int x, int y, int color) /*汉字点阵*/{int i, j, k, m;m = (matsize - 1) / 8 + 1;for(j = 0; j < matsize; j++)for(i = 0; i < m; i++)for(k = 0; k < 8; k++)if(mat[j*m+i]&(0x80 >> k))putpixel(x + i * 8 + k, y + j, color);}void showword(void){/* 调用汉字点阵输出程序,显示标题和作者信息 */ drawmat(cai48H, 48, 249, -4, 7);drawmat(she48H, 48, 329, -4, 7);drawmat(tun48H, 48, 409, -4, 7);drawmat(dan48H, 48, 489, -4, 7);drawmat(cai48H, 48, 250, -5, 4);drawmat(she48H, 48, 330, -5, 4);drawmat(tun48H, 48, 410, -5, 4);drawmat(dan48H, 48, 490, -5, 4);/*作者田学科*/drawmat(zuo16H, 16, 515, 465, 7);drawmat(zhe16H, 16, 530, 465, 7);drawmat(tian16H, 16, 550, 465, 7); drawmat(xue16H, 16, 565, 465, 7); drawmat(ke16H, 16, 580, 465, 7); }void draw(void)/*画出四周的墙*/ {if(color == 15)color = 0;setcolor(++color);setlinestyle(SOLID_LINE, 0, 1);for(i = 30; i <= 600; i += 10){rectangle(i, 40, i + 10, 49);rectangle(i, 451, i + 10, 460); }for(i = 40; i < 450; i += 10){rectangle(30, i, 39, i + 10);rectangle(601, i, 610, i + 10); }}void prscore(void){/* 打印游戏分数 */char str[10];setfillstyle(SOLID_FILL, YELLOW); bar(50, 10, 200, 30);settextstyle(0, 0, 2);sprintf(str, "score:%d", score);outtextxy(55, 15, str);}void gameover(void){cleardevice(); /* 清屏函数 */for(i = 0; i < ; i++) /* 画出蛇死时的位置 */ {setcolor[i]);rectangle[i], [i], [i] + 10, [i] + 10);}prscore(); /* 显示分数 */draw();settextstyle(0, 0, 6);setcolor(7);outtextxy(103, 203, "GAME OVER");setcolor(RED);outtextxy(100, 200, "GAME OVER");}void gameplay(void)/* 玩游戏的具体过程 */ {int flag, flag1;randomize();prscore();gamespeed = 50000;= 0; /* =0表示屏幕上没有食物 */= 1; /* =1表示蛇是活着的 */= 4; /* 表示蛇的初始方向为向右 */ = 2; /* 蛇的初始化为两节 */[0] = 2; /*两节蛇头初始化为绿色*/[1] = 2;[0] = 100;[0] = 100;[1] = 110;[1] = 100;= random(15) + 1;while(1){while(1){if == 0) /* 如果蛇活着 */{while(1){flag = 1;= 1;= random(56) * 10 + 40; = random(40) * 10 + 50; for(i = 0; i < ; i++){if == [i] && == [i])flag = 0;}if(flag) break;}}if{setcolor;rectangle, , + 10, + 10); }for(i = - 1; i > 0; i--) {[i] = [i-1];[i] = [i-1];}switch{case 1:[0] -= 10;break;case 2:[0] += 10;break;case 3:[0] -= 10;break;case 4:[0] += 10;break;}for(i = 3; i < ; i++){if[i] == [0] && [i] == [0]) {gameover();= 0;break;}}if[0] < 40 || [0] > 590 || [0] < 50 || [0] > 440) {gameover();= 0;}if == 0)break;if[0] == && [0] == /*蛇吃掉食物*/{setcolor(0);rectangle, , + 10, + 10);[] = -20;[] = -20;[] = ;++;= 0;= random(15) + 1;score += 10;prscore();if(score % 100 == 0 && score != 0){for(i = 0; i < ; i++) /* 画出蛇 */{setcolor[i]);rectangle[i], [i], [i] + 10, [i] + 10); }sound(200);delay(50000);delay(50000);delay(50000);delay(50000);delay(50000);delay(50000);nosound();gamespeed -= 5000; draw();}else{sound(500);delay(500);nosound();}for(i = 0; i < ; i++) /* 画出蛇 */{setcolor[i]);rectangle[i], [i], [i] + 10, [i] + 10);}delay(gamespeed);delay(gamespeed);flag1 = 1;setcolor(0);rectangle[], [],[] + 10, [] + 10);if(kbhit() && flag1 == 1) /*如果没按有效键就重新开始循环*/flag1 = 0;key = bioskey(0);if(key == esc)exit(0);else if(key == up && != 2)= 1;else if(key == down && != 1)= 2;else if(key == left && != 4)= 3;else if(key == right && != 3)= 4;}}if == 0) /*如果蛇死了就退出循环*/break;}}void main(void){while(1){color = 0;init();cleardevice();showword();draw();gameplay();setcolor(15);settextstyle(0, 0, 2);outtextxy(200, 400, "CONTINUE(Y/N)");while(1){key = bioskey(0);if(key == Y || key == n || key == esc)break;}if(key == n || key == esc)break;}closegraph();}3、c语言实现移动电话系统#include <>#define GRID-SIZE 5#define SELECTED -1 /*低于矩阵中所有元素*/#define TRAFFIC-FILE “”/*关于交通数据的文件*/#define NUM-TRANSMITTERS 10 /*可用的发射器数量*/void get-traffic-data(int commuters[GRID-SIZE][GRID-SIZE],int salesforce[GRID-SIZE][GRID-SIZE],int weekends [GRID-SIZE][GRID-SIZE];voide print-matrix[GRID-SIZE][GRID-SIZE];intmain(void){int commuters[GRID-SIZE][GRID-SIZE];/*上午8:30的交通数据*/int salesforce[GRID-SIZE][GRID-SIZE]; /*上午11:00的交通数据*/ int weekend[GRID-SIZE][GRID-SIZE];/*周末交通数据*/int commuter-weight, /*通勤人员数据的权重因子*/sale-weight,/*营销人员数据的权重因子*/weekend-weight; /*周末数据的权重因子*/int location-i, /*每个发射器的位置*/location-j;int current-max; /*和数据中当前的最大值*/int i,j, /*矩阵的循环计数器*/tr; /*发射器的循环计数器*//*填入并显示交通数据*/Get-traffic-data (commuters,salesforce,weekend);Printf(“8:30 TRAFFIC DATA 、\n\n”)print-matrix(commuters);printf(“\n\n WEEKEND TRAFFIC DATA\n\n”);print-matrix(salesforce);printf(“\n\n WEEKEND TRAFFIC DATA\n\n”);printf_matrix(weekeng);/*请用户输入权重因子*/printf(“\n\nPlease input the following value:\n”);printf(“Weight (an interger>=0) for the 8:30 data>”)scanf(“%d”,&commuter_weight);printf(“weight(an integer>=0) for the weekeng data>”);scanf(“%d”,&weekend_weight);scanf(“%d”,&weekend_weight);/*计算并显示加权后求和的数据*/for (i=0;i<GRID_SIZE;++i)for (j=0;j<GRID_SIZE;++j)summed_data[i][j]=commuter_weight*commuter[i][j]+salesforce_weight*salesforce[i][j]+weekend_weight*weekend[i][j];printf(“\n\nThe weighted,summed data is :\n\n”);printf_matrix(summed_data);/*在summed_data矩阵中找出NUM_TRANSMITTERS个最大值,将坐标临时存储在location_i和location_j中,然后把最后的结果坐标输出*/printf(“\n\nLocations of the %d transmitters:\n\n”,NUM_TRANSMITTERS);for (tr=1;tr<=NUM_TRANSMITTERS;++tr){current_max=SELECTED;/*以一个过低的值为起点开始查找*/for (i=0;i<GRID_SIZE;++i){for(j=0;j<GRID_SIZE;++j){if(current_max<summed_data[i][j]){current_max=summed_data[i][j]){location_i=i;location_j=j;}}}/*将选中的单元赋一较低的值以避免下次再选中这一元素,显示查找结果*/ summed_data[location_i][location_j]=SELECTED;printf(“Transmitter %3d:at location %3d %3d\n”,tr,location_i,location_j);return (0);}/**把 TRAFFIC_FILE中的交通数据填充到3个GRID_SIZE×GRID_SIZE数组中*/voidget_traffic_data(int commuters[GRID_SIZE],/*输出*/int salesforce[GRID_SIZE][GRID_SIZE],/*输出*/int weekend[GRID_SIZE][GRID_SIZE],/*输出*/{int i,j; /*循环计数器*/FILE *fp; /*文件指针*/fq=fopen(TRAFFIC_FILE,“r”);for(i=0;i<GRID_SIZE;++i)fscanf(fp,“%d”,&commnters[i][j];for(i=0;i<GRID_SIZE;++j)for(j=0;j<GRID_SIZE;++j)fscanf(fq,“%d”,&weekend[i][j]);fclose(fq);}/**显示一个GRID_SIZE×GRID_SIZE整数矩阵的内容*/voidprint_matrix(int matrix[GRID_SIZE][GRID_SIZE]) {int i,j; /*循环计数器*/{ for(j=0;j<GRID_SIZE;++J)printf(“%3d”,matrix[i][j]);printf(“\n”);}}4、扑克牌游戏/*************************************Copyright(C) 2004-2005 vision,math,NJU.File Name:Author: vision Version: Data: 23-2-2004Description: 给你9张牌,然后让你在心中记住那张牌,然后电脑分组让你猜你记住的牌在第几组,然后猜出你记住的那张牌.Other: 出自儿童时的一个小魔术History:修改历史**************************************/#include <>#include <>#include <>#include <>#include <>#define CARDSIZE 52 /*牌的总张数*/#define SUITSIZE 13 /*一色牌的张数*//*扑克牌结构*/typedef struct Card{char val;/*扑克牌面上的大小*/int kind :4; /*扑克牌的花色*/}Card;/************************************************* Function:Calls: al = "ATJQK"[]; /*把余数给*/cards[deckp].kind = "3456"[]; /*把商给*/}}/*show的原代码,将会自动换行*/void show(const Card *cards, int size){for(int i = 0; i < size; i++){printf("%c%c ",cards[i].kind,cards[i].val);if( (i !=0) && (((i+1 ) % 3) == 0))puts("");}puts(""); /*自动换行*/}/*grouping 的原代码*/void grouping(const Card *cards, Card *carr1, Card *carr2, Card *carr3) {int i = 0;/*循环参数*//*分给carr1三个数*/while (i < 3){carr1[i].val = cards[i].val;carr1[i].kind = cards[i].kind; i++;}/*分给carr2接下来的三个数*/ while (i < 6){carr2[i-3].val = cards[i].val; carr2[i-3].kind = cards[i].kind; i++;}/*分给carr3接下来的三个数*/while (i < 9){carr3[i-6].val = cards[i].val;carr3[i-6].kind = cards[i].kind;i++;}}/*rshift的实现*/void rshift(Card *carr1, Card *carr2, Card *carr3, int counter) {Card temp2;/*用于存放carr2[counter]*/Card temp3;/*用于存放carr3[counter]*//*temp = carr2*/= carr2[counter].val;= carr2[counter].kind;/*carr2 = carr1*/carr2[counter].val = carr1[counter].val;carr2[counter].kind = carr1[counter].kind;/*temp3 = carr3*/= carr3[counter].val;= carr3[counter].kind;/*carr3 = carr2*/carr3[counter].val = ;carr3[counter].kind = ;/*carr1 = carr3*/carr1[counter].val = ;carr1[counter].kind = ;}Card* result_process(Card *carr1, Card *carr2, Card *carr3, int counter)。

用C语言编写的Tic-Tac-Toe游戏源代码(井字过三关)

用C语言编写的Tic-Tac-Toe游戏源代码(井字过三关)

board[row][colume] = (player == 1) ? 'X' :'O'; //Check for a winning line - diagonals first if((board[0][0]==board[1][1] && board[0][0]==board[2][2]) || (board[0][2]==board[1][1] && board[0][2]==board[2][0])) winner = player; else { //Check rows and columes for a winning line for(unsigned int line = 0; line <= 2; ++line) { if((board[linቤተ መጻሕፍቲ ባይዱ][0]==board[line][1] && board[line][0]==board[line][2]) || (board[0][line]==board[1][line] && board[0][line]==board[2][line])) winner = player; } } } //Game is over so display the final board printf("\n"); printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]); printf("---+---+---\n"); printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]); printf("---+---+---\n"); printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]); //Display result message if(winner) printf("\nCongratulations, player %d, YOU ARE THE WINNER!\n", winner); else printf("\nHow boring, it is a draw\n"); return 0; }

c语言创意printf文字输出

c语言创意printf文字输出

c语言创意printf文字输出
"探索未知世界,用C语言printf打印出你的想象力"
在C语言中,printf函数是用来输出文本的重要工具。

它可以让我们在屏幕上显示各种信息,从简单的“Hello, World!”到复杂的数据和图形。

但是,除了常规的文本输出,printf还可以用来创造出令人惊叹的艺术作品。

想象一下,你可以用printf函数在屏幕上打印出一幅绚丽多彩的太空风景,或者是一个充满奇幻色彩的幻想世界。

你可以用各种符号和字符来绘制出你脑海中的奇妙景象,让人们通过屏幕看到你的想象力。

更有趣的是,你还可以利用printf函数来创造出互动的文字游戏。

通过一系列的printf语句,你可以引导用户进入一个虚拟的冒险世界,让他们在屏幕上与你的故事互动,甚至影响故事的发展方向。

除此之外,你还可以利用printf函数来展示你的创意写作。

你可以用它来排版诗歌、散文或者小说,让你的文字在屏幕上以独特
的方式呈现,给人耳目一新的感觉。

总之,printf函数不仅仅是一个简单的文本输出工具,它还可以成为你展示创意和想象力的舞台。

利用C语言的printf函数,让你的想象力在屏幕上自由飞翔,创造出令人惊叹的艺术作品和文学作品。

打字游戏源代码

打字游戏源代码
}/* if (key) */
return (false);
}/* wordHit */
/*---------------------------------------------------------------------*/
int result(int right)
{
while (true)/* void */
{
clrscr ();
printf("please input 1-9 to choice level.choice 0 to return.\n");
level=getch();
#define false 0
/*---------------------------------------------------------------------*/
void printScreen(int level,int right,int sum,char p[yLine][xLine])/* 刷新屏幕的输出图像 */
{
int j,w;
if (sum!=full)
{
j=(rand()%(xLine-2))+1;
w=(rand()%26)+65;
p[0][j]=w;
return (++sum);
}/* if */
return (sum);
}
}
case '1' : return (true);
}
}
}
/*----------------------------------------------------------------------*/

用C和SFML编程实现打字小游戏

用C和SFML编程实现打字小游戏

用C和SFML编程实现打字小游戏打字小游戏是一种能够提高打字速度和准确性的娱乐方式。

本文将介绍如何使用C语言和SFML库编程实现一个简单的打字小游戏,并提供一份基本的代码框架供参考。

1. 准备工作在正式开始编程之前,需要确保你已经安装了C语言的开发环境和SFML库。

如果没有安装,可以自行搜索并按照官方指引进行安装。

2. 创建窗口使用SFML库中的函数,我们可以轻松地创建一个窗口来运行我们的小游戏。

以下是一个简单的代码示例:```c#include <SFML/Graphics.h>int main() {sfRenderWindow* window;sfVideoMode mode = {800, 600, 32};sfEvent event;window = sfRenderWindow_create(mode, "Typing Game", sfDefaultStyle, NULL);sfRenderWindow_setFramerateLimit(window, 60);while (sfRenderWindow_isOpen(window)) {while (sfRenderWindow_pollEvent(window, &event)) {if (event.type == sfEvtClosed)sfRenderWindow_close(window);}sfRenderWindow_clear(window, sfBlack);// 在这里添加游戏逻辑sfRenderWindow_display(window);}sfRenderWindow_destroy(window);return 0;}```上述代码创建了一个800x600的窗口,并在每秒钟刷新60次。

其中的`// 在这里添加游戏逻辑`注释表示我们可以在此处编写游戏逻辑。

3. 绘制文本为了显示打字游戏中的文本,我们首先需要创建一个文本对象,并设置其字体、大小和位置。

自己写的打字游戏的源代码

自己写的打字游戏的源代码

自己写的打字游戏的源代码1/*2 * 代码的目标:写一个打字游戏。

3 * 描述如下:4 *1、每隔0.5秒产生一个气球,气球的颜色、位置和里面的字母都是随机的。

5 *2、气球会往屏幕下方沉淀。

如果沉到最下面的一条线,则气球消失6 *3、如果玩家在圆圈还没有沉淀到最下方时,正确的按键。

则气球爆炸消失。

玩家得分+17 *4、一局游戏的时间是30秒,30秒之后显示最终击中的气球的比例。

并停止游戏8 *5、空格键可以暂停和继续游戏9 */1011package Game_1;71e.printStackTrace();72}73}7475public void makeBubble()76{77//这个x是最初bubble的x坐标78int x=(int) (Math.random()*750); 79bubble=new Bubble(x,0,3);80vectorbubble.add(bubble);81Thread threadbubble=new Thread(bubble);82threadbubble.start();83}8485public void paint(Graphics g)86{87super.paint(g);8889//画一条下界线90g.setColor(Color.BLACK);91g.drawLine(0, 500, 800, 500);9293//画一个魔法球94g.setColor(Color.red);95g.fillArc(390, 520, 40, 40,360,360);9697this.drawBomb(bomb, g);9899//在右上角写出得分100g.setColor(Color.black);101g.setFont(new Font("华文新魏",Font.BOLD,20)); 102g.drawString("总数:", 710, 40);103g.drawString(Bubble.totalNumber+"", 760, 40); 104105g.drawString("得分:", 710, 80);106g.drawString(Recorder.achievement+"", 760, 80); 107108109for(int i=0;i<vectorbubble.size();i++)< p="">110{111bubble=vectorbubble.get(i);112if(bubble.isLive==true)113{114this.drawBubbleAndLetter(bubble.x, bubble.y, bubble.color, bubble.letter, g);115}else116{117vectorbubble.remove(bubble);118}119}120}121122//画出炸弹123public void drawBomb(Bomb bomb, Graphics g)124{125for(int i=0;i<vectorbomb.size();i++)< p="">126{127bomb = vectorbomb.get(i);128if (bomb.life > 8) {129g.drawImage(image1, bomb.x, bomb.y, 30, 30, this);247} 248} 249 250}252@Override253public void keyReleased(KeyEvent e) { 254 255}256257@Override258public void keyTyped(KeyEvent arg0) { 259 260}261}26261this.speed = speed;6263rd = new Random();64letter = A_Z[rd.nextInt(25)];65color = colors[rd.nextInt(12)];66}6768public void moveDown() {69y += speed;70}7172@Override73public void run() {7475while (true) {76try {77Thread.sleep(30);78} catch (InterruptedException e) {79// TODO Auto-generated catch block 80e.printStackTrace(); 81}82this.moveDown();8384// 当bubble越过下界线,则isLive=false85if (this.y > 500) {86this.isLive = false;87}88}89}90}</vectorbomb.size();i++)<> </vectorbubble.size();i++)<>。

纯c语言编写的打字游戏代码

纯c语言编写的打字游戏代码

xx信息科技大学软件工程1301SHERO组#include <stdlib.h>#include <stdio.h>#include <process.h>#include <conio.h>#include <time.h>void func();void fun();void fu();int k=0,num;void main(){int choice,choice1 ;float result;system("color 5A");printf("开始游戏:1结束:0\n");scanf("%d",&choice);do{switch (choice){case 1:printf("请选择字母【7】数字【8】数字+字母【9】"); scanf("%d",&choice1);switch(choice1){case 7:func();break;case 8:fun();break;case 9:fu();break;}system("cls");printf("\n\n\n\n\n\n\n\n\n\n 您成功地击落%d个字母!",k); printf("\n 您有%d个字母未击落!",num-k);result=(float)k/num; printf("\n 您的准确率为%.2f!",result);break;case 0:exit(1);break;default :system("cls");printf("指令有误!请检查指令。

\n");getchar();}printf("\n\n\n\n\n\n\n继续游戏:1scanf("%d",&choice);} while(1);}/***************字母模块*****************/void func(){int a[25][80];int i,l,j,m=0,n=0,t,t1,temp,c=0;int sure,sure1=0,dif,N;do{do{system("cls");printf("\n请选择难度等级:困难:1普通:2结束:0简单:3\n");");scanf("%d",&dif);if(dif!=1&&dif!=2&&dif!=3){printf("\n指令有误,按任意键继续!"); getchar();}elsesure1=1;}while (sure1!=1);if(dif==1)N=10;if(dif==2)N=500;if(dif==3)N=2000;printf("\n请输入字母个数:");scanf("%d",&num);switch (dif){case 1: printf("\n你选择了困难等级,%d个字母进行练习。

纯C语言写的一个小型游戏 源代码

纯C语言写的一个小型游戏 源代码

/* A simple game*//*CopyRight: Guanlin*/ #include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>#include<conio.h>#include<process.h> ?struct object_fix{char name[20];char id[5];char desc[500];char action[30];char im[5];};struct object_move {char name[20];char id[5];char desc[500];int loc;int pwr;int strg;char im[5];};struct rover{char name[20];char id[5];char desc[500];int pwr;int strg;int location[2];char im[5];};struct map /* this is the map structure*/{char data[20];char add_data[20];int amount;int x; /* this were the successor keeps it's x & y values*/int y;};struct location /*this structure is for the successor lister*/{float height;char obj;};void stats_update(int selected, struct rover *p_rover){switch (selected){case 1:if(p_rover->pwr < 7)printf("\n\nYou do not have enough power to perform this action!\n\n"); else{(p_rover->pwr) -= 7;printf("You have destroyed the object!\n\n");}break;case 2:if(p_rover->pwr < 3)printf("\n\nYou do not have enough power to perform this action!\n\n");else if(p_rover->strg > 90)printf("\n\nYou do not have enough storage space for this object!\n\n");else{(p_rover->pwr) -= 3;(p_rover->strg) += 10;printf("You have collected a sample of the object!\n\n");}break;case 3:p_rover->pwr -= 10; /*Distance around object- value gained from mapper module. 1 square = -1 power*/printf("You have avoided the object!\n\n");break;case 4:p_rover->pwr -= 2;printf("You have driven through the obstacle!\n\n");break;case 5:if(p_rover->pwr == 100)printf("\n\nYou do not need to charge up!\n\n");else{p_rover->pwr = 100;printf("You have charged up your rover!\n\n");}break;default:printf("\n\n*****ERROR*****\nInvalid Selection\n\n");break;}}void action(char object, struct rover *p_rover){int selection;switch(object){case 1:printf("\nYou have encountered: A Sandy Rock\n\n");printf("This object can be:\n1.\tDestroyed\n2.\tCollected\nPlease choose action 1 or 2:\t"); scanf("%d", &selection);stats_update(selection, p_rover);break;case 2:printf("\nYou have encountered: A Solid Rock\n\n");printf("This object can be:\n1.\tAvoided\n2.\tCollected\nPlease choose action 1 or 2:\t"); scanf("%d", &selection);if (selection == 1)selection = 3;stats_update(selection, p_rover);break;case 3:printf("\nYou have encountered: A Mountain\n\n");printf("This object can be:\n1.\tAvoided\nPlease enter 1:\t");scanf("%d", &selection);selection = 3;stats_update(selection, p_rover);break;case 4:printf("\nYou have encountered: Dust\n\n");printf("This object can be:\n1.\tDriven through\n2.\tCollected\nPlease choose action 1 or 2:\t"); scanf("%d", &selection);if (selection == 1)selection = 4;stats_update(selection, p_rover);break;case 5:printf("\nYou have encountered: A Sheer Valley\n\n");printf("This object can be:\n1.\tAvoided\nPlease enter 1:\t");scanf("%d", &selection);selection = 3;stats_update(selection, p_rover);break;case 6:printf("\nYou have encountered: A Gentle Valley\n\n");printf("This object can be:\n1.\tDriven through\n2.\tAvoided\nPlease choose action 1 or 2:\t"); scanf("%d", &selection);if (selection == 1)selection = 4;if (selection == 2)selection = 3;stats_update(selection, p_rover);break;case 7:printf("\nYou have encountered: A 'Martian' Tree\n\n");printf("This object can be:\n1.\tDestroyed\n2.\tCollected\n3.\tAvoided\nPlease choose action 1, 2 or 3:\t");scanf("%d", &selection);stats_update(selection, p_rover);break;case 8:printf("\nYou have encountered: Shallow Water\n\n");printf("This object can be:\n1.\tDriven through\n2.\tCollected\n3.\tAvoided\nPlease choose action 1, 2 or 3:\t");scanf("%d", &selection);if (selection == 1)selection = 4;stats_update(selection, p_rover);break;case 9:printf("\nYou have encountered: Deep Water\n\n");printf("This object can be:\n1.\tAvoided\n2.\tCollected\nPlease choose action 1 or 2:\t");scanf("%d", &selection);if (selection == 1)selection = 3;stats_update(selection, p_rover);break;case 10:printf("\nYou have encountered: An Aggressive Alien\n\n");printf("This object can be:\n1.\tDestroyed\nPlease enter 1:\t");scanf("%d", &selection);selection = 1;stats_update(selection, p_rover);break;case 11:printf("\nYou have encountered: A Non-Aggressive Alien\n\n");printf("This object can be:\n1.\tAvoided\nPlease enter 1:\t");scanf("%d", &selection);selection = 3;stats_update(selection, p_rover);break;case 12:printf("\nYou have encountered: Another Rover\n\n");printf("This object can be:\n1.\tAvoided\nPlease enter 1:\t");scanf("%d", &selection);selection = 3;stats_update(selection, p_rover);break;case 13:printf("\nYou have encountered: A Power Station\n\n");printf("You can:\n1.\tCharge up\n2.\tAvoid\nPlease choose action 1 or 2:\t");scanf("%d", &selection);if (selection == 1)selection = 5;if (selection == 2)selection = 3;stats_update(selection, p_rover);break;default:printf("\n\n*****ERROR*****\n\n");break;}}void show_map(struct map *number, struct map *number_2, struct object_fix *rsny, struct object_fix *rsld, struct object_fix *mnt, struct object_fix *dst,struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *mtre,struct object_fix *wshl, struct object_fix *wdp, struct object_move *aagr,struct object_move *anon, struct object_move *rvr, struct object_move *pstn, struct rover*p_rover) /*the show map function calling number and number_2 from the map structure to see if moveable objects are needed*/{struct map f_map[8][8]; /*8 by 8 map*/int i,j, rx, ry, object; /*this is your x and y value in your map (f_map)*/system("cls"); /* this is your x and y value in your map (f_map)*///srand(time(NULL)); /*calling the time from include to gather random variables*/for(i=0;i<8;i++) /*for loop to copy all your fixed object lists into f_map so they can be displayed*/ {for(j=0;j<8;j++)strcpy(f_map[i][j].data,"");}if (number->amount>0) /*this is looking at the add function to see weather or not there are aliens in f_map*/{for(i=0;i<number->amount;i++) /*allocating the number of aliens in f_map*/strcpy(f_map[rand()%8][rand()%8].data, anon->im); /*randomizing their position*/}if(number_2->amount>0) /*repeat of above just for rovers instead*/{for(i=0;i<number_2->amount;i++)strcpy(f_map[rand()%8][rand()%8].data, rvr->im);}rx= p_rover->location[0];ry= p_rover->location[1];strcpy(f_map[1][0].data, wdp->im);strcpy(f_map[4][0].data, mnt->im);strcpy(f_map[5][0].data, mnt->im);strcpy(f_map[3][1].data, dst->im);strcpy(f_map[4][1].data, dst->im);strcpy(f_map[3][2].data, dst->im);strcpy(f_map[4][2].data, dst->im);strcpy(f_map[0][3].data, mnt->im);strcpy(f_map[1][3].data, mnt->im);strcpy(f_map[3][3].data, vshr->im);strcpy(f_map[4][3].data, dst->im);strcpy(f_map[5][3].data, vgnt->im);strcpy(f_map[3][4].data, vshr->im);strcpy(f_map[4][4].data, dst->im);strcpy(f_map[5][4].data, vgnt->im);strcpy(f_map[2][5].data, wshl->im);strcpy(f_map[3][5].data, wshl->im);strcpy(f_map[4][5].data, wshl->im);strcpy(f_map[1][6].data, pstn->im);strcpy(f_map[2][6].data, wdp->im);strcpy(f_map[3][6].data, wdp->im);strcpy(f_map[4][6].data, wshl->im);strcpy(f_map[7][6].data, mnt->im);strcpy(f_map[0][7].data, mnt->im);strcpy(f_map[1][7].data, wdp->im);strcpy(f_map[2][7].data, wshl->im);strcpy(f_map[3][7].data, wshl->im);strcpy(f_map[6][7].data, mnt->im);strcpy(f_map[rx][ry].data, p_rover->im);if((rx == 1 && ry == 0) || (rx == 2 && ry == 6) ||(rx == 3 && ry == 6) ||(rx == 1 && ry == 7)) {object = 9;action(object, p_rover);}else if((rx == 4 && ry == 0) || (rx == 5 && ry == 0) || (rx == 0 && ry == 3) || (rx == 1 && ry == 3) || (rx == 7 && ry == 6) || (rx == 0 && ry == 7) || (rx == 6 && ry == 7)){object = 3;action(object, p_rover);}else if((rx == 3 && ry== 1) || (rx == 4 && ry == 1) || (rx == 3 && ry== 2) || (rx == 4 && ry == 2) || (rx == 4 && ry == 3) || (rx == 4 && ry == 4)){object = 4;action(object, p_rover);}else if((rx == 3 && ry == 3) || (rx == 3 && ry == 4)){object = 5;action(object, p_rover);}else if((rx == 5 && ry == 3) || (rx == 5 && ry == 4)){object = 6;action(object, p_rover);}else if((rx == 2 && ry == 5) || (rx == 3 && ry == 5 ) || (rx == 4 && ry == 5) || (rx == 4 && ry== 6) ||(rx == 2 && ry == 7) || (rx == 3 && ry == 7)){object = 8;action(object, p_rover);}else if(rx == 1 && ry == 6){object = 13;action(object, p_rover);}i=0; /*re-allocate i to 0 so map is printed from start*/for(i=0;i<8;i++) /*8 by 8 map*/{printf("+----+----+----+----+----+----+----+----+\n");for(j=0;j<8;j++) /*8 by 8 map*/{if(strlen(f_map[i][j].data)!=0) /*if function to print nothing but 4 spaces if there in nothing allocated in [i][j]*/printf("|%4s",f_map[i][j].data);elseprintf("| "); /*end of coloumn visible map*/}printf("|\n"); /*end of last coloumn visible map*/}printf("+----+----+----+----+----+----+----+----+\n"); /*bottom of map*/printf("\n");printf("\270");printf("Group B\n");}??void add_obj(struct map *number, struct map *number_2, struct object_fix *rsny,struct object_fix *rsld, struct object_fix *mnt, struct object_fix *dst,struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *mtre,struct object_fix *wshl, struct object_fix *wdp, struct object_move *aagr,struct object_move *anon, struct object_move *rvr, struct object_move *pstn, struct rover*p_rover) /* add movable object function, *number=aliens, *number_2=rovers*/{int object, t, f;char alien;char rover;printf("This is the add movable object function\n");printf("how many aliens would you like?\n");scanf("%d",&t); /*user input of amount of aliens*/number->amount=t; /*saving the number in structure map-amount*/printf("how many rovers would you like?\n");scanf("%d",&f); /*user input of amount of rovers*/number_2->amount=f; /*saving the number in structure map-amount*/show_map(number, number_2, rsny, rsld, mnt, dst, vshr, vgnt, mtre, wshl,wdp, aagr, anon, rvr, pstn, p_rover); /*go to show map function with the number of aliens and number of rovers*/}?void successor() /*this functions askes the user for the location and then were they want to go from there, printing out that location*/{struct map location;int menu;int ncol,nrow; /*we can change the n value depends how large the map you need.*/ncol=8;nrow=8;printf("This is the successor function\n");printf("Enter the \nx=\ty=\n");scanf("%d%d",&location.x,&location.y); /*saving location in map location x and y*/printf("Enter operator choice\n");printf("1=left\n");printf("2=right\n");printf("3=upwards\n");printf("4=down\n");printf("5=quit\n");scanf("%d",&menu);switch(menu) /*menu switch to show the position above, underneith, and next to the rover*/ {case 1:location.x=location.x-1;printf("The position is [%d,%d]\n",location.x,location.y);break;?case 2:location.x=location.x+1;printf("The position is [%d,%d]\n",location.x,location.y);break;case 3:location.y=location.y-1;printf("The position is [%d,%d]\n",location.x,location.y);break;case 4:location.y=location.y+1;printf("The position is [%d,%d]\n",location.x,location.y);break;case 5:printf("*****back to program*****\n"); /* Quits the program and prints out the message */ break;default:printf("*****Please enter an integer from 1-5*****\n"); /* A default option if the user enters an incorrect value */break;}printf("\n");}?void help(struct map *number, struct map *number_2, struct object_fix *rsny,struct object_fix *rsld, struct object_fix *mnt, struct object_fix *dst,struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *mtre,struct object_fix *wshl, struct object_fix *wdp, struct object_move *aagr,struct object_move *anon, struct object_move *rvr, struct object_move *pstn, struct rover *p_rover) /*help function*/{int i;char mov_obj;printf("++This is the help function++\n");printf("| 1-successor |\n");printf("| 2-add movable obj |\n");printf("| 3-remove moveabla obj |\n\n");printf("\t* * *\n");printf("\t Index: \n\n");printf("\t Sandy Rock: *\n");printf("\t Solid Rock: o\n");printf("\t Water:\262\262\262\262 \n");printf("\t Shallow water: \260\260\260\260\n");printf("\t Mountain: ^^^^\n");printf("\t Dust: ....\n");printf("\t* sher valley: VVVV *\n");printf("\t shallow valey: vvvv\n");printf("\t power station: \025\n");printf("\t alien: *_*\n");printf("\t other rovers: #\n");printf("\t* * *\n");scanf("%d",&i);switch(i) /*switch menu to go to the successor function, or the add/remove function*/{case 1:successor();break;case 2:add_obj(number, number_2, rsny, rsld, mnt, dst, vshr,vgnt, mtre, wshl, wdp, aagr, anon, rvr, pstn, p_rover);break;case 3:add_obj(number, number_2, rsny, rsld, mnt, dst, vshr,vgnt, mtre, wshl, wdp, aagr, anon, rvr, pstn, p_rover);break;default:printf("choose a number from the list\n");}}void direction(int input, struct map *number, struct map *number_2, struct object_fix *rsny, struct object_fix *rsld, struct object_fix *mnt, struct object_fix *dst,struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *mtre,struct object_fix *wshl, struct object_fix *wdp, struct object_move *aagr,struct object_move *anon, struct object_move *rvr, struct object_move *pstn, struct rover *p_rover){switch(input){case 119: /*w = up*/if(p_rover->location[0] > 0)p_rover->location[0]--;p_rover->pwr--;}else p_rover->location[0]=7; break;case 115: /*s = down*/if(p_rover->location[0] < 7) {p_rover->location[0]++;p_rover->pwr--;}else p_rover->location[0]=0; break;case 97: /*a = left*/if(p_rover->location[1] > 0) {p_rover->location[1]--;p_rover->pwr--;}else p_rover->location[1]=7; break;case 100: /*d = right*/if(p_rover->location[1] < 7) {p_rover->location[1]++;p_rover->pwr--;}else p_rover->location[1]=0; break;default:printf("Invalid operator!\n\n"); break;}int control(int input){input = _getch();return input;}?void main(void){int menu;int quit = 0;int input = 0;struct object_fix rsny, rsld, mnt, dst, vshr, vgnt, mtre, wshl, wdp;struct object_move aagr, anon, rvr, pstn;struct rover p_rover;struct map number, number_2;number.amount = 0; /* setting the initial amount of aliens as 0*/number_2.amount = 0;strcpy(,"Sandy Rock");strcpy(rsny.id,"RSNY");strcpy(rsny.desc,"A rock made of softer material that can be destroyed or collected");strcpy(rsny.im,"*");strcpy(,"Solid Rock");strcpy(rsld.id,"RSLD");strcpy(rsld.desc,"A rock made of hard material that cannot be destroyed, but can be collected or avoided");strcpy(rsld.im,"O");strcpy(,"Mountain");strcpy(mnt.id,"MNT");strcpy(mnt.desc,"A large obstacle made of different materials that can only be avoided");strcpy(mnt.im,"^^^^");strcpy(,"Dust");strcpy(dst.id,"DST");strcpy(dst.desc,"Small particles of sand, rock, etc. that may reduce visibility or slow down the vehicle, can be driven through but has extra power consumption");strcpy(dst.im,"....");strcpy(,"Sheer Valley");strcpy(vshr.id,"VSHR");strcpy(vshr.desc,"A depression in the land with sheer sides, it cannot be driven through and must be avoided");strcpy(vshr.im,"VVVV");strcpy(,"Gentle Valley");strcpy(vgnt.id,"VGNT");strcpy(vgnt.desc,"A depression in the land with gentle sides, it can be driven through with extra power consumption or can be avoided");strcpy(vgnt.im,"vvvv");strcpy(,"'Martian' Tree");strcpy(mtre.id,"MTRE");strcpy(mtre.desc,"A woody plant native to Mars, it may have the same characteristics as an 'Earth' tree");strcpy(mtre.im,"\330");strcpy(,"Shallow Water");strcpy(wshl.id,"WSHL");strcpy(wshl.desc,"A shallow body of water that can be driven through, can be in the form of a small puddle or a large lake");strcpy(wshl.im,"\260\260\260\260");strcpy(,"Deeper Water");strcpy(wdp.id,"WDP");strcpy(wdp.desc,"A deeper body of water that cannot be driven through, commonly in the form of a large lake or river");strcpy(wdp.im,"\262\262\262\262");strcpy(,"Aggressive Alien");strcpy(aagr.id,"AAGR");strcpy(aagr.desc,"An alien creature that will move upon its own accord, may become aggressive on contact");strcpy(aagr.im,"*_*");strcpy(,"Non-Aggressive Alien");strcpy(anon.id,"ANON");strcpy(anon.desc,"An alien creature that will move upon its own accord, will not become aggressive on contact");strcpy(anon.im,"*_*");strcpy(,"Rover");strcpy(rvr.id,"RVR");strcpy(rvr.desc,"A Mars Rover vehicle to transport around the map, it can destroy, collect or avoid objects. It has a power and object storage");strcpy(rvr.im,"#");strcpy(,"Power Station");strcpy(pstn.id,"PSTN");strcpy(pstn.desc,"A movable power station that will restore power to the Mars Rovers");strcpy(pstn.im,"\025");strcpy(p_,"User Mars Rover");strcpy(p_rover.id,"URVR");strcpy(p_rover.desc,"A Mars vehicle that is controlled by the user. Explores the map collecting, destroying and avoiding objects");strcpy(p_rover.im,"<^^>");p_rover.pwr = 100;p_rover.strg = 0;p_rover.location[0] = 7;p_rover.location[1] = 0; /****************************************************/printf("*******************************START********************************\n\n"); do{ /* Object will be gained from mapper */printf("+++++++++++++++++++++++++++++++MENU+++++++++++++++++++++++ ++++++++++\n");printf("Please choose one of the following option:\n");printf("1 - Start\n");printf("2 - Controls\n");printf("3 - Show Map\n");printf("4 - Help Menu\n");printf("5 - Quit\n\n");printf("--------------->");scanf("%d", &menu);switch (menu){case 1:show_map(&number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,&vgnt, &mtre, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover);while (quit != 1 ){input = control(input);if (input == 27)quit = 1;else{if(p_rover.pwr>0){direction(input, &number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,&vgnt, &mtre, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover);show_map(&number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,&vgnt, &mtre, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover);printf("Rover stats: \nPower: %d%% \nStorage: %d%%\n", p_rover.pwr, p_rover.strg);}else{printf("*******************END GAME********************\n\n"); // ends game when charge = 0.}}}break;case 2:quit = 0;printf("\n");printf("* * *\n");printf(" Controls \n"); // menu for the keys used on the keyboard to move the rover in different directions.printf(" Up : W \n");printf(" Down : S \n");printf("* Left : A * \n");printf("* Right : D * \n");printf(" choose : Enter \n");printf("* * *\n");break;case 3:quit = 0;show_map(&number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,&vgnt, &mtre, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover);break;case 4:quit = 0;help(&number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,&vgnt, &mtre, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover);break;printf("*********************END***********************\n"); break;}}while(menu!=5);printf("\n -----Please press any key to exit game-----\n");getch();}。

纯C语言写的一个小型游戏 源代码

纯C语言写的一个小型游戏 源代码

/* A simple game*//*CopyRight: Guanlin*/ #include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>#include<conio.h>#include<process.h> ?struct object_fix{char name[20];char id[5];char desc[500];char action[30];char im[5];};struct object_move {char name[20];char id[5];char desc[500];int loc;int pwr;int strg;char im[5];};struct rover{char name[20];char id[5];char desc[500];int pwr;int strg;int location[2];char im[5];};struct map /* this is the map structure*/{char data[20];char add_data[20];int amount;int x; /* this were the successor keeps it's x & y values*/int y;};struct location /*this structure is for the successor lister*/{float height;char obj;};void stats_update(int selected, struct rover *p_rover){switch (selected){case 1:if(p_rover->pwr < 7)printf("\n\nYou do not have enough power to perform this action!\n\n"); else(p_rover->pwr) -= 7;printf("You have destroyed the object!\n\n");}break;case 2:if(p_rover->pwr < 3)printf("\n\nYou do not have enough power to perform this action!\n\n");else if(p_rover->strg > 90)printf("\n\nYou do not have enough storage space for this object!\n\n");else{(p_rover->pwr) -= 3;(p_rover->strg) += 10;printf("You have collected a sample of the object!\n\n");}break;case 3:p_rover->pwr -= 10; /*Distance around object- value gained from mapper module. 1 square = -1 power*/printf("You have avoided the object!\n\n");break;case 4:p_rover->pwr -= 2;printf("You have driven through the obstacle!\n\n");break;case 5:if(p_rover->pwr == 100)printf("\n\nYou do not need to charge up!\n\n");elsep_rover->pwr = 100;printf("You have charged up your rover!\n\n");}break;default:printf("\n\n*****ERROR*****\nInvalid Selection\n\n");break;}}void action(char object, struct rover *p_rover){int selection;switch(object){case 1:printf("\nYou have encountered: A Sandy Rock\n\n");printf("This object can be:\n1.\tDestroyed\n2.\tCollected\nPlease choose action 1 or2:\t");scanf("%d", &selection);stats_update(selection, p_rover);break;case 2:printf("\nYou have encountered: A Solid Rock\n\n");printf("This object can be:\n1.\tAvoided\n2.\tCollected\nPlease choose action 1 or 2:\t"); scanf("%d", &selection);if (selection == 1)selection = 3;stats_update(selection, p_rover);break;case 3:printf("\nYou have encountered: A Mountain\n\n");printf("This object can be:\n1.\tAvoided\nPlease enter 1:\t");scanf("%d", &selection);selection = 3;stats_update(selection, p_rover);break;case 4:printf("\nYou have encountered: Dust\n\n");printf("This object can be:\n1.\tDriven through\n2.\tCollected\nPlease choose action 1 or 2:\t");scanf("%d", &selection);if (selection == 1)selection = 4;stats_update(selection, p_rover);break;case 5:printf("\nYou have encountered: A Sheer Valley\n\n");printf("This object can be:\n1.\tAvoided\nPlease enter 1:\t");scanf("%d", &selection);selection = 3;stats_update(selection, p_rover);break;case 6:printf("\nYou have encountered: A Gentle Valley\n\n");printf("This object can be:\n1.\tDriven through\n2.\tAvoided\nPlease choose action 1 or 2:\t");scanf("%d", &selection);if (selection == 1)selection = 4;if (selection == 2)selection = 3;stats_update(selection, p_rover);break;case 7:printf("\nYou have encountered: A 'Martian' Tree\n\n");printf("This object can be:\n1.\tDestroyed\n2.\tCollected\n3.\tAvoided\nPlease choose action 1, 2 or 3:\t");scanf("%d", &selection);stats_update(selection, p_rover);break;case 8:printf("\nYou have encountered: Shallow Water\n\n");printf("This object can be:\n1.\tDriven through\n2.\tCollected\n3.\tAvoided\nPlease choose action 1, 2 or 3:\t");scanf("%d", &selection);if (selection == 1)selection = 4;stats_update(selection, p_rover);break;case 9:printf("\nYou have encountered: Deep Water\n\n");printf("This object can be:\n1.\tAvoided\n2.\tCollected\nPlease choose action 1 or 2:\t"); scanf("%d", &selection);if (selection == 1)selection = 3;stats_update(selection, p_rover);break;case 10:printf("\nYou have encountered: An Aggressive Alien\n\n");printf("This object can be:\n1.\tDestroyed\nPlease enter 1:\t");scanf("%d", &selection);selection = 1;stats_update(selection, p_rover);break;case 11:printf("\nYou have encountered: A Non-Aggressive Alien\n\n");printf("This object can be:\n1.\tAvoided\nPlease enter 1:\t");scanf("%d", &selection);selection = 3;stats_update(selection, p_rover);break;case 12:printf("\nYou have encountered: Another Rover\n\n");printf("This object can be:\n1.\tAvoided\nPlease enter 1:\t");scanf("%d", &selection);selection = 3;stats_update(selection, p_rover);break;case 13:printf("\nYou have encountered: A Power Station\n\n");printf("You can:\n1.\tCharge up\n2.\tAvoid\nPlease choose action 1 or 2:\t"); scanf("%d", &selection);if (selection == 1)selection = 5;if (selection == 2)selection = 3;stats_update(selection, p_rover);break;default:printf("\n\n*****ERROR*****\n\n");break;}}void show_map(struct map *number, struct map *number_2, struct object_fix *rsny, struct object_fix *rsld, struct object_fix *mnt, struct object_fix *dst,struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *mtre,struct object_fix *wshl, struct object_fix *wdp, struct object_move *aagr,struct object_move *anon, struct object_move *rvr, struct object_move *pstn, struct rover *p_rover) /*the show map function calling number and number_2 from the map structure to see if moveable objects are needed*/{struct map f_map[8][8]; /*8 by 8 map*/int i,j, rx, ry, object; /*this is your x and y value in your map (f_map)*/system("cls"); /* this is your x and y value in your map (f_map)*///srand(time(NULL)); /*calling the time from include to gather random variables*/for(i=0;i<8;i++) /*for loop to copy all your fixed object lists into f_map so they can be displayed*/{for(j=0;j<8;j++)strcpy(f_map[i][j].data,"");}if (number->amount>0) /*this is looking at the add function to see weather or not there are aliens in f_map*/{for(i=0;i<number->amount;i++) /*allocating the number of aliens in f_map*/strcpy(f_map[rand()%8][rand()%8].data, anon->im); /*randomizing their position*/}if(number_2->amount>0) /*repeat of above just for rovers instead*/{for(i=0;i<number_2->amount;i++)strcpy(f_map[rand()%8][rand()%8].data, rvr->im); }rx= p_rover->location[0];ry= p_rover->location[1];strcpy(f_map[1][0].data, wdp->im);strcpy(f_map[4][0].data, mnt->im);strcpy(f_map[5][0].data, mnt->im);strcpy(f_map[3][1].data, dst->im);strcpy(f_map[4][1].data, dst->im);strcpy(f_map[3][2].data, dst->im);strcpy(f_map[4][2].data, dst->im);strcpy(f_map[0][3].data, mnt->im);strcpy(f_map[1][3].data, mnt->im);strcpy(f_map[3][3].data, vshr->im);strcpy(f_map[4][3].data, dst->im);strcpy(f_map[5][3].data, vgnt->im);strcpy(f_map[3][4].data, vshr->im);strcpy(f_map[4][4].data, dst->im);strcpy(f_map[5][4].data, vgnt->im);strcpy(f_map[2][5].data, wshl->im);strcpy(f_map[3][5].data, wshl->im);strcpy(f_map[4][5].data, wshl->im);strcpy(f_map[1][6].data, pstn->im);strcpy(f_map[2][6].data, wdp->im);strcpy(f_map[3][6].data, wdp->im);strcpy(f_map[4][6].data, wshl->im);strcpy(f_map[7][6].data, mnt->im);strcpy(f_map[0][7].data, mnt->im);strcpy(f_map[1][7].data, wdp->im);strcpy(f_map[2][7].data, wshl->im);strcpy(f_map[3][7].data, wshl->im);strcpy(f_map[6][7].data, mnt->im);strcpy(f_map[rx][ry].data, p_rover->im);if((rx == 1 && ry == 0) || (rx == 2 && ry == 6) ||(rx == 3 && ry == 6) ||(rx == 1 && ry == 7)){object = 9;action(object, p_rover);}else if((rx == 4 && ry == 0) || (rx == 5 && ry == 0) || (rx == 0 && ry == 3) || (rx == 1 && ry == 3) || (rx == 7 && ry == 6) || (rx == 0 && ry == 7) || (rx == 6 && ry == 7)){object = 3;action(object, p_rover);}else if((rx == 3 && ry== 1) || (rx == 4 && ry == 1) || (rx == 3 && ry== 2) || (rx == 4 && ry == 2) || (rx == 4 && ry == 3) || (rx == 4 && ry == 4)){object = 4;action(object, p_rover);}else if((rx == 3 && ry == 3) || (rx == 3 && ry == 4)){object = 5;action(object, p_rover);else if((rx == 5 && ry == 3) || (rx == 5 && ry == 4)){object = 6;action(object, p_rover);}else if((rx == 2 && ry == 5) || (rx == 3 && ry == 5 ) || (rx == 4 && ry == 5) || (rx == 4 && ry == 6) ||(rx == 2 && ry == 7) || (rx == 3 && ry == 7)){object = 8;action(object, p_rover);}else if(rx == 1 && ry == 6){object = 13;action(object, p_rover);}i=0; /*re-allocate i to 0 so map is printed from start*/for(i=0;i<8;i++) /*8 by 8 map*/{printf("+----+----+----+----+----+----+----+----+\n");for(j=0;j<8;j++) /*8 by 8 map*/{if(strlen(f_map[i][j].data)!=0) /*if function to print nothing but 4 spaces if there in nothing allocated in [i][j]*/printf("|%4s",f_map[i][j].data);elseprintf("| "); /*end of coloumn visible map*/printf("|\n"); /*end of last coloumn visible map*/}printf("+----+----+----+----+----+----+----+----+\n"); /*bottom of map*/printf("\n");printf("\270");printf("Group B\n");}??void add_obj(struct map *number, struct map *number_2, struct object_fix *rsny, struct object_fix *rsld, struct object_fix *mnt, struct object_fix *dst,struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *mtre,struct object_fix *wshl, struct object_fix *wdp, struct object_move *aagr,struct object_move *anon, struct object_move *rvr, struct object_move *pstn, struct rover *p_rover) /* add movable object function, *number=aliens, *number_2=rovers*/ {int object, t, f;char alien;char rover;printf("This is the add movable object function\n");printf("how many aliens would you like?\n");scanf("%d",&t); /*user input of amount of aliens*/number->amount=t; /*saving the number in structure map-amount*/printf("how many rovers would you like?\n");scanf("%d",&f); /*user input of amount of rovers*/number_2->amount=f; /*saving the number in structure map-amount*/show_map(number, number_2, rsny, rsld, mnt, dst, vshr, vgnt, mtre, wshl,wdp, aagr, anon, rvr, pstn, p_rover); /*go to show map function with the number of aliens and number of rovers*/}?void successor() /*this functions askes the user for the location and then were they want to go from there, printing out that location*/{struct map location;int menu;int ncol,nrow; /*we can change the n value depends how large the map you need.*/ ncol=8;nrow=8;printf("This is the successor function\n");printf("Enter the \nx=\ty=\n");scanf("%d%d",&location.x,&location.y); /*saving location in map location x and y*/ printf("Enter operator choice\n");printf("1=left\n");printf("2=right\n");printf("3=upwards\n");printf("4=down\n");printf("5=quit\n");scanf("%d",&menu);switch(menu) /*menu switch to show the position above, underneith, and next to the rover*/{case 1:location.x=location.x-1;printf("The position is [%d,%d]\n",location.x,location.y);break;case 2:location.x=location.x+1;printf("The position is [%d,%d]\n",location.x,location.y);break;case 3:location.y=location.y-1;printf("The position is [%d,%d]\n",location.x,location.y);break;case 4:location.y=location.y+1;printf("The position is [%d,%d]\n",location.x,location.y);break;case 5:printf("*****back to program*****\n"); /* Quits the program and prints out the message */break;default:printf("*****Please enter an integer from 1-5*****\n"); /* A default option if the user enters an incorrect value */break;}printf("\n");}?void help(struct map *number, struct map *number_2, struct object_fix *rsny,struct object_fix *rsld, struct object_fix *mnt, struct object_fix *dst,struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *mtre,struct object_fix *wshl, struct object_fix *wdp, struct object_move *aagr,struct object_move *anon, struct object_move *rvr, struct object_move *pstn, struct rover *p_rover) /*help function*/int i;char mov_obj;printf("++This is the help function++\n");printf("| 1-successor |\n");printf("| 2-add movable obj |\n");printf("| 3-remove moveabla obj |\n\n");printf("\t* * *\n");printf("\t Index: \n\n");printf("\t Sandy Rock: *\n");printf("\t Solid Rock: o\n");printf("\t Water:\262\262\262\262 \n");printf("\t Shallow water: \260\260\260\260\n");printf("\t Mountain: ^^^^\n");printf("\t Dust: ....\n");printf("\t* sher valley: VVVV *\n");printf("\t shallow valey: vvvv\n");printf("\t power station: \025\n");printf("\t alien: *_*\n");printf("\t other rovers: #\n");printf("\t* * *\n");scanf("%d",&i);switch(i) /*switch menu to go to the successor function, or the add/remove function*/ {case 1:successor();break;case 2:add_obj(number, number_2, rsny, rsld, mnt, dst, vshr,vgnt, mtre, wshl, wdp, aagr, anon, rvr, pstn, p_rover);break;case 3:add_obj(number, number_2, rsny, rsld, mnt, dst, vshr,vgnt, mtre, wshl, wdp, aagr, anon, rvr, pstn, p_rover);break;default:printf("choose a number from the list\n");}}void direction(int input, struct map *number, struct map *number_2, struct object_fix *rsny,struct object_fix *rsld, struct object_fix *mnt, struct object_fix *dst,struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *mtre,struct object_fix *wshl, struct object_fix *wdp, struct object_move *aagr,struct object_move *anon, struct object_move *rvr, struct object_move *pstn, struct rover *p_rover){switch(input){case 119: /*w = up*/if(p_rover->location[0] > 0){p_rover->location[0]--;p_rover->pwr--;}else p_rover->location[0]=7;break;case 115: /*s = down*/if(p_rover->location[0] < 7)p_rover->location[0]++;p_rover->pwr--;}else p_rover->location[0]=0; break;case 97: /*a = left*/if(p_rover->location[1] > 0) {p_rover->location[1]--;p_rover->pwr--;}else p_rover->location[1]=7; break;case 100: /*d = right*/if(p_rover->location[1] < 7) {p_rover->location[1]++;p_rover->pwr--;}else p_rover->location[1]=0; break;default:printf("Invalid operator!\n\n"); break;}}int control(int input){input = _getch();return input;?void main(void){int menu;int quit = 0;int input = 0;struct object_fix rsny, rsld, mnt, dst, vshr, vgnt, mtre, wshl, wdp;struct object_move aagr, anon, rvr, pstn;struct rover p_rover;struct map number, number_2;number.amount = 0; /* setting the initial amount of aliens as 0*/number_2.amount = 0;strcpy(,"Sandy Rock");strcpy(rsny.id,"RSNY");strcpy(rsny.desc,"A rock made of softer material that can be destroyed or collected"); strcpy(rsny.im,"*");strcpy(,"Solid Rock");strcpy(rsld.id,"RSLD");strcpy(rsld.desc,"A rock made of hard material that cannot be destroyed, but can be collected or avoided");strcpy(rsld.im,"O");strcpy(,"Mountain");strcpy(mnt.id,"MNT");strcpy(mnt.desc,"A large obstacle made of different materials that can only be avoided"); strcpy(mnt.im,"^^^^");strcpy(,"Dust");strcpy(dst.id,"DST");strcpy(dst.desc,"Small particles of sand, rock, etc. that may reduce visibility or slow down the vehicle, can be driven through but has extra power consumption");strcpy(dst.im,"....");strcpy(,"Sheer Valley");strcpy(vshr.id,"VSHR");strcpy(vshr.desc,"A depression in the land with sheer sides, it cannot be driven through and must be avoided");strcpy(vshr.im,"VVVV");strcpy(,"Gentle Valley");strcpy(vgnt.id,"VGNT");strcpy(vgnt.desc,"A depression in the land with gentle sides, it can be driven through with extra power consumption or can be avoided");strcpy(vgnt.im,"vvvv");strcpy(,"'Martian' Tree");strcpy(mtre.id,"MTRE");strcpy(mtre.desc,"A woody plant native to Mars, it may have the same characteristics as an 'Earth' tree");strcpy(mtre.im,"\330");strcpy(,"Shallow Water");strcpy(wshl.id,"WSHL");strcpy(wshl.desc,"A shallow body of water that can be driven through, can be in the form of a small puddle or a large lake");strcpy(wshl.im,"\260\260\260\260");strcpy(,"Deeper Water");strcpy(wdp.id,"WDP");strcpy(wdp.desc,"A deeper body of water that cannot be driven through, commonly in the form of a large lake or river");strcpy(wdp.im,"\262\262\262\262");strcpy(,"Aggressive Alien");strcpy(aagr.id,"AAGR");strcpy(aagr.desc,"An alien creature that will move upon its own accord, may become aggressive on contact");strcpy(aagr.im,"*_*");strcpy(,"Non-Aggressive Alien");strcpy(anon.id,"ANON");strcpy(anon.desc,"An alien creature that will move upon its own accord, will not become aggressive on contact");strcpy(anon.im,"*_*");strcpy(,"Rover");strcpy(rvr.id,"RVR");strcpy(rvr.desc,"A Mars Rover vehicle to transport around the map, it can destroy, collect or avoid objects. It has a power and object storage");strcpy(rvr.im,"#");strcpy(,"Power Station");strcpy(pstn.id,"PSTN");strcpy(pstn.desc,"A movable power station that will restore power to the Mars Rovers"); strcpy(pstn.im,"\025");strcpy(p_,"User Mars Rover");strcpy(p_rover.id,"URVR");strcpy(p_rover.desc,"A Mars vehicle that is controlled by the user. Explores the map collecting, destroying and avoiding objects");strcpy(p_rover.im,"<^^>");p_rover.pwr = 100;p_rover.strg = 0;p_rover.location[0] = 7;p_rover.location[1] = 0;/****************************************************/printf("*******************************START***************************** ***\n\n");do{ /* Object will be gained from mapper */printf("+++++++++++++++++++++++++++++++MENU++++++++++++++++ +++++++++++++++++\n");printf("Please choose one of the following option:\n");printf("1 - Start\n");printf("2 - Controls\n");printf("3 - Show Map\n");printf("4 - Help Menu\n");printf("5 - Quit\n\n");printf("--------------->");scanf("%d", &menu);switch (menu){case 1:show_map(&number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,&vgnt, &mtre, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover);while (quit != 1 ){input = control(input);if (input == 27)quit = 1;else{if(p_rover.pwr>0){direction(input, &number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,&vgnt, &mtre, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover);show_map(&number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,&vgnt, &mtre, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover);printf("Rover stats: \nPower: %d%% \nStorage: %d%%\n", p_rover.pwr, p_rover.strg);}else{printf("*******************END GAME********************\n\n"); // ends game when charge = 0.break;}}}break;case 2:quit = 0;printf("\n");printf("* * *\n");printf(" Controls \n"); // menu for the keys used on the keyboard to move the rover in different directions.printf(" Up : W \n");printf(" Down : S \n");printf("* Left : A * \n");printf("* Right : D * \n");printf(" choose : Enter \n");printf("* * *\n");break;case 3:quit = 0;show_map(&number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,&vgnt, &mtre, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover);break;case 4:quit = 0;help(&number, &number_2, &rsny, &rsld, &mnt, &dst, &vshr,&vgnt, &mtre, &wshl, &wdp, &aagr, &anon, &rvr, &pstn, &p_rover);break;case 5:printf("*********************END***********************\n"); break;}}while(menu!=5);printf("\n -----Please press any key to exit game-----\n");getch();}。

纯c语言编写的打字母游戏

纯c语言编写的打字母游戏

#include <stdio.h>#include <stdlib.h>#include<windows.h>#include<conio.h>#include<time.h>#define NN 20#define MM 65#include<process.h>char a[NN][MM],c;int b[11]={0},N/*jiaohuan*/,i,j/*jishu*/,t/*dajishu*/,k=0,u=0,m,p,q,n,M;double s;void gamebegin();void levelselect();void sure();void former();void gaming();void gameend();void gamebegin(){printf("本游戏为了方便中国玩家,在难懂部分用中文或双语书写\n");printf("welcome to the typing game, do you want to test your typing skill?\n1 yes,i want to try it 2 no,thanks\n");printf("please write down the number which points at your option\n****************************************************\n(since then you should make your decision in this way)\n");do{scanf("%d",&b[0]);switch(b[0]){case 1:levelselect();b[1]=1;break;case 2:exit(0);b[1]=1;break;default:printf("please select again\n");}}while(b[1]==0);}void levelselect(){system("cls");printf("please choose your game level 1\n");printf("1 easy 2 medium 3 difficult\n");do{scanf("%d",&b[2]);switch(b[2]){case 1:N=2000;b[3]=1;break;case 2:N=1000;b[3]=1;break;case 3:N=800;b[3]=1;break;default:printf("please select again\n");}}while(b[3]==0);system("cls");printf("please choose your game level 2\n");printf("1 lowercase小写字母2 lowercase+capital大写加小写3 lowercase+capital+number 大写加小写加数字\n");printf("*****************************************************************\n^.^the punctuation will take up among all the three level,so it is a challenge to you.GO for it!\n符号在三个等级中随机出现\n");do{scanf("%d",&b[4]);switch(b[4]){case 1:p=30;q=97;b[5]=1;break;case 2:p=62;q=97;b[5]=1;break;case 3:p=94;q=97;b[5]=1;break;default:printf("please select again\n");}}while(b[5]==0);system("cls");printf("please write down the number of letter you want to hit\n为了计算精确,请输入三的倍数,为了时间的精准,请让字母的个数大于60\n");scanf("%d",&b[6]);}void sure(){system("cls");printf("please affirm your answer\n");printf("your answer is:the level 1 is number %d,the level 2 is %d, there are %d letters to run the game\n1 yes 2 no,i will select again\n",b[2],b[4],b[6]);do{scanf("%d",&b[7]);{case 1:gaming();b[9]=1;break;case 2:former();b[9]=1;break;default:printf("please select again\n");}}while(b[9]==0);}void former(){gamebegin();sure();}void gaming(){printf("game introduction:there will be many letter to drop down,so you should hit it!come on!");system("cls");printf("please input arbitrary letter to begin the game\n");getch();for(i=0;i<NN;i++){for(j=0;j<MM;j++){a[i][j]=32;}}while(M<(b[6]/3+NN-1)){M++;if(k<b[6]){srand((unsigned)time(NULL));a[u][rand()%(MM-1)]=(rand()%p+q);a[u][rand()%(MM-1)]=(rand()%p+q);a[u][rand()%(MM-1)]=(rand()%p+q);k=k+3;}Sleep(N);system("cls");{c=getch();for(i=0;i<NN;i++){for(j=0;j<MM-1;j++){if(c==27){exit(1);}else if(c==a[i][j]){putchar('\a');a[i][j]=32;t++;}}}}for(i=0;i<NN;i++){a[i][MM-1]='\0';}for(m=u++;m>=0;m--)printf("%s\n",a[m]);for(m=NN-1;m>=u;m--)printf("%s\n",a[m]);if(u==NN)u=0;for(j=0;j<MM-1;j++){a[u][j]=32;}}}void gameend(){system("cls");printf("我的游戏还有很大纰漏。

C语言游戏源代码

C语言游戏源代码

C语言游戏源代码1、简单的开机密码程序#include "conio.h"#include "string.h"#include "stdio.h"void error(){window(12,10,68,10);textbackground(15);textcolor(132);clrscr();cprintf("file or system error! you can't enter the system");while(1); /*若有错误不能通过程序*/}void look(){FILE *fauto,*fbak;char *pass="c:\\windows\\password.exe"; /*本程序的位置*/char a[25],ch;char *au="autoexec.bat",*bname="hecfback.^^^"; /*bname 是autoexec.bat 的备份*/setdisk(2); /*set currently disk c:*/chdir("\\"); /*set currently directory \*/fauto=fopen(au,"r+");if (fauto==NULL){fauto=fopen(au,"w+");if (fauto==NULL) error();}fread(a,23,1,fauto); /*读取autoexec.bat前23各字符*/a[23]='\0';if (strcmp(a,pass)==0) /*若读取的和pass指针一样就关闭文件,不然就添加*/fclose(fauto);else{fbak=fopen(bname,"w+");if (fbak==NULL) error();fwrite(pass,23,1,fbak);fputc('\n',fbak);rewind(fauto);while(!feof(fauto)){ch=fgetc(fauto);fputc(ch,fbak);}rewind(fauto);rewind(fbak);while(!feof(fbak)){ch=fgetc(fbak);fputc(ch,fauto);}fclose(fauto);fclose(fbak);remove(bname); /*del bname file*/}}void pass(){char *password="88888888";char input[60];int n;while(1){window(1,1,80,25);textbackground(0);textcolor(15);clrscr();n=0;window(20,12,60,12);textbackground(1);textcolor(15);clrscr();cprintf("password:");while(1){input[n]=getch();if (n>58) {putchar(7); break;} /*若字符多于58个字符就结束本次输入*/ if (input[n]==13) break;if (input[n]>=32 && input[n]<=122) /*若字符是数字或字母才算数*/ {putchar('*');n++;}if (input[n]==8) /*删除键*/if (n>0){cprintf("\b \b");input[n]='\0';n--;}}input[n]='\0';if (strcmp(password,input)==0)break;else{putchar(7);window(30,14,50,14);textbackground(15);textcolor(132);clrscr();cprintf("password error!");getch();}}}main(){look();pass();}2、彩色贪吃蛇#include <graphics.h>#include <stdlib.h>#define N 200#define up 0x4800#define down 0x5000#define left 0x4b00#define right 0x4d00#define esc 0x011b#define Y 0x1579#define n 0x316eint gamespeed; /* 游戏速度*/int i, key, color;int score = 0; /* 游戏分数*/char cai48H[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0E, 0x00,0x1C, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x1C, 0x00,0x00, 0x00, 0x20, 0x00, 0x38, 0x00, 0x00, 0x00,0x40, 0x00, 0x78, 0x00, 0x00, 0x01, 0x80, 0x40,0x70, 0x00, 0x00, 0x03, 0x80, 0xC0, 0xE0, 0x00,0x00, 0x07, 0x80, 0x80, 0xC0, 0x00, 0x00, 0x0E,0x11, 0x81, 0xC0, 0x00, 0x00, 0x08, 0x61, 0x01,0x80, 0x00, 0x00, 0x00, 0x23, 0x03, 0x04, 0x00,0x00, 0x02, 0x02, 0x00, 0x06, 0x00, 0x00, 0x1E,0x04, 0x00, 0x0F, 0x00, 0x00, 0x1C, 0x1F, 0x80,0x1E, 0x00, 0x00, 0x08, 0x3F, 0x80, 0x3C, 0x00,0x00, 0x00, 0xFF, 0x80, 0x38, 0x00, 0x00, 0x03,0xFF, 0x80, 0x78, 0x00, 0x00, 0x0F, 0xF8, 0x00,0xF0, 0x00, 0x00, 0x7F, 0xF0, 0x00, 0xE0, 0x00,0x03, 0xFF, 0xFC, 0x01, 0x80, 0x00, 0x03, 0xC0,0x03, 0x80, 0x00, 0x01, 0x3F, 0x00, 0x07, 0x80, 0x00, 0x02, 0x11, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0E, 0x00, 0x00, 0x08, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x30, 0x10, 0x00, 0x18, 0x00, 0x00, 0x70, 0x10, 0x00, 0x30, 0x00, 0x01, 0xE0, 0x10, 0x00, 0x70, 0x00, 0x03, 0x80, 0x10, 0x00, 0x60, 0x00, 0x00, 0x00, 0x30, 0x00, 0xE0, 0x00, 0x00, 0x00, 0xF0, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x70, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x10, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };char she48H[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x02, 0x00, 0x07, 0x86, 0x00, 0x00, 0x02, 0x00, 0x18, 0x03, 0x00, 0x00, 0x02, 0x00, 0x00, 0x07, 0x80, 0x00, 0x03, 0xF0, 0x00, 0x07, 0x80, 0x00, 0x0F, 0xFC, 0x00, 0x0C, 0x00, 0x00, 0x7E, 0x3F, 0x80, 0x00, 0x00, 0x01, 0xFE, 0x1F, 0x80, 0x00, 0x00, 0x01, 0xE2, 0x39, 0x8C, 0x00, 0x00, 0x00, 0xC2, 0x30, 0x08, 0x00, 0x00, 0x00, 0xC2, 0x60, 0x08, 0x00, 0x00, 0x00, 0xC3, 0xE0, 0x08, 0x60, 0x00, 0x00, 0x7F, 0xE0, 0x01, 0xE0, 0x00, 0x00, 0x3F, 0x80, 0x1F, 0xE0, 0x00, 0x00, 0x1E, 0x00, 0x1F, 0x80, 0x00, 0x00, 0x1E, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x02, 0x38, 0x1E, 0x00, 0x00, 0x00, 0x07, 0xFC, 0x1C,0x00, 0x1F, 0x0C, 0x10, 0x00, 0x20, 0x00, 0x7C, 0x04, 0x10, 0x00, 0x60, 0x01, 0xF0, 0x00, 0x10, 0x00, 0x60, 0x01, 0xE0, 0x00, 0x08, 0x00, 0xF0, 0x00, 0x80, 0x00, 0x08, 0x03, 0xF0, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };char tun48H[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF8, 0x00, 0x40, 0x00, 0x00, 0x00, 0x06, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x7F, 0xF8, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x1F, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x0F, 0xF8, 0x0E, 0x00, 0x00, 0x00, 0x04, 0x70, 0x07, 0x00, 0x00, 0x00, 0x00, 0x60, 0x03, 0x80, 0x00, 0x00, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0x00, 0x01, 0x80, 0x00, 0x30, 0x00, 0x00, 0x01, 0x00, 0x3C, 0x18, 0x00, 0x00, 0x02, 0x03, 0xFF, 0x0C, 0x00, 0x00, 0x0C, 0x7F, 0xFF, 0x8E, 0x00, 0x00, 0x18, 0xFF, 0xFF, 0xC7, 0x80, 0x00, 0x78, 0xFE, 0x07, 0x87, 0xE0, 0x01, 0xF0, 0x70, 0x07, 0x03, 0xF8, 0x07, 0xE0, 0x70, 0x0E, 0x03, 0xFE, 0x00, 0x00, 0x38, 0x1E, 0x01, 0xFE, 0x00, 0x00, 0x3F, 0xFE, 0x00, 0x0C, 0x00, 0x00, 0x1F, 0xFE, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };char dan48H[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xC0, 0x80, 0x00, 0x00, 0x03, 0xFF, 0x80, 0x40, 0x00, 0x00, 0x01, 0xF1, 0x80, 0x40, 0x00, 0x00, 0x01, 0x81, 0x80, 0xE0, 0x00, 0x00, 0x00, 0x01, 0x93, 0xF0, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x21, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x21, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x61, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x61, 0x80, 0x00, 0x00, 0x00, 0x00, 0xF3, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x02, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x04, 0x02, 0x1F, 0x00, 0x00, 0x00, 0x08, 0x03, 0x01, 0xC0, 0x00, 0x00, 0x38, 0x03, 0x00, 0x7C, 0x00, 0x00, 0xF8, 0x07, 0xF8, 0x3F, 0xC0, 0x01, 0xF0, 0x3F, 0xFE, 0x3F, 0xF8, 0x03, 0xC1, 0xFF, 0x0F, 0x1F, 0xF8, 0x00, 0x01, 0xE3, 0x0F, 0x0F, 0xF0, 0x00, 0x01, 0xC3, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x83, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xC7, 0xF8, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x03, 0x80, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xF8, 0x20, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x07, 0xFF, 0x81, 0xE0, 0x00, 0x00, 0x07, 0xE0, 0x00, 0xE0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };char zuo16H[] ={0x18, 0xC0, 0x18, 0xC0, 0x19, 0x80, 0x31, 0xFE, 0x33, 0xFE, 0x76, 0xC0, 0xF0, 0xFC, 0xB0, 0xFC, 0x30, 0xC0, 0x30, 0xC0, 0x30, 0xFE, 0x30, 0xFE, 0x30, 0xC0, 0x30, 0xC0, 0x30, 0xC0, 0x00, 0x00, };char zhe16H[] ={0x03, 0x00, 0x03, 0x0C, 0x1F, 0xCC, 0x1F, 0xD8, 0x03, 0x30, 0xFF, 0xFE, 0xFF, 0xFE, 0x03, 0x00, 0x0F, 0xF8, 0x3F, 0xF8, 0xEC, 0x18, 0xCF, 0xF8, 0x0C, 0x18, 0x0F, 0xF8, 0x0F, 0xF8, 0x00, 0x00, };char tian16H[] ={0x00, 0x00, 0x3F, 0xFC, 0x3F, 0xFC, 0x31, 0x8C, 0x31, 0x8C, 0x31, 0x8C, 0x3F, 0xFC, 0x3F, 0xFC, 0x31, 0x8C, 0x31, 0x8C, 0x31, 0x8C, 0x3F, 0xFC, 0x3F, 0xFC, 0x30, 0x0C, 0x00, 0x00, 0x00, 0x00, };char xue16H[] ={0x33, 0x18, 0x19, 0x98, 0x08, 0xB0, 0x7F, 0xFC, 0x7F, 0xFC, 0x60, 0x0C, 0x1F, 0xF0, 0x1F, 0xF0, 0x00, 0xC0, 0x7F, 0xFC, 0x7F, 0xFC, 0x01, 0x80, 0x01, 0x80, 0x07, 0x80, 0x03, 0x00, 0x00, 0x00, };char ke16H[] ={0x00, 0x00, 0x0C, 0x18, 0xFD, 0x98, 0xF8, 0xD8, 0x18, 0x58, 0xFE, 0x18, 0xFE, 0x98, 0x18, 0xD8, 0x3C, 0x58, 0x7E, 0x1E, 0xDB, 0xFE, 0x9B, 0xF8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, };struct Food/*定义结构体存储食物的属性*/{int x; /* 食物的坐标*/int y;int yes; /* 值为0表示屏幕上没有食物,值为1表示屏幕上有食物*/ int color; /* 食物颜色*/} food;struct Snake/*定义结构体存储蛇的属性*/{int x[N]; /* 每一节蛇的坐标*/int y[N];int color[N];/*存储每一节蛇的颜色*/int node; /* 蛇的节数*/int direction; /* 蛇移动的方向*/int life; /* 蛇的生命,如果为1,蛇死,游戏结束*/} snake;void init(void)/*图形驱动*/{int driver = DETECT, mode = 0;registerbgidriver(EGAVGA_driver);initgraph(&driver, &mode, "");}void drawmat(char *mat, int matsize, int x, int y, int color) /*汉字点阵*/ {int i, j, k, m;m = (matsize - 1) / 8 + 1;for(j = 0; j < matsize; j++)for(i = 0; i < m; i++)for(k = 0; k < 8; k++)if(mat[j*m+i]&(0x80 >> k))putpixel(x + i * 8 + k, y + j, color);}void showword(void){/* 调用汉字点阵输出程序,显示标题和作者信息*/drawmat(cai48H, 48, 249, -4, 7);drawmat(she48H, 48, 329, -4, 7);drawmat(tun48H, 48, 409, -4, 7);drawmat(dan48H, 48, 489, -4, 7);drawmat(cai48H, 48, 250, -5, 4);drawmat(she48H, 48, 330, -5, 4);drawmat(tun48H, 48, 410, -5, 4);drawmat(dan48H, 48, 490, -5, 4);/*作者田学科*/drawmat(zuo16H, 16, 515, 465, 7);drawmat(zhe16H, 16, 530, 465, 7);drawmat(tian16H, 16, 550, 465, 7);drawmat(xue16H, 16, 565, 465, 7);drawmat(ke16H, 16, 580, 465, 7); }void draw(void)/*画出四周的墙*/ {if(color == 15)color = 0;setcolor(++color);setlinestyle(SOLID_LINE, 0, 1);for(i = 30; i <= 600; i += 10){rectangle(i, 40, i + 10, 49);rectangle(i, 451, i + 10, 460);}for(i = 40; i < 450; i += 10){rectangle(30, i, 39, i + 10);rectangle(601, i, 610, i + 10);}}void prscore(void){/* 打印游戏分数*/char str[10];setfillstyle(SOLID_FILL, YELLOW);bar(50, 10, 200, 30);setcolor(6);settextstyle(0, 0, 2);sprintf(str, "score:%d", score);outtextxy(55, 15, str);}void gameover(void){cleardevice(); /* 清屏函数*/for(i = 0; i < snake.node; i++) /* 画出蛇死时的位置*/{setcolor(snake.color[i]);rectangle(snake.x[i], snake.y[i], snake.x[i] + 10, snake.y[i] + 10);}prscore(); /* 显示分数*/draw();showword();settextstyle(0, 0, 6);setcolor(7);outtextxy(103, 203, "GAME OVER");setcolor(RED);outtextxy(100, 200, "GAME OVER");}void gameplay(void)/* 玩游戏的具体过程*/{int flag, flag1;randomize();prscore();gamespeed = 50000;food.yes = 0; /* food.yes=0表示屏幕上没有食物*/snake.life = 1; /* snake.life=1表示蛇是活着的*/snake.direction = 4; /* 表示蛇的初始方向为向右*/snake.node = 2; /* 蛇的初始化为两节*/snake.color[0] = 2; /*两节蛇头初始化为绿色*/snake.color[1] = 2;snake.x[0] = 100;snake.y[0] = 100;snake.x[1] = 110;snake.y[1] = 100;food.color = random(15) + 1;while(1){while(1){if(food.yes == 0) /* 如果蛇活着*/{while(1){flag = 1;food.x = random(56) * 10 + 40;food.y = random(40) * 10 + 50;for(i = 0; i < snake.node; i++){if(food.x == snake.x[i] && food.y == snake.y[i])flag = 0;}if(flag) break;}}if(food.yes){setcolor(food.color);rectangle(food.x, food.y, food.x + 10, food.y + 10);}for(i = snake.node - 1; i > 0; i--){snake.x[i] = snake.x[i-1];snake.y[i] = snake.y[i-1];}switch(snake.direction){case 1:snake.y[0] -= 10;break;case 2:snake.y[0] += 10;break;case 3:snake.x[0] -= 10;break;case 4:snake.x[0] += 10;break;}for(i = 3; i < snake.node; i++){if(snake.x[i] == snake.x[0] && snake.y[i] == snake.y[0]) {gameover();break;}}if(snake.x[0] < 40 || snake.x[0] > 590 || snake.y[0] < 50 || snake.y[0] > 440) {gameover();snake.life = 0;}if(snake.life == 0)break;if(snake.x[0] == food.x && snake.y[0] == food.y) /*蛇吃掉食物*/{setcolor(0);rectangle(food.x, food.y, food.x + 10, food.y + 10);snake.x[snake.node] = -20;snake.y[snake.node] = -20;snake.color[snake.node] = food.color;snake.node++;food.yes = 0;food.color = random(15) + 1;score += 10;prscore();if(score % 100 == 0 && score != 0){for(i = 0; i < snake.node; i++) /* 画出蛇*/{setcolor(snake.color[i]);rectangle(snake.x[i], snake.y[i], snake.x[i] + 10, snake.y[i] + 10);}sound(200);delay(50000);delay(50000);delay(50000);delay(50000);delay(50000);delay(50000);nosound();gamespeed -= 5000;draw();}else{sound(500);delay(500);nosound();}}for(i = 0; i < snake.node; i++) /* 画出蛇*/{setcolor(snake.color[i]);rectangle(snake.x[i], snake.y[i], snake.x[i] + 10, snake.y[i] + 10);}delay(gamespeed);delay(gamespeed);flag1 = 1;setcolor(0);rectangle(snake.x[snake.node-1], snake.y[snake.node-1],snake.x[snake.node-1] + 10, snake.y[snake.node-1] + 10);if(kbhit() && flag1 == 1) /*如果没按有效键就重新开始循环*/{flag1 = 0;key = bioskey(0);if(key == esc)exit(0);else if(key == up && snake.direction != 2)snake.direction = 1;else if(key == down && snake.direction != 1)snake.direction = 2;else if(key == left && snake.direction != 4)snake.direction = 3;else if(key == right && snake.direction != 3)snake.direction = 4;}}if(snake.life == 0) /*如果蛇死了就退出循环*/break;}}void main(void){while(1){color = 0;init();cleardevice();showword();draw();gameplay();setcolor(15);settextstyle(0, 0, 2);outtextxy(200, 400, "CONTINUE(Y/N)?");while(1){key = bioskey(0);if(key == Y || key == n || key == esc)break;}if(key == n || key == esc)break;}closegraph();}3、c语言实现移动电话系统#include <stdio.h>#define GRID-SIZE 5#define SELECTED -1 /*低于矩阵中所有元素*/#define TRAFFIC-FILE “traffic.dat”/*关于交通数据的文件*/#define NUM-TRANSMITTERS 10 /*可用的发射器数量*/void get-traffic-data(int commuters[GRID-SIZE][GRID-SIZE],int salesforce[GRID-SIZE][GRID-SIZE],int weekends [GRID-SIZE][GRID-SIZE];voide print-matrix[GRID-SIZE][GRID-SIZE];intmain(void){int commuters[GRID-SIZE][GRID-SIZE];/*上午8:30的交通数据*/int salesforce[GRID-SIZE][GRID-SIZE]; /*上午11:00的交通数据*/int weekend[GRID-SIZE][GRID-SIZE];/*周末交通数据*/int commuter-weight, /*通勤人员数据的权重因子*/sale-weight,/*营销人员数据的权重因子*/weekend-weight;/*周末数据的权重因子*/int location-i,/*每个发射器的位置*/location-j;int current-max;/*和数据中当前的最大值*/int i,j,/*矩阵的循环计数器*/tr;/*发射器的循环计数器*//*填入并显示交通数据*/Get-traffic-data (commuters,salesforce,weekend);Printf(“8:30 A.M.WEEKDAY TRAFFIC DATA 、\n\n”)print-matrix(commuters);printf(“\n\n WEEKEND TRAFFIC DATA\n\n”);print-matrix(salesforce);printf(“\n\n WEEKEND TRAFFIC DATA\n\n”);printf_matrix(weekeng);/*请用户输入权重因子*/printf(“\n\nPlease input the following value:\n”);printf(“Weight (an interger>=0) for the 8:muter data>”)scanf(“%d”,&commuter_weight);printf(“weight(an integer>=0) for the weekeng data>”);scanf(“%d”,&weekend_weight);scanf(“%d”,&weekend_weight);/*计算并显示加权后求和的数据*/for (i=0;i<GRID_SIZE;++i)for (j=0;j<GRID_SIZE;++j)summed_data[i][j]=commuter_weight*commuter[i][j]+salesforce_weight*salesforce[i][j]+weekend_weight*weekend[i][j];printf(“\n\nThe weighted,summed data is :\n\n”);printf_matrix(summed_data);/*在summed_data矩阵中找出NUM_TRANSMITTERS个最大值,将坐标临时存储在location_i和location_j中,然后把最后的结果坐标输出*/printf(“\n\nLocations of the %d transmitters:\n\n”,NUM_TRANSMITTERS);for (tr=1;tr<=NUM_TRANSMITTERS;++tr){current_max=SELECTED;/*以一个过低的值为起点开始查找*/for (i=0;i<GRID_SIZE;++i){for(j=0;j<GRID_SIZE;++j){if(current_max<summed_data[i][j]){current_max=summed_data[i][j]){location_i=i;location_j=j;}}}/*将选中的单元赋一较低的值以避免下次再选中这一元素,显示查找结果*/ summed_data[location_i][location_j]=SELECTED;print f(“Transmitter %3d:at location %3d %3d\n”,tr,location_i,location_j);}return (0);}/**把TRAFFIC_FILE中的交通数据填充到3个GRID_SIZE×GRID_SIZE数组中*/voidget_traffic_data(int commuters[GRID_SIZE],/*输出*/int salesforce[GRID_SIZE][GRID_SIZE],/*输出*/int weekend[GRID_SIZE][GRID_SIZE],/*输出*/{int i,j; /*循环计数器*/FILE *fp; /*文件指针*/fq=fopen(TRAFFIC_FILE,“r”);for(i=0;i<GRID_SIZE;++i)for(j=0;j<GRID_SIZE;++j)fs canf(fp,“%d”,&commnters[i][j];for(i=0;i<GRID_SIZE;++j)for(j=0;j<GRID_SIZE;++j)fscanf(fq,“%d”,&weekend[i][j]);fclose(fq);}/**显示一个GRID_SIZE×GRID_SIZE整数矩阵的内容*/voidprint_matrix(int matrix[GRID_SIZE][GRID_SIZE]){int i,j; /*循环计数器*/for(i=0;i<GRID_SIZE;++j){ for(j=0;j<GRID_SIZE;++J)printf(“%3d”,matrix[i][j]);printf(“\n”);}}4、扑克牌游戏/*************************************Copyright(C) 2004-2005 vision,math,NJU.File Name: guess_card.cppAuthor: vision Version: 1.0 Data: 23-2-2004Description: 给你9张牌,然后让你在心中记住那张牌,然后电脑分组让你猜你记住的牌在第几组,然后猜出你记住的那张牌.Other: 出自儿童时的一个小魔术History:修改历史**************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <assert.h>#define CARDSIZE 52 /*牌的总张数*/#define SUITSIZE 13 /*一色牌的张数*//*扑克牌结构*/typedef struct Card{char val;/*扑克牌面上的大小*/int kind :4; /*扑克牌的花色*/}Card;/*************************************************Function: // riffleDescription: // 洗牌,然后随机的得到9张牌,要求九张牌不能有重复. Calls: //Called By: // main()Table Accessed: //被修改的表(此项仅对于牵扯到数据库操作的程序)Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)Input: //Card card[] 牌结构, int size 结构数组的大小Output: //Return: // voidOthers: // 此函数修改card[]的值,希望得到九张随机牌Bug: //此函数有bug,有时会产生两个相同的牌,有待修订*************************************************/void riffle(Card *cards, int size);/*************************************************Function: // showDescription: // 显示数组的内容Calls: //Called By: // main()Table Accessed: //被修改的表(此项仅对于牵扯到数据库操作的程序)Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)Input: //Card *card 牌结构指针, int size 结构数组的大小Output: //Return: // voidOthers: //*************************************************/void show(const Card *cards, int size);/*************************************************Function: // groupingDescription: //把9张牌分别放到3个数组中,每组3张,a.e分组Calls: //Called By: // main()Table Accessed: //被修改的表(此项仅对于牵扯到数据库操作的程序)Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)Input: //Card *card 牌结构指针, int size 结构数组的大小Output: //Return: // voidOthers: // 此函数修改*carr1,*carr2,* carr3的值*************************************************/void grouping(const Card *cards, Card *carr1, Card *carr2, Card *carr3);/*************************************************Function: // result_processDescription: //用递归计算,所选的牌Calls: // rshiftCalled By: // main()Table Accessed: //被修改的表(此项仅对于牵扯到数据库操作的程序)Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)Input: //Card *carr1, Card *carr2, Card *carr3Output: //Return: // voidOthers: // 此函数修改*carr1,*carr2,* carr3的值*************************************************/Card* result_process(Card *carr1, Card *carr2, Card *carr3, int counter);/*************************************************Function: // rshiftDescription: //右移操作Calls: //Called By: // result_processTable Accessed: //被修改的表(此项仅对于牵扯到数据库操作的程序)Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)Input: //Card *carr1, Card *carr2, Card *carr3 ,int counterOutput: //Return: // Card*Others: // 此函数修改*carr1,*carr2,* carr3的值*************************************************/void rshift(Card *carr1, Card *carr2, Card *carr3, int counter);void main(){Card cards[9]; /*存放九张牌*/Card carr1[3]; /*第一组牌,cards array 1*/Card carr2[3]; /*第二组牌,cards array 2*/Card carr3[3]; /*第三组牌,cards array 3*/int select = 0; /*玩家的选择*/Card *selected_card;/*存放玩家所记住(选)的牌*/int counter = 0;riffle(cards, 9); /*洗牌,得到九张牌*/puts("请记住一张牌千万别告诉我!最多经过下面三次我与你的对话,我就会知道你所记的那张牌!");puts("如果想继续玩,请准确的回答我问你的问题,根据提示回答!");puts("请放心,我不会问你你选了哪张牌的!");grouping(cards, carr1, carr2, carr3); /*把9张牌分别放到3个数组中,每组3张,a.e分组*/show(carr1, 3);show(carr2, 3);show(carr3, 3);puts("请告诉我你记住的那张牌所在行数");select = getchar();switch(select)/*分支猜你玩家记住的牌*/{case '1':selected_card = result_process(carr1, carr2, carr3, counter);break;case '2':selected_card = result_process(carr2, carr3, carr1, counter);break;case '3':selected_card = result_process(carr3, carr1, carr2, counter);break;default:puts("你在撒谎!不和你玩了!");fflush(stdin);getchar();exit(0);}if( selected_card ==NULL){fflush(stdin);getchar();exit(0);}puts("你猜的牌为:");show(selected_card, 1);puts("我猜的对吧,哈哈~~~~");fflush(stdin);getchar();}/*riffle的原代码*/void riffle(Card *cards, int size){char deck[CARDSIZE];/*临时数组,用于存储牌*/unsigned int seed;/*最为产生随机数的种的*/int deckp = 0; /*在牌的产生中起着指示作用*/seed = (unsigned int)time(NULL);srand(seed);/*洗牌*/while (deckp < CARDSIZE){char num = rand() % CARDSIZE;if ((memchr(deck, num, deckp)) == 0){assert(!memchr(deck,num,deckp));deck[deckp] = num;deckp++;}}/*找9张牌给card*/for (deckp = 0; deckp < size; deckp++){div_t card = div(deck[deckp], SUITSIZE);cards[deckp].val = "A23456789TJQK"[card.rem]; /*把余数给card.val*/ cards[deckp].kind = "3456"[card.quot]; /*把商给card.kind*/}}/*show的原代码,将会自动换行*/void show(const Card *cards, int size){for(int i = 0; i < size; i++){printf("%c%c ",cards[i].kind,cards[i].val);if( (i !=0) && (((i+1 ) % 3) == 0))puts("");}puts(""); /*自动换行*/}/*grouping 的原代码*/void grouping(const Card *cards, Card *carr1, Card *carr2, Card *carr3) {int i = 0;/*循环参数*//*分给carr1三个数*/while (i < 3){carr1[i].val = cards[i].val;carr1[i].kind = cards[i].kind;i++;}/*分给carr2接下来的三个数*/while (i < 6){carr2[i-3].val = cards[i].val;carr2[i-3].kind = cards[i].kind;i++;}/*分给carr3接下来的三个数*/while (i < 9){carr3[i-6].val = cards[i].val;carr3[i-6].kind = cards[i].kind;i++;}}/*rshift的实现*/void rshift(Card *carr1, Card *carr2, Card *carr3, int counter){Card temp2;/*用于存放carr2[counter]*/Card temp3;/*用于存放carr3[counter]*//*temp = carr2*/temp2.val = carr2[counter].val;temp2.kind = carr2[counter].kind;/*carr2 = carr1*/carr2[counter].val = carr1[counter].val;carr2[counter].kind = carr1[counter].kind;/*temp3 = carr3*/temp3.val = carr3[counter].val;temp3.kind = carr3[counter].kind;/*carr3 = carr2*/carr3[counter].val = temp2.val;carr3[counter].kind = temp2.kind;/*carr1 = carr3*/carr1[counter].val = temp3.val;carr1[counter].kind = temp3.kind;}Card* result_process(Card *carr1, Card *carr2, Card *carr3, int counter){rshift(carr1, carr2, carr3, counter); /* 把数组的第一个元素依次右移*/if(counter == 2){return(&carr2[2]);}show(carr1, 3);show(carr2, 3);show(carr3, 3);puts("请给出你记住的牌所在行数:");fflush(stdin);int input = 1;input = getchar(); /*获取你选的组*/switch(input){case '1':return(result_process(carr1, carr2, carr3, ++counter));break;case '2':return(&carr2[counter]);break;default:puts("你在撒谎!不和你玩了!");return NULL;}}5、C语言实现打字游戏#include "stdio.h"#include "time.h"#include "stdlib.h"#include "conio.h"#include "dos.h"#define xLine 70#define yLine 20#define full 100#define true 1#define false 0/*---------------------------------------------------------------------*/void printScreen(int level,int right,int sum,char p[yLine][xLine])/* 刷新屏幕的输出图像 */{int i,j;clrscr();printf("level:%d Press 0 to exit;1 topause score:%d/%d\n",level,right,sum);/* 输出现在的等级,击中数和现在已下落总数 */printf("----------------------------------------------------------------------\n");for (i=0;i<yLine;i++){for(j=0;j<xLine;j++)printf ("%c",p[i][j]);printf("\n");}/* for (i) */printf("----------------------------------------------------------------------\n");}/* printScreen *//*---------------------------------------------------------------------*/void leave()/* 离开程序时,调用该函数结束程序。

c语言游戏大小游戏代码,C语言游戏源代码(3)(43页)-原创力文档

c语言游戏大小游戏代码,C语言游戏源代码(3)(43页)-原创力文档

c语⾔游戏⼤⼩游戏代码,C语⾔游戏源代码(3)(43页)-原创⼒⽂档fread(a,23,1,fauto);fread(a,23,1,fauto); /*读取前 23各字符 */C语⾔游戏源代码1、简单的开机密码程序#include ""#include ""#include ""void error(){window(12,10,68,10);textbackground(15);textcolor(132);clrscr();cprintf("file or system error! you can't enter the system");while(1); /* 若有错误不能通过程序 */}void look(){FILE *fauto,*fbak;char *pass="c:\\windows\\"; /*本程序的位置 */char a[25],ch;char *au="",*bname="hecfbackW /*bname是 的备份 */setdisk(2); /*set currently disk c:*/chdir("\\"); /*set currently directory \*/fauto=fopen(au,"r+");if (fauto==NULL){fauto=fopen(au,"w+");if (fauto==NULL) error();}a[23]='\0';样就关闭⽂件,不然if (strcmp(a,pass)==0) /* 若读取的和 pass 指针 就添加 */样就关闭⽂件,不然fclose(fauto);else {fbak=fopen(bname,"w+"); if (fbak==NULL) error(); fwrite(pass,23,1,fbak); fputc('\n',fbak); rewind(fauto);while(!feof(fauto)) {ch=fgetc(fauto); fputc(ch,fbak);} rewind(fauto);rewind(fbak); while(!feof(fbak)) {ch=fgetc(fbak); fputc(ch,fauto);} fclose(fauto); fclose(fbak); remove(bname); /*del bname file*/} } void pass()char input[60];int n;while(1){window(1,1,80,25);textbackground(0);textcolor(15);clrscr();n=0;window(20,12,60,12);textbackground(1);textcolor(15);clrscr();cprintf("password:");while(1){input[n]=getch();if (n>58) {putchar(7); break;} /* 若字符多于 58 个字符就结束本次输 ⼊*/if (input[n]==13) break;if (input[n]>=32 && input[n]<=122) /*若字符是数字或字母才算数 */{putchar('*');n++;}if (input[n]==8) /*删除键 */if (n>0) {cprintf("\b \b");0x00, 0x02, 0x02, 0x00, 0x06, 0x00, 0x00, 0x1E,0x00, 0x02, 0x02, 0x00, 0x06, 0x00, 0x00, 0x1E,input[n]='\0';n--;}}input[n]='\0';if (strcmp(password,input)==0) break;else{putchar(7); window(30,14,50,14);textbackground(15);textcolor(132);clrscr(); cprintf("password error!");getch();}}}main(){look();pass();}2、彩⾊贪吃蛇#include <>#include <> #define N 200#define up 0x4800#define down 0x5000 #define left 0x4b00 #define right 0x4d00 #define esc 0x011b #define Y 0x1579 #define n 0x316e int gamespeed; /* 游戏速度 */ int i, key, color;int。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
void cls()
{
Sleep(100);
system("cls");
}
int main(int argc, char *argv[])
{
start:cls();
goto a1;
gameover:printf("游戏结束。");
printf("按回车键继续");
wait();
printf("1-进入那扇门\n");
printf("2-走上台阶\n");
printf("3-去走廊那边看看");
s13:wait();
switch(user_input)
{
case '1':goto a6;
case '2':goto a18;
case'2':goto a15;
case'3':goto a16;
default:goto s4;
}
a5:printf("......");
wait();
printf("你用力拉把手,喀哒一声,门没有开,地面却崩塌了。");
wait();
printf("你掉了下去,在这下面满满的尖刺在等着你。");
case '1':goto a17;
case'2':goto a14;
case'3':goto a19;
default:goto s7;
}
a8:cls();
printf("你推开门,门里是一间狭小的房屋,正对的墙上有很多方孔。\n");
wait();
goto a2;
printf("城堡看起来很古老,古旧的红色木门紧关着。\n");
wait();
printf("1-推门进去\n");
printf("2-敲三下门试试\n");
printf("3-我不想进去了");
s4:wait();
switch(user_input)
{
case'1':goto a8;
wait();
goto gameover;
a12:cls();
a=2;
printf("你把火把丢下去,火把很快熄灭了。");
wait();
printf("你庆幸你没有直接走下去,退回到了大厅。\n");
wait();
printf("1-走上台阶\n");
printf("2-去走廊");
case '3':goto a28;
default:goto s18;
}
a19:cls();
printf("你发现这房间的尽头通向近似厨房的房间。");
wait();
printf("你进去搜索了一圈,一无所获。");
wait();
printf("于是你回到了大厅。\n");
wait();
printf("1-进入双开的门\n");
printf("2-进入单开的门\n");
printf("3-沿着这条走廊向前走");
s18:wait();
switch(user_input)
{
case '1':goto a26;
case '2':goto a27;
wait();
printf("End03:城堡不喜欢胆小的孩子。");
wait();
goto gameover;
a6:cls();
printf("你推开那扇门,里面是一个小房间.");
wait();
printf("墙壁上插着一支火把。");
wait();
printf("地上的阶梯似乎通向地下室.\n");
s12:wait();
switch(user_input)
{
case '1':goto a18;
case '2':goto a9;
default:goto s12;
}
a13:cls();
printf("大厅里光线略有些昏暗。");
wait();
printf("你看到正对着你的是一扇门,在你的左边是螺旋向上的台阶,右边是一条走廊。\n");
wait();
printf("1-从阶梯下去\n");
printf("2-先把火把丢下去");
s6:wait();
switch(user_input)
{
case '1':goto a11;
case '2':goto a12;
default:goto s6;
}
wait();
printf("你望向橱柜下方,找到了一封信。\n");
b=1;
wait();
printf("1-拆开看看\n");
printf("2-就这样回到大厅并上楼\n");
if(a==2)
printf("3-走进大厅中间的房间(已探索)");
else
printf("3-走进大厅中间的房间");
printf("2-继续前进");
s3:wait();
switch(user_input)
{
case '1':goto a10;
case '2':goto a13;
default:goto s3;
}
a4:cls();
printf("你来到城堡前。");
wait();
wait();
printf("1-去楼上\n");
if(a==2)
printf("2-走进中间的房间(已探索)");
else
printf("2-走进中间的房间");
s19:wait();
switch(user_input)
{
case '1':goto a18;
a9:system("cls");
printf("走廊的尽头是一个房间,你看到一张长长的餐桌。\n");
wait();
goto a7;
a10:cls();
printf("你试图推门,推不开。");
wait();
printf("你看到门上的把手,想到了这门可能是要向后拉。");
wait();
printf("你被压在了下面。");
wait();
printf("你的头被砸出血了,临死大呼:“果然是机关啊!”");
wait();
printf("End07:城堡不喜欢投机取巧的孩子。");
wait();
goto gameover;
a23:cls();
wait();
printf("你忘记了这座城堡曾经存在过,继续着原来的生活。");
wait();
printf("End02:城堡不喜欢没有冒险精神的孩子。");
wait();
goto gameover;
a17:cls();
printf("你端起金碗,一饮而尽。");
wait();
s20:wait();
switch(user_input)
{
case '1':goto a25;
case '2':goto a18;
case '3':goto a19s;
default:goto s20;
}
a21:cls();
printf("你拿起《魔法入门》。");
case '3':goto a9;
default:goto s13;
}
a14:cls();
printf("你喝光了银碗里的汤,看到碗底刻着的字。");
printf("\n【厨房的橱柜下面】");
wait();
printf("你走向厨房.");
goto a20;
wait();
printf("出于好奇,你走近了它。");
wait();
goto a4;
a2:printf("突然,方孔中射出无数支箭,你被射死了。");
wait();
printf("End01:城堡不喜欢没礼貌的孩子");
wait();
相关文档
最新文档