im trying to create a class that will create a 20x20 grid with 5 random x's and 100 random o's. But its currently giving me ascii chars instead. any help would be appreciated!
#include "Lifegrid.h"
using namespace std;
int main()
{
int r1;
int r2;
int r3;
int oldi;
int oldj;
int count1;
int count2;
char grid[20][20];
Lifegrid mygrid;
mygrid.drawgrid();
mygrid.printGrid();
system("pause");
return 0;
}
Lifegrid.h:
#ifndef GRID
#define GRID
#include <iostream>
#include <string>
#include<cstdlib>
using namespace std;
class Lifegrid
{
protected:
int r1;
int r2;
int r3;
int oldi;
int oldj;
int count1;
int count2;
char grid[20][20];
public:
void drawgrid()
{
for(int i=0;i<20;i++)
{
for(int j=0;j<20;j++)
{
srand((unsigned)time(0));
r1 = rand()%2;
r2 = rand()%20;
r3 = rand()%20;
if(r1 ==1)
{
oldi = i;
oldj = j;
i = r2;
j = r3;
if((grid[i][j]=='x')||(grid[i][j]=='o')||(count1>=5))
{
i=i-1;
}
else
{
grid[i][j] = 'x';
count1++;
}
i = oldi;
j = oldj;
}
if(r1==0)
{
oldi = i;
oldj = j;
i = r2;
j = r3;
if((grid[i][j]=='x')||(grid[i][j]=='o')||(count2>=100))
{
i=i-1;
}
else
{
grid[i][j] = 'o';
count2++;
}
i = oldi;
j = oldj;
}
}
}
}
void printGrid()
{
for(int i=0;i<20;i++)
{
for(int j=0;j<20;j++)
{
cout << grid[i][j] ;
}
cout << endl;
}
}
};
#endif