예제 #1
0
        public MainWindow()
        {
            InitializeComponent();

            _figureDrawer = new FigureDrawer(new TileDrawer(MainCanvas));
            _fieldDrawer  = new FieldDrawer(new TileDrawer(MainCanvas));

            Game = new Game(new RandomNextFigureFactory());
            Game.FigureStateChanged += GameOnFigureStateChanged;
            Game.LinesChanged       += GameOnLinesChanged;
            Game.StateChanged       += GameOnStateChanged;

            Game.Field = Field.CreateField(FieldHelper.FieldDefaultWidth, FieldHelper.FieldDefaultHeight, "DimGray");
            Game.ResetFigure(_figureFactory.CreateRandomFigure());

            _figureDrawer.DrawFigure(Game.Figure, Game.FigurePositionX, Game.FigurePositionY);
            _fieldDrawer.AttachToField(Game.Field);


            _timer = new System.Windows.Threading.DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(10)
            };

            _timer.Tick += (sender, args) => { Game.Tick(); };

            _timer.Start();
        }
예제 #2
0
        public MainWindow()
        {
            InitializeComponent();

            _figureDrawer     = new FigureDrawer(new TileDrawer(MainCanvas));
            _fieldDrawer      = new FieldDrawer(new TileDrawer(MainCanvas));
            _nextFigureDrawer = new FigureDrawer(new TileDrawer(NextFigureCanvas));

            Game = new Game(new RandomNextFigureFactory());
            Game.FigureStateChanged += GameOnFigureStateChanged;
            Game.LinesChanged       += GameOnLinesChanged;
            Game.StateChanged       += GameOnStateChanged;

            Game.Field = Field.CreateField(FieldHelper.FieldDefaultWidth, FieldHelper.FieldDefaultHeight, "DimGray");
            Game.ResetFigure(Game.GetCurrentFigureValue());

            _figureDrawer.DrawFigure(Game.Figure, Game.FigurePositionX, Game.FigurePositionY);
            _nextFigureDrawer.DrawFigure(Game.GetNextFigureValue(), 0, 0);
            _fieldDrawer.AttachToField(Game.Field);


            _timer = new System.Windows.Threading.DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(10)
            };
            _timer.Tick += (sender, args) => { Game.Tick(); };
            _timer.Start();

            TimeTextBlock.Text = Game.GetGameTimerValue().ToString("hh\\:mm\\:ss");

            _userGameSessionTimer = new System.Windows.Threading.DispatcherTimer {
                Interval = TimeSpan.FromSeconds(1)
            };
            _userGameSessionTimer.Tick += (sender, args) =>
            {
                Game.GameTimerTick();
                TimeTextBlock.Text = Game.GetGameTimerValue().ToString("hh\\:mm\\:ss");
            };
            _userGameSessionTimer.Start();
        }