C语言魔方游戏.docx

上传人:asd****56 文档编号:70326626 上传时间:2023-01-19 格式:DOCX 页数:19 大小:71.55KB
返回 下载 相关 举报
C语言魔方游戏.docx_第1页
第1页 / 共19页
C语言魔方游戏.docx_第2页
第2页 / 共19页
点击查看更多>>
资源描述

《C语言魔方游戏.docx》由会员分享,可在线阅读,更多相关《C语言魔方游戏.docx(19页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、#include #include #include #include #include #pragma comment(lib,opengl32.lib)#pragma comment(lib,glu32.lib)#define ROTX 1#define ROTY 2#define ROTZ 3#define ROTL 4#define ROTR 5#define ROTU 6#define ROTD 7int w=500;int h=500;float r=0;int sr=1;int R_state,R_count;int Begin_G=0;typedef struct MPOINT

2、 float x, y, z; MPOINT;typedef struct MRECTMPOINT Ft4;int cid;MRECT;MRECT Art83, Ert122;typedef struct GMRECTMRECT Ar43, Er42, Fr4;int aval, eval, fval;GMRECT;GMRECT X1, X2, X3, Y1, Y2, Y3, Z1, Z2, Z3;MRECT A13=-150,150,150,-150,50,150,-50,50,150,-50,150,150,-150,150,150,-50,150,150,-50,150,50,-150,

3、150,50,-150,150,150,-150,150,50,-150,50,50,-150,50,150;MRECT A23=150,150,150,150,50,150,50,50,150,50,150,150,150,150,150,50,150,150,50,150,50,150,150,50,150,150,150,150,150,50,150,50,50,150,50,150;MRECT E12=-50,150,150,-50,50,150,50,50,150,50,150,150,-50,150,150,50,150,150,50,150,50,-50,150,50;MRECT

4、 E52=-150,150,50,-150,50,50,-150,50,-50,-150,150,-50,-150,150,50,-50,150,50,-50,150,-50,-150,150,-50;MRECT E92=-150,50,150,-150,-50,150,-50,-50,150,-50,50,150,-150,50,150,-150,-50,150,-150,-50,50,-150,50,50;MRECT Frt6=-50,50,150,-50,-50,150,50,-50,150,50,50,150,-50,150,50,50,150,50,50,150,-50,-50,15

5、0,-50,-150,50,50,-150,-50,50,-150,-50,-50,-150,50,-50;int V133 =4,4,1, V23 =0,4,4;int X1_a4=0,3,7,4, X1_e4=8,5,11,4, X1_f4=2;int X2_a4=0, X2_e4=0,1,2,3, X2_f4=0,4,3,1;int X3_a4=1,2,6,5, X3_e4=9,6,10,7, X3_f4=5;int Y1_a4=0,1,5,4, Y1_e4=0,7,3,4, Y1_f4=1;int Y2_a4=0, Y2_e4=8,9,10,11, Y2_f4=0,5,3,2;int

6、Y3_a4=3,2,6,7, Y3_e4=1,6,2,5, Y3_f4=4;int Z1_a4=0,1,2,3, Z1_e4=0,9,1,8, Z1_f4=0;int Z2_a4=0, Z2_e4=4,7,6,5, Z2_f4=1,5,4,2;int Z3_a4=4,5,6,7, Z3_e4=3,10,2,11, Z3_f4=3;typedef struct COLORID float r, g, b; COLORID;COLORID Fcr6=0.75f,0.0f,0.0f,0.0f,0.75f,0.0f,0.0f,0.0f,0.75f,1.0f,0.6f,0.3f,0.0f,0.75f,0

7、.75f,0.75f,0.0f,0.75f;LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);void init_Rect()int i,j;for(i=0;i3;i+)Art0i=A1i; Art1i=A2i;for(i=0;i3;i+)for(j=0;j4;j+)Art2i.Ftj.x=Art1i.Ftj.x;Art2i.Ftj.y=-Art1i.Ftj.y;Art2i.Ftj.z=Art1i.Ftj.z;Art3i.Ftj.x=Art0i.Ftj.x;Art3i.Ftj.y=-Art0i.Ftj.y;Art3i.Ftj.z=Art0i.F

8、tj.z;Art4i.Ftj.x=Art0i.Ftj.x;Art4i.Ftj.y=Art0i.Ftj.y;Art4i.Ftj.z=-Art0i.Ftj.z;Art5i.Ftj.x=Art1i.Ftj.x;Art5i.Ftj.y=Art1i.Ftj.y;Art5i.Ftj.z=-Art1i.Ftj.z;Art6i.Ftj.x=Art2i.Ftj.x;Art6i.Ftj.y=Art2i.Ftj.y;Art6i.Ftj.z=-Art2i.Ftj.z;Art7i.Ftj.x=Art3i.Ftj.x;Art7i.Ftj.y=Art3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=-Ert8i.Ftj.z;Ert00.cid=0; Ert01.cid=1; Ert10.cid=0; Ert11.cid=5;Ert20.cid=3; Ert21.cid=5; Ert30.cid=3; Ert31.cid=1;Ert40.cid=2; Ert41.cid=1; Ert50.cid=2; Ert51.cid=5;Ert60.c

13、id=4; Ert61.cid=5; Ert70.cid=4; Ert71.cid=1;Ert80.cid=0; Ert81.cid=2; Ert90.cid=0; Ert91.cid=4;Ert100.cid=3; Ert101.cid=4; Ert110.cid=3; Ert111.cid=2;for(i=0;i0)for(i=1;it.aval;i+)Artai0.cid=t.Ari-12.cid;Artai2.cid=t.Ari-10.cid;Artai1.cid=t.Ari-11.cid;if(t.aval)Arta00.cid=t.Art.aval-12.cid;Arta02.ci

14、d=t.Art.aval-10.cid;Arta01.cid=t.Art.aval-11.cid;if(rcount=2)for(i=1;it.eval;i+)Ertei0.cid=t.Eri-11.cid;Ertei1.cid=t.Eri-10.cid;Erte00.cid=t.Ert.eval-11.cid;Erte01.cid=t.Ert.eval-10.cid;elsefor(i=1;it.eval;i+)Ertei0.cid=t.Eri-10.cid;Ertei1.cid=t.Eri-11.cid;Erte00.cid=t.Ert.eval-10.cid;Erte01.cid=t.E

15、rt.eval-11.cid;for(i=1;it.fval;i+)Frtfi.cid=t.Fri-1.cid;Frtf0.cid=t.Frt.fval-1.cid;elsefor(i=0;it.aval-1;i+)Artai0.cid=t.Ari+12.cid;Artai2.cid=t.Ari+10.cid;Artai1.cid=t.Ari+11.cid;if(t.aval)Artat.aval-10.cid=t.Ar02.cid;Artat.aval-12.cid=t.Ar00.cid;Artat.aval-11.cid=t.Ar01.cid;if(rcount=2)for(i=0;it.

16、eval-1;i+)Ertei0.cid=t.Eri+11.cid;Ertei1.cid=t.Eri+10.cid;Ertet.eval-10.cid=t.Er01.cid;Ertet.eval-11.cid=t.Er00.cid;elsefor(i=0;it.eval-1;i+)Ertei0.cid=t.Eri+10.cid;Ertei1.cid=t.Eri+11.cid;Ertet.eval-10.cid=t.Er00.cid;Ertet.eval-11.cid=t.Er01.cid;for(i=0;i0)for(i=1;it.aval;i+)Artai0.cid=t.Ari-11.cid

17、;Artai1.cid=t.Ari-10.cid;Artai2.cid=t.Ari-12.cid;if(t.aval)Arta00.cid=t.Art.aval-11.cid;Arta01.cid=t.Art.aval-10.cid;Arta02.cid=t.Art.aval-12.cid;for(i=1;it.eval;i+)Ertei0.cid=t.Eri-11.cid;Ertei1.cid=t.Eri-10.cid;Erte00.cid=t.Ert.eval-11.cid;Erte01.cid=t.Ert.eval-10.cid;for(i=1;it.fval;i+)Frtfi.cid=

18、t.Fri-1.cid;Frtf0.cid=t.Frt.fval-1.cid;elsefor(i=0;it.aval-1;i+)Artai0.cid=t.Ari+11.cid;Artai1.cid=t.Ari+10.cid;Artai2.cid=t.Ari+12.cid;if(t.aval)Artat.aval-10.cid=t.Ar01.cid;Artat.aval-11.cid=t.Ar00.cid;Artat.aval-12.cid=t.Ar02.cid;for(i=0;it.eval-1;i+)Ertei0.cid=t.Eri+11.cid;Ertei1.cid=t.Eri+10.ci

19、d;Ertet.eval-10.cid=t.Er01.cid;Ertet.eval-11.cid=t.Er00.cid;for(i=0;it.fval-1;i+)Frtfi.cid=t.Fri+1.cid;Frtft.fval-1.cid=t.Fr0.cid;void RotateZ(GMRECT t,int a,int e,int f,int rcount,int sr)int i;if(sr0)for(i=1;i0)Arta01.cid=t.Art.aval-12.cid;Arta02.cid=t.Art.aval-11.cid;Arta00.cid=t.Art.aval-10.cid;i

20、f(rcount=2)for(i=1;it.eval;i+)Ertei0.cid=t.Eri-11.cid;Ertei1.cid=t.Eri-10.cid;Erte00.cid=t.Ert.eval-11.cid;Erte01.cid=t.Ert.eval-10.cid;elsefor(i=1;it.eval;i+)Ertei0.cid=t.Eri-10.cid;Ertei1.cid=t.Eri-11.cid;Erte00.cid=t.Ert.eval-10.cid;Erte01.cid=t.Ert.eval-11.cid;for(i=1;it.fval;i+)Frtfi.cid=t.Fri-

21、1.cid;Frtf0.cid=t.Frt.fval-1.cid;elsefor(i=0;i0)Artat.aval-11.cid=t.Ar02.cid;Artat.aval-12.cid=t.Ar01.cid;Artat.aval-10.cid=t.Ar00.cid;if(rcount=2)for(i=0;it.eval-1;i+)Ertei0.cid=t.Eri+11.cid;Ertei1.cid=t.Eri+10.cid;Ertet.eval-10.cid=t.Er01.cid;Ertet.eval-11.cid=t.Er00.cid;elsefor(i=0;it.eval-1;i+)E

22、rtei0.cid=t.Eri+10.cid;Ertei1.cid=t.Eri+11.cid;Ertet.eval-10.cid=t.Er00.cid;Ertet.eval-11.cid=t.Er01.cid;for(i=0;it.fval-1;i+)Frtfi.cid=t.Fri+1.cid;Frtft.fval-1.cid=t.Fr0.cid;GMRECT init_Gmrect(int a,int e,int f,int v)int i,j;GMRECT t;t.aval=v0; t.eval=v1; t.fval=v2;for(i=0;it.aval;i+)for(j=0;j3;j+)

23、t.Arij=Artaij;for(i=0;it.eval;i+)for(j=0;j2;j+)t.Erij=Erteij;for(i=0;it.fval;i+)t.Fri=Frtfi;return t;void MakeGmrectdata()X1=init_Gmrect(X1_a,X1_e,X1_f,V13);X2=init_Gmrect(X2_a,X2_e,X2_f,V2);X3=init_Gmrect(X3_a,X3_e,X3_f,V13);Y1=init_Gmrect(Y1_a,Y1_e,Y1_f,V13);Y2=init_Gmrect(Y2_a,Y2_e,Y2_f,V2);Y3=in

24、it_Gmrect(Y3_a,Y3_e,Y3_f,V13);Z1=init_Gmrect(Z1_a,Z1_e,Z1_f,V13);Z2=init_Gmrect(Z2_a,Z2_e,Z2_f,V2);Z3=init_Gmrect(Z3_a,Z3_e,Z3_f,V13);void DrawFace(MRECT ft)int i,dx,dy,dz;glBegin(GL_QUADS);for(i=0;i4;i+) glColor3f(Fcrft.cid.r,Fcrft.cid.g,Fcrft.cid.b);glVertex3f(ft.Fti.x,ft.Fti.y,ft.Fti.z);glEnd();g

25、lColor3f(1.0f,1.0f,1.0f);glBegin(GL_LINE_LOOP);for(i=0;i4;i+)dx=dy=dz=1;if(ft.Fti.x0) dx=-dx;if(ft.Fti.y0) dy=-dy;if(ft.Fti.z0) dz=-dz;glVertex3f(ft.Fti.x+dx,ft.Fti.y+dy,ft.Fti.z+dz);glEnd();void DrawRFace(GMRECT t)int i,j;for(i=0;it.aval;i+)for(j=0;j3;j+) DrawFace(t.Arij);for(i=0;it.eval;i+)for(j=0;j2;j+)DrawFace(t.Erij);for(i=0;ihInstance,NULL);void OnGame()if(r5000)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 休闲娱乐

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁