Beispiel #1
0
        static void CenteredRectangleTest()
        {
            CDrawer can = new CDrawer(800, 600, false);

            can.AddCenteredRectangle(400, 300, 796, 596, Color.Red);
            for (int i = 0; i < 500; ++i)
            {
                can.AddCenteredRectangle(s_rnd.Next(100, 700), s_rnd.Next(100, 500), s_rnd.Next(5, 190), s_rnd.Next(5, 190), RandColor.GetColor(), s_rnd.Next(6), RandColor.GetColor());
            }
            can.Render();
            Console.ReadKey();
        }
Beispiel #2
0
        //Take in a canvas and scale, draw all of the blocks
        public void Render(CDrawer canvas, int Size)
        {
            canvas.Clear();

            for (int x = 0; x < XLength; x++)
            {
                for (int y = 0; y < YLength; y++)
                {
                    //Ignore nulls and retainer blocks, don't need to render them
                    if (grid[x, y] != null && !(grid[x, y] is RetainerBlock))
                    {
                        //Centered point
                        Point point = new Point(x * Size + (Size / 2), y * Size + (Size / 2));
                        //If free block, offset the point by Animation state
                        if (grid[x, y] is FreeBlock && grid[x, y].life != Life.Dying)
                        {
                            point.Y += (Size / 10) * grid[x, y].AnimationState; //Move down 1/10 of the size, per AnimationState
                        }

                        //Get our side length, shrunk by death
                        int sideLength = Size;
                        if (grid[x, y].life == Life.Dying)
                        {
                            // (-10%) * State + Size
                            sideLength = (-(Size / 10)) * grid[x, y].AnimationState + Size; //Shrink by 10% of size for every AnimationState
                        }

                        //Add every block using the point and size we just made
                        canvas.AddCenteredRectangle(point.X, point.Y, sideLength, sideLength, grid[x, y].Colour, 1, Color.Black);
                    }
                }
            }

            canvas.Render();
        }
        //******************************************************
        //Render Method: Draw the Shape as a square.
        //******************************************************
        public override void Render(CDrawer drawer)
        {
            //Draw line to parent
            base.Render(drawer);

            drawer?.AddCenteredRectangle((int)_position.X, (int)_position.Y, _size, _size, _color);
        }
Beispiel #4
0
        //runs everytime when pressed
        // when enabled draw on moseclick with desied shape
        private void timer1_Tick(object sender, EventArgs e)
        {
            Point click;                                 // tracks mouse clicks to draw shape

            _draw.GetLastMouseLeftClick(out click);      // draw on mouse click

            if (_bColorSet && _shape)
            {
                if (_iShape == 1)
                {
                    if (_borderCheck)
                    {
                        _draw.AddCenteredRectangle(click.X, click.Y, 50, 50, _color, 2, Color.White);
                        _draw.Render();
                    }
                    else
                    {
                        _draw.AddCenteredRectangle(click.X, click.Y, 50, 50, _color);
                        _draw.Render();
                    }
                }
                if (_iShape == 0)
                {
                    if (_borderCheck)
                    {
                        _draw.AddCenteredEllipse(click.X, click.Y, 50, 50, _color, 2, Color.White);
                        _draw.Render();
                    }
                    else
                    {
                        _draw.AddCenteredEllipse(click.X, click.Y, 50, 50, _color);
                        _draw.Render();
                    }
                }
            }
            else
            {
                if (!_borderCheck && !_shape)
                {
                    MessageBox.Show("Error: Properties have not been set.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #5
0
        // Render for use in Square, modify as required for Circle class Render
        protected override void vRender(CDrawer dr)
        {
            dr.AddCenteredRectangle(Pos, (int)Length, (int)Length, Color.LightCyan, 2, Color.Red);
            Rectangle tout = new Rectangle(
                (int)(Pos.X - Length),
                (int)(Pos.Y - Length),
                (int)(Length * 2),
                (int)(Length * 2));

            dr.AddText($"{Length}", Math.Max((int)(Length * 0.4), 8), tout, Color.Black);
        }
 public override void Render(CDrawer canvas)
 {
     canvas.AddCenteredRectangle((int)point.X, (int)point.Y, 20, 20, color);
     base.Render(canvas);
 }
Beispiel #7
0
        static void Main(string[] args)
        {
            //intializing
            Color       objColor       = new Color();
            List <info> structureslist = new List <info>();
            CDrawer     canvas         = new CDrawer();
            Point       location       = new Point(200, 200);
            info        infoN;
            string      filename;
            Shape       shape = Shape.Circle;
            int         i     = 0;

            Options(ref canvas);                                // Open Menu

            while (true)                                        // go into while loop unless it fails
            {
                if (canvas.GetLastMouseLeftClick(out location)) //catch mouse click point
                {
                    //change shape information depends on click location
                    if (location.X > 20 && location.X < 70 && location.Y > 40 && location.Y < 90)
                    {
                        objColor = Color.Red;
                    }

                    else if (location.X > 80 && location.X < 170 && location.Y > 20 && location.Y < 90)
                    {
                        objColor = Color.Green;
                    }

                    else if (location.X > 180 && location.X < 270 && location.Y > 40 && location.Y < 90)
                    {
                        objColor = Color.Blue;
                    }

                    else if (location.X > 280 && location.X < 350 && location.Y > 40 && location.Y < 90)
                    {
                        shape = Shape.Circle;
                    }

                    else if (location.X > 360 && location.X < 450 && location.Y > 40 && location.Y < 90)
                    {
                        shape = Shape.Squre;
                    }

                    else if (location.X > 460 && location.X < 510 && location.Y > 40 && location.Y < 90)
                    {
                        shape = Shape.Star;
                    }

                    else if (location.X > 520 && location.X < 590 && location.Y > 40 && location.Y < 90) //Save option
                    {
                        Console.Write("Enter your filename: ");                                          //choosing saving file name
                        filename = Console.ReadLine();

                        StreamWriter swOutputFile = new StreamWriter(filename);
                        //save shape information each line
                        foreach (info item in structureslist)
                        {
                            swOutputFile.WriteLine("{0},{1},{2},{3}", item._shape, item._shapeColor, item.XLocation, item.YLocatoin);
                        }
                        swOutputFile.Close(); //save
                    }


                    else if (location.X > 600 && location.X < 670 && location.Y > 40 && location.Y < 90) //Load Option
                    {
                        Console.Write("Enter your filename: ");                                          // choose loading file name
                        filename = Console.ReadLine();

                        //initializing for load variables
                        StreamReader  swInputFile;
                        List <string> LoadList = new List <string>();
                        string        text;
                        try // catch error while opening file
                        {
                            swInputFile = new StreamReader(filename);
                            while ((text = swInputFile.ReadLine()) != null)
                            {
                                string[] text2;
                                text2 = text.Split(',');
                                info infoO;
                                infoO._shapeColor = Color.Red;
                                infoO._shape      = Shape.Circle;
                                infoO.XLocation   = 0;
                                infoO.YLocatoin   = 0;
                                switch (text2[0]) //check shape type
                                {
                                case "Cirlce": { infoO._shape = Shape.Circle; break; }

                                case "Square": { infoO._shape = Shape.Squre; break; }

                                case "Star": { infoO._shape = Shape.Star; break; }
                                }
                                switch (text2[1])//check shape color
                                {
                                case "Color [Red]": { infoO._shapeColor = Color.Red; break; }

                                case "Color [Green]": { infoO._shapeColor = Color.Green; break; }

                                case "Color [Blue]": { infoO._shapeColor = Color.Blue; break; }
                                }
                                infoO.XLocation = Convert.ToInt64(text2[2]); //check shape X location
                                infoO.YLocatoin = Convert.ToInt64(text2[3]); //check shape Y location
                                structureslist.Add(infoO);                   //add on to list to save information

                                foreach (info item in structureslist)        //Call information on to GDI drawer from list
                                {
                                    switch (item._shape)
                                    {
                                    case Shape.Circle:
                                    {
                                        if (item._shapeColor == Color.Red)
                                        {
                                            canvas.AddCenteredEllipse((int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Red);
                                        }
                                        else if (item._shapeColor == Color.Green)
                                        {
                                            canvas.AddCenteredEllipse((int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Green);
                                        }
                                        else if (item._shapeColor == Color.Blue)
                                        {
                                            canvas.AddCenteredEllipse((int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Blue);
                                        }
                                        break;
                                    }

                                    case Shape.Squre:
                                    {
                                        if (item._shapeColor == Color.Red)
                                        {
                                            canvas.AddCenteredRectangle((int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Red);
                                        }
                                        else if (item._shapeColor == Color.Green)
                                        {
                                            canvas.AddCenteredRectangle((int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Green);
                                        }
                                        else if (item._shapeColor == Color.Blue)
                                        {
                                            canvas.AddCenteredRectangle((int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Blue);
                                        }
                                        break;
                                    }

                                    case Shape.Star:
                                    {
                                        if (item._shapeColor == Color.Red)
                                        {
                                            canvas.AddText("S", 20, (int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Red);
                                        }
                                        else if (item._shapeColor == Color.Green)
                                        {
                                            canvas.AddText("S", 20, (int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Green);
                                        }
                                        else if (item._shapeColor == Color.Blue)
                                        {
                                            canvas.AddText("S", 20, (int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Blue);
                                        }
                                        break;
                                    }
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error, the error was {0}", e);
                        }
                    }

                    else if (location.X > 680 && location.X < 750 && location.Y > 40 && location.Y < 90)
                    {
                        canvas.Clear();      // clear GDI drawer
                        Options(ref canvas); //Recall menu
                    }
                    else //If mouse click location is out of menu area draw the shapes
                    {
                        switch (shape)//Goes into diffrent options depends on the shape
                        {
                        case Shape.Circle:
                        {
                            canvas.AddCenteredEllipse(location, 20, 20, objColor);
                            infoN._shape      = shape;
                            infoN._shapeColor = objColor;
                            infoN.XLocation   = location.X;
                            infoN.YLocatoin   = location.Y;
                            structureslist.Add(infoN);

                            break;
                        }

                        case Shape.Squre:
                        {
                            canvas.AddCenteredRectangle(location, 20, 20, objColor);
                            infoN._shape      = shape;
                            infoN._shapeColor = objColor;
                            infoN.XLocation   = location.X;
                            infoN.YLocatoin   = location.Y;
                            structureslist.Add(infoN);
                            break;
                        }

                        case Shape.Star:
                        {
                            canvas.AddText("S", 20, location.X, location.Y, 20, 30, objColor);
                            infoN._shape      = shape;
                            infoN._shapeColor = objColor;
                            infoN.XLocation   = location.X;
                            infoN.YLocatoin   = location.Y;
                            structureslist.Add(infoN);
                            break;
                        }
                        }
                    }
                }
            }
        }
Beispiel #8
0
 public void Render(CDrawer canvas, Color sColor)
 {
     canvas.AddCenteredRectangle(_box.X, _box.Y, _box.Width, _box.Height, sColor);
 }
Beispiel #9
0
        /// <summary>
        /// the main event for game code
        /// does everything needed for game to run
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Timer_Tick(object sender, EventArgs e)
        {
            Point pt;

            missile.boomRadius = boomTrackBar.Value;
            labelBommVal.Text  = boomTrackBar.Value.ToString();

            //add enemy missiles to list and update label
            if (foemissiles.Count < missilesUpDown.Value)
            {
                missile newMissile = new missile();
                foemissiles.Add(newMissile);
                missilsIN += 1;
            }

            //colilsion check
            List <missile> colided = friendlyMissile.Intersect(foemissiles).ToList();

            //remove all colided missiles
            //also update score and update counter for removed missiles
            foreach (missile item in colided)
            {
                while (foemissiles.Remove(item))
                {
                    score += 100;
                    gone  += 1;
                }
            }

            //remove any missiles outside of boundaries
            friendlyMissile.RemoveAll(missile.Explosion);
            missile.Loading = true;
            foemissiles.RemoveAll(missile.boundaryCheckLeftRIght);

            // if missile reaches bottom of gdi lives --
            if (foemissiles.RemoveAll(missile.BoundaryCheckUpDown) >= 1)
            {
                lives -= 1;
            }

            // and a "bunker" where frindly misslies spawn
            CDrawer.AddCenteredRectangle(CDrawer.ScaledWidth / 2, CDrawer.ScaledHeight, 30, 30, Color.Green);
            CDrawer.AddText($"Lives {lives} Score {score}", 60, Color.Cyan);

            // update labels
            labelmissIN.Text    = missilsIN.ToString();
            labelDestroyed.Text = gone.ToString();
            labelFriend.Text    = friendlyIN.ToString();
            labelKD.Text        = KD.ToString();

            //update k/d ratio as long as there is at least 1 missle on screen
            if (friendlyIN > 0)
            {
                KD = (double)Math.Round(Convert.ToDecimal((missilsIN / friendlyIN)), 2);
            }

            missile.Loading = false;//start rending in missiles and effects

            //movment for enemy missiles
            foreach (missile item in foemissiles)
            {
                item.move();
                item.DrawMissiles();
            }

            //movment for friendly missiles
            foreach (missile item in friendlyMissile)
            {
                //bool for friend?
                item.move();
                item.DrawMissiles();
            }

            //on a left click spawn a friendly missile and update label
            if (CDrawer.GetLastMouseLeftClick(out pt))
            {
                friendlyMissile.Add(new missile(pt));
                friendlyIN++;
            }

            //when adjusting timerinterval stop the game
            //adjust interval and resume game
            if (timer1.Enabled)
            {
                timer1.Stop();
            }
            this.timer1.Interval = (int)intervalUpDown.Value;
            timer1.Start();

            //if a game over happens
            //set game over state, stop the timer
            //and display game over text
            if (currentState == eGameState.Over)
            {
                currentState   = eGameState.Unstarted;
                timer1.Enabled = false;
                timer1.Stop();
                missile.Loading = true;
                CDrawer.AddText("GAME OVER", 60, Color.Cyan);
                missile.Loading = false;
            }

            //if lives 0 game is over
            if (lives == 0)
            {
                currentState = eGameState.Over;
            }
        }
 //
 public void ShowBlock(CDrawer nextB)
 {
     nextB.AddCenteredRectangle(_bLocal, 1, 1, myColor);
 }
 //
 public void ShowBlock()
 {
     _drawer.AddCenteredRectangle(_bLocal, 1, 1, myColor);
 }