/// <inheritdoc/> public void SaveCurrentState(PacmanModel model) { XmlSerializer serializer2 = new XmlSerializer(typeof(PacmanModel)); if (model != null) { using (TextWriter textWriter = new StreamWriter(this.path + $"{model.User.Username}State.xml")) { serializer2.Serialize(textWriter, model); } } }
private void LoadGame(int level, int score = 0) { this.stw = new Stopwatch(); if (this.isLoaded) { this.model = this.repo.LoadCurrentState(this.username); this.model.Transform(); } else { this.model = new PacmanModel(this.ActualWidth, this.ActualHeight); this.model.User = new User(this.username, 0); this.model.Score = score; this.model.Level = level; } this.logic = new PacmanLogic(this.model, this.lvl + $"{this.model.Level}.lvl", !this.isLoaded); this.renderer = new PacmanRenderer(this.model); this.isLoaded = false; Window win = Window.GetWindow(this); if (win != null) { if (this.tickTimer != null) { this.tickTimer.Stop(); } this.tickTimer = new DispatcherTimer(); this.tickTimer.Interval = TimeSpan.FromMilliseconds(200); this.tickTimer.Tick += this.TickTimer_Tick; this.tickTimer.Start(); win.KeyDown += this.Win_KeyDown; } this.InvalidateVisual(); this.stw.Start(); }
/// <summary> /// Initializes a new instance of the <see cref="PacmanLogic"/> class. /// </summary> /// <param name="model">Pacman model itself.</param> /// <param name="fname">Level path.</param> /// <param name="newGame">Boolean value determing if the game is new or loaded.</param> public PacmanLogic(PacmanModel model, string fname, bool newGame) { this.model = model; if (!File.Exists(fname)) { throw new FileNotFoundException("File Not Found"); } string[] lines = File.ReadAllLines(fname); this.width = int.Parse(lines[0], CultureInfo.CurrentCulture); this.height = int.Parse(lines[1], CultureInfo.CurrentCulture); this.model.Walls = new bool[this.width, this.height]; this.model.Map = new char[this.width, this.height]; this.model.TileSize = Math.Min(this.model.GameWidth / this.width, this.model.GameHeight / this.height); if (newGame) { this.NewGame(lines); } else { this.LoadGame(lines); } }
/// <summary> /// Initializes a new instance of the <see cref="PacmanRenderer"/> class. /// </summary> /// <param name="model">Pacman model itself.</param> public PacmanRenderer(PacmanModel model) { this.model = model; }