/** CLONE ALL THE THINGS! **/ public object Clone() { CloneTimeBegin = Environment.TickCount; // Create a new copy of the object that we want GameState _temp = (GameState)this.MemberwiseClone(); _temp.Map = (Map)this.Map.Clone(); _temp.Pacman = (Pacman)this.Pacman.Clone(); // Grab a copy of pacman while we're at it _temp.Pacman.GameState = _temp; _temp.GameOver = delegate(object sender, EventArgs e) { }; // Genereate the maps _temp.maps = new Map[4]; _temp.maps[0] = (Map)maps[0].Clone(); _temp.maps[1] = (Map)maps[1].Clone(); // Commenting this out for testing purposes //for (int i = 0; i < maps.Length; i++) //{ // _temp.maps[i] = (Map)maps[i].Clone(); //} // Generate the new array of ghosts _temp.Ghosts = new Ghost[4]; _temp.Ghosts[0] = _temp.Red = (Red)Red.Clone(); _temp.Ghosts[1] = _temp.Pink = (Pink)Pink.Clone(); _temp.Ghosts[2] = _temp.Blue = (Blue)Blue.Clone(); _temp.Ghosts[3] = _temp.Brown = (Brown)Brown.Clone(); // Assign the newly generated game state manually // to the objects. _temp.Brown.GameState = _temp; _temp.Pink.GameState = _temp; _temp.Blue.GameState = _temp; _temp.Red.GameState = _temp; // Generate a random controller for the future simulations _temp.Controller = new SimRandomPac(); // Loop through the ghosts and assign the game state appropriately for (int i = 0; i < _temp.Ghosts.Length; i++) { _temp.Ghosts[i].GameState = _temp; } CloneTimeEnd = Environment.TickCount; return(_temp); }