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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cmath>
using namespace std;
class bunny
{
public:
bunny (int h = 0): age (h) {}
int ageing (int h)
{
age++;
return age;
}
void setsex (char s)
{
sex = s;
}
char getsex ()
{
return sex;
}
bunny (int x=5, int y=5): posx (x), posy (y) {}
void setname (string x)
{
name = x;
}
string getname ()
{
return name;
}
int setposx (int x)
{
posx=x;
}
int setposy (int y)
{
posy=y;
}
void de_edge (char *array[10][10])//-1- HERE IS DE_EDGE
{
if (array [posx+1][posy]== "*")
{
posx-2;
}
}
void hopabout ()
{
int box;
box=1+(rand()%4);
switch (box)
{
case 1:
posx++;
break;
case 2:
posx--;
break;
case 3:
posy++;
break;
case 4:
posy--;
break;
}
}
int getposx ()
{
return posx;
}
int getposy ()
{
return posy;
}
string name;
int posx;
int posy;
char bunicon;
char sex;
int age;
int box;
};
char z = '*';
char x = ' ';
char brdray [10] [10] = { {z,z,z,z,z,z,z,z,z,z},
{z,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,z}, {z,z,z,z,z,z,z,z,z,z} };
int getrand (); ///these guys are the function prototypes
char definesex ();
void getboard ();
string namelist ();
void createobj ();
void clearboard (char brdray [10][10]);
//////////////////////////////////////////////////////////////////////////////
int main()
{
char *array = &brdray[10][10]; //-2- here i point to the array
bool gameover = false;
bool gobreed = false;
srand(time(0));
vector <bunny>bunnies;
for (int aa = 0;aa<8;aa++)
{
bunnies.push_back(bunny(0,0)) ; //push back a default constructed bunny.
bunny& workingBunny = bunnies.back() ; // manipulate the last bunny in the vector
workingBunny.setname(namelist()) ;
workingBunny.setsex(definesex()) ;
workingBunny.setposy(getrand());
workingBunny.setposx(getrand());
workingBunny.de_edge(array);//-3- here i hoped to pass to the class
brdray [workingBunny.getposx()][workingBunny.getposy()] = (workingBunny.getsex());
}
return 0;
}
|