Esempio n. 1
0
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            // Double Buffering
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);

            GAtomicConfiguration._setPlayingAreaTopLeft(new Point(20, 20));
            GAtomicConfiguration._setPlayingAreaAtomicObjectSize(30);

            GAtomicConfiguration._setMiniatureAreaAtomicObjectSize(20);

            selected_element_row = -1;
            selected_element_col = -1;

            label_movements      = new Label();
            label_movements.Name = "label_movements";
            label_movements.Size = new Size(150, 20);
            //label_movements.BorderStyle = BorderStyle.FixedSingle;
            label_movements.TextAlign = ContentAlignment.MiddleLeft;
            label_movements.Font      = new Font("Times New Roman", 12);
            this.Controls.Add(label_movements);

            _newGame("Water");
        }
Esempio n. 2
0
        private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (game_over)
            {
                return;
            }

            Point p = new Point(e.X - GAtomicConfiguration._getPlayingAreaTopLeft().X, e.Y - GAtomicConfiguration._getPlayingAreaTopLeft().Y);

            // up or left
            if ((p.Y < 0) || (p.X < 0))
            {
                return;
            }

            // bottom
            if ((p.Y > elements.GetLength(0) * GAtomicConfiguration._getPlayingAreaAtomicObjectSize()) || (p.X > elements.GetLength(1) * GAtomicConfiguration._getPlayingAreaAtomicObjectSize()))
            {
                return;
            }

            int row = p.Y / GAtomicConfiguration._getPlayingAreaAtomicObjectSize();
            int col = p.X / GAtomicConfiguration._getPlayingAreaAtomicObjectSize();

            _selectElement(row, col);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
 private void _fillSimplyTheDirectionsArrows()
 {
     // fill 'simply' the arrows
     for (int r = 0; r < elements.GetLength(0); r++)
     {
         for (int c = 0; c < elements.GetLength(1); c++)
         {
             if ((elements.GetValue(r, c) != null) && (elements.GetValue(r, c) is GAtomicDirectionArrow))
             {
                 elements.SetValue(new GAtomicObject(GAtomicConfiguration._getPlayingAreaTopLeft(), r, c, GAtomicConfiguration._getPlayingAreaAtomicObjectSize()), r, c);
                 //break;
             }
         }
     }
 }
Esempio n. 5
0
        private void _setSizesAndPlacement(int game_board_rows, int game_board_cols, int miniature_board_rows, int miniature_board_cols)
        {
            //---------------------------Placement-and-sizes--------------------------------
            game_area_rect = new Rectangle(0, 0, 2 * GAtomicConfiguration._getPlayingAreaTopLeft().X + game_board_cols * GAtomicConfiguration._getPlayingAreaAtomicObjectSize(), 2 * GAtomicConfiguration._getPlayingAreaTopLeft().Y + game_board_rows * GAtomicConfiguration._getPlayingAreaAtomicObjectSize());

            int miniature_area_height = miniature_board_rows * GAtomicConfiguration._getMiniatureAreaAtomicObjectSize();

            //if (miniature_area_height > size2 * game_area_rect.Height / 3 - GAtomicConfiguration._getPlayingAreaTopLeft ().Y - 20*/

            miniature_area_rect = new Rectangle(game_area_rect.Width, GAtomicConfiguration._getPlayingAreaTopLeft().Y, miniature_board_cols * GAtomicConfiguration._getMiniatureAreaAtomicObjectSize(), miniature_area_height);

            label_movements.Location = new Point(miniature_area_rect.Left, 2 * game_area_rect.Height / 3);
            movements            = 0;
            label_movements.Text = String.Format("Movements : -");

            this.ClientSize = new Size(game_area_rect.Width + GAtomicConfiguration._getPlayingAreaTopLeft().X + miniature_area_rect.Width, game_area_rect.Height);
        }
Esempio n. 6
0
        private void _newGame(String game)
        {
            String open_file_name = Directory.GetCurrentDirectory() + "/games/" + game + ".gagh";

            if (!File.Exists(open_file_name))
            {
                return;
            }

            game_over = false;

            selected_element_row = -1;
            selected_element_col = -1;

            current_game = game;
            this.Text    = "GAtomic - " + current_game;

            // Read file
            bool error = false;

            try
            {
                // Load formula
                GLDoorsFileOperations file_operations = new GLDoorsFileOperations(open_file_name);
                file_operations.OpenFileForRead();

                String s = "";
                bool   b = false;
                // Name OK, read line anyway
                file_operations.ReadStringLineFromFile(out s, out b);
                // Read sizes
                file_operations.ReadStringLineFromFile(out s, out b);
                String sizes_string = s;
                s = s.Substring(5);
                int rows = Convert.ToInt32(s.Substring(0, s.IndexOf("x")));
                int cols = Convert.ToInt32(s.Substring(s.IndexOf("x") + 1));

                //---------------------------Board-size--------------------------------
                elements = Array.CreateInstance(typeof(GAtomicObject), rows, cols);

                file_operations.ReadStringLineFromFile(out s, out b);
                sizes_string       = s;
                s                  = s.Substring(10);
                rows               = Convert.ToInt32(s.Substring(0, s.IndexOf("x")));
                cols               = Convert.ToInt32(s.Substring(s.IndexOf("x") + 1));
                miniature_elements = Array.CreateInstance(typeof(GAtomicObject), rows, cols);
                //---------------------------Board-size--------------------------------

                //---------------------------Placement-and-sizes--------------------------------
                _setSizesAndPlacement(elements.GetLength(0), elements.GetLength(1), miniature_elements.GetLength(0), miniature_elements.GetLength(1));

                Point miniature_top_left = new Point(miniature_area_rect.Left, miniature_area_rect.Top);
                //---------------------------Placement-and-sizes--------------------------------

                //--------------------------------Miniatures-----------------------------------------------
                number_of_elements = 0;
                int row = 0;
                int col = 0;
                for (row = 0; row < miniature_elements.GetLength(0); row++)
                {
                    for (col = 0; col < miniature_elements.GetLength(1); col++)
                    {
                        file_operations.ReadStringLineFromFile(out s, out b);
                        if (!b)
                        {
                            // erreur
                            error = true;
                            break;
                        }
                        if (s == "EMPTY")
                        {
                            miniature_elements.SetValue(new GAtomicObject(new Point(miniature_area_rect.Left, miniature_area_rect.Top), row, col, GAtomicConfiguration._getMiniatureAreaAtomicObjectSize()), row, col);
                        }
                        else
                        {
                            // Read and add
                            object o = GAtomicElementObject._getAtomicElementFromString(s, new Point(miniature_area_rect.Left, miniature_area_rect.Top), row, col, GAtomicConfiguration._getMiniatureAreaAtomicObjectSize(), 0);
                            if (o != null)
                            {
                                miniature_elements.SetValue((GAtomicElementObject)o, row, col);
                                number_of_elements++;
                            }
                        }
                    } // end of for (col = 0; col < miniature_elements.GetLength (1); cols++)

                    if (error)
                    {
                        break;
                    }
                }
                //--------------------------------Miniatures-----------------------------------------------

                //--------------------------------Checking-elements--------------------------------------
                _selectCheckingConnectionsAndElements();
                //--------------------------------Checking-elements--------------------------------------

                int    index     = 0;
                Random rnd       = new Random();
                int    sel_index = rnd.Next();
                sel_index %= number_of_elements;
                int start_element_row = 0;
                int start_element_col = 0;
                //-----------------------------------------Game-Area--------------------------------------------
                for (row = 0; row < elements.GetLength(0); row++)
                {
                    for (col = 0; col < elements.GetLength(1); col++)
                    {
                        file_operations.ReadStringLineFromFile(out s, out b);
                        if (!b)
                        {
                            // erreur
                            error = true;
                            break;
                        }
                        if (s == "EMPTY")
                        {
                            elements.SetValue(new GAtomicObject(GAtomicConfiguration._getPlayingAreaTopLeft(), row, col, GAtomicConfiguration._getPlayingAreaAtomicObjectSize()), row, col);
                        }
                        else if (s == "BRICK")
                        {
                            elements.SetValue(new GAtomicBrick(GAtomicConfiguration._getPlayingAreaTopLeft(), row, col, GAtomicConfiguration._getPlayingAreaAtomicObjectSize()), row, col);
                        }
                        else
                        {
                            // Read and add
                            object o = GAtomicElementObject._getAtomicElementFromString(s.Substring(0, 19), GAtomicConfiguration._getPlayingAreaTopLeft(), row, col, GAtomicConfiguration._getPlayingAreaAtomicObjectSize(), index++);
                            if (o != null)
                            {
                                elements.SetValue((GAtomicElementObject)o, row, col);
                                if (sel_index == index - 1)
                                {
                                    start_element_row = row;
                                    start_element_col = col;
                                }
                            }
                            else
                            {
                                error = true;
                                break;
                            }
                        }
                    }

                    if (error)
                    {
                        break;
                    }
                }

                // Select start element
                _selectElement(start_element_row, start_element_col);

                this.Invalidate();

                file_operations.CloseFile();
            }
            catch (GAtomicElementObjectInvalidException)
            {
                MessageBox.Show("Invalid atomic element object.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                error = true;
            }
            catch
            {
                error = true;
            }
        }
Esempio n. 7
0
        public bool _canMoveAndIfYesSetArrows(int row, int col)
        {
            object o2 = null;

            bool can_move_up = false, can_move_right = false, can_move_down = false, can_move_left = false;

            // check up
            if (row > 0)
            {
                o2 = elements.GetValue(row - 1, col);
                if ((o2 is GAtomicElementObject) || (o2 is GAtomicBrick))
                {
                }
                else
                {
                    can_move_up = true;
                    elements.SetValue(new GAtomicDirectionArrow(GAtomicMovementDirection.UP, GAtomicConfiguration._getPlayingAreaTopLeft(), row - 1, col, GAtomicConfiguration._getPlayingAreaAtomicObjectSize()), row - 1, col);
                }
            }
            // check right
            if (col < elements.GetLength(1) - 1)
            {
                o2 = elements.GetValue(row, col + 1);
                if ((o2 is GAtomicElementObject) || (o2 is GAtomicBrick))
                {
                }
                else
                {
                    can_move_right = true;
                    elements.SetValue(new GAtomicDirectionArrow(GAtomicMovementDirection.RIGHT, GAtomicConfiguration._getPlayingAreaTopLeft(), row, col + 1, GAtomicConfiguration._getPlayingAreaAtomicObjectSize()), row, col + 1);
                }
            }
            // check down
            if (row < elements.GetLength(0) - 1)
            {
                o2 = elements.GetValue(row + 1, col);
                if ((o2 is GAtomicElementObject) || (o2 is GAtomicBrick))
                {
                }
                else
                {
                    can_move_down = true;
                    elements.SetValue(new GAtomicDirectionArrow(GAtomicMovementDirection.DOWN, GAtomicConfiguration._getPlayingAreaTopLeft(), row + 1, col, GAtomicConfiguration._getPlayingAreaAtomicObjectSize()), row + 1, col);
                }
            }
            // check left
            if (col > 0)
            {
                o2 = elements.GetValue(row, col - 1);
                if ((o2 is GAtomicElementObject) || (o2 is GAtomicBrick))
                {
                }
                else
                {
                    can_move_left = true;
                    elements.SetValue(new GAtomicDirectionArrow(GAtomicMovementDirection.LEFT, GAtomicConfiguration._getPlayingAreaTopLeft(), row, col - 1, GAtomicConfiguration._getPlayingAreaAtomicObjectSize()), row, col - 1);
                }
            }

            if (can_move_up || can_move_right || can_move_down || can_move_left)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }