ok, I am attempting to make a basic rundown program for a text based adventure game. the code:
Code:
/* -----Hunt---------------------------------*\
* By Matthew Valley Copyright 2003 *
* The objective of this game is to gain 100pt *
* or die(yes this will be an objective). *
* *
\**********************************************/
/* header files*/
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <conio.h>
using namespace std;
/* Definitions*/
#define PLAYER_OUT 3
#define MONSTER_OUT 8
#define GRASS 1
#define BUSH 2
#define MAX_MONSTERS 10
#define MAX_GRID 30
/* global variable Declarations */
int i, j;
//1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U
int Map_Grid[MAX_GRID][MAX_GRID] = //editted out as would not fit.
void DisplayMap()
{
for (i = 0; i < MAX_GRID; i++)
{
for (j = 0; j < MAX_GRID; j++)
{
cout << Map_Grid[i][j];
}
cout <<"\n";
}
};
void BeginDisplay()
{
cout <<"** -----BASEMENT-----------------------------** \n"
<<"* By Matthew Valley Copyright 2003 * \n"
<<"* The objective of this game is to gain 100pt * \n"
<<"* contact: [email protected] * \n"
<<"* * \n"
<<"************************************************ \n";
};
/*
initialize player and monster classes, as well as
those of the Items.
*/
/* Main Player Class*/
class PLAYER_C
{
public:
int weapon;
int Dmg;
int Health;
int Res;
int Mag;
int Plyr_Char_Pos_X;
int Plyr_Char_Pos_Y;
};
/* Main monster class */
class MONSTER
{
public:
int Dmg;
int Health;
int Res;
int Monster_Pos_X;
int Monster_Pos_Y;
};
/* Main Item Class*/
class ITEM
{
public:
int ResAdd;
int ResSub;
int MagAdd;
int MagSub;
};
int main()
{
int End_Game;
int amulet = 0, sword, ring;
MONSTER monsters[MAX_MONSTERS];
PLAYER_C Plyr;
for (i = 0; i < MAX_MONSTERS; i++)
{
monsters[i].Dmg = 11;
monsters[i].Health = 5;
monsters[i].Res = 0;
monsters[i].Monster_Pos_X = rand() % MAX_GRID;
monsters[i].Monster_Pos_Y = rand() % MAX_GRID;
Map_Grid[monsters[i].Monster_Pos_Y][monsters[i].Monster_Pos_X] = MONSTER_OUT;
}
Plyr.Plyr_Char_Pos_X =20;
Plyr.Plyr_Char_Pos_Y =20;
Plyr.Health = 100;
Map_Grid[20][20] = PLAYER_OUT;
BeginDisplay();
DisplayMap();
for (End_Game = 200; End_Game > 0 ; End_Game--)
{
cout << End_Game/2 <<" turns left \n"
<< Plyr.Health<<"health left \n";
cout <<" Which Direction Do you wish to go,\n N(W)\n E(D) \n S(S)\n W(A)\n: ";
switch (getchar())
{
case 'W':
if (Map_Grid[Plyr.Plyr_Char_Pos_Y - 1][Plyr.Plyr_Char_Pos_X] != 2)
if (Map_Grid[Plyr.Plyr_Char_Pos_Y -1][Plyr.Plyr_Char_Pos_X ] != 4)
{
Plyr.Plyr_Char_Pos_Y = Plyr.Plyr_Char_Pos_Y - 1;
Map_Grid[Plyr.Plyr_Char_Pos_Y][Plyr.Plyr_Char_Pos_X] = PLAYER_OUT;
Map_Grid[Plyr.Plyr_Char_Pos_Y + 1][Plyr.Plyr_Char_Pos_X] = GRASS;
break;
}
else
break;
case 'S':
if (Map_Grid[Plyr.Plyr_Char_Pos_Y + 1][Plyr.Plyr_Char_Pos_X] != 2)
if (Map_Grid[Plyr.Plyr_Char_Pos_Y +1][Plyr.Plyr_Char_Pos_X ] != 4)
{
Plyr.Plyr_Char_Pos_Y = Plyr.Plyr_Char_Pos_Y + 1;
Map_Grid[Plyr.Plyr_Char_Pos_Y][Plyr.Plyr_Char_Pos_X] = PLAYER_OUT;
Map_Grid[Plyr.Plyr_Char_Pos_Y -1][Plyr.Plyr_Char_Pos_X] = GRASS;
break;
}
else
break;
case 'D':
if (Map_Grid[Plyr.Plyr_Char_Pos_Y][Plyr.Plyr_Char_Pos_X +1] != 2)
if (Map_Grid[Plyr.Plyr_Char_Pos_Y][Plyr.Plyr_Char_Pos_X +1] != 4)
{
Plyr.Plyr_Char_Pos_X = Plyr.Plyr_Char_Pos_X + 1;
Map_Grid[Plyr.Plyr_Char_Pos_Y][Plyr.Plyr_Char_Pos_X] = PLAYER_OUT;
Map_Grid[Plyr.Plyr_Char_Pos_Y][Plyr.Plyr_Char_Pos_X - 1] = GRASS;
break;
}
else
break;
case 'A':
if (Map_Grid[Plyr.Plyr_Char_Pos_Y][Plyr.Plyr_Char_Pos_X -1] != 2)
if (Map_Grid[Plyr.Plyr_Char_Pos_Y][Plyr.Plyr_Char_Pos_X -1] != 4)
{
Plyr.Plyr_Char_Pos_X = Plyr.Plyr_Char_Pos_X - 1;
Map_Grid[Plyr.Plyr_Char_Pos_Y][Plyr.Plyr_Char_Pos_X] = PLAYER_OUT;
Map_Grid[Plyr.Plyr_Char_Pos_Y][Plyr.Plyr_Char_Pos_X + 1] = GRASS;
break;
}
else
break;
default:
break;
}
cout << "\n\n\n\n\n";
DisplayMap();
cout << "\n\n\n";
}
cout << " GAME OVER !";
return 0;
}
Now, I have a problem. when it displays the map, only the last 18 rows are displayed on screen. also, is there anyway I can more efficiently make maps, than writing them up over and over with different combinations?
thanks,