コード例 #1
0
ファイル: World.cs プロジェクト: tlevytskyy/MyFirstAdventure
        public static void UpdateMiniMap(Location CurrentLocation)
        {
            MiniMap.Clear();

            int[] cordarray = new int[2] {
                CurrentLocation.Coordinates[0] - 2, CurrentLocation.Coordinates[1] - 2
            };
            for (int row = 0; row < 5; row++)
            {
                for (int columb = 0; columb < 5; columb++)
                {
                    foreach (Location locals in Locations)
                    {
                        if (locals.Coordinates.SequenceEqual(cordarray))
                        {
                            MiniMap.AddRectangle(row, columb, 1, 1, Color.Red);
                            MiniMap.AddText(locals.Name, 10, row, columb, 1, 1, Color.White);
                        }
                        if (CurrentLocation.Coordinates.SequenceEqual(cordarray))
                        {
                            MiniMap.AddRectangle(row, columb, 1, 1, Color.Green);
                            MiniMap.AddText(CurrentLocation.Name, 10, row, columb, 1, 1, Color.White);
                        }
                    }

                    cordarray[1]++;
                }
                cordarray[1] = CurrentLocation.Coordinates[1] - 2;
                cordarray[0]++;
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: yohosuff/GDIDrawer
        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();
        }
コード例 #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
ファイル: Drawings.cs プロジェクト: sjc17/CNT-Hangman
 // Draw letter buttons
 public static void LetterButtons(ref CDrawer HangingPost)
 {
     // Create Buttons A-M
     for (int a = 0; a < 13; a++)
     {
         HangingPost.AddRectangle((a * 40) + 250, 10, 30, 30, Color.Gray);
         HangingPost.AddText(((char)(a + 65)).ToString() + " ", 16, (a * 40) + 250, 10, 30, 30, Color.Black);
     }
     // Create Buttons N-Z
     for (int a = 0; a < 13; a++)
     {
         HangingPost.AddRectangle((a * 40) + 250, 50, 30, 30, Color.Gray);
         HangingPost.AddText(((char)(a + 78)).ToString() + " ", 16, (a * 40) + 250, 50, 30, 30, Color.Black);
     }
 }
コード例 #5
0
        /// <summary>
        /// render squares on gdi screen
        /// </summary>
        /// <param name="cDrawer"></param>
        /// <param name="lampNum"></param>
        public void RenderLamp(CDrawer cDrawer, int lampNum)
        {
            int row    = lampNum % cDrawer.ScaledWidth;
            int column = lampNum / cDrawer.ScaledWidth;//ScaledHeight

            if (_byTick > _byToggle)
            {
                cDrawer.AddRectangle(row, column, 1, 1, _LampColor, _Border, Color.Black);
            }
            else
            {
                cDrawer.AddRectangle(row, column, 1, 1, Color.Black, _Border, Color.Black);
            }
            cDrawer.Render();
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: jaredmcnamee/BitCounter
        /// <summary>
        /// Method for updating the canvas
        /// </summary>
        public void UpdateCanvas()
        {
            //clearing the canvas
            _canvas.Clear();

            //getting the max value of the dicitonary
            int max = drawDic.Max(x => x.Value);

            lock (drawDic)
            {
                //for each key value pair creating a rectangel and coloring it based its value/max value ratio
                foreach (KeyValuePair <byte, int> kvp in drawDic)
                {
                    int x   = (int)kvp.Key % 16;
                    int y   = (int)kvp.Key / 16;
                    int col = (int)(((double)kvp.Value / max) * 255);
                    _canvas.AddRectangle(x * 50, y * 50, 50, 50, Color.FromArgb(col, col, col));;

                    //if the color isn't black drawing it to the screen
                    if (col > 0)
                    {
                        _canvas.AddText($"{kvp.Key:X}", 10, x * 50, y * 50, 50, 50, Color.Yellow);
                    }
                }
            }
            //rending the canvas
            _canvas.Render();
        }
コード例 #7
0
        /// <summary>
        /// display blocks on certian key stroke
        /// set boundaris for gdi window
        /// </summary>
        /// <param name="drawer"></param>
        public virtual void ShowBlock(CDrawer drawer)
        {
            // Create a Size structure.
            SizeF inflateSize = new SizeF(3, 3);

            //Use one of the RectangleF helper methods to determine if the block center point has exceeded the CDrawer boundaries
            //make rect obj based on cdrwar dimensions//thecn check if out
            //btm of gdi
            if (localSize.IntersectsWith(new RectangleF(0, drawer.ScaledHeight + (localSize.Height / 2), drawer.ScaledWidth, 10)))
            {
                outside = true;
                return;
            }
            //left border
            if (localSize.IntersectsWith(new RectangleF(0 - (localSize.Width / 2) - 10, 0, 10, drawer.ScaledHeight)))
            {
                outside = true;
                return;
            }
            //right border
            if (localSize.IntersectsWith(new RectangleF(drawer.ScaledWidth + (localSize.Width / 2), 0, 10, drawer.ScaledHeight)))
            {
                outside = true;
                return;
            }
            else
            {
                //draw black rect(copy)
                //then draw real rect on top of it
                RectangleF temp = localSize;
                temp.Inflate(inflateSize);
                drawer.AddRectangle((int)temp.X, (int)temp.Y, (int)temp.Width, (int)temp.Height, Color.Black);//background square
            }
        }
コード例 #8
0
        // render as vertical bar in drawer
        public void Render(CDrawer cr, Rectangle rect)
        {
            int iFillHeight = (int)(rect.Height * _fFillRatio); // effective height of rectangle color

            // add rectangle to the bottom of the canvas
            cr.AddRectangle(rect.X, rect.Y + (cr.m_ciHeight - iFillHeight), rect.Width, iFillHeight,
                            (this is CColourLine) ? (this as CColourLine).cColor : Color.Red, 1, Color.Black);
        }
コード例 #9
0
        // render as vertical bar in drawer
        protected void SubRender(CDrawer cr, Rectangle rect, Color col)
        {
            int iFillHeight = getFillHeight(rect.Height); // set color height

            // draw rectangles on the bottom of the canvas
            cr.AddRectangle(rect.X, rect.Y + (cr.m_ciHeight - iFillHeight),
                            rect.Width, iFillHeight, col, 1, Color.Black);
        }
コード例 #10
0
 //Show all Grid in white border
 //FOR TESTING ONLY
 public void ShowAll(CDrawer canvas)
 {
     foreach (Grid item in arrayGrid)
     {
         canvas.AddRectangle(item.currentGrid.X * Bsize, item.currentGrid.Y * Bsize, Bsize, Bsize, Color.Black, 2, Color.White);
         canvas.Render();
     }
 }
コード例 #11
0
        /// <summary>
        /// show items in queue in cdrawer
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="xStart"></param>
        /// <param name="yStart"></param>
        /// <param name="scale"></param>
        public void ShowSheeple(CDrawer canvas, int xStart, int yStart, int scale)
        {
            canvas.AddRectangle(xStart * scale, yStart * scale, scale * currentItems, scale, sheepColor);

            //But only show the current item count if it is first in line
            if (xStart == 0)
            {
                canvas.AddText(currentItems.ToString(), 12, xStart * scale, yStart * scale, scale * currentItems, scale, Color.Black);
            }
        }
コード例 #12
0
        private void UI_timer_Tick(object sender, EventArgs e)
        {
            if (canvas == null)
            {
                return;
            }
            if (mySheeple.Count != 0)
            {
                foreach (Queue <Sheeple> thisQueue in queue)
                {
                    if (thisQueue.Count < 10 && mySheeple.Count != 0)
                    {
                        thisQueue.Enqueue(mySheeple.Pop());
                    }
                }
            }
            UI_ListBox.Items.Clear();
            foreach (Sheeple i in mySheeple)
            {
                totalNum += i._totalItem;
            }

            foreach (Queue <Sheeple> i in queue)
            {
                if (i.Count != 0)
                {
                    UI_ListBox.Items.Add(i.Count());
                    Sheeple temp = i.Peek();
                    temp.Process();
                    if (temp.Done)
                    {
                        totalNum += temp._totalItem;
                        i.Dequeue();
                    }
                }
                canvas.Clear();
                int sumX = 0;
                int sumY = 0;
                foreach (Queue <Sheeple> myQueue in queue)
                {
                    sumX = 0;
                    foreach (Sheeple eeple in myQueue)
                    {
                        canvas.AddRectangle(sumX, sumY, eeple._currentItem, 1, Color.FromArgb(eeple._Color));
                        sumX += eeple._currentItem;
                    }
                    sumY += 1;
                }
                canvas.Render();
            }
        }
コード例 #13
0
ファイル: Form1.cs プロジェクト: ManuMathews/Backup-USB
        public void freshStart()
        {
            Random randomNumber = new Random();

            numberOfInitallyEnabledPoints = randomNumber.Next(60, 1000);
            btn_Stop.Enabled = false;
            timer1.Stop();

            foregroundArray = new byte[80, 60];   //Reference: Rectangular/two-dimentional arrays
            backgroundArray = new byte[80, 60];   //Reference: Rectangular/two-dimentional arrays
            for (int i = 0; i < 80; i++)
            {
                for (int j = 0; j < 60; j++)
                {
                    foregroundArray[i, j] = 0;
                    backgroundArray[i, j] = 0;
                }
            }

            for (int i = 0; i < numberOfInitallyEnabledPoints; i++)
            {
                foregroundArray[randomNumber.Next(0, 79), randomNumber.Next(0, 59)] = 1;
            }

            for (int i = 0; i < 79; i++)
            {
                for (int j = 0; j < 59; j++)
                {
                    if (foregroundArray[i, j] == 1)
                    {
                        drawingBoard.AddRectangle(i, j, 1, 1, Color.White);
                    }
                }
            }

            drawingBoard.Render();
        }
コード例 #14
0
ファイル: MyExample.cs プロジェクト: ManuMathews/Backup-USB
        static void Main(string[] args)
        {
            //int x = 0;
            //ConsoleKeyInfo keyPressed;



            //while(x < 10)
            //{
            //  Console.WriteLine(x);
            //++x;
            //}


            //keyPressed = Console.ReadKey();

            //Console.WriteLine(keyPressed.Key);

            //Console.ReadKey();


            /// end of that part
            //start of new part



            CDrawer canvas = new CDrawer(800, 600);

            Console.WriteLine("Draw Something");

            canvas.AddCenteredEllipse(200, 100, 100, 100, Color.Red, 2, Color.White);

            canvas.AddLine(50, 50, 400, 500, Color.Green, 5);

            canvas.AddRectangle(400, 300, 100, 50, Color.Purple, 2, Color.White);
            canvas.AddText("meat", 24, Color.Magenta);
            canvas.AddText("Bacon", 36, 300, 150, 250, 50, Color.Lime);

            Console.ReadKey();


            //to have random color:-    "RandColor.GetColor()"
        }
コード例 #15
0
        //function for rendering all grid in array
        public void Render(CDrawer canvas)
        {
            canvas.Clear();
            //creating instance before loop for preventing creating new instance during rendering
            Point temp = new Point(0, 0);

            for (int row = 0; row < arrayGrid.GetLength(0); row++)
            {
                for (int col = 0; col < arrayGrid.GetLength(1); col++)
                {
                    if (arrayGrid[row, col].live == Alive.alive)
                    {
                        //get the location of grid for rendering
                        temp = arrayGrid[row, col].position;

                        canvas.AddRectangle(temp.X, temp.Y, arrayGrid[row, col].size, arrayGrid[row, col].size, arrayGrid[row, col].color, 3, Color.Black);

                        canvas.Render();
                    }
                }
            }
        }
コード例 #16
0
ファイル: Program.cs プロジェクト: yohosuff/GDIDrawer
        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();
        }
コード例 #17
0
 /// <summary>
 /// overide to add the square then show rectangle
 /// invoke the base method and add new rectangle
 /// </summary>
 /// <param name="drawer"></param>
 public override void ShowBlock(CDrawer drawer)
 {
     //invoke base method and add rect in my color
     base.ShowBlock(drawer);
     drawer.AddRectangle((int)localSize.X, (int)localSize.Y, (int)localSize.Width, (int)localSize.Height, myColor);
 }
コード例 #18
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;
                    }
                }
            }
        }
コード例 #19
0
ファイル: Shape.cs プロジェクト: dlallan/TetrisInCSharp
 //Function name:    ShowBlock
 //Description:      Draw block onto the canvas.
 //Returns:          void
 //Arguments:        none
 public void ShowBlock()
 {
     _canvas.AddRectangle(_iXLocation, _iYLocation, 1, 1, _cColor, 1, Color.Gray);
 }
コード例 #20
0
 public void Render(int xPos, int yPos, CDrawer canvas)
 {
     canvas.AddRectangle(xPos, yPos, _blockSize, _blockSize, ColorProp);
 }
コード例 #21
0
ファイル: Program.cs プロジェクト: ReanItaru/Pong
        static void Main(string[] args)
        {
            Random rng        = new Random();
            int    xVelocity  = 1;                  //the rate at which the ball moves on the X plane
            int    yVelocity  = 1;                  //the rate at which the ball moves on the Y plane
            int    xBall      = 80;
            int    yBall      = 60;
            int    wallTop    = 0;                  //top boundry of screen/game
            int    wallRight  = 0;                  //right boundry of screen/game
            int    wallBottom = 0;                  //bottom boundry of screen/game
            bool   playAgain  = true;
            Point  playerPosition;                  //location of mouse so paddle can be appropriately set on the Y plane

            const int playerPositionX = 0;          //the constant postion of the paddle against the left side of screen

            CDrawer gdi = new CDrawer();

            gdi.Scale            = 5;
            gdi.ContinuousUpdate = false;

            do
            {
                while (true)
                {
                    //sets the boundry for the ball with as a visual
                    for (wallTop = 0; wallTop < 160; wallTop = ++wallTop)
                    {
                        gdi.SetBBScaledPixel(wallTop, 0, Color.SkyBlue);
                    }
                    for (wallRight = 0; wallRight < 120; wallRight = ++wallRight)
                    {
                        gdi.SetBBScaledPixel(wallTop - 1, wallRight, Color.SkyBlue);
                    }
                    for (wallBottom = 0; wallBottom < 160; wallBottom = ++wallBottom)
                    {
                        gdi.SetBBScaledPixel(wallBottom, wallRight - 1, Color.SkyBlue);
                    }

                    //the ball
                    while (xBall < wallRight && yBall < wallTop && yBall > wallBottom)
                    {
                        gdi.AddRectangle(xBall, yBall, 2, 2, Color.Gainsboro);

                        //the paddle
                        gdi.GetLastMousePosition(out playerPosition);

                        //playerPositionYStart = playerPositionYStart + playerPosition;
                        gdi.AddLine(playerPositionX, (playerPosition.Y + 25) / 5, playerPositionX, (playerPosition.Y - 25) / 5, Color.DarkRed, 10);



                        //the delay, new images then removal of old images to create "animation"
                        gdi.Render();
                        System.Threading.Thread.Sleep(20);
                        gdi.Clear();

                        xBall += xVelocity;
                        yBall += yVelocity;
                    }
                }

                playAgain = false;
            } while (playAgain);
        }
コード例 #22
0
 public void Render(CDrawer dr)
 {
     dr.AddRectangle(_X * _TileSize, _Y * _TileSize, _TileSize - 1, _TileSize - 1, Color.Red);
 }
コード例 #23
0
        public static void Draw(Type type, int x, int y)
        {
            if (type == Type.sand)
            {
                _Canvas.AddRectangle(x, y, 1, 1, Color.Yellow, 2, Color.Black);
            }
            if (type == Type.wall)
            {
                _Canvas.AddRectangle(x, y, 1, 1, Color.Gray, 1, Color.Black);
            }

            if (type == Type.water)
            {
                if (rand.Next(0, 1000) < 500)
                {
                    _Canvas.AddRectangle(x, y, 1, 1, Color.Blue, 1, Color.CornflowerBlue);
                }
                else
                {
                    _Canvas.AddRectangle(x, y, 1, 1, Color.Blue, 2, Color.CornflowerBlue);
                }
            }

            if (type == Type.fire)
            {
                if (rand.Next(0, 1000) < 500)
                {
                    _Canvas.AddRectangle(x, y, 1, 1, Color.OrangeRed, 2, Color.OrangeRed);
                }
                else
                {
                    _Canvas.AddRectangle(x, y, 1, 1, Color.OrangeRed, 2, Color.Red);
                }
            }

            if (type == Type.dirt)
            {
                _Canvas.AddRectangle(x, y, 1, 1, Color.SaddleBrown, 1, Color.Black);
            }

            if (type == Type.lava)
            {
                if (rand.Next(0, 1000) < 500)
                {
                    _Canvas.AddRectangle(x, y, 1, 1, Color.Red);
                }
                else
                {
                    _Canvas.AddRectangle(x, y, 1, 1, Color.Orange);
                }
            }

            if (type == Type.tree)
            {
                _Canvas.AddRectangle(x, y, 1, 1, Color.ForestGreen);
            }

            if (type == Type.waterspawner)
            {
                _Canvas.AddRectangle(x, y, 1, 1, Color.Blue, 1, Color.Brown);
            }
            if (type == Type.sandspawner)
            {
                _Canvas.AddRectangle(x, y, 1, 1, Color.Yellow, 1, Color.Brown);
            }
            /////
            if (type == Type.firespawner)
            {
                _Canvas.AddRectangle(x, y, 1, 1, Color.Red, 1, Color.Brown);
            }
            return;
        }
コード例 #24
0
        static public void DrawHistogram(CDrawer gdi, int[] grades)
        {
            int    width      = 0;                          //starting position of the x-axis for each bar
            int    height     = 0;                          //starting position of the y-axis for each bar
            int    textHeight = 0;                          //determines where the text representing how big each bar is will go
            double increments = 0.0;                        //used to simplify the graphing math, MUST be double to minimize rounding errors
            int    lengthBar  = 0;                          //determines how long each bar is based on its groups size
            int    count      = 0;                          //incrimental counter used to cycle through the full array

            int[]    groupedGrades = new int[11];           //each value in the array is the size of a grouping of numbers
            int[]    array         = (int[])grades.Clone(); //cloned the parameter to prevent changing the original array
            Color[]  barColour;                             //each group will have an individual colour assosiated with it
            string[] group;                                 //the groups that the paramter array will be sorted into
            gdi.Clear();

            //counting grades per group catagory: 0-9, 10-19, 20-29, ect with 100 being stand alone in the final group
            for (count = 0; count < array.GetLength(0); count++)
            {
                //simplifies the groups
                if (array[count] < 10)
                {
                    array[count] = 1;
                }
                else if (array[count] > 9 && array[count] < 20)
                {
                    array[count] = 2;
                }
                else if (array[count] > 19 && array[count] < 30)
                {
                    array[count] = 3;
                }
                else if (array[count] > 29 && array[count] < 40)
                {
                    array[count] = 4;
                }
                else if (array[count] > 39 && array[count] < 50)
                {
                    array[count] = 5;
                }
                else if (array[count] > 49 && array[count] < 60)
                {
                    array[count] = 6;
                }
                else if (array[count] > 59 && array[count] < 70)
                {
                    array[count] = 7;
                }
                else if (array[count] > 69 && array[count] < 80)
                {
                    array[count] = 8;
                }
                else if (array[count] > 79 && array[count] < 90)
                {
                    array[count] = 9;
                }
                else if (array[count] > 89 && array[count] < 100)
                {
                    array[count] = 10;
                }
                else if (array[count] > 99)
                {
                    array[count] = 11;
                }

                //determines size of the groups
                switch (array[count])
                {
                case 1:
                    groupedGrades[0]++;
                    break;

                case 2:
                    groupedGrades[1]++;
                    break;

                case 3:
                    groupedGrades[2]++;
                    break;

                case 4:
                    groupedGrades[3]++;
                    break;

                case 5:
                    groupedGrades[4]++;
                    break;

                case 6:
                    groupedGrades[5]++;
                    break;

                case 7:
                    groupedGrades[6]++;
                    break;

                case 8:
                    groupedGrades[7]++;
                    break;

                case 9:
                    groupedGrades[8]++;
                    break;

                case 10:
                    groupedGrades[9]++;
                    break;

                case 11:
                    groupedGrades[10]++;
                    break;
                }
            }

            //using the created parallel arrays does the actual drawing of the histogram
            for (count = 0; count < groupedGrades.GetLength(0); count++)
            {
                //any variables that were too long to define above or needed the array values != 0 to function
                group = new string[11] {
                    "0 to 9", "10 to 19", "20 to 29", "30 to 39",
                    "40 to 49", "50 to 59", "60 to 69", "70 to 79", "80 to 89", "90 to 99", "100"
                };
                barColour = new Color[11] {
                    Color.Magenta, Color.LightYellow, Color.LimeGreen, Color.LightSteelBlue,
                    Color.Sienna, Color.DarkOrchid, Color.DodgerBlue, Color.Goldenrod, Color.Maroon, Color.Indigo, Color.Khaki
                };
                width      = count * 72;
                increments = 600.0 / groupedGrades.Max();
                lengthBar  = (groupedGrades[count] * (int)(increments));

                //creates a special exception for groups that have no numbers in them
                if (groupedGrades[count] != 0)
                {
                    height     = (580 - ((int)(increments) * groupedGrades[count]));
                    textHeight = ((height) + ((lengthBar) / 2));

                    gdi.AddRectangle(width, height, 72, lengthBar, barColour[count]);
                    gdi.AddText("" + groupedGrades[count], 13, width, textHeight, 72, 20, Color.Black);
                }
                else
                {
                    textHeight = 290;
                    gdi.AddText("" + groupedGrades[count], 13, width, textHeight, 72, 20, Color.White);
                }

                gdi.AddText(group[count], 10, width, 580, 72, 20, Color.White);
            }
            gdi.Render();
        }
コード例 #25
0
ファイル: Shape.cs プロジェクト: rmak-naz/CMPE2300_PolyRel
 public override void Render(CDrawer dr)
 {
     base.Render(dr);
     dr.AddRectangle((int)_pos.X, (int)_pos.Y, 20, 20, _color);
 }
コード例 #26
0
 //Implements unique version of vRender, drawing a rectangle. .Render() still calls vRender.
 protected override void vRender(CDrawer canvas)
 {
     canvas.AddRectangle(position.X - 10, position.Y - 10, size, size, color);
 }
コード例 #27
0
 /// <summary>
 /// draw the rectangle
 /// </summary>
 public void AddBlock()
 {
     drawer.AddRectangle(rectangle, _Color);
 }
コード例 #28
0
        //*********************************************************************
        //Method:       private static void Draw(int[] aGrades)
        //Purpose:      Draw The amount of Grades in ranges of 10 up to 100 as bars
        //Parameters:   int[] aGrades - Arrays of Grades
        //Returns:      Nothing
        //*********************************************************************
        private static void DrawHistogram(int[] aGrades)
        {
            int[]   numRange = new int[11];        //Store amount of numbers in a each range
            int     index;                         //Index of an array
            CDrawer Draw = new CDrawer();          //Window to Draw the histogram

            Color[] cGrade = new Color[11];        //Color of the bar of the histrogram
            Color   cStore;                        //Temporay store colors
            Random  rColor = new Random();         //Rng use to generate colors

            string[] stringRange = new string[11]; //Ranges in string form to use as labels
            double   height;                       //Height of an bar
            double   width;                        //Width of an bar

            //Count amount of numbers in each Range
            for (index = 0; index < aGrades.Length; index++)
            {
                //Check to see if the number is below or above 50
                if (aGrades[index] < 50)
                {
                    //Check to see what range the number is in
                    if ((0 <= aGrades[index]) && (aGrades[index] <= 9))
                    {
                        //Increase the amount in the range 0-9 by 1
                        numRange[0]++;
                    }
                    else if (aGrades[index] <= 19)
                    {
                        //Increase the amount in the range of 10-19 by 1
                        numRange[1]++;
                    }
                    else if (aGrades[index] <= 29)
                    {
                        //Increase the amount in the range 20-29 by 1
                        numRange[2]++;
                    }
                    else if (aGrades[index] <= 39)
                    {
                        //Increase the amount in the range 30-39 by 1
                        numRange[3]++;
                    }
                    else
                    {
                        //Increase the amount in the range 30-39 by 1
                        numRange[4]++;
                    }
                }
                else
                {
                    //Check to see what range the number is in
                    if ((50 <= aGrades[index]) && (aGrades[index] <= 59))
                    {
                        //Increase the amount in the range 50-59 by 1
                        numRange[5]++;
                    }
                    else if (aGrades[index] <= 69)
                    {
                        //Increase the amount in the range 60-69 by 1
                        numRange[6]++;
                    }
                    else if (aGrades[index] <= 79)
                    {
                        //Increase the amount in the range 70-79 by 1
                        numRange[7]++;
                    }
                    else if (aGrades[index] <= 89)
                    {
                        //Increase the amount in the range 80-89 by 1
                        numRange[8]++;
                    }
                    else if (aGrades[index] <= 99)
                    {
                        //Increase the amount in the range 80-89 by 1
                        numRange[9]++;
                    }
                    else
                    {
                        //Increase the amouint that eqaul 100 by 1
                        numRange[10]++;
                    }
                }
            }

            //Add colors and strings to the Arrays
            for (index = 0; index < cGrade.Length; index++)
            {
                //Gerate random colors and make sure they are not already in the array
                do
                {
                    cStore = Color.FromArgb(rColor.Next(0, 255), rColor.Next(0, 255), rColor.Next(0, 255));
                }while (cGrade.Contains(cStore));

                //Add the color to the Array
                cGrade[index] = cStore;

                //Add the strings to the Array depending on the Index
                if (index == 0)
                {
                    //If it the first Index store 0 to 9 in the Array
                    stringRange[index] = $"0 to 9";
                }
                else if (index == cGrade.Length - 1)
                {
                    //If it the Last index store the index number follow by a zero in the Array
                    stringRange[index] = $"{index}0";
                }
                else
                {
                    //Any other Index store {index}0 to {index}9 to the Array.
                    stringRange[index] = $"{index}0 to {index}9";
                }
            }

            //Draw the Histogram
            for (index = 0; index < numRange.Length; index++)
            {
                //Calculate the width of an bar
                width = 800 / numRange.Length;

                //Draw the bar of the Histogram
                if (numRange[index] != 0)
                {
                    //Calculate the Length of an bar
                    height  = numRange[index];
                    height /= numRange.Max();
                    height *= 580;

                    //Draw the bars and the amount in the Bars
                    Draw.AddRectangle((Convert.ToInt32(width * index)), 580 - Convert.ToInt32(height), Convert.ToInt32(width), Convert.ToInt32(height), cGrade[index], 0);
                    Draw.AddText($"{numRange[index]}", 20, Convert.ToInt32(width * index), Convert.ToInt32((height / 2) + 564 - Convert.ToInt32(height)), Convert.ToInt32(width), 32, Color.Black);
                }

                //draw the labels of the Historgram
                Draw.AddText($"{stringRange[index]}", 12, Convert.ToInt32(width * index), 580, Convert.ToInt32(width), 20, Color.White);
            }
        }