Example #1
0
        public void CreateTile()
        {
            Panel1 newTile = new Panel1(); //creates new tile panel

            numTiles++;

            if (imageAdded == true)                                        //if image has been added to all tiles
            {                                                              //fill color does need it
                newTile.BackgroundImage       = Image.FromFile(imagePath); //get tile from panel selected
                newTile.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            }
            else
            {
                newTile.BackColor = backgroundTile;               //fills tile with color
                imageAdded        = false;
            }

            newTile.Size        = new Size(wTile, hTile);            //sets size of tile
            newTile.Location    = new Point(position.X, position.Y); //sets position of tile
            newTile.Name        = "tile" + numTiles;                 //changes name of tile to "tile#"
            newTile.MouseClick += Panel_Click;                       //creates event for tile / addes mouseClick event

            intersectsWith(newTile);                                 //checks if the new tile intersects with all other created tiles
            tilesCreated.Add(newTile);                               //adds panel to list of al tiles created

            Controls.Add(newTile);                                   //adds panel to the form

            newTile.BringToFront();                                  //bring before the picturebox background   SAME AS below???
            pbBackground.SendToBack();                               //prevents the BG panel from covering the new highlight panel
        }
Example #2
0
 private void showConnections_Click(object sender, EventArgs e)
 {
     if (allClicked.Any())
     {
         if (allClicked.Count == 1)
         {
             foreach (Panel1 hilightedPanel in allClicked.First().connectedList)
             {
                 Color  green          = Color.Green;
                 Panel1 greenHighlight = highlight(hilightedPanel, green); //highlights all of the tiles that are connected green
                 greenHighlight.BringToFront();                            //*******may cause issues with showing the unit******
                 hilightedPanel.BringToFront();                            //*******may cause issues with showing the unit******
                 allHighlight.Add(greenHighlight);                         //adds the highlight to the list so that the highlight can be deleted when you click away
             }
         }
         else
         {
             foreach (Panel1 hilightedPanel in allClicked.First().connectedList)
             {
                 Color  green          = Color.Green;
                 Panel1 greenHighlight = highlight(hilightedPanel, green); //highlights all of the tiles that are connected green
                 greenHighlight.BringToFront();                            //*******may cause issues with showing the unit******
                 hilightedPanel.BringToFront();                            //*******may cause issues with showing the unit******
                 allHighlight.Add(greenHighlight);                         //adds the highlight to the list so that the highlight can be deleted when you click away
             }
             MessageBox.Show("this button only shows connections for the first selected tile, highlighted in green");
         }
     }
     else
     {
         //error message
         MessageBox.Show("Select a tile to show its connections highlighted in green.");
     }
 }
Example #3
0
        public void rulerVert()
        {
            Panel1 p = new Panel1();

            p.Size      = new Size(5, 5);
            p.Location  = new Point(((pbBackground.Location.X)), pbBackground.Location.Y + ruler);
            p.BackColor = Color.Black;
            Label l = new Label();

            l.Text      = ruler.ToString();
            l.Location  = new Point(((pbBackground.Location.X + 3)), pbBackground.Location.Y + ruler);
            l.BackColor = Color.Transparent;
            l.AutoSize  = true;

            rulerLabels.Add(l);
            rulerList.Add(p);
            Controls.Add(p);
            Controls.Add(l);
            p.BringToFront();
            l.BringToFront();

            System.Drawing.Drawing2D.GraphicsPath buttonPath = new System.Drawing.Drawing2D.GraphicsPath();
            System.Drawing.Rectangle newPanel = p.ClientRectangle;
            buttonPath.AddEllipse(newPanel);
            p.Region = new System.Drawing.Region(buttonPath);
        }
Example #4
0
        public void rulerHori() //got bored and made this to see where to start the tile
        {                       //slightly ugly but it does what its supposed to
            if (ruler <= this.Width)
            {
                Panel1 p = new Panel1();
                p.Size      = new Size(5, 5);
                p.Location  = new Point(((pbBackground.Location.X) + ruler), pbBackground.Location.Y);
                p.BackColor = Color.Black;
                Label l = new Label();
                l.Text      = ruler.ToString();
                l.Location  = new Point(((pbBackground.Location.X + 3) + ruler), pbBackground.Location.Y + 2);
                l.BackColor = Color.Transparent;
                l.AutoSize  = true;

                rulerLabels.Add(l);
                rulerList.Add(p);
                Controls.Add(p);
                Controls.Add(l);
                p.BringToFront();
                l.BringToFront();

                System.Drawing.Drawing2D.GraphicsPath buttonPath = new System.Drawing.Drawing2D.GraphicsPath();
                System.Drawing.Rectangle newPanel = p.ClientRectangle;
                buttonPath.AddEllipse(newPanel);
                p.Region = new System.Drawing.Region(buttonPath);
                ruler   += 50;
                rulerVert();
                rulerHori();
            }
        }
Example #5
0
        private void LoadProgram_Click(object sender, EventArgs e)
        {
            /*
             *
             * the Load_Click method must take the information from the saved text file,
             * then break it into inputs to be called by the Create_Tile method and addUnit method
             *
             */

            //read the original text file and put into the string array
            #region loadText

            string totalString   = "";
            string allTileString = "";
            string allUnitString = "";

            /*
             * try
             * {
             *  //Pass the file path and file name to the StreamReader constructor
             *  StreamReader sr = new StreamReader(mydocpath + @"\BoardGame.txt");
             *
             *
             *
             *  //Read the first line of text
             *  //allTileString = sr.ReadLine();
             *  //allUnitString = sr.ReadLine();
             *  totalString = sr.ReadLine();
             *
             *  //close the file
             *  sr.Close();
             *
             *  MessageBox.Show(totalString);
             *  char tileVSUnitDelimiter = tileAndUnitSeperator;//splits the string along this seperator which is removed
             *  string[] arrayOfUnitsAndTiles = totalString.Split(tileVSUnitDelimiter);//cut the loaded string into the tile and unit portions
             *  allTileString = arrayOfUnitsAndTiles[0];
             *  allUnitString = arrayOfUnitsAndTiles[1];
             * }
             * catch (Exception a)
             * {
             *  MessageBox.Show("Exception: " + a.Message);
             *  return;//ends the load method
             * }
             *
             */

            Stream         myStream        = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            // Insert code to read the stream here.
                            StreamReader myStreamReader = new StreamReader(myStream);
                            totalString = myStreamReader.ReadLine();
                            myStreamReader.Close();


                            //MessageBox.Show(totalString);
                            char     tileVSUnitDelimiter  = tileAndUnitSeperator;                   //splits the string along this seperator which is removed
                            string[] arrayOfUnitsAndTiles = totalString.Split(tileVSUnitDelimiter); //cut the loaded string into the tile and unit portions
                            allTileString = arrayOfUnitsAndTiles[0];
                            allUnitString = arrayOfUnitsAndTiles[1];
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Canceled Load");
                return;
            }



            #endregion loadText

            //could be turned into a method for restarting
            #region clearPreexistingStuff
            //need to clear the preexisting stuff on the board before loading
            //clear units
            if (masterUnitList.Any())
            {
                //List<Unit> tempUnitList = masterUnitList;

                foreach (Unit preexistingUnits in masterUnitList)
                {
                    //call method for removing units
                    deleteUnitMethod(preexistingUnits);
                }
                masterUnitList.Clear();
            }

            unitNum = 0;//reset count of units

            //clear tiles
            List <Panel1> allPanels = tilesCreated; //temp list of all of the tiles

            deleteList(allPanels);                  //deletes all the tiles
            tilesCreated.Clear();                   //clears all references from the master list of tiles
            numTiles = 0;                           //reset count of tiles

            #endregion clearPreexistingStuff

            #region loadTiles

            //String value = "This is a short string.";
            //MessageBox.Show(allTileString);//used to verify what is going into the loadTiles area

            if (allTileString != "")
            {
                char     delimiter1   = tileSeperator;//splits the string along this seperator which is removed
                string[] arrayOfTiles = allTileString.Split(delimiter1);

                foreach (string tileString in arrayOfTiles)
                {
                    //split the string into the attributes
                    char     delimiter3            = attributeSeperator;
                    string[] arrayOfTileAttributes = tileString.Split(delimiter3);

                    /*
                     *
                     * //attributes
                     * 0= string tileName = eachpanel.Name;
                     * 1= string tileXLocation = eachpanel.Location.X.ToString();
                     * 2= string tileYLocation = eachpanel.Location.Y.ToString();
                     * 3= string tileBackgroundImage = eachpanel.BackColor.Name;//make sure I know what this actually is
                     * 4= string tileWidth = eachpanel.Width.ToString();
                     * 5= string tileHeight = eachpanel.Height.ToString();
                     *
                     */

                    //make the tile based on the attributes
                    Panel1 newTile = new Panel1();

                    //setting the name
                    newTile.Name = arrayOfTileAttributes[0];
                    numTiles++;

                    //method for setting the Location
                    int X = 0;
                    int Y = 0;
                    int.TryParse(arrayOfTileAttributes[1], out X);
                    int.TryParse(arrayOfTileAttributes[2], out Y);
                    newTile.Location = new Point(X, Y);



                    //method for setting the dimensions
                    int height = 0;
                    int width  = 0;
                    int.TryParse(arrayOfTileAttributes[5], out height);
                    int.TryParse(arrayOfTileAttributes[4], out width);
                    newTile.Size = new Size(width, height);

                    //standard commands to add to the form
                    newTile.MouseClick += Panel_Click; //creates event for tile / addes mouseClick event
                    intersectsWith(newTile);           //checks if the new tile intersects with all other created tiles
                    tilesCreated.Add(newTile);         //adds panel to list of al tiles created

                    Controls.Add(newTile);             //adds panel to the form

                    //method for setting the color
                    int   argbValue = 0;
                    Color tileColor = new Color();
                    //tileColor = Color.FromName(arrayOfTileAttributes[3]);
                    int.TryParse(arrayOfTileAttributes[3], out argbValue);
                    tileColor = Color.FromArgb(argbValue);
                    // MessageBox.Show(tileColor.ToString());
                    newTile.BackColor = tileColor;


                    newTile.BringToFront();    //bring before the picturebox background   SAME AS below???
                    pbBackground.SendToBack(); //prevents the BG panel from covering the new highlight panel
                }
            }
            else
            {
                MessageBox.Show("incorrect format for loading tiles");
            }
            #endregion loadTiles

            #region loadUnits

            if (allUnitString != "")
            {
                char     delimeter2   = tileSeperator;
                string[] arrayOfUnits = allUnitString.Split(delimeter2);

                /*
                 * 0 = string unitName= eachUnit.getName();
                 * 1 = string tileUnitIsOn = eachUnit.getLocation().Name;//gives the name of the tile the unit is on
                 * 2 = string unitColor = eachUnit.getColor().Name;
                 */


                foreach (string unitString in arrayOfUnits)
                {
                    //split the string into the attributes
                    char     delimiter3            = attributeSeperator;
                    string[] arrayOfUnitAttributes = unitString.Split(delimiter3);
                    //make the unit based on the attributes
                    foreach (Panel1 panel in tilesCreated)
                    {
                        if (panel.Name == arrayOfUnitAttributes[1])
                        {
                            Unit thisUnit = createUnit(panel);
                            thisUnit.setName(arrayOfUnitAttributes[0]);

                            Color unitColor = Color.FromName(arrayOfUnitAttributes[2]);
                            thisUnit.setColor(unitColor);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("no units loaded");
            }



            #endregion loadUnits
        }