Ejemplo n.º 1
0
        /// <summary>
        /// Handles the action, when a save or load button is pressed.
        /// </summary>
        /// <param name="key">ConsoleKey key.</param>
        /// <returns>Returns true, if save/load button is pressed. Otherwise false.</returns>
        private bool OnSaveLoadButtonPressed(ConsoleKey key)
        {
            switch (key)
            {
            case SAVE_BUTTON:
            {
                this.gameSaver.MementoField  = this.PlayField.SaveMemento();
                this.gameSaver.MementoPlayer = this.gamePlayer.SaveMemento();
                this.gameSaver.SaveGame();
                return(true);
            }

            case LOAD_BUTTON:
            {
                this.gameSaver.LoadGame();
                this.PlayField = this.InitializeField(this.gameSaver.MementoField.FieldDimension);
                this.PlayField.LoadMemento(this.gameSaver.MementoField);
                this.gamePlayer.LoadMemento(this.gameSaver.MementoPlayer);
                CellRegionEventArgs e = new CellRegionEventArgs(0, 0, this.PlayField.PlayfieldSize, this.PlayField.PlayfieldSize);
                this.OnCellsInRegionRedefined(e);
                return(true);
            }

            default:
                return(false);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Register event for cell changes.
 /// </summary>
 /// <param name="e">CellEventArgs e.</param>
 protected virtual void OnCellsInRegionRedefined(CellRegionEventArgs e)
 {
     if (this.CellsInRegionRedefined != null)
     {
         this.CellsInRegionRedefined(this, e);
     }
 }
Ejemplo n.º 3
0
        public void TestIfCellRegionEventArgsIsSetWithCorrectStartXStartYEndXAndY()
        {
            CellRegionEventArgs testRegionEvent = new CellRegionEventArgs(1, 2, 3, 4);
            bool arePropertiesCorrect = testRegionEvent.RegionStartX == 1 && testRegionEvent.RegionStartY == 2
                                        && testRegionEvent.RegionEndX == 3 && testRegionEvent.RegionEndY == 4;

            Assert.AreEqual(arePropertiesCorrect, true, string.Format("Exprected CellRegionEvent with region start x = 1, region start y = 2, region end x = 3, region end y = 4. Received region start x = {0}, region start y = {1}, region end x = {2}, region end y = {3}", testRegionEvent.RegionStartX, testRegionEvent.RegionStartY, testRegionEvent.RegionEndX, testRegionEvent.RegionEndY));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles the action, when a save or load button is pressed.
        /// </summary>
        /// <param name="key">ConsoleKey key.</param>
        /// <returns>Returns true, if save/load button is pressed. Otherwise false.</returns>
        private bool OnSaveLoadButtonPressed(ConsoleKey key)
        {
            switch (key)
            {
                case SAVE_BUTTON:
                    {
                        this.gameSaver.MementoField = this.PlayField.SaveMemento();
                        this.gameSaver.MementoPlayer = this.gamePlayer.SaveMemento();
                        this.gameSaver.SaveGame();
                        return true;
                    }

                case LOAD_BUTTON:
                    {
                        this.gameSaver.LoadGame();
                        this.PlayField = this.InitializeField(this.gameSaver.MementoField.FieldDimension);
                        this.PlayField.LoadMemento(this.gameSaver.MementoField);
                        this.gamePlayer.LoadMemento(this.gameSaver.MementoPlayer);
                        CellRegionEventArgs e = new CellRegionEventArgs(0, 0, this.PlayField.PlayfieldSize, this.PlayField.PlayfieldSize);
                        this.OnCellsInRegionRedefined(e);
                        return true;
                    }

                default:
                    return false;
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Register event for cell changes.
 /// </summary>
 /// <param name="e">CellEventArgs e.</param>
 protected virtual void OnCellsInRegionRedefined(CellRegionEventArgs e)
 {
     if (this.CellsInRegionRedefined != null)
     {
         this.CellsInRegionRedefined(this, e);
     }
 }
Ejemplo n.º 6
0
 public void TestIfCellRegionEventArgsRegionStartYCreateWithNegativeNumberWillThrowArgumentNullException()
 {
     CellRegionEventArgs testRegionEvent = new CellRegionEventArgs(1, -2, 3, 4);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Called when a there is a group new ICell objects being controlled by the attached GameEngine object. The default behavior is to create new 
        /// corresponding CellView objects and redraw them.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="BattleFiled.GameEngine.CellRegionEventArgs" /> instance containing the event data.</param>
        protected virtual void OnCellsInRegionRedefinedHandler(object sender, CellRegionEventArgs e)
        {
            int startX = e.RegionStartX;
            int startY = e.RegionStartY;
            int endX = e.RegionEndX;
            int endY = e.RegionEndY;
            Playfield playfield = this.Engine.PlayField;
            bool shouldChangeColor = false;

            for (int indexX = startX; indexX < endX; indexX++)
            {
                if (endX % 2 == 0)
                {
                    shouldChangeColor = !shouldChangeColor;
                }

                for (int indexY = startY; indexY < endY; indexY++)
                {
                    ICellView view = this.CreateCellView(playfield[indexX, indexY], shouldChangeColor);
                    this.CellViews[indexX, indexY] = view;
                    view.Draw();
                    shouldChangeColor = !shouldChangeColor;
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Called when a group of ICell objects controlled by the attached GameEngine object change their state. The default behavior is to redraw the 
        /// corresponding ICellView objects maintained by this class.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="BattleFiled.GameEngine.CellRegionEventArgs" /> instance containing the event data.</param>
        protected virtual void OnCellsInRegionChangedHandler(object sender, CellRegionEventArgs e)
        {
            int startX = e.RegionStartX;
            int startY = e.RegionStartY;
            int endX = e.RegionEndX;
            int endY = e.RegionEndY;

            for (int indexX = startX; indexX < endX; indexX++)
            {
                for (int indexY = startY; indexY < endY; indexY++)
                {
                    this.CellViews[indexX, indexY].Draw();
                }
            }
        }