Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Header.h"
- #include <ctime>
- #include <cstdlib>
- Lunch::Lunch(int X, int Y) //defines lunch to have x&y coords and represented by L
- {
- Xpos = X;
- Ypos = Y;
- LunchRep = 'L';
- }
- void school::SetSize(const int n)
- {
- ActualSize = n;
- return;
- }
- bool Collision(Lunch & lunch, janitor & jan, int & DayCounter)
- {
- bool Collided = false;
- if (lunch.Xpos == jan.m_xval && lunch.Ypos == jan.m_yval)
- {
- Collided = true;
- }
- return Collided;
- }
- void place_me(school & skool, Lunch & lunch, const int Size)//randomly places
- //lunch position
- {
- lunch.Xpos = 1;
- lunch.Ypos = 1;
- //lunch.Xpos = (rand() % (Size - 2)) + 1;
- //lunch.Ypos = (rand() % (Size - 2)) + 1;
- skool.School[lunch.Xpos][lunch.Ypos] = lunch.LunchRep;
- }
- void random_move(school & skool, Lunch & lunch)//sets random movement for lunch
- {
- int Movement;
- skool.School[lunch.Ypos][lunch.Xpos] = ' ';
- Movement = rand() % 4;
- switch (Movement)
- {
- case 0:
- if (skool.School[lunch.Ypos + 1][lunch.Xpos] == ' ')//checks for wall
- {
- if (lunch.Ypos < Size - 1)
- {
- lunch.Ypos++;
- }
- }
- break;
- case 1:
- if (skool.School[lunch.Ypos][lunch.Xpos + 1] == ' ')//checks for wall
- {
- if (lunch.Xpos < Size - 1)
- {
- lunch.Xpos++;
- }
- }
- break;
- case 2:
- if (skool.School[lunch.Ypos - 1][lunch.Xpos] == ' ')//checks for wall
- {
- if (lunch.Ypos > 1)
- {
- lunch.Ypos--;
- }
- }
- break;
- case 3:
- if (skool.School[lunch.Ypos][lunch.Xpos - 1] == ' ')//checks for wall
- {
- if (lunch.Xpos > 1)
- {
- lunch.Xpos--;
- }
- }
- break;
- }
- skool.School[lunch.Ypos][lunch.Xpos] = lunch.LunchRep;
- cout << Movement << endl << "Lunch: " << lunch.Ypos << ", " << lunch.Xpos << endl;
- }
- void school::print(const int Size, const char School[MAX][MAX])//creates school
- {
- for(int i = 0;i < Size;i++)
- {
- for (int j = 0;j < Size;j++)
- {
- cout << School[i][j] << ' ';
- }
- cout << endl;
- }
- return;
- }
- void school::clear(char School[MAX][MAX])//clears current data in school array
- {
- for (int i = 0;i < MAX;i++)
- {
- for (int j = 0;j < MAX;j++)
- {
- School[i][j] = '\0';
- }
- }
- return;
- }
- //places windows and walls on the border of school
- void school::build(const int Size, school & skool, Lunch & lunch, janitor & Jan)
- {
- char Window = 'W', Wall = 'D';
- for(int i = 0; i < Size; i++)
- {
- for(int j = 0; j < Size; j++)
- {
- if(i == 0 || j == 0 || i == Size - 1 || j == Size - 1)
- {
- if ((i > 0 && i < Size - 1 && i % 5 == 0) || (j > 0 && j < Size - 1 && j % 5 == 0))
- {
- School[i][j] = Window;
- }
- else
- {
- School[i][j] = Wall;
- }
- }
- else
- {
- School[i][j] = ' ';
- }
- }
- }
- random_move(skool, lunch);
- rand_walk(skool, Jan);
- print(Size, skool.School);
- return;
- }
- //places janitor
- void place_Janitor (school & escuela, janitor & Willie, const int Size)
- {
- Willie.m_xval = Size - 2;
- Willie.m_yval = Size - 2;
- escuela.School[Willie.m_xval][Willie.m_yval] = Willie.jancharacter;
- }
- //places willie in school and walks him in random directions with possibility of a double step
- void rand_walk (school & escuela, janitor & Willie)
- {
- int rand_step;
- int Twostep = 0;
- escuela.School[Willie.m_yval][Willie.m_xval] = ' ';
- rand_step = rand() %4;
- switch (rand_step)
- {
- case 0:
- if (escuela.School[Willie.m_yval + 1][Willie.m_xval] == ' ')
- {
- Willie.m_yval++;
- Twostep = rand() %2;
- if (escuela.School[Willie.m_yval + 1][Willie.m_xval] == ' ')
- {
- if (Twostep == 1)
- {
- Willie.m_yval++;
- }
- }
- }
- case 1:
- if (escuela.School[Willie.m_yval][Willie.m_xval + 1] == ' ')
- {
- Willie.m_xval++;
- Twostep = rand() %2;
- if (escuela.School[Willie.m_yval][Willie.m_xval + 1] == ' ')
- {
- if (Twostep== 1)
- {
- Willie.m_xval++;
- }
- }
- }
- case 2:
- if (escuela.School[Willie.m_yval - 1][Willie.m_xval] == ' ')
- {
- Willie.m_yval--;
- Twostep = rand() %2;
- if (escuela.School[Willie.m_yval - 1][Willie.m_xval] == ' ')
- {
- if (Twostep== 1)
- {
- Willie.m_yval--;
- }
- }
- }
- case 3:
- if (escuela.School[Willie.m_yval][Willie.m_xval - 1] == ' ')
- {
- Willie.m_xval--;
- Twostep = rand() %2;
- if (escuela.School[Willie.m_yval][Willie.m_xval - 1] == ' ')
- {
- if (Twostep == 1)
- {
- Willie.m_xval--;
- }
- }
- }
- }
- escuela.School[Willie.m_yval][Willie.m_xval] = Willie.jancharacter;
- cout << rand_step << endl << "Janitor: " << Willie.m_yval << ", " << Willie.m_xval << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement