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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
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;
}
int getposx ()
{
return posx;
}
int getposy ()
{
return posy;
}
string name;
int posx;
int posy;
char bunicon;
char sex;
int age;
};
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 ();
char definesex ();
void getboard ();
string namelist ();
void createobj ();
//////////////////////////////////////////////////////////////////////////////
int main()
{
srand(time(0));
vector <bunny>bunnies;
bunny (namelist()); ///is this bunny im creating here (iwould also like to set the objects name to the setname)
bunnies.push_back (namelist()); ///the same as the one im pushing back
bunnies[0].setsex(definesex());
cout << bunnies[0].getsex()<<endl;
bunnies[0].setname (namelist());///how could i use the namelist to set the name
}
//////////////////////////////////////////////////////////////////////////////
string namelist ()
{
string namearray [18] = {"bon","fur","fluff","foof","bax","tig","uru","ira","esa","afe","ige","ifi","floof","tix","dar","vini","ter", "von"};
///will two objects that end up with the same name be a problem too?
string none = namearray [getrand()%18];
string ntwo =namearray [getrand()*4%18];
string nthree=namearray [getrand()*7%18];
string fullname=none+ntwo+nthree;
return fullname;
}
void getboard ()
{
for (int a = 0;a<10;a++)
{
for (int b =0;b<10;b++)
cout << brdray [a][b];
cout<<endl;
}
}
int getrand ()
{
return 1+(rand()%6);
}
int getposx (int x)
{
for (int a = 0;a<10;a++)
{
for (int b =0;b<10;b++)
{
brdray [a] [b];
if (brdray[a] [b]);///here is a half started function for finding the position
///it was very flawed, the aim was to check the ///position of other objects in relation to itself but im only going to
///have chars that represent objects on the board (brdray)
}
}
}
char definesex ()
{
char m = 'm';
char f = 'f';
int a;
int b;
a=getrand();
b=getrand();
if (a<b)
{
return 'm';
}
else if (a>b)
{
return 'f';
}
}
|