/// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// </summary> public override void Initialize() { // TODO: Add your initialization code here taken = false; hider = null; base.Initialize(); }
//finish competing against a hider public bool finishWithHider() { opponent = null; //if all hiders have been found if (hidersFound.Count == World.getWorld().numOfHiders) { return true; } return false; }
//checks whether item is blocking seeker from seeing hider public bool IsBlocking(Seeker seeker, Hider hider) { bool rv = false; foreach(PrimitiveShape p in getCageShapes()) { foreach (Vector3 v in hider.getPartsPositions()) { rv = rv || p.isBlockingLineOfSight(seeker.getEyesPosition(), v); } } return rv; }
//returns whether or not seeker can see hider public static float CanSee(Hider hider, Vector3 pos) { List<Vector3> locs = hider.getPartsPositions(); float res = 0.5f; float frac = 0.5f / locs.Count; //for each body part in hider foreach (Vector3 loc in locs) //for each item in world for (int j = 0; j < World.getWorld().numOfItems; j++) { //if seeker can't see hider if (!World.getWorld().items[j].IsBlocking(pos, loc)) { res += frac; } } return res; }
//this function needs to be fixed up very badly!! /// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// </summary> public override void Initialize() { borders = new Vector3[4]; borders[0] = new Vector3(20, 0, 0); borders[1] = new Vector3(-20, 0, 0); borders[2] = new Vector3(20, 0, -2000); borders[3] = new Vector3(-20, 0, -2000); map = new FieldMap((int)Math.Abs(borders[0].X - borders[3].X) / squareSize, (int)(Math.Abs(borders[0].Z - borders[3].Z) / squareSize)); if (gameType == GameType.Hide || gameType == GameType.Seek) { items = new Item[numOfItems]; for (int i = 0; i < numOfItems; i++) { items[i] = new Rock(Game, new Vector3(0, 0, -10 * i), new Vector3(1, 1, 1), 0, this); //tell map that this place is off-limits //this is not correct because we have negative x coordinates!!! map.addBlock((int)items[i].location.X / squareSize, (int)-items[i].location.Z / squareSize); //depending on item size may need to block 2 or more squares? } hiders = new Hider[numOfHiders]; for (int i = 0; i < numOfHiders; i++) { hiders[i] = new Hider(Game, this); //tell map that this place is off-limits //this is not correct because we have negative x coordinates!!! map.addBlock((int)hiders[i].location.X / squareSize, (int)-hiders[i].location.Z / squareSize); } gamePhase = GamePhase.Counting; } else if (gameType == GameType.HidePractice) { hiders = null; items = new Item[1]; items[0] = new Rock(Game, new Vector3(0, 0, -10), new Vector3(1, 1, 1), 0, this); } else // gameType == SeekPractice { hiders = new Hider[1]; hiders[0] = new Hider(Game, this); items = new Item[2]; items[0] = new Rock(Game, new Vector3(5, 0, -10), new Vector3(1, 1, 1), 0, this); items[1] = new Rock(Game, new Vector3(-5, 0, -10), new Vector3(1, 1, 1), 0, this); } if (gameType == GameType.Hide) seeker = new Seeker(Game, this, countNum); else seeker = null; if (gameType == GameType.Hide || gameType == GameType.HidePractice) { meHider = new MeHider(Game, this); meSeeker = null; } else { meSeeker = new MeSeeker(Game, this, countNum); meHider = null; } base.Initialize(); }
//returns distance between seeker and hider private float GetDist(Hider hider) { float xDist = location.X - hider.Location.X; float zDist = location.Z - hider.Location.Z; return (float)Math.Sqrt(xDist * xDist + zDist * zDist); }
//returns whether or not seeker notices hider private bool CanFind(Hider hider) { float visibleBodyParts = SeekerImp.CanSee(hider, getEyesPosition()); //calculate relative distance to hider within sight range float distPercentage = GetDistPercentage(GetDist(hider)); //calculate total probability of seeker noticing hider float totalChance = visibleBodyParts * distPercentage; Random rand = new Random(); //generate random number, if number is within probability return true. otherwise, return false double randDouble = rand.NextDouble(); if (randDouble < totalChance) return true; else return false; }
//checks if given hider has been found yet internal bool foundYet(Hider hider) { return hidersFound.Contains(hider); }
//register hider as found public void hiderFound(Hider hider) { opponent = hider; hidersFound.AddLast(hider); hider.Found(); }
//constructor for SeekerImp class public SeekerImp() { opponent = null; hidersFound = new LinkedList<Hider>(); }
//checks whether seeker can see given hider (will be relevant also for practice levels) //should be rewritten to call IsBlocking function in Item private bool CanSee(Hider hider) { //create line of sight from seeker's eyes to limbs[i] in hider. i.e., can seeker see limb #i? for (int j = 0; j < world.numOfItems; j++) { if (world.items[j].IsBlocking(this, hider))//if seeker can't see hider { return false; } } return true; }