Exemple #1
0
        public bool _moveElement(GAtomicMovementDirection direction)
        {
            // selected_element_row, selected_element_col
            int row = selected_element_row;
            int col = selected_element_col;

            while (_moveElementOneStep(row, col, direction))
            {
                if (direction == GAtomicMovementDirection.LEFT)
                {
                    col--;
                }
                else if (direction == GAtomicMovementDirection.RIGHT)
                {
                    col++;
                }
                else if (direction == GAtomicMovementDirection.UP)
                {
                    row--;
                }
                else if (direction == GAtomicMovementDirection.DOWN)
                {
                    row++;
                }
                else
                {
                    break;
                }

                //System.Threading.Thread.Sleep (500);
            }

            movements++;
            label_movements.Text = String.Format("Movements : {0}", movements);

            // Check if success
            if (_gameSuccess())
            {
                MessageBox.Show("Success.", "Success.");
                game_over = true;
                return(true);
            }
            // Check new directions and set arrows
            bool can_move = _canMoveAndIfYesSetArrows(row, col);

            selected_element_row = -1;
            selected_element_col = -1;

            if (can_move)
            {
                selected_element_row = row;
                selected_element_col = col;

                this.Invalidate(game_area_rect);

                return(true);
            }

            return(false);
        }
Exemple #2
0
        public bool _moveElementOneStep(int row, int col, GAtomicMovementDirection direction)
        {
            int new_row = row;
            int new_col = col;

            if (direction == GAtomicMovementDirection.LEFT)
            {
                new_col--;
            }
            else if (direction == GAtomicMovementDirection.RIGHT)
            {
                new_col++;
            }
            else if (direction == GAtomicMovementDirection.UP)
            {
                new_row--;
            }
            else if (direction == GAtomicMovementDirection.DOWN)
            {
                new_row++;
            }
            else
            {
                return(false);
            }

            if (!_validRowAndColumn(new_row, new_col))
            {
                return(false);
            }

            object o2 = elements.GetValue(new_row, new_col);

            if ((o2 is GAtomicElementObject) || (o2 is GAtomicBrick))
            {
                return(false);
            }

            object o = elements.GetValue(row, col);

            if (!(o is GAtomicElementObject))
            {
                return(false);
            }

            // change top left
            ((GAtomicElementObject)o).TopLeft = new Point(GAtomicConfiguration._getPlayingAreaTopLeft().X + new_col * GAtomicConfiguration._getPlayingAreaAtomicObjectSize(), GAtomicConfiguration._getPlayingAreaTopLeft().Y + new_row * GAtomicConfiguration._getPlayingAreaAtomicObjectSize());
            // new position
            elements.SetValue((GAtomicElementObject)o, new_row, new_col);

            // clear old position
            elements.SetValue(new GAtomicObject(GAtomicConfiguration._getPlayingAreaTopLeft(), row, col, GAtomicConfiguration._getPlayingAreaAtomicObjectSize()), row, col);

            this.Invalidate(game_area_rect);

            return(true);
        }
 public GAtomicDirectionArrow(GAtomicMovementDirection mv_dir, Point t_l, int row, int col, int s)
     : base(t_l, row, col, s)
 {
     movement_direction = mv_dir;
 }