C语言版3D魔方游戏源代码

  • q5_615546
    了解作者
  • 20.5KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-09 02:43
    上传日期
很好的3D魔方游戏源代码,赶快下起,下载运行就能玩,让你过把瘾!!
3D魔方游戏源代码.rar
  • 3D魔方游戏源代码
  • WcgCube.plg
    1.1KB
  • WcgCube.dsp
    4.1KB
  • WcgCube.dsw
    537B
  • WcgCube.ncb
    41KB
  • main.cpp
    4.2KB
  • CubeGame.cpp
    13.5KB
  • wcgcube.cpp
    5.4KB
  • wcgcube.h
    1.6KB
  • WcgCube.opt
    51.5KB
  • cubemanage.cpp
    13.5KB
  • cubemanage.h
    1.7KB
内容介绍
/*************************************************************************** cubemanage.cpp - description ------------------- begin : Sat Nov 3 2001 copyright : (C) 2001 by wguzgg email : wguzgg@263.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include <iostream.h> #include "cubemanage.h" CubeManage::CubeManage(){ for (int i=0;i<CUBE_SIZE;i++) { for (int j=0;j<CUBE_SIZE;j++) { for (int k=0;k<CUBE_SIZE;k++) { cubes[i][j][k]=new WcgCube(); } } } } CubeManage::~CubeManage(){ for (int i=0;i<CUBE_SIZE;i++) { for (int j=0;j<CUBE_SIZE;j++) { for (int k=0;k<CUBE_SIZE;k++) { delete cubes[i][j][k]; } } } } void CubeManage::turn(int rotateType) { if (rotateType==1) { turnByZShun(2); } else if (rotateType==2) { turnByXShun(2); } else if (rotateType==3) { turnByZNi(0); } else if (rotateType==4) { turnByXNi(0); } else if (rotateType==5) { turnByYShun(2); } else if (rotateType==6) { turnByYNi(0); } else if (rotateType==7) { turnByZNi(2); } else if (rotateType==8) { turnByXNi(2); } else if (rotateType==9) { turnByZShun(0); } else if (rotateType==10) { turnByXShun(0); } else if (rotateType==11) { turnByYNi(2); } else if (rotateType==12) { turnByYShun(0); } } void CubeManage::draw(int rotateType,GLfloat rotate) { GLfloat PI=3.1415f; GLfloat cubeRadium=10.0f; GLfloat cubeSpace=2.0f; GLfloat x,y,z; int i,j,k; x=ORIENTX-(CUBE_SIZE/2)*(cubeRadium*2+cubeSpace); y=ORIENTZ-(CUBE_SIZE/2)*(cubeRadium*2+cubeSpace); z=ORIENTZ-(CUBE_SIZE/2)*(cubeRadium*2+cubeSpace); if (rotateType==0) { for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { for (k=0;k<CUBE_SIZE;k++) { (cubes[i][j][k])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z+(cubeRadium*2+cubeSpace)*k); } } } } else if (rotateType==1) { glPushMatrix(); glRotatef(360-180*rotate/PI,0.0f,0.0f,1.0f); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { (cubes[i][j][CUBE_SIZE-1])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z+(cubeRadium*2+cubeSpace)*(CUBE_SIZE-1)); } } glPopMatrix(); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { for (k=0;k<CUBE_SIZE-1;k++) { (cubes[i][j][k])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z+(cubeRadium*2+cubeSpace)*k); } } } } else if (rotateType==2) { glPushMatrix(); glRotatef(360-180*rotate/PI,1.0f,0.0f,0.0f); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { (cubes[CUBE_SIZE-1][i][j])->draw(x+(cubeRadium*2+cubeSpace)*(CUBE_SIZE-1),y+(cubeRadium*2+cubeSpace)*i,z+(cubeRadium*2+cubeSpace)*j); } } glPopMatrix(); for (i=0;i<CUBE_SIZE-1;i++) { for (j=0;j<CUBE_SIZE;j++) { for (k=0;k<CUBE_SIZE;k++) { (cubes[i][j][k])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z+(cubeRadium*2+cubeSpace)*k); } } } } else if (rotateType==3) { glPushMatrix(); glRotatef(360-180*rotate/PI,0.0f,0.0f,-1.0f); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { (cubes[i][j][0])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z); } } glPopMatrix(); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { for (k=1;k<CUBE_SIZE;k++) { (cubes[i][j][k])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z+(cubeRadium*2+cubeSpace)*k); } } } } else if (rotateType==4) { glPushMatrix(); glRotatef(360-180*rotate/PI,-1.0f,0.0f,0.0f); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { (cubes[0][i][j])->draw(x,y+(cubeRadium*2+cubeSpace)*i,z+(cubeRadium*2+cubeSpace)*j); } } glPopMatrix(); for (i=1;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { for (k=0;k<CUBE_SIZE;k++) { (cubes[i][j][k])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z+(cubeRadium*2+cubeSpace)*k); } } } } else if (rotateType==5) { glPushMatrix(); glRotatef(360-180*rotate/PI,0.0f,1.0f,0.0f); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { (cubes[i][CUBE_SIZE-1][j])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*(CUBE_SIZE-1),z+(cubeRadium*2+cubeSpace)*j); } } glPopMatrix(); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE-1;j++) { for (k=0;k<CUBE_SIZE;k++) { (cubes[i][j][k])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z+(cubeRadium*2+cubeSpace)*k); } } } } else if (rotateType==6) { glPushMatrix(); glRotatef(360-180*rotate/PI,0.0f,-1.0f,0.0f); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { (cubes[i][0][j])->draw(x+(cubeRadium*2+cubeSpace)*i,y,z+(cubeRadium*2+cubeSpace)*j); } } glPopMatrix(); for (i=0;i<CUBE_SIZE;i++) { for (j=1;j<CUBE_SIZE;j++) { for (k=0;k<CUBE_SIZE;k++) { (cubes[i][j][k])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z+(cubeRadium*2+cubeSpace)*k); } } } } else if (rotateType==7) { glPushMatrix(); glRotatef(180*rotate/PI,0.0f,0.0f,1.0f); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { (cubes[i][j][CUBE_SIZE-1])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z+(cubeRadium*2+cubeSpace)*(CUBE_SIZE-1)); } } glPopMatrix(); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { for (k=0;k<CUBE_SIZE-1;k++) { (cubes[i][j][k])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z+(cubeRadium*2+cubeSpace)*k); } } } } else if (rotateType==8) { glPushMatrix(); glRotatef(180*rotate/PI,1.0f,0.0f,0.0f); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { (cubes[CUBE_SIZE-1][i][j])->draw(x+(cubeRadium*2+cubeSpace)*(CUBE_SIZE-1),y+(cubeRadium*2+cubeSpace)*i,z+(cubeRadium*2+cubeSpace)*j); } } glPopMatrix(); for (i=0;i<CUBE_SIZE-1;i++) { for (j=0;j<CUBE_SIZE;j++) { for (k=0;k<CUBE_SIZE;k++) { (cubes[i][j][k])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z+(cubeRadium*2+cubeSpace)*k); } } } } else if (rotateType==9) { glPushMatrix(); glRotatef(180*rotate/PI,0.0f,0.0f,-1.0f); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { (cubes[i][j][0])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z); } } glPopMatrix(); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { for (k=1;k<CUBE_SIZE;k++) { (cubes[i][j][k])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z+(cubeRadium*2+cubeSpace)*k); } } } } else if (rotateType==10) { glPushMatrix(); glRotatef(180*rotate/PI,-1.0f,0.0f,0.0f); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { (cubes[0][i][j])->draw(x,y+(cubeRadium*2+cubeSpace)*i,z+(cubeRadium*2+cubeSpace)*j); } } glPopMatrix(); for (i=1;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { for (k=0;k<CUBE_SIZE;k++) { (cubes[i][j][k])->draw(x+(cubeRadium*2+cubeSpace)*i,y+(cubeRadium*2+cubeSpace)*j,z+(cubeRadium*2+cubeSpace)*k); } } } } else if (rotateType==11) { glPushMatrix(); glRotatef(180*rotate/PI,0.0f,1.0f,0.0f); for (i=0;i<CUBE_SIZE;i++) { for (j=0;j<CUBE_SIZE;j++) { (cubes[i][CU
评论
    相关推荐