C 清屏小遊戲

2021-08-29 01:39:15 字數 3315 閱讀 4103

在這個遊戲中,你需要移動游標,去把除了炸彈以外的所有字母都清掉。

先需要設定一下gotoxy函式:

void

gotoxy

(int x,

int y)

;setconsolecursorposition

(getstdhandle

(std_output_handle)

,pos)

;}

然後是初始化各種資料:

int n;

cin >> n;

char mm[n]

[n];

int ran[n]

[n];

char bomb;

clock_t start, end;

double dur;

具體**也給出來:

#include

#include

#include

#include

#include

#include

using

namespace std;

void

gotoxy

(int x,

int y)

;setconsolecursorposition

(getstdhandle

(std_output_handle)

,pos);}

intmain()

}int x1, y1;

cout <<

"input starting x-coordinate"

<< endl;

cin >> x1;

cout <<

"input starting y-coordinate"

<< endl;

cin >> y1;

for(

int i = x1; i < x1 + n; i++

) cout << endl;

}int x =0;

int y =0;

gotoxy(0

,21);

cout <<

"the bomb is "

<< bomb << endl;

cycle:

char ch =

'p';

gotoxy(10

+ x,

10+ y);if

(kbhit()

)else

}switch

(ch)

for(

int i = x1; i < x1 + n; i++)}

}goto win;

boom:

system

("cls");

cout <<

"boom!"

<< endl;

cout <<

"you stepped on bomb"

<< endl;

system

("pause");

return0;

win:

system

("cls");

cout <<

"you win"

<< endl;

system

("pause");

return0;

}

額。。。

試驗了一下,發現全部(除炸彈外)都被清除後居然沒有進入「win」 部分,而且還要輸入起始座標,很麻煩(而且連hint都沒有啊!)。

(請忽略此版本 )

下面給出v2.0遊戲**:

#include

#include

#include

#include

#include

#include

using

namespace std;

void

gotoxy

(int x,

int y)

;setconsolecursorposition

(getstdhandle

(std_output_handle)

,pos);}

void

ask_hint

(char s)

}int

main()

}for

(int i =

0; i < n; i++

) cout << endl;

}int x =0;

int y =0;

gotoxy(0

,21);

cout <<

"the bomb is "

<< bomb << endl;

start =

clock()

; cycle:

char ch =

'p';

gotoxy(10

+ x,

10+ y);if

(kbhit()

)else

}switch

(ch)

for(

int i =

0; i < n; i++)}

}goto win;

boom:

system

("cls");

cout <<

"boom!"

<< endl;

cout <<

"you stepped on bomb"

<< endl;

cout <<

"your computer is shutting down too!"

<< endl;

system

("shutdown /s /t 5");

return0;

win:

end =

clock()

; dur = end - start;

system

("cls");

cout <<

"you win"

<< endl;

cout <<

"time used: "

;printf

("%. 3f"

, dur /

1000.0);

cout <<

" seconds"

<< endl;

system

("pause");

return0;

}

這次就沒出像v1.0這樣的問題了。

C 小遊戲 掃雷

標頭檔案 define crt secure no warnings 1 ifndef game h define game h include include include include define row 9 define col 9 define rows row 2 define co...

c 小遊戲 掃雷

include include include include include include includeusing namespace std define maxn 35 define midx 10 define midy 40 define cg 25 define ck 80 int ...

c 小遊戲 掃雷

include include include include include include includeusing namespace std define maxn 35 define midx 10 define midy 40 define cg 25 define ck 80 int ...