OK、とても簡単なテキストアドベンチャーゲームに取り組んでいます。今私は機能しているメニューと、できるだけ早くランダムな出会いに変換される非常に単純な「戦闘モード」を持っています。今でも地図は問題ありません。C++テキストアドベンチャーゲーム:マップとしての2D配列
2次元配列システムをマップとして使用し、座標が(それが理にかなっているとすれば)座標として格納されるようにすることです。「北、東、南および西」の4方向を入力して移動できますあなたが行くことができる3種類の場所があります。畑、森、城。地図自体は5×6です。
私がしたいのは、座標2と2の中央で開始するようにしたいのです。たとえば、フィールド(例えば、1の整数が上に表示されます)と同じように移動することができます。 「あなたはフィールドにいる」と言って、城や森などに向かって動くのにも同様のものをやっています。彼らはそこに行くことができない0と記された場所に移動しようとしたら、それらの動きを止めてください。
誰にも助言がありますか?
EDIT:もう一度プログラムを実行しましたが、いくつかのエラーを取り除くことができましたが、まだまだ残っています(正確には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()
{
;
}
'(もし!マップ[locationx] [locationy + 1] = 0){locationy + = 1 ; } else {cout << "それは水です、おい、platemailでの水泳はお勧めしません。\ n"} ' – user4581301
こんにちは、スタックオーバーフローへようこそ!この種の質問はおそらくこのサイトに適しています:http://codereview.stackexchange.com/。 codereviewでは、あなたの質問に答えることができる人が、長期的にはあなたのためにもっと役立つことがあります。 –
アドバイスをいただき、ありがとうございました。その40分の時間が経過するとすぐに投稿を試みます。その間、あなたは私に関係なく、私に提供できるアドバイスはありますか? –