導航:首頁 > 源碼編譯 > 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游戲編程入門及源碼相關的資料

熱點內容
路由器多種加密方法 瀏覽:604
程序員阻止電腦自動彈出定位 瀏覽:166
如何做伺服器服務商 瀏覽:759
su剖切命令 瀏覽:726
devc編譯背景 瀏覽:211
學習單片機的意義 瀏覽:51
音頻演算法AEC 瀏覽:911
加密貨幣容易被盜 瀏覽:82
蘋果平板如何開啟隱私單個app 瀏覽:704
空調壓縮機一開就停止 瀏覽:528
如何下載虎牙app 瀏覽:847
日語年號的演算法 瀏覽:955
dev裡面的編譯日誌咋調出來 瀏覽:298
php函數引用返回 瀏覽:816
文件夾和文件夾的創建 瀏覽:259
香港加密貨幣牌照 瀏覽:838
程序員鼓勵自己的代碼 瀏覽:393
計算機網路原理pdf 瀏覽:752
吃雞國際體驗服為什麼伺服器繁忙 瀏覽:96
php中sleep 瀏覽:491