游戏问题。 [英] Game question.

查看:56
本文介绍了游戏问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写游戏,我在地图上移动角色

时遇到了麻烦。


这就是我现在所拥有的。它涉及win32编程但是

不是我的问题。我想要一些建议如何让我的代码更好。
更好。如果您需要更多代码,我会发布它。我在早期

开发游戏。


map.h:


#include< map。 h>

#include< fstream.h>

#include< windows.h>

#include" structlib.h"

#include" space.h"


#ifndef maze_h

#define maze_h


类迷宫{

const static int numx = 38;

const static int numy = 30;

space grid [numy] [numx ];

map< char,dir>钥匙;

HWND hwnd;


char gchr;

coord pcoord;


dir n; / *方向* /

dir s;

dir e;

dir w;


void fill();

ifstream& cfill(ifstream&,char&); / *从文件中读取地图* /

int convx(int x){return x * 12;}

int convy(int y){return y * 8;}

public:

迷宫();

迷宫(const迷宫&);

~maze();

void showall(HWND);

void move(HWND,char);

void show(HWND);

};

#endif

#include" maze.h"


maze :: maze(){


n.ud = -1;

n.lr = 0;

s.ud = 1;

s.lr = 0;

e.ud = 0;

e.lr = 1;

w.ud = 0;

w.lr = -1;


键[''n''] = n;

键[ ''s''] = s;

键[''e''] = e;

键[''w''] = w;


fill();

pcoord.x = 1;

pcoord.y = 1;

player pl;

player * play =& pl;

grid [pcoord.x] [pcoord.y] .SetPlayer(play);


}


迷宫::迷宫(const maze& mz){}


迷宫::〜ma ze(){

删除[]网格;

}


ifstream&迷宫:: cfill(ifstream& in,char& spc){

in>> spc;

返回;

}


void maze :: fill(){

int l1 = 0;

int l2 = 0;


ifstream f(" level.txt");

if(!f.is_open()){

MessageBox(NULL," Missing) File!"," Error!",MB_OK);

exit(1);

}

for(l1 = 0 ; l1!= numy; l1 ++){

for(l2 = 0; l2!= numx; l2 ++){

if(cfill(f,gchr)){

grid [l1] [l2] .readCH(gchr);

}

}

}

l2 = 0;

}


void maze :: showall(HWND hwnd){

HDC hdc = GetDC(hwnd);

int lp1 = 0;

int lp2 = 0;


char ch;


for(lp1 = 0; lp1!= numy; lp1 ++){

for(lp2 = 0; lp2!= numx; lp2 ++){

ch = grid [lp1] [lp2] .getCH();

TextOut(hdc,convy(lp2),convx(lp1),& ch,1);

}

}

ReleaseDC(hwnd,hdc);

}


void maze :: move(HWND hwnd,char dir){

玩家*玩;

coord tcoord;

show(hwnd);

tcoord.x = pcoord.x + keys [dir]。 ud;

tcoord.y = pcoord.y + keys [dir] .lr;


if(!grid [tcoord.x] [tcoord.y ] .CheckWall()){

MessageBox(NULL,不能通过Wall!,Ouch,MB_OK);

return;

}

grid [pcoord.x] [pcoord.y] .ClearPlayer();

pcoord.x = tcoord.x;

pcoord.y = tcoord.y;

grid [pcoord.x] [pcoord.y] .SetPlayer(play);


show(hwnd);

}


void maze :: show(HWND hwnd){

HDC hdc = GetDC (hwnd);

int lp1 = pcoord.x-1;

int lp2 = pcoord.y-1;


char ch;


for(lp1; lp1!=(pcoord.y)+1; lp1 ++){

for(lp2; lp2!=(pcoord.x)+1; lp2 ++){

ch = grid [lp1] [lp2] .getCH() ;

TextOut(hdc,convy(lp2),convx(lp1),& ch,1);

}

}

ReleaseDC(hwnd,hdc);


}

I am writing a game and I am having trouble with moving the character
on the map.

Here is what I have right now. It involves win32 programming but that
not my problem. I would like some suggestions how I can make my code
better. If you need more code I will post it. I am in early
devlopment of the game.

map.h:

#include<map.h>
#include<fstream.h>
#include<windows.h>
#include "structlib.h"
#include "space.h"

#ifndef maze_h
#define maze_h

class maze{
const static int numx = 38;
const static int numy = 30;
space grid[numy][numx];
map<char,dir> keys;
HWND hwnd;

char gchr;
coord pcoord;

dir n; /* directions */
dir s;
dir e;
dir w;

void fill();
ifstream& cfill(ifstream&, char&); /*Reads map from file */
int convx(int x){return x*12;}
int convy(int y){return y*8;}
public:
maze();
maze(const maze&);
~maze();
void showall(HWND);
void move(HWND, char);
void show(HWND);
};
#endif
#include "maze.h"

maze::maze(){

n.ud = -1;
n.lr = 0;
s.ud = 1;
s.lr = 0;
e.ud = 0;
e.lr = 1;
w.ud = 0;
w.lr = -1;

keys[''n'']=n;
keys[''s'']=s;
keys[''e'']=e;
keys[''w'']=w;

fill();
pcoord.x = 1;
pcoord.y = 1;
player pl;
player* play = &pl;
grid[pcoord.x][pcoord.y].SetPlayer(play);

}

maze::maze(const maze& mz){}

maze::~maze(){
delete [] grid;
}

ifstream& maze::cfill(ifstream& in, char& spc){
in>>spc;
return in;
}

void maze::fill(){
int l1 = 0;
int l2 = 0;

ifstream f ("level.txt");
if (! f.is_open()) {
MessageBox(NULL, "Missing File!", "Error!", MB_OK);
exit (1);
}
for(l1=0; l1 != numy; l1++){
for(l2=0; l2 != numx; l2++){
if(cfill(f, gchr)){
grid[l1][l2].readCH(gchr);
}
}
}
l2 = 0;
}

void maze::showall(HWND hwnd){
HDC hdc = GetDC(hwnd);
int lp1 = 0;
int lp2 = 0;

char ch;

for(lp1 = 0; lp1 != numy; lp1++){
for(lp2 = 0; lp2 != numx; lp2++){
ch = grid[lp1][lp2].getCH();
TextOut(hdc, convy(lp2),convx(lp1),&ch,1);
}
}
ReleaseDC(hwnd, hdc);
}

void maze::move(HWND hwnd, char dir){
player* play;
coord tcoord;
show(hwnd);
tcoord.x = pcoord.x + keys[dir].ud;
tcoord.y = pcoord.y + keys[dir].lr;

if (!grid[tcoord.x][tcoord.y].CheckWall()){
MessageBox(NULL, "Can''t Go through Wall!", "Ouch", MB_OK);
return;
}
grid[pcoord.x][pcoord.y].ClearPlayer();
pcoord.x = tcoord.x;
pcoord.y = tcoord.y;
grid[pcoord.x][pcoord.y].SetPlayer(play);

show(hwnd);
}

void maze::show(HWND hwnd){
HDC hdc = GetDC(hwnd);
int lp1 = pcoord.x-1;
int lp2 = pcoord.y-1;

char ch;

for(lp1; lp1 != (pcoord.y)+1; lp1++){
for(lp2; lp2 != (pcoord.x)+1; lp2++){
ch = grid[lp1][lp2].getCH();
TextOut(hdc, convy(lp2),convx(lp1),&ch,1);
}
}
ReleaseDC(hwnd, hdc);

}

推荐答案

>我正在写一个游戏,我在地图上移动角色
> I am writing a game and I am having trouble with moving the character
时遇到了麻烦。

这就是我现在所拥有的。它涉及win32编程,但这不是我的问题。我想要一些建议如何让我的代码更好。如果您需要更多代码,我会发布它。我很早就开始了游戏开发。
on the map.

Here is what I have right now. It involves win32 programming but that
not my problem. I would like some suggestions how I can make my code
better. If you need more code I will post it. I am in early
devlopment of the game.




到底出了什么问题?你能进一步描述这个问题吗(例如文字

没有显示,显示不正确等等?)在重新绘制所有内容之前,你是否忘了画出

背景?字符?


更好的是,发布到m​​icrosoft.public.win32.programmer.gdi,我很有信心

都是那些专业的Windows GDI专家在那里。


问候,

Ben



What exactly is wrong? Can you describe the problem even further (e.g. text
isn''t displayed, incorrectly displayed, etc?) Did you forget to paint the
background before you repaint all the characters?

Even better, post to microsoft.public.win32.programmer.gdi, I''m sure there
are all those professional Windows GDI experts there.

Regards,
Ben


enki写道:
我正在写一个游戏,我在地图上移动角色时遇到了麻烦。

这就是我现在所拥有的。它涉及win32编程,但这不是我的问题。


你怎么知道的?如果某些东西在窗口中没有正确显示,那么它很可能是一个win32问题,这当然是偏离主题的。

我想要一些建议我怎样才能使我的代码更好。如果您需要更多代码,我会发布它。我很早就开始游戏了。

map.h:
#include< map.h>
#include< fstream.h> ;
#include< windows.h>

#include" structlib.h"
#include" space.h"

#ifndef maze_h
#define maze_h
类迷宫{
const static int numx = 38;
const static int numy = 30;
space grid [numy] [numx];
map< char,dir>钥匙;
HWND hwnd;


我对你的设计有一个建议。你在一个

类中混合了两个主要但无关的b $ b无关责任 - 迷宫逻辑和用户界面,所以你可以考虑分离迷宫布局,移动和逻辑
。如果您有一个简单的迷宫类,只需要关注

本身的迷宫数据和操作,并且不知道HWND或DC

或Windows文本显示或消息框,您可以使用它可以在任何地方使用

更容易理解和维护你的代码。

char gchr;
coord pcoord;

目录N; / *方向* /
dir s;
dir e;
dir w;

void fill();
ifstream& cfill(ifstream&,char&); / *从文件中读取地图* /
int convx(int x){return x * 12;}
int convy(int y){return y * 8;}

public:
maze();
maze(const maze&);
~maze();
void showall(HWND);
void move(HWND,char );
void show(HWND);
};
I am writing a game and I am having trouble with moving the character
on the map.

Here is what I have right now. It involves win32 programming but that
not my problem.
How do you know? If something isn''t displayed correctly in a window then it
very likely is a win32 problem, which of course is off-topic here.
I would like some suggestions how I can make my code
better. If you need more code I will post it. I am in early
devlopment of the game.

map.h:

#include<map.h>
#include<fstream.h>
#include<windows.h>
#include "structlib.h"
#include "space.h"

#ifndef maze_h
#define maze_h

class maze{
const static int numx = 38;
const static int numy = 30;
space grid[numy][numx];
map<char,dir> keys;
HWND hwnd;
I have a suggestion about your design. You are mixing two major but
unrelated responsibilities - maze logic and user interface - in a single
class, so you could consider separating the maze layout, movement and logic
from your GUI code. If you have a simple maze class that just concerns
itself with the maze data and operations and knows nothing of HWNDs or DCs
or windows text display or message boxes you could use it anywhere and it
would be much easier to understand and maintain your code.
char gchr;
coord pcoord;

dir n; /* directions */
dir s;
dir e;
dir w;

void fill();
ifstream& cfill(ifstream&, char&); /*Reads map from file */
int convx(int x){return x*12;}
int convy(int y){return y*8;}
public:
maze();
maze(const maze&);
~maze();
void showall(HWND);
void move(HWND, char);
void show(HWND);
};




[snip]


DW



[snip]

DW


我认为这是一个好点。我是一名未受过训练的程序员,我自己教过

。我经常读书来理解这门语言。我有点经常听说我应该编写程序来解决这些问题。

我确实用控制台编写了这个程序。我正在尝试添加一个

interfact。我试图找出如何使这项工作。


我真的不知道如何分离这两个概念。我会认为这是关于它的b
并尝试将其解决。

I think that is a good point. I am an untrained programmer, I taught
myself. I have often read books to understand the language. I have
often heard that I should just write programs to figure the stuff out.
I do have this program written in a console. I am trying to add an
interfact to it. I am trying to figure out how to make this work.

I realy have no idea how to seperate the two concepts. I will think
about it and try to figue somthingf out.


这篇关于游戏问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆