當前位置:首頁 » 編程語言 » c語言設計報告游戲

c語言設計報告游戲

發布時間: 2022-05-31 17:57:57

Ⅰ 如何用c語言製作游戲

你可以先去【繪學霸】網站找「游戲設計/游戲製作」板塊的【免費】視頻教程-【點擊進入】完整入門到精通視頻教程列表: www.huixueba.net/web/AppWebClient/AllCourseAndResourcePage?type=1&tagid=307&zdhhr-11y04r-1818074554951406228

想要系統的學習可以考慮報一個網路直播課,推薦CGWANG的網路課。老師講得細,上完還可以回看,還有同類型錄播課可以免費學(贈送終身VIP)。

自製能力相對較弱的話,建議還是去好點的培訓機構,實力和規模在國內排名前幾的大機構,推薦行業龍頭:王氏教育。
王氏教育全國直營校區面授課程試聽【復制後面鏈接在瀏覽器也可打開】: www.huixueba.com.cn/school/3dmodel?type=2&zdhhr-11y04r-1818074554951406228

在「游戲設計/游戲製作」領域的培訓機構里,【王氏教育】是國內的老大,且沒有加盟分校,都是總部直營的連鎖校區。跟很多其它同類型大機構不一樣的是:王氏教育每個校區都是實體面授,老師是手把手教,而且有專門的班主任從早盯到晚,爆肝式的學習模式,提升會很快,特別適合基礎差的學生。

大家可以先把【繪學霸】APP下載到自己手機,方便碎片時間學習——繪學霸APP下載: www.huixueba.com.cn/Scripts/download.html

Ⅱ c語言實訓貪吃蛇報告書

《高級語言程序設計》課程設計 實驗報告

題目:貪吃蛇
專業:計算機
班級: 軟體
姓名:
成績:
指導教師:

完成日期:2008年09月23日

一、目的
1. 進一步掌握和利用C語言進行程設計的能力;
2、 進一步理解和運用結構化程設計的思想和方法;
3、 初步掌握開發一個小型實用系統的基本方法;
4、 學會調試一個較長程序的基本方法;
5、 學會利用流程圖或N-S圖表示演算法
6、 掌握書寫程設計開發文檔的能力(書寫課程設計報告);

二、內容與設計思想。
(1).系統功能與分析(填寫你所設計的菜單及流程圖)。

功能:進行貪食蛇游戲
分析:定義鍵盤方向鍵操作,隨機數發生器產生食物,並分別利用函數判斷貪食蛇的長度及游戲是否成功等.
並能夠輸入游戲成績.

(2).數據結構

struct Food
{
int x;/*食物的橫坐標*/
int y;/*食物的縱坐標*/
int yes;/*判斷是否要出現食物的變數*/
}food;/*食物的結構體*/

struct Snake
}
int x[N];
int y[N];
int node;/*蛇的節數*/
int direction;/*蛇移動方向*/
int life;/* 蛇的生命,0活著,1死亡*/
}snake;

(3).模塊設計
根據功能需要:
源文件 :#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>

函數名 功能
void main() 游戲主程序
void Init(void); 圖形驅動
void Close(void); 圖形結束
void DrawK(void); 開始畫面
void GameOver(void); 結束游戲
void GamePlay(void); 玩游戲具體過程
void PrScore(void); 輸出成績

(3)總體設計思想:
利用圖形驅動,製作美觀的游戲界面.
通過隨機函數產生隨機數,控制游戲過程食物的出現.
定義鍵盤操作,控制游戲過程蛇的移動方向.
畫出邊界,並判斷游戲是否結束.
統計游戲過程蛇吃的食物數量,計算並輸出遊戲成績.

(4)調試過程: 測試數據及結果,出現了哪些問題,如何修改的

這里,你就寫一下你平時出錯的地方,與如何修改的.這里我也不好幫你寫.

(5)程序有待改進的地方及本次實習的收獲和建議

收獲:加深認識了程序編譯過程的中團隊合作的重要性.
提高了自己的編程能力

(7)源程序清單(主要代碼)

清單只要將上面的程序全部粘帖就可以了.

Ⅲ C語言設計游戲,如何用結構體記錄輸贏次數

一般用dev C++的圖形模式 就可以開發C環境下的小型游戲如果是大型的3D 建議用java去寫比如拿 貪吃蛇做一個例子 #define N 200/*定義全局常量*/
#define m 25
#include
#include
#include
#include
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define Esc 0x011b
int i,j,key,k;
struct Food/*構造食物結構體*/
{
int x;
int y;
int yes;
}food;
struct Goods/*構造寶貝結構體*/
{
int x;
int y;
int yes;
}goods;
struct Block/*構造障礙物結構體*/
{
int x[m];
int y[m];
int yes;
}block;
struct Snake{/*構造蛇結構體*/
int x[N];
int y[N];
int node;
int direction;
int life;
}snake;
struct Game/*構建游戲級別參數體*/
{
int score;
int level;
int speed;
}game;
/*定義函數*/
void init(void);/*定義圖形驅動*/
void close(void);/*定義關閉函數*/
void drawk(void);/*定義界面函數*/
void gameover(void);/*定義游戲結束函數*/
void gameplay(void);/*定義游戲主函數*/
void prscore(void);/*定義得分函數*/

void main(void){/*主函數體,調用以下四個函數*/
init();
setbkcolor(7);
drawk();
gameplay();
close();
}

void init(void){/*構建圖形驅動函數*/
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
cleardevice();
}

void drawk(void){/*構建游戲界面函數*/
/*setbkcolor(LIGHTGREEN);*/
char str3[50];
setfillstyle(SOLID_FILL,BLUE);/*條型邊框,顯示版本信息*/
bar3d(48,9,610,38,1,45);
setcolor(YELLOW);/*版本信息*/
sprintf(str3,"Version:5.01,Powerwing Studio");
outtextxy(330,20,str3);
setfillstyle(LTSLASH_FILL,YELLOW);/*設定牆邊的填充形式*/
bar3d(48,48,58,462,0,0);/*設定牆邊*/
bar3d(48,39,611,48,0,0);
bar3d(48,452,611,462,0,0);
bar3d(602,39,611,462,0,0);

}

void gameplay(void){/*構建游戲主函數*/
/*初始化游戲角色*/
randomize();/*隨機數發生器*/
goods.yes=1;
block.yes=1;
food.yes=1;/*場景中需建立新的食物*/
snake.life=1;/*初始化蛇生命值*/
snake.direction=1;/*蛇起始的移動方向定義為向右*/
snake.x[0]=100;snake.y[0]=100;/*蛇頭的位置坐標初始化*/
snake.x[1]=110;snake.y[1]=100;
snake.node=2;/*蛇初始化節數,共兩節只有蛇頭*/
/*初始化障礙物的數組*/
block.x[0]=170;block.y[0]=270;/*level 1*/
block.x[1]=410;block.y[1]=310;
block.x[2]=300;block.y[2]=200;
block.x[3]=320;block.y[3]=420;
block.x[4]=250;block.y[4]=350;
block.x[5]=220;block.y[5]=320;/*level 2*/
block.x[6]=310;block.y[6]=410;
block.x[7]=400;block.y[7]=500;
block.x[8]=230;block.y[8]=230;
block.x[9]=280;block.y[9]=280;
block.x[10]=170;block.y[10]=280;/*level 3*/
block.x[11]=420;block.y[11]=310;
block.x[12]=310;block.y[12]=200;
block.x[13]=320;block.y[13]=400;
block.x[14]=250;block.y[14]=260;/*level 4*/
block.x[15]=220;block.y[15]=330;
block.x[16]=130;block.y[16]=410;
block.x[17]=310;block.y[17]=510;
block.x[18]=230;block.y[18]=340;
block.x[19]=280;block.y[19]=380;
block.x[20]=270;block.y[20]=170;/*level 5*/
block.x[21]=410;block.y[21]=450;
block.x[22]=190;block.y[22]=200;
block.x[23]=150;block.y[23]=320;
block.x[24]=270;block.y[24]=350;
block.x[25]=340;block.y[25]=320;

game.score=0;
game.speed=50000;
game.level=1;
prscore();/*得分初始化*/
while(1){/*判斷為真可以按Esc退出循環結束游戲*/
while(!kbhit()){/*無按鍵按下時,蛇自己移動身體*/

if(game.level==1){/*畫出障礙物*/
for(j=0;j<5;j++){
setcolor(5);/**/
rectangle(block.x[j],block.y[j],block.x[j]+10,block.y[j]-10);
block.yes=0;
}
}
if(game.level==2){/*畫出障礙物*/
for(j=0;j<9;j++){
setcolor(5);/**/
rectangle(block.x[j],block.y[j],block.x[j]+10,block.y[j]-10);
block.yes=0;
}
}
if(game.level==3){/*畫出障礙物*/
for(j=0;j<14;j++){
setcolor(5);/**/
rectangle(block.x[j],block.y[j],block.x[j]+10,block.y[j]-10);
block.yes=0;
}
}
if(game.level==4){/*畫出障礙物*/
for(j=0;j<19;j++){
setcolor(5);/**/
rectangle(block.x[j],block.y[j],block.x[j]+10,block.y[j]-10);
block.yes=0;
}
}
if(game.level==5){/*畫出障礙物*/
for(j=0;j<25;j++){
setcolor(5);/**/
rectangle(block.x[j],block.y[j],block.x[j]+10,block.y[j]-10);
block.yes=0;
}
}
if(food.yes==1){/*需要畫出新的食物*/
food.x=rand()%400+60;/*獲得間隔60的隨機數食物坐標值*/
food.y=rand()%350+60;
while(food.x%10!=0)/*判斷坐標值是否滿足被10整除,否,自動增加*/
food.x++;
while(food.y%10!=0)
food.y++;
food.yes=0;/*新的食物已經產生*/
}

if(goods.yes==1){/*需要畫出新的寶物*/
goods.x=rand()%380+60;/*獲得間隔60的隨機數寶貝坐標值*/
goods.y=rand()%320+80;
while(goods.x%10!=0)/*判斷坐標值是否滿足被10整除,否,自動增加*/
goods.x++;
while(goods.y%10!=0)
goods.y++;
goods.yes=0;/*新的寶貝已經產生*/
}
if(goods.yes==0){/*新寶貝產生,應顯示出來*/

setcolor(0);/*擦除*/
rectangle(goods.x,goods.y,goods.x+10,goods.y-10);
delay(50);/*延時*/
setcolor(YELLOW);
goods.x=goods.x+random(10)-random(20);/*隨機數增量*/
goods.y=goods.y+random(10)-random(20);
while(goods.x%10!=0)/*判斷變化後的坐標值是否滿足被10整除,否,自動增加*/
goods.x++;
while(goods.y%10!=0)
goods.y++;
rectangle(goods.x,goods.y,goods.x+10,goods.y-10);/*重畫出寶貝*/
if(goods.x585||goods.y445){/*判定寶貝是否越界*/
setcolor(0);/*擦除越界的寶貝*/
rectangle(goods.x,goods.y,goods.x+10,goods.y-10);
goods.yes=1;/*越界後重新生成寶貝*/
}

}

if(food.yes==0){/*新食物產生,應顯示出來*/
setcolor(GREEN);
setlinestyle(SOLID_LINE,0,THICK_WIDTH);/*設定當前線型*/
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.x[0]+=10;break;/*向右*/
case 2:snake.x[0]-=10;break;/*向左*/
case 3:snake.y[0]-=10;break;/*向上*/
case 4:snake.y[0]+=10;break;/*向下*/
}
for(i=3;i<snake.node;i++){/*超過4節後,判斷蛇自身碰撞*/
if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0]){/*即自身的任一節坐標值與蛇頭坐標相等*/
for(i=1;i<snake.node-1;i++){/*擦除自己碰撞後位置蛇的身子*/
setcolor(0);
rectangle(snake.x[i],snake.y[i],snake.x[i]+10,snake.y[i]-10);
rectangle(snake.x[snake.node-1],snake.y[snake.node-1],
snake.x[snake.node-1]+10,snake.y[snake.node-1]-10);
}
snake.life-=1;/*生命值減少一*/
snake.node-=5;
prscore();/*輸出結果*/
if(snake.life==0){/*判斷生命值是否為0*/
gameover();/*游戲結束*/
break;/*退出內循環*/
}
}
}
if(snake.x[0]595||snake.y[0]455){/*判斷蛇是否與牆體碰撞*/
for(i=1;i<snake.node-1;i++){/*擦除撞牆後位置蛇的身子*/
setcolor(0);
rectangle(snake.x[i],snake.y[i],snake.x[i]+10,snake.y[i]-10);
rectangle(snake.x[snake.node-1],snake.y[snake.node-1],
snake.x[snake.node-1]+10,snake.y[snake.node-1]-10);
}
snake.x[0]=100;snake.y[0]=100;/*蛇頭的位置坐標重新初始化*/
snake.x[1]=110;snake.y[1]=100;
snake.direction=1;/*蛇起始的移動方向定義為向右*/
snake.life-=1;/*生命值減少一*/
snake.node-=5;/*相應節數減少5節*/
prscore();
if(snake.life==0){
gameover();
break;
}
}
/*判斷蛇與障礙物碰撞,食物是否與障礙物重疊*/
if(game.level==1){/*判斷級別,並設定相應的障礙物數量,即數組個數*/
k=5;
}
else if(game.level==2){
k=9;
}
else if(game.level==3){
k=14;
}
else if(game.level==4){
k=19;
}
else if(game.level==5){
k=25;
}
for(j=0;j<k;j++){
if(snake.x[0]==block.x[j]&&snake.y[0]==block.y[j]){
for(i=1;i<snake.node-1;i++){/*擦除撞牆後位置蛇的身子*/
setcolor(0);
rectangle(snake.x[i],snake.y[i],snake.x[i]+10,snake.y[i]-10);
rectangle(snake.x[snake.node-1],snake.y[snake.node-1],
snake.x[snake.node-1]+10,snake.y[snake.node-1]-10);
}
if(food.x==block.x[j]&&block.y[j]==food.y){/*防止障礙物與食物重疊*/
setcolor(0);/*設定食物的顏色為背景色,即擦除*/
rectangle(food.x,food.y,food.x+10,food.y-10);
food.yes=1;/*食物重新生成*/
}
snake.x[0]=100;snake.y[0]=100;/*蛇頭的位置坐標重新初始化*/
snake.x[1]=110;snake.y[1]=100;
snake.direction=1;/*蛇起始的移動方向定義為向右*/
snake.life-=1;
snake.node-=5;
prscore();
if(snake.life==0){
gameover();
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.node++;/*蛇身增加一節*/
if(snake.node>2){/*當節數每增加5節生命值增加一*/
snake.life=1+fabs((snake.node-2)/5);
}
food.yes=1;/*場景需要增加食物*/
game.score+=20;/*加分*/
prscore();/*輸出得分*/
}
if(snake.x[0]==goods.x&&snake.y[0]==goods.y){/*判定蛇是否得到寶貝*/
setcolor(0);/*設定寶貝的顏色為背景色,即擦除*/
rectangle(goods.x,goods.y,goods.x+10,goods.y-10);
goods.yes=1;/*場景需要增加新的寶貝*/
game.score+=100;/*得到寶貝後加100分*/
prscore();/*輸出得分*/
}

if(game.score<500){/*設定游戲速度和難度級別*/
game.speed=50000;
game.level=1;}
else if(game.score>=500&&game.score<1000){
game.level=2;
game.speed=40000;}
else if(game.score>=1000&&game.score<1500){
game.level=3;
game.speed=30000;}
else if(game.score>=1500&&game.score<2000){
game.level=4;
game.speed=20000; }
else if(game.score>=5000){
game.level=5;
game.speed=10000;}

setcolor(4);/*畫出移動的蛇*/
setlinestyle(SOLID_LINE,0,THICK_WIDTH);/*設定當前線型*/
for(i=0;i<snake.node;i++)
rectangle(snake.x[i],snake.y[i],snake.x[i]+10,snake.y[i]-10);
delay(game.speed);
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);

} /*endwhile(! kbhit) */

if(snake.life==0)/*判斷循環結束條件:蛇死或者檢測到Esc按鍵*/
break;

key=bioskey(0);/*判斷按鍵*/
if(key==Esc)
break;
/*判斷蛇頭接收到的用戶按鍵響應的移動方向*/
else if(key==UP&&snake.direction!=4)
snake.direction=3;
else if(key==RIGHT&&snake.direction!=2)
snake.direction=1;
else if(key==LEFT&&snake.direction!=1)
snake.direction=2;
else if(key==DOWN&&snake.direction!=3)
snake.direction=4;

}/*endwhile(1)*/
}
void gameover(void){/*游戲結束處理*/
cleardevice();/*清屏*/
prscore();/*輸出得分*/
setcolor(RED);/*列印出「Game Over」字樣*/
settextstyle(0,0,4);
outtextxy(200,200,"Game Over!");
getch();
}

void prscore(void){/*定義分數輸出函數*/
char str1[10];
char str2[10];
char str4[20];
setfillstyle(SOLID_FILL,BLUE);/*用於清除舊的顯示信息*/
bar(49,10,320,37);
setcolor(WHITE);
settextstyle(0,0,1);
sprintf(str1,"score:%d",game.score);/*輸出得分*/
outtextxy(55,20,str1);
sprintf(str2,"level:%d",game.level);/*輸出級別*/
outtextxy(250,20,str2);
sprintf(str4,"life:%d",snake.life);/*輸出級別*/
outtextxy(150,20,str4);
}

void close(void){/*定義關閉函數,退出圖形模式*/
getch();
closegraph();
}

Ⅳ 用C語言設計小游戲的程序急!!!

用c++實現的"貪吃蛇"游戲源碼
// greedsnake.cpp
#include <bios.h>
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#include <stdlib.h>
#include <time.h>
#include "conf.h"

typedef struct node
{
int x,y;
struct node *next;
}Node;

typedef struct
{
Node *head,*tail;
int length;
}Snake;
typedef struct
{
int left,top,right,bottom;
}Frame;

typedef enum //四個方向
{
up,down,left,right
}Direction;

typedef enum
{
false,true
}bool;//*/

void InitGraphMode(); //初始化圖形驅動
void CloseGraphMode();
void Foot(int,int);
void Head(int,int);
void CreateFrame(); //完成整個游戲框架的繪制
void CreateSnake(); //創建一條兩個節點的蛇,蛇的每一節是隊列中的一個節點
bool PlayGame(); //游戲的主體函數,
int Hit(int,int); //判斷是否越界,或者撞到自身,兩個參數分別是新的頭接點的x,y坐標
bool GameOver(); //繪制游戲結束時彈出的對話框
void Enqueue(Node); //入隊函數
Node Dequeue(); //出隊函數
void ClearKeyBuf(); //清除鍵盤緩沖,此函數可以消除不停的按無效鍵的影響

Snake snake;
Frame frame;
void main()
{
InitGraphMode();
do
{
CreateFrame();
}while(PlayGame());
CloseGraphMode();
}
void InitGraphMode()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"../bgi/");
cleardevice();
}
void CloseGraphMode()
{
cleardevice();
closegraph();
}
void CreateFrame()
{
setbkcolor(CYAN);
//下面的四行代碼用於計算主框架的左上角和右下角的坐標
frame.left=(getmaxx()+1-BlockWidth*RowOfFrame)/2;
frame.top=(getmaxy()+1-BlockHeight*ColumnOfFrame)/2;
frame.right=frame.left+BlockWidth*RowOfFrame;
frame.bottom=frame.top+BlockHeight*ColumnOfFrame;
Head(frame.left+100,frame.top-20);
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(frame.left,frame.top,frame.right,frame.bottom);
setlinestyle(SOLID_LINE,1,1);
setcolor(DARKGRAY);
line(frame.left,frame.top,frame.right,frame.top);
line(frame.left,frame.top,frame.left,frame.bottom);
setlinestyle(SOLID_LINE,1,1);
setcolor(WHITE);
line(frame.left,frame.bottom,frame.right,frame.bottom);
line(frame.right,frame.top,frame.right,frame.bottom);
setlinestyle(DOTTED_LINE,1,1);
setcolor(BLUE);
for(int row=1;row<RowOfFrame;row++)
line(frame.left+row*BlockWidth,frame.top,frame.left+row*BlockWidth,frame.bottom);
for(int column=1;column<ColumnOfFrame;column++)
line(frame.left,frame.top+column*BlockHeight,frame.right,frame.top+column*BlockHeight);
Foot(frame.left,frame.bottom+20);
}
void CreateSnake()
{
Node *node1=new Node;
Node *node2=new Node;
node1->x=frame.left+BlockWidth;
node1->y=frame.top;
node1->next=NULL;
snake.tail=node1;
node2->x=frame.left;
node2->y=frame.top;
node2->next=snake.tail;
snake.head=node2;
snake.length=2;
setfillstyle(SOLID_FILL,BLUE);
bar(snake.head->x+1,snake.head->y+1,snake.head->x+BlockWidth-1,snake.head->y+BlockHeight-1);
bar(snake.tail->x+1,snake.tail->y+1,snake.tail->x+BlockWidth-1,snake.tail->y+BlockHeight-1);
}

bool PlayGame()
{
int speed=300,key;
Direction CurrentDirection=right;
Node randomNode;
Node newNode,outNode;
bool neednode=true;
bool overlap=false;
int randx,randy;
CreateSnake();

while(true)
{
if(neednode==true)
{
randomize();
do
{
randx=frame.left+rand()%RowOfFrame*BlockWidth;
randy=frame.top+rand()%ColumnOfFrame*BlockHeight;
for(Node *p=snake.head;p!=NULL;p=p->next)//hit itself
if(randx==p->x&&randy==p->y)
{overlap=true;break;}
}
while(overlap==true);
randomNode.x=randx;
randomNode.y=randy;
randomNode.next=NULL;
setfillstyle(SOLID_FILL,RED);
bar(randomNode.x+1,randomNode.y+1,randomNode.x+BlockWidth-1,randomNode.y+BlockHeight-1);
neednode=false;
}

if((key=bioskey(1))!=0)
{
switch(key)
{
case ESC: return false;
case UP:
if(CurrentDirection!=down)
CurrentDirection=up;
ClearKeyBuf();
break;
case DOWN:
if(CurrentDirection!=up)
CurrentDirection=down;
ClearKeyBuf();
break;
case LEFT:
if(CurrentDirection!=right)
CurrentDirection=left;
ClearKeyBuf();
break;
case RIGHT:
if(CurrentDirection!=left)

CurrentDirection=right;
ClearKeyBuf();
break;
case PAGEUP:speed=speed-100;
if(speed<100)
speed=100;
ClearKeyBuf();
break;
case PAGEDOWN:speed=speed+100;
if(speed>500)
speed=500;
ClearKeyBuf();
break;
default :break;
}
}
int headx=snake.tail->x;
int heady=snake.tail->y;
switch(CurrentDirection)
{
case up: heady-=BlockHeight;break;
case down: heady+=BlockHeight;break;
case left: headx-=BlockWidth;break;
case right: headx+=BlockWidth;break;
}
if(Hit(headx,heady)) //whether the snake hit the wall or itself
return GameOver();
else
{ //eat
if(headx==randomNode.x&&heady==randomNode.y)
{
Enqueue(randomNode);
setfillstyle(SOLID_FILL,BLUE);
bar(randomNode.x+1,randomNode.y+1,randomNode.x-1+BlockWidth,randomNode.y-1+BlockHeight);
neednode=true;
}
else //no eat
{
newNode.x=headx;
newNode.y=heady;
newNode.next=NULL;
Enqueue(newNode);
outNode=Dequeue();
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(outNode.x+1,outNode.y+1,outNode.x+BlockWidth-1,outNode.y+BlockHeight-1);
setfillstyle(SOLID_FILL,BLUE);
bar(newNode.x+1,newNode.y+1,newNode.x-1+BlockWidth,newNode.y-1+BlockHeight);
}
}
delay(speed);
}
}
void ClearKeyBuf()
{
do
bioskey(0);
while(bioskey(1));
}

void Foot(int x,int y)
{
setcolor(BLUE);
outtextxy(x,y,"writer:[T]RealXL E-MAIL:[email protected]");
}
void Head(int x,int y)
{
setcolor(RED);
outtextxy(x,y,"GREEDY SNAKE");
}
void Enqueue(Node inNode)
{
Node *p=new Node;
p->x=inNode.x;
p->y=inNode.y;
p->next=inNode.next;
snake.tail->next=p;
snake.tail=p;
snake.length++;
}
Node Dequeue()
{
Node *p=snake.head;
Node outNode=*p;
snake.head=p->next;
snake.length--;
delete p;
return outNode;
}

int Hit(int x,int y)
{
if(x<frame.left||x>=frame.right||y<frame.top||y>=frame.bottom)//hit the wall
return 1;

Node *p=snake.head->next;
for(int i=snake.length-1;i>3;i--,p=p->next)//hit itself
if(x==p->x&&y==p->y)
return 1;
return 0;
}

bool GameOver()
{
int x=getmaxx()/2-50;
int y=getmaxy()/2-20;
setfillstyle(SOLID_FILL,DARKGRAY);
bar(x+3,y+3,x+103,y+43);
setfillstyle(SOLID_FILL,MAGENTA);
bar(x,y,x+100,y+40);
setlinestyle(0,3,1);
setcolor(RED);
rectangle(x,y,x+100,y+40);
outtextxy(x+20,y+10,"GAGE OVER!");
char c;
while(true) //按q或Q表示退出程序,按r或R表示重新開始游戲
{
c=getch();
if(c=='q'||c=='Q')
return false;
else if(c=='r'||c=='R')
return true;
}
}

C++五子棋源程序:

#include
#include
#include
#define backcolor CYAN
#define defaultcolor BLACK
#define linecolor MAGENTA
#define player1_color RED
#define player2_color WHITE
#define error_color RED
#define winner_color RED

const int left=40;
const int top=390;
const int d=30;
const int line_num=9;
const int turn=0;
const int r=d/3;
const int j=10;
int x,y,k=1,step=(line_num+1)*(line_num+1);
union REGS regs1,regs2;
class player1;
class player2;
class qipan{
public:
qipan();
~qipan(){};
void init_qipan();
friend void fall(player1 &num1,player2 &num2,qipan &num);
friend void input(player1 &num1,player2 &num2,qipan &num);

private:
int point[line_num+1][line_num+1];

};
class player1{
public:
player1();
~player1(){};
friend void fall(player1 &num1,player2 &num2,qipan &num);
friend void input(player1 &num1,player2 &num2);
friend int judge_winner(player1 &num1,player2 &num2);
private:
int point1[line_num+1][line_num+1];
};
class player2{
public:
player2();
~player2(){};
friend void fall(player1 &num1,player2 &num2,qipan &num);
friend void input(player1 &num1,player2 &num2,qipan &num);
friend int judge_winner(player1 &num1,player2 &num2);
private:
int point2[line_num+1][line_num+1];
};
void input(player1 &num1,player2 &num2);
void fall(player1 &num1,player2 &num2,qipan &num);
int judge_winner(qipan &num,player1 &num1,player2 &num2);
void inputerror();
void display_winner(int);

void main()
{
int driver=DETECT,mode;
initgraph(&driver,&mode,"e:\tc30\bgi");

qipan num;
player1 num1;
player2 num2;
while(step--)
{
input(num1,num2,num);
fall(num1,num2,num);
if(judge_winner(num1,num2))
{
display_winner(k);
}
}

// getchar();
}
qipan::qipan(void)
{ int j,i;
char ch[2]="0";
setbkcolor(backcolor);
setcolor(linecolor);
for(i=0;i<=line_num;i++)
{
line(left,top-i*d,left+line_num*d,top-i*d);
}
for(i=0;i<=line_num;i++)
{
line(left+i*d,top,left+i*d,top-line_num*d);
}
for(i=0;i<=line_num;i++)
{ if(*ch=='9'+1) *ch='a';
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(left+i*d-2,top+r+3,ch);
(*ch)=(*ch)+1;
}
*ch='0';
for(i=0;i<=line_num;i++)
{if(*ch=='9'+1) *ch='a';
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(left-r-10,top-d*i-3,ch);
(*ch)=(*ch)+1;
}

setcolor(defaultcolor);

for(i=0;i<=line_num;i++)
{
for(j=0;j<=line_num;j++)
point[i][j]=0;
}
}

void fall(player1 &num1,player2 &num2,qipan &num)
{
int flag=k%2;
if(flag)
{ setcolor(player2_color);
num2.point2[x][y]=1;
num.point[x][y]=2;
circle(left+d*x,top-d*y,r);
setfillstyle(1,player2_color);
floodfill(left+d*x,top-d*y,player2_color);
}
else
{ num1.point1[x][y]=1;
num.point[x][y]=1;
setcolor(player1_color);
circle(left+d*x,top-d*y,r);
setfillstyle(1,player1_color);
floodfill(left+d*x,top-d*y,player1_color);
}

setcolor(defaultcolor);
}

void input(player1 &num1,player2 &num2,qipan &num)
{ char xx,yy;

k++;
while(1)
{
regs1.h.ah=0;
xx=int86(22,®s1,®s1)-'0';
if(xx==('q'-'0')||xx==('Q'-'0'))
{ step=0;
return;
}
regs1.h.ah=0;
yy=int86(22,®s1,®s1)-'0';

if(yy==('q'-'0')||yy==('Q'-'0'))
{
step=0;
return ;
}
if(xx<0||xx>line_num)
{ inputerror();
continue;
}
if(yy<0||yy>line_num)
{inputerror();
continue;
}

if(num.point[xx][yy]==0)
{
break;
}
else
{
inputerror();
continue;
}
}

x=(int)xx;
y=(int)yy;

setcolor(backcolor);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(left+d*line_num/3,top+d*2,"Input error");
setcolor(defaultcolor);
}

player1::player1()
{
int i,j;
for(i=0;i<=line_num;i++)
{
for(j=0;j<=line_num;j++)
point1[i][j]=0;
}
}

player2::player2()
{ int i,j;
for(i=0;i<=line_num;i++)
{
for(j=0;j<=line_num;j++)
point2[i][j]=0;
}
}
void inputerror(void)
{ setcolor(error_color);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(left+d*line_num/3,top+d*2,"Input error");
setcolor(defaultcolor);
}

int judge_winner(player1 &num1,player2 &num2)
{
int count=0,m=0,n=0,a=0,b=0,xx0,yy0;
int flag=k%2;
xx0=x; yy0=y;
if(!flag)
{ //left <-------> right
while(xx0>=1&&m<4) {xx0--;m++;}
while(n<9&&xx0<=line_num)
{
if(num1.point1[xx0][y]==1)
{
count++;
if(count==5) return 1;
}
else
{
count=0;
}
n++;
xx0++;
}
//up <------> down
count=0; xx0=x; m=0; n=0;
while(yy0>=1&&m<4){yy0--;m++;}
while(n<9&&yy0<=line_num)
{
if(num1.point1[x][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
{
count=0;
}
n++;
yy0++;
}
//left up ----- right down
xx0=x;
yy0=y;
m=0;
n=0;
count=0;
while(xx0>=1&&m<4){ xx0--; a++; m++;} m=0;
while(yy0<=line_num&&m<4){ yy0++; b++; m++;}
if(a<=b)
{
xx0=x-a; yy0=y+a;
}
else
{
xx0=x-b; yy0=y+b;
}
while(xx0<=line_num&&yy0>=0&&n<9)
{
if(num1.point1[xx0][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
{
count=0;
}
xx0++;
yy0--;
n++;
}
//right up <-----> left down
count=0;
a=0;
b=0;
n=0;
m=0;
xx0=x;
yy0=y;
while(xx0while(yy0if(a<=b)
{
xx0=x+a;
yy0=y+a;
}
else
{
xx0=x+b;
yy0=y+b;
}
while(xx0>=0&&yy0>=0&&n<9)
{
if(num1.point1[xx0][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
count=0;
xx0--;
yy0--;
n++;
}
//no winer
return 0;
}
else
{
//left <-------> right
while(xx0>=1&&m<4) {xx0--;m++;}
while(n<9&&xx0<=line_num)
{
if(num1.point1[xx0][y]==1)
{
count++;
if(count==5) return 1;
}
else
{
count=0;
}
n++;
xx0++;
}
//up <------> down
count=0; xx0=x; m=0; n=0;
while(yy0>=1&&m<4){yy0--;m++;}
while(n<9&&yy0<=line_num)
{
if(num2.point2[x][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
{
count=0;
}
n++;
yy0++;
}
//left up ----- right down
xx0=x;
yy0=y;
m=0;
n=0;
count=0;
while(xx0>=1&&m<4){ xx0--; a++; m++;} m=0;
while(yy0<=line_num&&m<4){ yy0++; b++; m++;}
if(a<=b)
{
xx0=x-a; yy0=y+a;
}
else
{
xx0=x-b; yy0=y+b;
}
while(xx0<=line_num&&yy0>=0&&n<9)
{
if(num2.point2[xx0][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
{
count=0;
}
xx0++;
yy0--;
n++;
}
//right up <-----> left down
count=0;
a=0;
b=0;
n=0;
m=0;
xx0=x;
yy0=y;
while(xx0while(yy0if(a<=b)
{
xx0=x+a;
yy0=y+a;
}
else
{
xx0=x+b;
yy0=y+b;
}
while(xx0>=0&&yy0>=0&&n<9)
{
if(num2.point2[xx0][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
count=0;
xx0--;
yy0--;
n++;
}
//no winer
return 0;

}
}

void display_winner(int k)
{
int flag=k%2;
if(!flag)
{ setcolor(winner_color);
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
outtextxy(left+d*2,top+40,"Red is winner");
setcolor(defaultcolor);
step=0;
getchar();
}
else
{ setcolor(winner_color);
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
outtextxy(left+2*d,top+40,"White is winner");
setcolor(defaultcolor);
step=0;

}
}

Ⅳ C語言程序設計課程設計撲克牌游戲,怎麼做

#include<conio.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
int jisuan(int);
int comptotal;
char s1[]="A234567890JQK";
//char s2[4][5]={"紅桃","黑桃","草花","方塊"};
char s2[4]={3,4,5,6};
int poke[52];
int ch;
int win=0;
int computer[5],user[5];
int usertotal;
int users;
int k;
int main()
{ void xipai(int poke[]);
void ai();
int i,j;
////////////////////////////////////////////////////////上面是變數和聲明
printf("\n這是簡單的廿一點游戲:\n");
for(i=0;i<52;i++)
{
if(i%13==0)putchar('\n');
poke[i]=i;
printf("%c%c%c ",s2[i/13],s1[i%13]=='0'?'1':' ',s1[i%13]);
}
putchar('\n');

/////////////////////////////////////////////////////////主代碼
k=0;
xipai(poke);
while(ch!=27)
{ comptotal=0;
usertotal=0;
if(k>=42)
{
printf("\n剩餘牌數不足十張,重新洗牌");
xipai(poke);
k=0;
}

printf("\n\n\n\n\n\n\n\n新局開始:\n");
printf("現在共有牌%2d張\n",52-k);
if(win==0)
{
computer[0]=k++;
user[0]=k++;
printf("\n電腦做莊,要牌:");
ai();
}
else
{
printf("\n玩家做莊,要牌:\n\t回車要牌\n\t空格過牌");
user[0]=k++;
computer[0]=k++;
}

printf("\n玩家開始要牌:\n");
usertotal=jisuan(poke[user[0]]);
printf("%c%c%c 共%2d點\t",s2[poke[user[0]]/13],s1[poke[user[0]]%13]=='0'?'1':' ',s1[poke[user[0]]%13],usertotal);
users=0;
ch=1;
while(ch!=32&&users<4)
{
ch=getch();
switch(ch)
{
case 27:
goto end;
break;
case 32:
break;
case 13:
user[++users]=k;
usertotal+=jisuan(poke[user[users]]);
printf("\b\b\b\b\b\b\b\b\b%c%c%c 共%2d點\t",s2[poke[k]/13],s1[poke[k]%13]=='0'?'1':' ',s1[poke[k]%13],usertotal);

k++;
if(usertotal>=21)ch=32;
break;
default:
break;
}
}
if(win==1)
{
printf("\n電腦開始要牌:\n");
ai();
}
printf("\n\n\n玩家的點數是%2d",usertotal);
printf("\n電腦的點數是%2d",comptotal);
printf("\n\n本局結算:");
if(comptotal>21&&usertotal<=21)
{
printf("\n\n電腦爆牌了");
win=1;
printf("\n恭喜,你贏了");
}

if(usertotal>21&&comptotal<=21)
{
printf("\n\n你爆牌了");
printf("\n下次小心點");
win=0;
}
if(usertotal>21&&comptotal>21)
{
printf("\n\n你們兩個,怎麼都這么不小心啊,都撐死了還要嗎");
}
if(usertotal<=21&&comptotal<=21)
{
if(usertotal>comptotal)
{
win=1;
printf("\n\n不錯,你贏了");
}
else if(usertotal<comptotal)
{
win=0;
printf("\n\n撐死膽大的,餓死膽小的,沒膽子,輸了吧");
}
else
printf("\n\n平了,算你走運");
}
getch();
}
end:
return 0;
}
void xipai(int poke[])
{
int y,tmp,i,j;
for(j=0;j<7;j++)
for(i=0;i<52;i++)
{
srand(time(0));
y=rand()%10;
tmp=poke[i];
poke[i]=poke[(y*i*i)%52];
poke[(y*i*i)%52]=tmp;
}

}
///////////////////////////////////////////////子函數
void ai()
{
int i;
comptotal=jisuan(poke[computer[0]]);
printf("\n%c%c%c 共%2d點\t",s2[poke[computer[0]]/13],s1[poke[computer[0]]%13]=='0'?'1':' ',s1[poke[computer[0]]%13],comptotal);
for(i=0;i<4;i++)
{
if(comptotal<17)
{
computer[i+1]=k++;
comptotal+=jisuan(poke[computer[i+1]]);
printf("\b\b\b\b\b\b\b\b\b%c%c%c 共%2d點\t",s2[poke[computer[i+1]]/13],s1[poke[computer[i+1]]%13]=='0'?'1':' ',s1[poke[computer[i+1]]%13],comptotal);
}
}
}

int jisuan(int i)
{int dian;
switch(i%13)
{
case 0:
case 10:
case 11:
case 12:
dian=1;
break;
default:
dian=i%13+1;
}
return dian;
}

Ⅵ C語言程序設計實驗報告怎麼寫啊

通過本試驗初步培養計算機邏輯解題能力。熟練掌握賦值語句和if語句的應用;掌握switch多路分支語句和if嵌套語句的使用

Ⅶ C語言編程 課程設計 數學游戲

我先編一編哦,代碼寫好了我會放在我的網路空間的文章里邊的,到時候你到那裡去找吧
你最好也自己編一編吧,編程這東西是越編越會的,不編永遠也不會的,加油啦!

Ⅷ 用C語言設計一個游戲,華容道的游戲,請高手幫忙~~

package 華容道;

import java.awt.*;
import java.awt.event.*;
//主函數
public class Main {
public static void main(String[] args) {
new Hua_Rong_Road();
}
}
//人物按鈕顏色
class Person extends Button implements FocusListener{
int number;
Color c=new Color(255,245,170);
Person(int number,String s)
{
super(s);
setBackground(c);//人物的顏色背景是黃色
this.number=number;
c=getBackground();
addFocusListener(this);//好像是焦點監聽器
}
public void focusGained(FocusEvent e)
{
setBackground(Color.red);//只要單擊該按鈕則按鈕變顏色
}
public void focusLost(FocusEvent e) {
setBackground(c);//上一個按鈕回復原先的顏色
}
}
//華容道總類
class Hua_Rong_Road extends Frame implements MouseListener,KeyListener,ActionListener{
Person person[] = new Person[10];
Button left,right,above,below;
Button restart = new Button("Start");//重新開始按鈕
public Hua_Rong_Road()
{
init();
setBounds(100,100,320,360);
setVisible(true);//設置Frame為可見,默認為不可見
validate();
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public void init()
{
setLayout(null);
add(restart);
restart.setBounds(100, 320, 120, 25);
restart.addActionListener(this);
String name[]={"我","陸遜","姜維","陳宮","許攸","鄧艾","周瑜","龐統","諸葛亮","賈詡"};
for(int k=0;k<name.length;k++)
{
person[k]=new Person(k,name[k]);
person[k].addMouseListener(this);
person[k].addKeyListener(this);
add(person[k]);
}//為所有的按鈕注冊所需的東西
person[0].setBounds(104, 54, 100, 100);
person[1].setBounds(104,154, 100, 50);
person[2].setBounds(54, 154, 50, 100);
person[3].setBounds(204, 154, 50, 100);
person[4].setBounds(54, 54, 50, 100);
person[5].setBounds(204, 54, 50, 100);
person[6].setBounds(54, 254,50, 50);
person[7].setBounds(204, 254, 50, 50);
person[8].setBounds(104, 204, 50, 50);
person[9].setBounds(154, 204, 50, 50);
//初始化按鈕的位子
person[0].requestFocus();
left=new Button();
right=new Button();
above=new Button();
below=new Button();
left.setBounds(49,49,5,260);
right.setBounds(254,49,5,260);
above.setBounds(49,49,210,5);
below.setBounds(49,304,210,5);
validate();
}
public void keyTyped(KeyEvent e){}
public void keyReleased(KeyEvent e){}
public void keyPressed(KeyEvent e)
{
Person man=(Person)e.getSource();
if(e.getKeyCode()==KeyEvent.VK_DOWN)
{
go(man,below);
}
if(e.getKeyCode()==KeyEvent.VK_UP)
{
go(man,above);
}
if(e.getKeyCode()==KeyEvent.VK_LEFT)
{
go(man,left);
}
if(e.getKeyCode()==KeyEvent.VK_RIGHT)
{
go(man,right);
}
}
public void mousePressed(MouseEvent e)
{
Person man =(Person)e.getSource();
int x=-1,y=-1;
x=e.getX();
y=e.getY();
int w=man.getBounds().width;
int h=man.getBounds().height;
if(y>h/2)
{
go(man,below);
}
if(y<h/2)
{
go(man,above);
}
if(x<w/2)
{
go(man,left);
}
if(x>w/2)
{
go(man,right);
}
}

public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
public void go(Person man,Button direction)
{
boolean move=true;
Rectangle manRect=man.getBounds();
int x=man.getBounds().x;
int y=man.getBounds().y;
if(direction==below)
y=y+50;
else if(direction==above)
y=y-50;
else if(direction==left)
x=x-50;
else if(direction==right)
x=x+50;
manRect.setLocation(x,y);
Rectangle directionRect=direction.getBounds();
for(int k=0;k<10;k++)
{
Rectangle personRect=person[k].getBounds();
if((manRect.intersects(personRect))&&(man.number!=k))
{
move=false;
}
}
if(manRect.intersects(directionRect))
{
move=false;
}
if(move==true)
{
man.setLocation(x,y);
}
}
public void actionPerformed(ActionEvent e)
{
dispose();
new Hua_Rong_Road();
}
}

Ⅸ 求助:c語言程序設計報告 猜數游戲 謝謝!

#include<stdio.h>
#include<stdlib.h>

#include<time.h>
int main()
{
int n,i,j=0,cnt=0;
char c;
srand(time(0));
do
{ j=0;
cnt=0;
i=rand()%100;
do
{
printf("輸入一個0~99的數字:");
cnt++;
scanf("%d",&n);
getchar();
if(n==i){printf("WINER!\nPlay again?Y/N:");j=1;}
else if(n>i)printf("GREATER THEN!\n");
else printf("LESS THEN!\n");
if(cnt>10){printf("END.\nThe answer=%d!\nPlay again?Y/N:",i);j=1;break;}
}
while(j==0);

c=getchar();
}
while(c=='y'||c=='Y');

return 0;
}

Ⅹ c語言程序設計實驗報告80~100行,關於一種小游戲的,語句簡單些,

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define MAX_PARKING_SIZE 10//停車場最大停車數量
#define PRIZE 10.00//停留每小時單價
#define true 1
#define false 0

typedef struct stack
{
long pos[MAX_PARKING_SIZE];//存儲車牌號碼
int time[MAX_PARKING_SIZE];//存儲進入車站的時間
int point;//最後一輛車的位置指針
}Stack;//定義棧-模擬停車場

typedef struct queue
{
int num;//存儲車牌號
struct queue *next;//指向下一輛車
}Queue;//定義隊列-模擬停車場外

void InitStack(Stack *s)
{
s->point=-1;
}//初始化棧

Queue *InitQueue()//初始化隊列
{
Queue *q;
q=(Queue *)malloc(sizeof(Queue));
q->next=NULL;
return q;
}

int StackPop(Stack *s,long *i,int *j)//退棧函數
{
if(s->point==-1)return false;
else
{
*i=s->pos[s->point];
*j=s->time[s->point];
s->point--;
return true;
}
}

int StackPush(Stack *s,long i,int j)//壓棧函數
{
if(s->point==MAX_PARKING_SIZE-1)return false;
else
{
s->point++;
s->pos[s->point]=i;
s->time[s->point]=j;
return true;
}
}

int QueuePop(Queue **qH,long *i)//退隊函數
{
Queue *temp;
if((*qH)->next==NULL)return false;
else
{
temp=(*qH)->next;
(*qH)->next=temp->next;
*i=temp->num;
free(temp);
return true;
}
}

int QueuePush(Queue **q,long i)//入隊函數
{
Queue *temp;
if((temp=(Queue *)malloc(sizeof(Queue)))==NULL)return false;
else
{
(*q)->next=temp;
temp->num=i;
temp->next=NULL;
*q=temp;
return true;
}
}

int main()
{
int time,i,j,inStack,inQueue;
long num;
char state;
Stack park;
Queue *H,*p,*temp,*temp2;
H=InitQueue();
p=H;
system("color 9E");
InitStack(&park);//初始化隊列和棧
printf("**********這里是停車場管理程序,歡迎使用**************\n");
printf("\n停車場最大能停車%d輛,停車時間不得超過24小時,現在停車的單價為每小時%.2f元\n",MAX_PARKING_SIZE,PRIZE);
while(1)
{
inStack=inQueue=0;temp=H;
printf("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
printf("┃ 停車場管理系統 ┃\n");
printf("┃ (A或a)汽車到達和已到汽車查詢 ┃\n");
printf("┃ (D或d)汽車離開 ┃\n");
printf("┃ (E或e)程序退出 ┃\n");
printf("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");
printf("\n您的選擇是:");

state=getche();
if(state=='a'||state=='A'||state=='d'||state=='D')
{
printf("\n輸入車牌號(數字):");
scanf("%ld",&num);
printf("\n輸入到達或查詢或離開的的時間(24小時制,單位:小時):");
scanf("%d",&time);
}
if(state=='a'||state=='A')
{
for(i=0;i<=park.point;i++)
if(park.pos[i]==num)
{
inStack=1;
break;
}//在車站中查找
for(j=1;temp->next!=NULL;j++)
{
temp2=temp;
temp=temp2->next;
if(temp->num==num)
{
inQueue=1;
break;
}
}//在車站外查找
if(inStack)
printf("\n查詢結果:輸入的汽車已經在車站中第%d個位置停留了%d個小時!\n",i+1,time>park.time[i]?time-park.time[i]:time+24-park.time[i]);
else if(inQueue)
printf("\n查詢結果:輸入的汽車已經在車站外第%d個位置等候\n",j);
else
{
if(StackPush(&park,num,time)==false)
{
QueuePush(&p,num);
printf("\n車站已滿,車輛停在場外。\n");
}
else printf("\n車輛成功進站!\n");
}//如果車輛到達,當車站已滿,停在車站外,否則,進入車站
}
else if(state=='d'||state=='D')//如果是離開
{
for(i=0;i<=park.point;i++)
if(park.pos[i]==num)
{
inStack=1;
break;
}//在車站中查找
if(inStack)//如果在車站中
{
printf("正要離開的汽車在車站中第%d個位置停留了%d個小時,應付%.2f元\n",i+1,time>park.time[i]?time-park.time[i]:time+24-park.time[i],time>park.time[i]?(time-park.time[i])*PRIZE:(time+24-park.time[i])*PRIZE);
while(i<park.point)
{
park.pos[i]=park.pos[i+1];
park.time[i]=park.time[i+1];
i++;
}
park.point--;//把離開的車輛從車站中刪除
if(H->next!=NULL)
{
QueuePop(&H,&num);
if(H->next==NULL)p=H;
StackPush(&park,num,time);
printf("\n停車場空出一位置。場外等候的%d號汽車入站了!\n",num);
}//如果車站外有車,入站
}
else//不在車站中
{
for(i=1;temp->next!=NULL;i++)
{
temp2=temp;temp=temp2->next;
if(temp->num==num)
{
inQueue=1;
break;
}
}//查找是否在車站外
if(inQueue)
{
printf("\n汽車在停車場外,不收費\n",i);
temp2->next=temp->next;
if(temp==p)p=temp2;
free(temp);
}//在車站外
else printf("\n對不起,您輸入了不存在的車牌號!\n");
}
}
else if(state=='e'||state=='E')
{
printf("\n");
break;
}
else printf("\n輸入錯誤!\n");
}
return 0;
}

熱點內容
免費ftp服務軟體 發布:2025-02-11 15:58:06 瀏覽:865
大櫻桃建園為什麼要配置授粉樹 發布:2025-02-11 15:58:00 瀏覽:628
五菱宏光s頂配有哪些配置 發布:2025-02-11 15:50:57 瀏覽:286
華為8加128配置有哪些 發布:2025-02-11 15:48:20 瀏覽:579
壓縮機三轉子 發布:2025-02-11 15:45:54 瀏覽:827
linux操作系統shell 發布:2025-02-11 15:45:53 瀏覽:338
安卓模擬器如何選擇安裝 發布:2025-02-11 15:34:26 瀏覽:176
安卓手機和華為哪個好用 發布:2025-02-11 15:32:11 瀏覽:555
大眾車載dv設置密碼多少 發布:2025-02-11 15:26:06 瀏覽:413
sqlserver連接超時 發布:2025-02-11 15:24:25 瀏覽:741