【发布时间】:2017-03-21 00:57:23
【问题描述】:
好的,我正在开发一款非常简单的文字冒险游戏。现在我有一个功能菜单和一个非常简单的“战斗模式”,它将尽快转换为随机遭遇。我现在遇到的问题是地图。
这个想法是使用 2D 阵列系统作为地图,并将位置存储为坐标(如果有意义的话)。您可以输入 4 个方向,“北、东、南和西”来四处移动,您可以去 3 种类型的地方。一片田野,一片森林,一座城堡。地图本身的大小是 5 x 6。
我想要做的是让你从坐标 2、2 的中心开始,然后你可以四处移动,例如一个字段(由顶部的整数指定的 1)它说“你在田野里”并为向城堡、森林等移动做类似的事情。我还希望它告诉玩家他们是否试图移动到标有 0 的位置,他们不能去那里停下来他们从移动。
有人有什么建议吗?
编辑:好的,所以我再次运行了我的程序,我已经设法摆脱了一些错误,但我还有很多错误(准确地说是 26 个,还有 1 个警告。) 有人愿意给我一些建议吗?
#pragma once
#include "Map.h"
#include <iostream>
using namespace std;
Map::Map()
{
}
void main()
{
// Declare variables & functions
int locationy;
int locationx;
char oper;
char location;
int pond = 0;
int field = 1;
int forest = 2;
int castle = 3;
int mapy;
int mapx;
int map;
//These two values declare the start location on the array map for the player
int mapy = 3;
int mapx = 3;
//These two variables track your current position on the map
mapy = 2;
mapx = 2;
map[locationy][locationx];
//Declares the amount of space within an array
int map[6][6] =
{
{ 0, 0, 0, 0, 0, 0 },
{ 0, 2, 1, 2, 1, 0 },
{ 0, 1, 2, 1, 2, 0 },
{ 0, 1, 2, 2, 1, 0 },
{ 0, 1, 3, 1, 2, 0 },
{ 0, 0, 0, 0, 0, 0 }
};
//Asks the player where they want to go around the map
cout << "Where to?" << endl;
//Request for user to enter an direction (I.e., North, East, South, West.)
cout << "Please choose North, East, South or West" << endl;
//Displays the inputted values
cin >> oper;
//Pauses system so we can see what the program does
system("pause");
//Checks input from the player
if (cin == "North")
{
//Moves location upwards on the y axis
if (map[locationx][locationy + 1] != 0) { locationy += 1; };
else { cout << "That is water, dude. Swimming in platemail is NOT recommended.\n";
}
//Checks input from the player
if (cin == "East")
{
//Moves location to the right on the x axis
if (map[locationx + 1][locationy] != 0) { locationy += 1; };
else { cout << "That is water, dude. Swimming in platemail is NOT recommended.\n";
}
//Checks input from the player
if (cin == "South")
{
//Moves location downwards on the y axis
if (map[locationx][locationy - 1] != 0) { locationy += 1; }
else { cout << "That is water, dude. Swimming in platemail is NOT recommended.\n";
}
//Checks input from the player
if (cin == "West")
{
//Moves location to the left on the x axis
if (map[locationx - 1][locationy] != 0) { locationy += 1; }
else { cout << "That is water, dude. Swimming in platemail is NOT recommended.\n"
};
}
Map::~Map()
{
;
}
【问题讨论】:
-
if (map[locationx][locationy + 1] != 0) { locationy += 1; } else { cout << "That is water, dude. Swimming in platemail is NOT recommended.\n" } -
嗨,欢迎来到 Stack Overflow!这种问题可能更适合这个网站:codereview.stackexchange.com。在 codereview 上,您可能会发现更多的人能够以从长远来看对您更有帮助的方式回答您的问题。
-
感谢您的建议,我会在 40 分钟后立即尝试在那里发帖。与此同时,您有什么建议可以给我吗?
-
在代码审查中,我们可以帮助您改进您的工作代码,但是这不是询问如何为您的代码编写新功能的好地方(这与“代码即还没有写”因此无法审查)。
-
你会建议我在哪里询问如何编写新功能?
标签: c++ arrays visual-c++