导航:首页 > 源码编译 > vc6游戏编程入门及源码

vc6游戏编程入门及源码

发布时间:2023-08-28 01:24:57

❶ 游程编码源代码

这个...........楼上的诸位说的都是什么啊。今天刚好看到这个问题,把你的E-mail给我把,我有纯c的源码(RLC)。

算了,直接贴关键部分吧。这个有一点C++成分,很容易改的。
bool CompressRunLength(BYTE *pSrc, int nSrcLen, BYTE *&pDes, int &nDesLen, int nBitsPerSample, void* nRuns, int nRunCount, int nRunSize);
bool DecompressRunLength(BYTE *pSrc, int nSrcLen, BYTE *&pDes, int &nDesLen);

#define GetDWORD(buf,bit,mask) ((*(DWORD*)(((BYTE*)buf)+((bit)>>3)))>>((bit)&7)&(mask))
#define GetWORD(buf,bit,mask) ((*(WORD*)(((BYTE*)buf)+((bit)>>3)))>>((bit)&7)&(mask))

int GetBitCount(int n)
{
int nBitCount = 0;
while(n)
n >>= 1, nBitCount++;
return nBitCount;
}

int BinarySearch(void* pValue, int nVlaueSize, void* pArray, int nCount)
{
int nIndex, nResult, nStart = 0, nEnd = nCount-1;
while(nStart <= nEnd)
{
nIndex = (nEnd+nStart)/2;
if((nResult = memcmp((BYTE*)pArray+nIndex*nVlaueSize, pValue, nVlaueSize)) == 0)
return nIndex;
if(nResult > 0)
nEnd = nIndex-1;
else
nStart = nIndex+1;
}
return -1;
}

bool CompressRunLength(BYTE *pSrc, int nSrcLen, BYTE *&pDes, int &nDesLen, int nBitsPerSample, void* nRuns, int nRunCount, int nRunSize)
{
pDes = (BYTE*)malloc(nSrcLen*2);
memset(pDes, 0, nSrcLen*2);

nDesLen = sizeof(DWORD);
*(DWORD*)pDes = nSrcLen; // save source length
*(pDes+nDesLen++) = nBitsPerSample; // save bits per sample
*(pDes+nDesLen++) = nRunCount; // save runs count
*(pDes+nDesLen++) = nRunSize; // save run bytes
memcpy(pDes+nDesLen, nRuns, nRunCount*nRunSize); // save runs
nDesLen += nRunCount*nRunSize;
nDesLen <<= 3; // bytes to bits
if(nRunCount == 0)
nRunCount = 256, nRunSize = 1, nRuns = NULL;

int nBitsPerTypeIndex = GetBitCount(nRunCount-1);
int nMaxRunLength = (1 << nBitsPerSample)-1, nRunLength, nRunIndex, nByte = 0;
// loop in the source buffer
while(nByte < nSrcLen)
if((nRuns && (nRunIndex = BinarySearch(pSrc+nByte, nRunSize, nRuns, nRunCount)) != -1 &&
memcmp(pSrc+nByte+nRunSize, (BYTE*)nRuns+nRunIndex*nRunSize, nRunSize) == 0) ||
(!nRuns && (nRunIndex = *(pSrc+nByte)) == *(pSrc+nByte+1)))
{ // set bit to 1 to indicate type found
*(pDes+(nDesLen>>3)) |= 1 << (nDesLen&7);
*(DWORD*)(pDes+(++nDesLen>>3)) |= nRunIndex << (nDesLen&7);
nDesLen += nBitsPerTypeIndex;
// skip the two repeated runs
nByte += nRunSize*2;
// get run length - 2 (without the two repeated runs)
nRunLength = 0;
while(nRunLength < nMaxRunLength && nByte < nSrcLen &&
((nRuns && memcmp(pSrc+nByte, (BYTE*)nRuns+nRunIndex*nRunSize, nRunSize) == 0) || (!nRuns && (BYTE)nRunIndex == *(pSrc+nByte))))
nRunLength++, nByte += nRunSize;
// save run length and increment destination length by bits per sample
*(DWORD*)(pDes+(nDesLen>>3)) |= nRunLength << (nDesLen&7);
nDesLen += nBitsPerSample;
}
else // one byte
*(WORD*)(pDes+(++nDesLen>>3)) |= *(pSrc+nByte++) << (nDesLen&7), nDesLen += 8;
nDesLen = (nDesLen+7)/8; // bits to bytes
pDes = (BYTE*)realloc(pDes, nDesLen);

return true;
}

bool DecompressRunLength(BYTE *pSrc, int nSrcLen, BYTE *&pDes, int &nDesLen)
{
if(nSrcLen == 0)
return true;

// allocate destination buffer
nDesLen = *(DWORD*)pSrc;
pDes = (BYTE*)malloc(nDesLen);
memset(pDes, 0, nDesLen);

// compression information
int nSrcIndex = sizeof(DWORD);
int nBitsPerSample = *(pSrc+nSrcIndex++);
int nRunCount = *(pSrc+nSrcIndex++);
int nRunSize = *(pSrc+nSrcIndex++);
void* nRuns = pSrc+nSrcIndex;
nSrcIndex += nRunSize*nRunCount;
nSrcIndex <<= 3; // bytes to bits
if(nRunCount == 0)
nRunCount = 256, nRunSize = 1, nRuns = NULL;

int nBitsPerTypeIndex = GetBitCount(nRunCount-1);
int nMaxTypeIndex = (1 << nBitsPerTypeIndex)-1;
int nMaxRunLength = (1 << nBitsPerSample)-1;
int nDesIndex = 0, nRunLength, nRunIndex, nRun, nByte;

nSrcLen <<= 3; // bytes to bits
while(nSrcIndex < nSrcLen-8)
if((*(pSrc+(nSrcIndex>>3)) >> (nSrcIndex++&7)) & 1)
{
nRunIndex = GetDWORD(pSrc, nSrcIndex, nMaxTypeIndex), nSrcIndex += nBitsPerTypeIndex;
nRunLength = GetDWORD(pSrc, nSrcIndex, nMaxRunLength)+2, nSrcIndex += nBitsPerSample;
for(nRun = 0; nRun < nRunLength; nRun++)
for(nByte = 0; nByte < nRunSize; nByte++, nDesIndex += 8)
*(WORD*)(pDes+(nDesIndex>>3)) |= nRuns ? GetWORD(nRuns+nRunSize*nRunIndex, nByte<<3, 0xff) : (BYTE)nRunIndex;
}
else // one byte
*(WORD*)(pDes+(nDesIndex>>3)) |= GetWORD(pSrc, nSrcIndex, 0xff), nDesIndex += 8, nSrcIndex += 8;

return true;
}

❷ 求vc++6.0c语言推箱子或贪吃蛇源代码带图库的

#include<stdio.h>
#include<process.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
#define WIDTH 40
#define HEIGH 12
enum direction{//方向
LEFT,
RIGHT,
UP,
DOWN
};
struct Food{//食物
int x;
int y;
};
struct Node{//画蛇身
int x;
int y;
struct Node *next;
};
struct Snake{//蛇属性
int lenth;//长度
enum direction dir;//方向
};
struct Food *food; //食物
struct Snake *snake;//蛇属性
struct Node *snode,*tail;//蛇身
int SPEECH=200;
int score=0;//分数
int smark=0;//吃食物标记
int times=0;
int STOP=0;
void Initfood();//产生食物
void Initsnake();//构造snake
void Eatfood();//头部前进
void Addnode(int x, int y);//增加蛇身
void display(struct Node *shead);//显示蛇身坐标
void move();//蛇移动
void draw();//画蛇
void Homepage();//主页
void keybordhit();//监控键盘按键
void Addtail();//吃到食物
void gotoxy(int x, int y)//定位光标
{
COORD pos;
pos.X = x - 1;
pos.Y = y - 1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void Initsnake()//构造snake
{
int i;
snake=(struct Snake*)malloc(sizeof(struct Snake));
tail=(struct Node*)malloc(sizeof(struct Node));
food = (struct Food*)malloc(sizeof(struct Food));
snake->lenth=5;//初始长度 5
snake->dir=RIGHT;//初始蛇头方向 右
for(i=2;i<=snake->lenth+2;i++)//增加 5 个结点
{
Addnode(i,2);
}
}
void Initfood()//产生食物
{
struct Node *p=snode;
int mark=1;
srand((unsigned)time(NULL));//以时间为种子产生随机数
while(1)
{
food->x=rand()%(WIDTH-2)+2;//食物X坐标
food->y=rand()%(HEIGH-2)+2;//食物Y坐标
while(p!=NULL)
{
if((food->x==p->x)&&(food->y==p->y))//如果食物产生在蛇身上
{//则重新生成食物
mark=0;//食物生成无效
break;
}
p=p->next;
}
if(mark==1)//如果食物不在蛇身上,生成食物,否则重新生成食物
{
gotoxy(food->x,food->y);
printf("%c",3);
break;
}
mark=1;
p=snode;
}
}
void move()//移动
{
struct Node *q, *p=snode;
if(snake->dir==RIGHT)
{
Addnode(p->x+1,p->y);
if(smark==0)
{
while(p->next!=NULL)
{
q=p;
p=p->next;
}
q->next=NULL;
free(p);
}
}
if(snake->dir==LEFT)
{
Addnode(p->x-1,p->y);
if(smark==0)
{
while(p->next!=NULL)
{
q=p;
p=p->next;
}
q->next=NULL;
free(p);
}
}
if(snake->dir==UP)
{
Addnode(p->x,p->y-1);
if(smark==0)
{
while(p->next!=NULL)
{
q=p;
p=p->next;
}
q->next=NULL;
free(p);
}
}
if(snake->dir==DOWN)
{
Addnode(p->x,p->y+1);
if(smark==0)
{
while(p->next!=NULL)
{
q=p;
p=p->next;
}
q->next=NULL;
free(p);
}
}
}
void Addnode(int x, int y)//增加蛇身
{
struct Node *newnode=(struct Node *)malloc(sizeof(struct Node));
struct Node *p=snode;
newnode->next=snode;
newnode->x=x;
newnode->y=y;
snode=newnode;//结点加到蛇头
if(x<2||x>=WIDTH||y<2||y>=HEIGH)//碰到边界
{
STOP=1;
gotoxy(10,19);
printf("撞墙,游戏结束,任意键退出!\n");//失败
_getch();
free(snode);//释放内存
free(snake);
exit(0);
}
while(p!=NULL)//碰到自身
{
if(p->next!=NULL)
if((p->x==x)&&(p->y==y))
{
STOP=1;
gotoxy(10,19);
printf("撞到自身,游戏结束,任意键退出!\n");//失败
_getch();
free(snode);//释放内存
free(snake);
exit(0);
}
p=p->next;
}
}
void Eatfood()//吃到食物
{
Addtail();
score++;
}
void Addtail()//增加蛇尾
{
struct Node *newnode=(struct Node *)malloc(sizeof(struct Node));
struct Node *p=snode;
tail->next=newnode;
newnode->x=50;
newnode->y=20;
newnode->next=NULL;//结点加到蛇头
tail=newnode;//新的蛇尾
}
void draw()//画蛇
{
struct Node *p=snode;
int i,j;
while(p!=NULL)
{
gotoxy(p->x,p->y);
printf("%c",2);
tail=p;
p=p->next;
}
if(snode->x==food->x&&snode->y==food->y)//蛇头坐标等于食物坐标
{
smark=1;
Eatfood();//增加结点
Initfood();//产生食物
}
if(smark==0)
{
gotoxy(tail->x,tail->y);//没吃到食物清除之前的尾结点
printf("%c",' ');//如果吃到食物,不清楚尾结点
}
else
{
times=1;
}
if((smark==1)&&(times==1))
{
gotoxy(tail->x,tail->y);//没吃到食物清除之前的尾结点
printf("%c",' ');//如果吃到食物,不清楚尾结点
smark=0;
}
gotoxy(50,12);
printf("食物: %d,%d",food->x,food->y);
gotoxy(50,5);
printf("分数: %d",score);
gotoxy(50,7);
printf("速度: %d",SPEECH);
gotoxy(15,14);
printf("按o键加速");
gotoxy(15,15);
printf("按p键减速");
gotoxy(15,16);
printf("按空格键暂停");
}
void HideCursor()//隐藏光标
{
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void Homepage()//绘主页
{
int x,y;
HideCursor();//隐藏光标
printf("----------------------------------------\n");
printf("|\t\t\t\t |\n");
printf("|\t\t\t\t |\n");
printf("|\t\t\t\t |\n");
printf("|\t\t\t\t |\n");
printf("|\t\t\t\t |\n");
printf("|\t\t\t\t |\n");
printf("|\t\t\t\t |\n");
printf("|\t\t\t\t |\n");
printf("|\t\t\t\t |\n");
printf("|\t\t\t\t |\n");
printf("----------------------------------------\n");
gotoxy(5,13);
printf("任意键开始游戏!按W.A.S.D控制方向");
_getch();
Initsnake();
Initfood();
gotoxy(5,13);
printf(" ");
}
void keybordhit()//监控键盘
{
char ch;
if(_kbhit())
{
ch=getch();
switch(ch)
{
case 'W':
case 'w':if(snake->dir==DOWN)//如果本来方向是下,而按相反方向无效
{
break;
}
else
snake->dir=UP;break;
case 'A':
case 'a':if(snake->dir==RIGHT)//如果本来方向是右,而按相反方向无效
{
break;
}
else
snake->dir=LEFT;break;
case 'S':
case 's':if(snake->dir==UP)//如果本来方向是上,而按相反方向无效
{
break;
}
else
snake->dir=DOWN;break;
case 'D':
case 'd':if(snake->dir==LEFT)//如果本来方向是左,而按相反方向无效
{
break;
}
else
snake->dir=RIGHT;break;
case 'O':
case 'o':
if(SPEECH>=150)//速度加快
{
SPEECH=SPEECH-50;
}
break;
case 'P':
case 'p':
if(SPEECH<=400)//速度减慢
{
SPEECH=SPEECH+50;
}
break;
case ' '://暂停
gotoxy(15,18);
printf("游戏已暂停,按任意键恢复游戏");
system("pause>nul");
gotoxy(15,18);
printf(" ");
break;
default:break;
}
}
}
int main(void)//程序入口
{
Homepage();
while(!STOP)
{
keybordhit();//监控键盘按键
move();//蛇的坐标变化
draw();//蛇的重绘
Sleep(SPEECH);//暂时挂起线程
}
return 0;
}

❸ 如何做一个C语言编程的汉诺塔游戏要有源代码。

#include<stdio.h>
void move(char x,char y)
{
printf("%c-->%c\n",x,y);
}
void hanoi(int n,char one ,char two,char three)
{
if(n==1) move(one,three);
else
{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
main()
{
int m;
printf("input the number of disks:");
scanf("%d",&m);
printf("the step to moving %3d diskes:\n"咐亩,m);
hanoi(m,'液简档A','B','C');
}
算法介绍:
其实算法非常简单,当盘子的个数为n时,移动的次数应等于2^n – 1(有兴趣的可以自己证明试试看)。后来一位美国学者发现一种出人意料的简单方法,只要轮流进行两步操作就可以了。首先把三根柱子按顺序排成品字型,把所有的圆盘按从大到小的顺序放在柱子A上,根据圆盘的数量确定柱子的排放顺序:若n为偶数,按顺时针方向依次摆放 A B C;
若n为奇数,按顺时针方向依次摆放 A C B。
(1)按顺时针方向把圆盘1从现在的柱子移动到下一根柱子,即当n为偶数时,若圆盘1在柱子A,则把它移动到B;若圆盘1在柱子B,则把它移动到C;若圆盘1在柱子C,则把它移动到A。
(2)闹乱接着,把另外两根柱子上可以移动的圆盘移动到新的柱子上。即把非空柱子上的圆盘移动到空柱子上,当两根柱子都非空时,移动较小的圆盘。这一步没有明确规定移动哪个圆盘,你可能以为会有多种可能性,其实不然,可实施的行动是唯一的。
(3)反复进行(1)(2)操作,最后就能按规定完成汉诺塔的移动。
所以结果非常简单,就是按照移动规则向一个方向移动金片:
如3阶汉诺塔的移动:A→C,A→B,C→B,A→C,B→A,B→C,A→C
汉诺塔问题也是程序设计中的经典递归问题,下面我们将给出递归和非递归的不同实现源代码。

❹ 学vc++游戏编程需什么基础

首先你要会,windows下程序的运行原理,会windows窗口应用程序设计,写windows窗口应用程序:
a最常用的就是MFC编程
b或用platform sdk (也就是windows api)

MFC是对windows api的类封装。

然后你就可以写扫雷,五子棋这样的程序了。
如果你想写那种网游里的效果。那就路漫漫了。
找本directX的书看看吧。用opengl也一样,会了这个,不难会那个。
openGL,还是directX了,两个函数库直接控制显卡,

❺ 用c++来编写一个小游戏的源代码,要100-200行就可以了,可以再vc环境下运行就可。。。本人急需!~!~!

//作者:小斌
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
//using namespace std;

const char LEFT=0x4b;
const char RIGHT=0x4d;
const char DOWN=0x50;
const char UP=0x48;
const char ESC=0x1b;
const char ENTER=0x0d;

const int BX=200;
const int BY=170;
const int SQ=30;

const int SQCL=10;
const int BkCl=BLUE;
const int SHAP1=2;
const int SHAP2=3;
const int SHAP3=4;
const int SHAP4=5;

void drawxiao(int &x, int &y)
{
int a=x*SQ+BX, b=y*SQ+BY;
setfillstyle(1, SQCL);
bar(a+1, b+1, a+SQ-1, b+SQ-1);
}

void clearxiao(int &x, int &y)
{
int a=x*SQ+BX, b=y*SQ+BY;
setfillstyle(1, BkCl);
bar(a+1, b+1, a+SQ-1, b+SQ-1);
}

void goleft(int &x, int &y)
{
if(x>0)
{
clearxiao(x, y);
drawxiao(--x, y);
}
}

void goright(int &x, int &y)
{
if(x<7)
{
clearxiao(x, y);
drawxiao(++x, y);
}
}

void godown(int &x, int &y)
{
if(y<7)
{
clearxiao(x, y);
drawxiao(x, ++y);
}
}

void goup(int &x, int &y)
{
if(y>0)
{
clearxiao(x, y);
drawxiao(x, --y);
}
}

void end()
{
closegraph();
exit(1);
}

void move(int &x, int &y)
{
int n=1;
drawxiao(x, y);
while(n)
switch(getch())
{
case LEFT :goleft(x, y); break;
case RIGHT :goright(x, y); break;
case DOWN :godown(x, y); break;
case UP :goup(x, y); break;
case ENTER :n=0; break;
case ESC :end();
}
}

void qipan()
{
int i;
setbkcolor(BkCl);
setfillstyle(1, 15);

for(i=0; i<9; i++)
{
line(BX, i*SQ+BY, BX+8*SQ, i*SQ+BY);
line(i*SQ+BX, BY, i*SQ+BX, BY+8*SQ);
}
}

void shap1(int x, int y)
{
int a=x*SQ+BX, b=y*SQ+BY;
setfillstyle(1, SHAP1);
bar(a+1, b+1, a+SQ-1, b+2*SQ-1);
bar(a-SQ+1, b+1+SQ, a, b-1+2*SQ);
}

void shap2(int x, int y)
{
int a=x*SQ+BX, b=y*SQ+BY;
setfillstyle(1, SHAP2);
bar(a+1, b+1, a+SQ-1, b+2*SQ-1);
bar(a+SQ, b+SQ+1, a+2*SQ-1, b+2*SQ-1);
}

void shap3(int x, int y)
{
int a=x*SQ+BX, b=y*SQ+BY;
setfillstyle(1, SHAP3);
bar(a+1, b+1, a+2*SQ-1, b+SQ-1);
bar(a+SQ+1, b+SQ, a+2*SQ-1, b+2*SQ-1);
}

void shap4(int x, int y)
{
int a=x*SQ+BX, b=y*SQ+BY;
setfillstyle(1, SHAP4);
bar(a+1, b+1, a+2*SQ-1, b+SQ-1);
bar(a+1, b+SQ, a+SQ-1, b+2*SQ-1);
}

void chessboard(int size, int tr, int tc, int dr, int dc)
{
if(size>=2)
{
size=size/2;
if(dc<tc+size)//左边半个棋盘
{
if(dr<tr+size)//左上
{
shap1(tr+size, tc+size-1);
chessboard(size, tr, tc, dr, dc);
chessboard(size, tr+size, tc, tr+size, tc+size-1);
}
else//左下
{
shap2(tr+size-1, tc+size-1);
chessboard(size, tr, tc, tr+size-1, tc+size-1);
chessboard(size, tr+size, tc, dr, dc);
}
chessboard(size, tr, tc+size, tr+size-1, tc+size);
chessboard(size, tr+size, tc+size, tr+size, tc+size);
}
else//在右边半个棋盘
{
if(dr<tr+size)//右上
{
shap3(tr+size-1, tc+size-1);
chessboard(size, tr, tc+size, dr, dc);
chessboard(size, tr+size, tc+size, tr+size, tc+size);
}
else//右下
{
shap4(tr+size-1, tc+size-1);
chessboard(size, tr, tc+size, tr+size-1, tc+size);
chessboard(size, tr+size, tc+size, dr, dc);
}
chessboard(size, tr, tc, tr+size-1, tc+size-1);
chessboard(size, tr+size, tc, tr+size, tc+size-1);
}
}
}

int main()
{
int driver=DETECT, mode;
int x=0, y=0;

initgraph(&driver, &mode, "C:\\JMSOFT\\DRV");

qipan();//画棋盘
move(x, y);//移动特殊方格

chessboard(8, 0, 0, x, y);//覆盖棋盘
getch();
return 0;
}

❻ 简述在VC++6.0环境下运行一个C++源程序的步骤

可以参考下面方法处理:


1、首先,打开我们的VC++6.0编程软件,点击左上角的“文件”菜单,并选择“新建”。


阅读全文

与vc6游戏编程入门及源码相关的资料

热点内容
吃鸡国际体验服为什么服务器繁忙 浏览:92
php中sleep 浏览:488
vr怎么看视频算法 浏览:84
手机app如何申报个人所得税零申报 浏览:692
如何截获手机app连接的ip 浏览:330
冰箱压缩机是否需要电容 浏览:344
python列表每一行数据求和 浏览:274
自己有一台服务器可以玩什么 浏览:656
社会学波普诺pdf 浏览:584
解压做食物的小视频 浏览:758
pdf怎么单独设置文件夹 浏览:474
业务逻辑程序员 浏览:659
addto新建文件夹什么意思 浏览:160
有服务器地址怎么安装软件 浏览:659
安卓如何完全清除数据 浏览:691
安卓安卓证书怎么信任 浏览:54
服务器被攻击如何解决 浏览:221
学霸变成程序员 浏览:882
c语言编译错误fatalerror 浏览:443
ipv4内部服务器地址怎么分配 浏览:464