Feb 15, 2017 at 9:31am Feb 15, 2017 at 9:31am UTC
I'm trying to figure out about how in my generate functions, I can randomly place a 'P' character and a 'G' character. But I don't understand how to change what I used for the random scatter of '*'s. Would really appreciate some help.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
#include "stdafx.h"
#include "Environment.h"
#include <iostream>
#include <ctime>
Environment::Environment()
{
width = 0;
height = 0;
}
void Environment::setEnvironment()
{
std::cout << "To set the environment, please enter the width and the height:" << std::endl;
std::cout << "Width: " ;
std::cin >> width;
std::cout << "Height: " ;
std::cin >> height;
std::cout << std::endl;
gridArray = new char [width * height];
for (int i = 0; i < width * height; i++)
{
gridArray[i] = ' ' ;
}
for (int i = 0; i < width; i++) //fills in top and bottom row top row
{
gridArray[i] = '*' ; //fills from 0 to width - 1 (top row filling from left to right)
gridArray[(width * height) - i - 1] = '*' ; //fills from width * height-1 (last array element backwards(bottom row from right to left))
}
for (int i = 0; i < height; i++)
{
gridArray[(i * width)] = '*' ; //fills left column from top to bottom
gridArray[(width * height)- 1 -(i * width)] = '*' ; //fills right column from bottom to top
}
srand(time(NULL));
for (int row = 0; row < width; row++)
{
for (int col = 0; col < height; col++)
{
gridArray[row * width + col];
if ((rand() % 100) < 30)
{
gridArray[row * width + col] = '*' ;
}
}
}
}
void Environment::printEnvironment()
{
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
std::cout << gridArray[(i * width) + j];
}
std::cout << std::endl;
}
for (int i = 0; i < 5; i++)
{
}
}
void Environment::generatePlayer()
{
srand(time(NULL));
int spawn;
spawn = rand() % (width * height) + 1;
if (gridArray[goal])
}
void Environment::generateGoal()
{
srand(time(NULL));
int goal;
}
Environment::~Environment()
{
}
Last edited on Feb 15, 2017 at 10:14am Feb 15, 2017 at 10:14am UTC