推箱子遊戲(簡易)

2021-10-09 20:54:13 字數 2681 閱讀 1972

標頭檔案:boxman.h

#define key_up 'w'

#define key_down 's'

#define key_left 'a'

#define key_right 'd'

#define key_quite 'q'

#define map_x 9

#define map_y 12

#define ratio 61

//畫素點

#define screen_width 960

#define screen_height 768

#define isvalid(pos) pos.x>=0 && pos.x=0 &&pos.ytypedef

enum _props props;

typedef

enum _direction direction;

typedef

struct _pos pos;

struct _pos

;enum _props

;enum _direction

;

.原始檔 :boxman.cpp

#include

#include

#include

#include

#include

#include

"boxman.h"

using

namespace std;

int hold=0;

//用來標記是否小人踩在目的地上

struct _pos man;

//小人在二維陣列中的位置

image images[all]

;//載入的陣列

int map[map_x]

[map_y]=,

,,,,

,,,,

};intmain()

putimage

(100

+j*61

,150

+i*61

,&images[map[i]

[j]]);

//對進行顯示}}

bool quite =

false;do

else

if(ch == key_down)

else

if(ch == key_left)

else

if(ch == key_right)

else

if(ch == key_quite)if(

isgameover()

)sleep

(100);

}}while

(!quite)

;system

("pause");

closegraph()

;return0;

}/************

* 作用:顯示道具

* line:道具在陣列的列座標

* cloumn:道具在陣列的行座標

* prop:道具的型別

***************/

void

changemap

(pos *pos,props prop)

void

gamecontrol

(direction direction)

//isvalid()為巨集展開if(

isvalid

(next_pos)

&& map[next_pos.x]

[next_pos.y]

== floor)

else

}elseif(

isvalid

(next_pos)

&& map[next_pos.x]

[next_pos.y]

== box_des)

elseif(

isvalid

(next_next_pos)

&& map[next_pos.x]

[next_pos.y]

== box)

else

}else

if(map[next_next_pos.x]

[next_next_pos.y]

== box_des)

}elseif(

isvalid

(next_next_pos)

&& map[next_pos.x]

[next_pos.y]

== hit)

}/************

*判斷遊戲是否結束

*如果陣列中不存在任何乙個箱子目的地,就代表遊戲結束**

**************/

bool

isgameover()

}}return

true;}

/*顯示遊戲結束畫面

*/void

gameover

(image *bg)

;settextstyle(20

,0,_t

("宋體"))

;drawtext(_t

("恭喜你~\n您終於成為了乙個的搬箱子老司機!"),

&rec,dt_center |dt_vcenter | dt_singleline)

;}

推箱子遊戲

大一寒假 1.寫 時我犯了乙個很大的錯誤 不然早就搞定了 把 與 混淆了 大忌啊 2.這裡實現了數位化編碼 3.上72 下80 左75 右77 4.特殊圖形可以到qq拼音符號裡獲取 include include include define x 1 人的位置 define y 5 define n...

推箱子遊戲

本專案開發環境為vs2017 c 對推箱子遊戲的觀察可以發現,該遊戲就是在乙個頁面對進行移動的操作。因此可以定義乙個二維陣列map,進行初始化。0 空地 1 牆壁 3 箱子的目的地 4 箱子 6 人 7 箱子與目的地重合 9 人在箱子目的地。如下 include include include in...

用C C設計簡易小遊戲 推箱子

如圖 1.定義角色與數值的關係 路 0 角色 2 牆壁 3 箱子 4 目標點 5 人在目標點上 7 有箱子的目標點 9 2.定義地圖 char map 8 8 3.定義記錄小人的位置座標的變數 4.進入迴圈 1.重新整理螢幕 2.顯示地圖 3.檢查是否勝利 判斷陣列中9的個數,把步數顯示 4.獲取方...