Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Threading;
- using System.Linq;
- using System.Threading.Tasks;
- class Program
- {
- static void Main(string[] args)
- {
- Hero hero = new Hero();
- hero.Shoot();
- GameHistory game = new GameHistory();
- game.History.Push(hero.SaveState());
- hero.Shoot();
- hero.RestoreState(game.History.Pop());
- hero.Shoot();
- Console.ReadLine();
- }
- }
- class Hero
- {
- private int patrons = 10;
- private int lavel = 5;
- public void Shoot()
- {
- if(patrons > 0)
- {
- patrons--;
- Console.WriteLine("Производим выстрел. Патронов осталось {0}", patrons);
- }
- else{
- Console.WriteLine("Патронов больше нет");
- }
- }
- public HeroMomento SaveState()
- {
- Console.WriteLine("Сохранение игры. Патронов: {0} Жизней: {1}", patrons, lavel);
- return new HeroMomento(patrons, lavel);
- }
- public void RestoreState(HeroMomento momento)
- {
- this.patrons = momento.Patrons;
- this.lavel = momento.Lavel;
- Console.WriteLine("Востановление. Патронов {0} Жизней {1}", patrons, lavel);
- }
- }
- class HeroMomento
- {
- public int Patrons{get; private set;}
- public int Lavel{get; private set;}
- public HeroMomento(int patrons, int lavel)
- {
- Patrons = patrons;
- Lavel = lavel;
- }
- }
- class GameHistory
- {
- public Stack<HeroMomento> History {get; private set;}
- public GameHistory()
- {
- History = new Stack<HeroMomento>();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement