用MFC做数塔游戏,要步骤截屏,求酷派大神f1截屏帮助!学校让我们转专业必须参加

帮忙做一个贪吃蛇游戏,要求MFC c++,要用到类,求大神帮助,最好能教我做一下,谢谢!!!_百度知道
帮忙做一个贪吃蛇游戏,要求MFC c++,要用到类,求大神帮助,最好能教我做一下,谢谢!!!
个吧 ,要是不想自己看的话,其实网上有类似的教程,或者你自己去看,恐怕就得花钱了啊所以鄙人可以尝试完成,找人帮你
其他类似问题
为您推荐:
贪吃蛇游戏的相关知识
其他1条回答
jpg" esrc="http?://b??
下载知道APP
随时随地咨询
出门在外也不愁用MFC做的贪吃蛇游戏,求大神。?
用MFC实现了简单的贪吃蛇游戏,采用的CFromView基类,方便添加控件,但我添加任意控件了之后,在运行游戏的时候,方向键就不管用了,不能控制蛇的爬行方向,是怎么回事啊?&br&&div class=&highlight&&&pre&&code class=&language-text&&void CSnakeView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
// TODO: Add your message handler code here and/or call default
///////////////获取按键方向//////////////////////
switch(nChar)
case VK_UP:if(snake[0].r!=2)snake[0].r=1;
case VK_DOWN:if(snake[0].r!=1)snake[0].r=2;
case VK_LEFT:if(snake[0].r!=4)snake[0].r=3;
case VK_RIGHT:if(snake[0].r!=3)snake[0].r=4;
CFormView::OnKeyDown(nChar, nRepCnt, nFlags);
&/code&&/pre&&/div&这是获取方向键的代码&br&void CSnakeView::OnDraw(CDC* pDC) &br&{&br& // TODO: Add your specialized code here and/or call the base class&br&&br& CBrush backBrush(RGB(255,255,255)); &br& CBrush* pOldBrush = pDC-&SelectObject(&backBrush); &br& CR &br& pDC-&GetClipBox(&rect);// 获取需要用背景刷子涂抹的区域 &br& pDC-&PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),PATCOPY); &br& pDC-&SelectObject(pOldBrush);&br& CSnakeDoc* pDoc = GetDocument();&br& ASSERT_VALID(pDoc); &br& pDC-&Rectangle(19,19,501,501);&br& pDC-&Rectangle(29,29,491,491);&br& pDC-&Rectangle(39,39,481,481);&br& oninit(); &br&}&br&这是通过OnDraw()实现的背景
用MFC实现了简单的贪吃蛇游戏,采用的CFromView基类,方便添加控件,但我添加任意控件了之后,在运行游戏的时候,方向键就不管用了,不能控制蛇的爬行方向,是怎么回事啊?void CSnakeView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
// TODO: Add your message handler code here and/or call default
///////////////获取按键方向//////////////////////
switch(nChar)
case VK_UP:if(snake[0].r!=2)snake[0].r=1;
case VK_DOWN:if(snake[0].r!=1)snake[0].r=2;
case VK_LEFT:if(snake[0].r!=4)snake[0].r=3;
case VK_RIGHT:if(snake[0].r!=3)snake[0].r=4;
CFormView::OnKeyDown(nChar, nRepCnt, nFlags);
这是获取方向键的代码void CSnakeView::OnDraw(CDC* pDC) { // TODO: Add your specialized code here and/or call the base class CBrush backBrush(RGB(255,255,255)); …
按投票排序
这种小游戏感觉还是直接用控制台比较合适,我也真是无聊呀#include&windows.h&
#include&wincon.h&
#include&iostream&
using namespace std;
HANDLE hOut;
HANDLE hIn;
unsigned long num_write;
int maxHeight=20;
int maxWidth=20;
void clearScreen()
CONSOLE_SCREEN_BUFFER_INFO bInfo;
GetConsoleScreenBufferInfo( hOut, &bInfo );
COORD home = {0, 0};
unsigned long size =bInfo.dwSize.X * bInfo.dwSize.Y;
FillConsoleOutputAttribute(hOut, bInfo.wAttributes, size, home, &num_write);
FillConsoleOutputCharacter(hOut, ' ', size, home, &num_write);
SetConsoleCursorPosition( hOut, home );
void DrawBox(int x,int y,bool isFood=false,bool background=false)
CONSOLE_SCREEN_BUFFER_INFO bInfo; // 窗口缓冲区信息
WORD att0,att1,attBack;
GetConsoleScreenBufferInfo( hOut, &bInfo ); // 获取窗口缓冲区信息
// 计算显示窗口大小和位置
att0 = FOREGROUND_GREEN| BACKGROUND_RED; // 阴影属性
att1 = FOREGROUND_RED |FOREGROUND_GREEN |FOREGROUND_BLUE | FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_BLUE;// 文本属性
attBack = BACKGROUND_INTENSITY | FOREGROUND_INTENSITY; // 文本属性
COORD posText = {x, y};
if(!background)
FillConsoleOutputAttribute(hOut, isFood?att0:att1,1, posText, &num_write);
COORD bg={0,0};
FillConsoleOutputAttribute(hOut, attBack,bInfo.dwSize.X*maxHeight, bg, &num_write);
SetConsoleTextAttribute(hOut, bInfo.wAttributes);
struct SnakeNode
int XPos,YPos;
SnakeNode* next;
SnakeNode(int x,int y,SnakeNode*n=NULL)
:XPos(x),YPos(y),next(n)
SnakeNode* Head,*Food;
int DirX=1;
int DirY=0;
int StartPosX=0;
int StartPosY=0;
void ShowSnake(SnakeNode* head)
DrawBox(0,0,false,true);
SnakeNode* ptr=head;
while(ptr)
DrawBox(ptr-&XPos,ptr-&YPos);
ptr=ptr-&next;
bool UpdateSnake(SnakeNode*Head)
DWORD wait = 200;
Sleep(wait);
clearScreen();
INPUT_RECORD _InRec;
WORD vKey=0;
//while(true)
if(PeekConsoleInput(hIn,&_InRec,1,&num_write))
vKey=_InRec.Event.KeyEvent.wVirtualKeyCode;
if(_InRec.EventType == KEY_EVENT)
if(vKey==37)//left
else if(vKey==39)//right
else if(vKey==38)//up
else if(vKey==40)//down
FlushConsoleInputBuffer(hIn);
int lastX=0;
int lastY=0;
SnakeNode* ptr=Head;
if(Head-&XPos+DirX==Food-&XPos&&Head-&YPos+DirY==Food-&YPos)
//add this node
SnakeNode* oldHead=new SnakeNode(Head-&XPos,Head-&YPos,Head-&next);
Head-&XPos=Food-&XPos;
Head-&YPos=Food-&YPos;
Head-&next=oldHead;
delete Food;
Food=new SnakeNode((rand()%20)*2,(rand()%maxHeight),0);
while(ptr)
if(ptr==Head)
lastX=ptr-&XPos;
lastY = ptr-&YPos;
ptr-&XPos+=DirX;
ptr-&YPos+=DirY;
int tmp=ptr-&XPos;
ptr-&XPos=lastX;
lastX=tmp;
tmp=ptr-&YPos;
ptr-&YPos=lastY;
lastY=tmp;
ptr=ptr-&next;
//check boundary
CONSOLE_SCREEN_BUFFER_INFO bInfo;
GetConsoleScreenBufferInfo( hOut, &bInfo );
if(Head-&XPos&0||Head-&XPos&=bInfo.dwSize.X||
Head-&YPos&0||Head-&YPos&=maxHeight)
cout&&"Thanks for playing \n created by kalluwa!";
return false;
ShowSnake(Head);
DrawBox(Food-&XPos,Food-&YPos,true);
return true;
int main(int argc, char** argv)
hOut = GetStdHandle(STD_OUTPUT_HANDLE); // 获取标准输出设备句柄
hIn = GetStdHandle(STD_INPUT_HANDLE);
//create snake
Head=new SnakeNode(2,1,0);
Head-&next=new SnakeNode(1,1,0);
Food = new SnakeNode(10,10,0);
while(UpdateSnake(Head));
OnKeyDown只有在焦点才能获得事件所以你加一个控件,把焦点抢了,自然就拿不到了参看MSDN
A nonsystem key is a keyboard key that is pressed when the ALT key is not pressed or a keyboard key that is pressed when CWnd has the input focus.
Because of auto-repeat, more than one OnKeyDown call may occur before an
member function call is made.
The bit that indicates the previous key state can be used to determine whether the OnKeyDown call is the first down transition or a repeated down transition.
IBM Enhanced 101- and 102-key keyboards, enhanced keys are the right
ALT and the right CTRL keys on the main sec the
INS, DEL, HOME, END, PAGE UP, PAGE DOWN, and arrow keys in the clusters
to the left o and the slash (/) and ENTER keys in
the numeric keypad.
Some other keyboards may support the extended-key bit in nFlags.
其实我想说用mfc做贪吃蛇有多想不开……
首先是CFormView吧?其次。。。你这个问题。。。不贴代码你以为有人能回答的出来?答得出来的都是骗子,或者是猜中了。。。。
应该是焦点的问题,窗口初始化时将焦点设置到整个窗口可以。不过感觉如果点击控件焦点还是会变,建议搜索下其他截获键盘的功能,如钩子.
已有帐号?
无法登录?
社交帐号登录我参加了主持人比赛,复赛有专业知识提问,求大神教我过关。(还是学生,没有功底)_百度知道
我参加了主持人比赛,复赛有专业知识提问,求大神教我过关。(还是学生,没有功底)
我有更好的答案
4个选择题。题型分为,4个判断题, 2个填空题,每题10分在主持人念题结束后10秒内答出,超时不计分
1. 大家好!
我今天演讲的题目是《成长的快乐 》
在人生路途里,每个人都能找到自己的快乐。尽而的充实和完善自己。像学生来说,校园就是他的快乐;因为社会的安排,使学生的活动的范围缩减唯一。但谁都不会反驳,因为一个人的学生时代是美好~快乐~充满希望的……
现在的我已是告别童年,迈入青年的小大人。虽然我的人生旅途才刚刚开始,但我由衷的感谢成长,是他给我带来了快乐,是他让我逐渐的走向成熟,更是他给我旅途中带来了不少的绿洲和海洋。
还记得,在小学我是一个天真浪漫,活泼可爱的女孩。由于在家里呆惯了,来到学校还不很自然,而且还很厌恶;但因我的天生性格,没多长时间就适应了。可老问题解决了,新问题又来了。我开始对学校的任何事物都产生疑问。例如:为什么老师教我而我不...
专业知识问答应该是偏向理论的吧,我想要一点理论常识
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 酷派大神f1截屏 的文章

 

随机推荐