public IGame ApplySnapShot(GameSnapeshot snapshot, EventHandler <TurtleStatusChangedEventArg> turtleStatusChangedHandler) { (this as IAcceptMine).LayMine(snapshot.Board_Mines); (this as IAcceptExitPoint).SetExitPoint(snapshot.Board_ExitPoint); (this as IAcceptTutle).AddTurtle(snapshot.Turtle_StartPosition, snapshot.Turtle_StartDirection, turtleStatusChangedHandler); this.turtle.MoveTo(snapshot.Turtle_CurrentPosition); while (this.turtle.CurrentDirection != snapshot.Turtle_CurrentDirection) { this.turtle.Rotate(); } if (snapshot.Turtle_Status == TurtleState.Killed) { this.turtle.Kill(); } else if (snapshot.Turtle_Status == TurtleState.Escaped) { this.turtle.Escape(); } return(this); }
GameSnapeshot IGame.TakeSnapshot() { GameSnapeshot snapshot = new GameSnapeshot(); if (this.board != null) { snapshot.Board_ExitPoint = this.board.ExitPoint; snapshot.Board_Height = this.board.Height; snapshot.Board_Width = this.board.Width; snapshot.Board_Mines = this.board.GetMines(); } if (this.turtle != null) { snapshot.Turtle_CurrentDirection = this.turtle.CurrentDirection; snapshot.Turtle_CurrentPosition = this.turtle.CurrentPosition; snapshot.Turtle_StartDirection = this.turtle.StartDirection; snapshot.Turtle_StartPosition = this.turtle.StartPosition; snapshot.Turtle_Status = this.turtle.Status; } return(snapshot); }
public static IGame LoadSnapshot(GameSnapeshot snapshot, EventHandler <TurtleStatusChangedEventArg> turtleStatusChangedHandler = null) { GameImplementation game = Create(snapshot.Board_Width, snapshot.Board_Height) as GameImplementation; return(game.ApplySnapShot(snapshot, turtleStatusChangedHandler)); }