Пример #1
0
        static void SBlocks()
        {
            CDrawer can = new CDrawer(800, 600, false);

            for (int i = 0; i < 500; ++i)
            {
                can.AddCenteredEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor(), 1, RandColor.GetColor());
                can.AddCenteredEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor(), 1);
                can.AddCenteredEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor());
                can.AddCenteredEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800));

                can.AddEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor(), 1, RandColor.GetColor());
                can.AddEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor(), 1);
                can.AddEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor());
                can.AddEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800));

                try
                {
                    can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64), s_rnd.NextDouble() * Math.PI * 2, RandColor.GetColor(), 1, RandColor.GetColor());
                    can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64), s_rnd.NextDouble() * Math.PI * 2, RandColor.GetColor(), 1);
                    can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64), s_rnd.NextDouble() * Math.PI * 2, RandColor.GetColor());
                    can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64), s_rnd.NextDouble() * Math.PI * 2);
                    can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64));
                }
                catch (Exception err)
                {
                    Console.WriteLine(err.Message);
                }

                try
                {
                    can.AddRectangle(s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), RandColor.GetColor(), 1, RandColor.GetColor());
                    can.AddRectangle(s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), RandColor.GetColor(), 1);
                    can.AddRectangle(s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), RandColor.GetColor());
                    can.AddRectangle(s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), s_rnd.Next(-10, 810), s_rnd.Next(-10, 610));
                }
                catch (Exception err)
                {
                    Console.WriteLine(err.Message);
                }

                try
                {
                    can.AddText("Rats", s_rnd.Next(0, 100), s_rnd.Next(0, 800), s_rnd.Next(0, 600), s_rnd.Next(0, 200), s_rnd.Next(0, 200), RandColor.GetColor());
                    can.AddText("Rats", s_rnd.Next(0, 100), s_rnd.Next(0, 800), s_rnd.Next(0, 600), s_rnd.Next(0, 200), s_rnd.Next(0, 200));
                    can.AddText("Rats", s_rnd.Next(0, 100), RandColor.GetColor());
                }
                catch (Exception err)
                {
                    Console.WriteLine(err.Message);
                }
            }

            can.Render();
            Console.ReadKey();
        }
Пример #2
0
        // occurs evertime program starts
        // when loaded gdi window is opened and initalized
        private void Form1_Load(object sender, EventArgs e)
        {
            _canvas.ContinuousUpdate = false;                          // allows objects to be drawn and animated cleanly
            const int SCALE = 20;                                      // scale constant

            _canvas.Scale = SCALE;                                     // sets pixels range for x and y
            _color        = Color.Red;                                 // set default shape color to red

            // draw circle in center of draw window for starting point
            _canvas.AddEllipse(_XPOS, _YPOS, 1, 1, Color.Red);
            _canvas.Render();
        }
Пример #3
0
 public static void DrawCurrency(double [] array, double originalValue)
 {
     //Draws respective currency in GDI drawer if it exists
     drawSpace.AddText("$" + originalValue.ToString(), 20, 325, 20, 150, 50, Color.Yellow);
     if (array[0] > 0)
     {
         drawSpace.AddRectangle(100, 100, 175, 75, Color.PaleVioletRed, 2, Color.Gray);
         drawSpace.AddText("$50 x " + array[0].ToString(), 10, 145, 100, 75, 75, Color.Black);
     }
     if (array[1] > 0)
     {
         drawSpace.AddRectangle(100, 200, 175, 75, Color.LawnGreen, 2, Color.Gray);
         drawSpace.AddText("$20 x " + array[1].ToString(), 10, 145, 200, 75, 75, Color.Black);
     }
     if (array[2] > 0)
     {
         drawSpace.AddRectangle(100, 300, 175, 75, Color.MediumPurple, 2, Color.Gray);
         drawSpace.AddText("$10 x " + array[2].ToString(), 10, 145, 300, 75, 75, Color.Black);
     }
     if (array[3] > 0)
     {
         drawSpace.AddRectangle(100, 400, 175, 75, Color.AliceBlue, 2, Color.Gray);
         drawSpace.AddText("$5 x " + array[3].ToString(), 10, 145, 400, 75, 75, Color.Black);
     }
     if (array[4] > 0)
     {
         drawSpace.AddEllipse(400, 100, 57, 57, Color.Silver, 2, Color.Gray);
         drawSpace.AddText("$2 x " + array[4].ToString(), 10, 390, 90, 75, 75, Color.Black);
     }
     if (array[5] > 0)
     {
         drawSpace.AddEllipse(400, 160, 57, 57, Color.Gold, 2, Color.Gray);
         drawSpace.AddText("$1 x " + array[5].ToString(), 10, 390, 150, 75, 75, Color.Black);
     }
     if (array[6] > 0)
     {
         drawSpace.AddEllipse(400, 220, 57, 57, Color.Silver, 2, Color.Gray);
         drawSpace.AddText("$0.25 x " + array[6].ToString(), 10, 390, 210, 75, 75, Color.Black);
     }
     if (array[7] > 0)
     {
         drawSpace.AddEllipse(400, 280, 57, 57, Color.Silver, 2, Color.Gray);
         drawSpace.AddText("$0.10 x " + array[7].ToString(), 10, 390, 270, 75, 75, Color.Black);
     }
     if (array[8] > 0)
     {
         drawSpace.AddEllipse(400, 340, 57, 57, Color.Silver, 2, Color.Gray);
         drawSpace.AddText("$0.05 x " + array[8].ToString(), 10, 390, 330, 75, 75, Color.Black);
     }
 }
Пример #4
0
        //Draw
        public void Draw()
        {
            Point Coor;

            if (drawSpace.GetLastMouseLeftClick(out Coor))
            {
                drawSpace.AddEllipse(Coor.X, Coor.Y, drawingSize, drawingSize, drawingColor);
            }
        }
Пример #5
0
        public void timer1_Tick(object sender, EventArgs e)
        {
            Point newCirclePoint;

            if (true == drawingBoard.GetLastMouseLeftClick(out newCirclePoint))
            {
                drawingBoard.AddEllipse(newCirclePoint.X - (circleSize / 2), newCirclePoint.Y - (circleSize / 2), circleSize, circleSize, circleColor);
            }
        }
Пример #6
0
        private void BallThread(object ThreadData)
        {
            Random R = new Random();

            for (int i = 0; i < 500; ++i)
            {
                int x = R.Next(Canvas.DrawerWindowSize.Width);
                int y = R.Next(Canvas.DrawerWindowSize.Height);

                Canvas.AddEllipse(x, y, (int)ThreadData, (int)ThreadData, RandColor.GetColor());
                Thread.Sleep(50);
            }
        }
Пример #7
0
        // Display the game in graphics window
        public void Display()
        {
            _canvas.Clear();
            _canvas.AddText("Score: ", 50, 0, 10, 220, 60, Color.White);
            _canvas.AddText(_score.ToString(), 50, 250, 10, 350, 60, Color.White);

            for (int x = 0; x < COLS; ++x)
            {
                for (int y = 0; y < ROWS; ++y)
                {
                    if (Bubbles[x, y].highlight)
                    {
                        _canvas.AddEllipse(x * BUBBLESIZE, y * BUBBLESIZE + OFFSET, BUBBLESIZE, BUBBLESIZE,
                                           Color.Pink);
                    }
                    else if (Bubbles[x, y].state == Bubble.State.Alive)
                    {
                        _canvas.AddEllipse(x * BUBBLESIZE, y * BUBBLESIZE + OFFSET, BUBBLESIZE, BUBBLESIZE,
                                           Bubbles[x, y].color);
                    }
                }
            }
        }
Пример #8
0
        //Display method
        //draw each ball based on ball location and color of ball
        private void Display()
        {
            canvas.Clear();

            for (int row = 0; row < ballLocation.GetLength(0); row++)
            {
                for (int col = 0; col < ballLocation.GetLength(1); col++)
                {
                    if (ballLocation[row, col].BallState == BallState.alive)
                    {
                        canvas.AddEllipse(col * BallSize, row * BallSize, BallSize, BallSize, ballLocation[row, col].BallColor);
                    }
                }
            }
        }
Пример #9
0
        private void BallThread(object ThreadData)
        {
            Random R = new Random();
            //Choose a random # of balls to spawn before thread dies
            int ballQuota = R.Next(10, 100);

            for (int i = 0; i < ballQuota; ++i)
            {
                int x = R.Next(Canvas.DrawerWindowSize.Width);
                int y = R.Next(Canvas.DrawerWindowSize.Height);

                Canvas.AddEllipse(x, y, (int)ThreadData, (int)ThreadData, RandColor.GetColor());
                Thread.Sleep(100);
            }
        }
Пример #10
0
        //display all the balls that in the array
        private void Display(CDrawer _canvas)
        {
            _canvas.Clear();

            //going over x and y axis and adding circles into the canvas
            for (int i = 0; i < width; ++i)
            {
                for (int j = 0; j < height; ++j)
                {
                    //if the ball is alive add the circle into that location
                    if (ballArray[i, j].state == State.Alive)
                    {
                        _canvas.AddEllipse(i * ballSize, j * ballSize, ballSize, ballSize, ballArray[i, j].ballColor);
                    }
                }
            }
        }
Пример #11
0
        //************************************************************************************
        //Method:  private void Display()
        //Purpose: draws all alive Balls in the array in the GDI drawer window
        //************************************************************************************
        private void Display()
        {
            int xPos; //used for iterating through the _bArray x indexes
            int yPos; //used for iterating through the _bArray y indexes

            _draw.Clear();

            //iterate through all array indexes
            for (xPos = 0; xPos < _bArray.GetLength(0); xPos++)
            {
                for (yPos = 0; yPos < _bArray.GetLength(1); yPos++)
                {
                    //if the current ball is alive, draw it
                    if (_bArray[xPos, yPos].state == ballState.appered)
                    {
                        _draw.AddEllipse(xPos * BSIZE, yPos * BSIZE, BSIZE, BSIZE, _bArray[xPos, yPos].color);
                    }
                }
            }
        }
Пример #12
0
        static void ClickEllipses()
        {
            Random  rnd = new Random();
            CDrawer can = new CDrawer();

            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Reset();
            watch.Start();
            can.AddText("Random Bounding Box Ellipses : 2s", 28, 0, 0, can.ScaledWidth, can.ScaledHeight, Color.White);
            can.AddText("Random Bounding Box Ellipses : 2s", 28, 2, 2, can.ScaledWidth + 2, can.ScaledHeight + 2, Color.Black);
            while (watch.ElapsedMilliseconds < 5000)
            {
                Point p = new Point(rnd.Next(-50, can.ScaledWidth + 50), rnd.Next(-50, can.ScaledHeight - 50));
                switch (rnd.Next(6))
                {
                case 0:
                    can.AddEllipse(p.X, p.Y, 100, 100);
                    break;

                case 1:
                    can.AddEllipse(p.X, p.Y, 100, 100, RandColor.GetKnownColor(), rnd.Next(1, 4), RandColor.GetKnownColor());
                    break;

                case 2:
                    can.AddPolygon(p.X, p.Y, 100, rnd.Next(3, 8));
                    break;

                case 3:
                    can.AddPolygon(p.X, p.Y, 100, rnd.Next(3, 8), rnd.NextDouble() * Math.PI, RandColor.GetKnownColor(), 2, RandColor.GetKnownColor());
                    break;

                case 4:
                    can.AddRectangle(p.X, p.Y, 100, 100);
                    break;

                case 5:
                    can.AddRectangle(p.X, p.Y, 100, 100, RandColor.GetKnownColor(), rnd.Next(1, 4), RandColor.GetKnownColor());
                    break;

                default:
                    break;
                }
                System.Threading.Thread.Sleep(100);
            }
            can.Close();

            can = new CDrawer(1000, 400, false);
            //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Reset();
            watch.Start();
            can.AddText("Random Bounding Box Ellipses : 2s", 28, 0, 0, can.ScaledWidth, can.ScaledHeight, Color.White);
            can.AddText("Random Bounding Box Ellipses : 2s", 28, 2, 2, can.ScaledWidth + 2, can.ScaledHeight + 2, Color.Black);
            while (watch.ElapsedMilliseconds < 2000)
            {
                Point p = new Point(rnd.Next(50, can.ScaledWidth - 50), rnd.Next(50, can.ScaledHeight - 50));
                can.AddCenteredEllipse(p.X, p.Y, 100, 100, RandColor.GetKnownColor(), 2, Color.White);
                can.AddCenteredEllipse(p.X, p.Y, 5, 5, RandColor.GetKnownColor(), 1, Color.Red);
                System.Threading.Thread.Sleep(100);
            }
            can.Render();
            System.Threading.Thread.Sleep(1000);
            can.Close();
        }
Пример #13
0
 private void Form1_Load(object sender, EventArgs e)
 {
     canvas.AddEllipse(xStart, yStart, circleDiameter, circleDiameter, circleColor, borderThickness, borderColor);
 }
Пример #14
0
 static void LeftClick(Point pos, CDrawer dr)
 {
     dr.AddEllipse(pos.X, pos.Y, 10, 10, Color.Yellow);
 }
Пример #15
0
        static void Main(string[] args)
        {
            CDrawer dr = new CDrawer();

            dr.BBColour = Color.White;
            Random rnd = new Random();

            dr.Scale = 20; // adjust scale to test ScaledWidth/ScaledHeight

            // Disable continuous update
            dr.ContinuousUpdate = false;
            // perform lengthy/high object count operation
            for (int i = 0; i < 1000; ++i)
            {
                dr.AddEllipse(rnd.Next(dr.ScaledWidth), rnd.Next(dr.ScaledHeight), 1, 1, RandColor.GetColor());
                dr.Render(); // tell drawer to show now, all elements have been added
            }


            int iNum = 0;

            iNum++;



            Point pCoord;          // coords to accept mouse click pos
            int   iNumClicks  = 0; // count number of clicks accepted
            int   iFalseAlarm = 0; // count the number of poll calls

            do
            {
                bool bRes = dr.GetLastMouseLeftClick(out pCoord); // poll
                if (bRes)                                         // new coords?
                {
                    ++iNumClicks;
                    dr.AddEllipse(pCoord.X - 10, pCoord.Y - 10, 20, 20);
                }
                else
                {
                    iFalseAlarm++;                      // not new coords
                }
            }while (iNumClicks < 10);

            Console.WriteLine("Checked for coordinates " + iFalseAlarm.ToString() + " times!");


            Console.ReadKey();

            /*
             * {
             *  FileStream foo = new FileStream("snot", FileMode.Create);
             *  MemoryStream ms = new MemoryStream();
             *  BinaryFormatter bf = new BinaryFormatter();
             *
             *  SThing temp = new SThing();
             *  temp.i = 42;
             *
             *  bf.Serialize(ms, temp);
             *  foo.Write(ms.GetBuffer(), 0, (int)ms.Length);
             *  foo.Close();
             * }
             *
             * {
             *  FileStream foo = new FileStream("snot", FileMode.Open);
             *  BinaryFormatter bf = new BinaryFormatter();
             *
             *  object o = bf.Deserialize(foo);
             *  if (o is SThing)
             *  {
             *      SThing temp = (SThing)o;
             *      Console.WriteLine (temp.i.ToString());
             *  }
             * }
             *
             * Console.ReadKey();
             */
        }
Пример #16
0
        static void Main(string[] args)
        {
            bool gameOver = false;      // Exit the Game
            bool gameExit = false;      // Exit the Program
            bool start    = false;      // Start the Game

            // Instance of random.
            Random rand = new Random();

            //x ball position
            int iX = 3;
            //y ball position
            int iY = rand.Next(2, 115);

            //amount ball moves in x direction for every loop
            int iXVelocity = 3;

            //amount ball moves in y direction for every loop
            int iYVelocity = 3;

            // Game score
            int score = 0;

            // Ball speed delay
            int ballSpeed = 120;

            //create a drawer window
            CDrawer Canvas = new CDrawer();

            Canvas.Scale = 5;

            // coordinates.
            Point coord;

            // Mouse position in Canvas
            int mouseYPos = 70;


            //loop until the ball leaves the visible window
            while (((iX < 160) || (iX > 0)) && !gameExit)
            {
                while (gameOver == false)
                {
                    // Erase the old ball and paddle.
                    Canvas.Clear();

                    // If left mouse click start the game.
                    if (Canvas.GetLastMouseLeftClick(out coord))
                    {
                        start = true;
                    }

                    // if start is true start the game.
                    if (start)
                    {
                        // Get the mouse position in the canva and scale it to 5.
                        if (Canvas.GetLastMousePosition(out coord))
                        {
                            mouseYPos = (coord.Y / 5) - 5;
                        }

                        // Add the paddle.
                        Canvas.AddRectangle(0, mouseYPos, 1, 10, Color.Red);

                        //draw the new ball
                        Canvas.AddEllipse(iX, iY, 2, 2);

                        //time delay to slow down the ball
                        System.Threading.Thread.Sleep(ballSpeed);

                        // If mouse is on paddle position bounce back.
                        if ((iY - 9) <= mouseYPos && (iY + 1) >= mouseYPos && iX <= 2)
                        {
                            // Reverse speed position (goes opposite way).
                            iXVelocity = -iXVelocity;
                            iYVelocity = -iYVelocity;

                            // increment the ball speed.
                            ballSpeed = ballSpeed <= 20 ? 1 : ballSpeed - 20;

                            // increment score.
                            score++;
                        }

                        // Increment the position with the velocity.
                        iX += iXVelocity;
                        iY += iYVelocity;

                        //check for bouncing off of the lower edge of the window
                        if ((iY > 118) || (iY < 0))
                        {
                            //reverse the y velocity (ball goes up)
                            iYVelocity = -iYVelocity;
                        }

                        // If ball position is greater than 160 reverse the X velocity (ball goes left).
                        if (iX > 160)
                        {
                            iXVelocity = -iXVelocity;
                        }

                        // If ball position is less than 0 game is over.
                        if (iX < 0)
                        {
                            gameOver = true;
                        }
                    }
                }

                // Erase the old ball and paddle.
                Canvas.Clear();

                // Display the final score and option buttons to play again and quit the game.
                Canvas.AddText($"Final Score: {score}", 36, Color.Gray);
                Canvas.AddText("Play Again", 12, 85, 84, 30, 45, Color.Green);
                Canvas.AddText("Quit", 12, 120, 84, 30, 45, Color.Gray);
                Canvas.AddRectangle(87, 103, 25, 8, Color.Empty, 1, Color.Green);
                Canvas.AddRectangle(122, 103, 25, 8, Color.Empty, 1, Color.Gray);
                while (gameOver == true)
                {
                    if (Canvas.GetLastMouseLeftRelease(out coord))
                    {
                        Console.WriteLine("Click!");
                    }
                    // If play again button is click start the game.
                    if (Canvas.GetLastMouseLeftClick(out coord) && (coord.X >= 435 && coord.X <= 560) && (coord.Y >= 515 && coord.Y <= 555))
                    {
                        // Initialize ball position and speed.
                        iX         = 3;
                        iY         = rand.Next(2, 115);
                        iXVelocity = 3;
                        iYVelocity = 3;
                        ballSpeed  = 120;
                        score      = 0;

                        // Start the game.
                        gameOver = false;
                        start    = true;
                    }

                    // If quit button is click quit the game.
                    if (Canvas.GetLastMouseLeftClick(out coord) && (coord.X >= 610 && coord.X <= 735) && (coord.Y >= 515 && coord.Y <= 555))
                    {
                        // Exit the game.
                        gameExit = true;
                        gameOver = false;
                    }
                }
            }
        }
Пример #17
0
 private void btn_StartDraw_Click(object sender, EventArgs e)
 {
     drawer.GetLastMouseLeftClick(out clickCoordinates);
     drawer.AddEllipse((clickCoordinates.X - (size / 2)), (clickCoordinates.Y - (size / 2)), size, size, color);
 }
Пример #18
0
 static void MouseMove(Point pos, CDrawer dr)
 {
     dr.AddEllipse(pos.X, pos.Y, 5, 5, Color.Red);
 }