private void UI_timer_Tick(object sender, EventArgs e) { List <Ball> listyMiddle = new List <Ball>(); //Move function for left drawer lock (listyBalls1) { foreach (Ball ball in listyBalls1) { ball.Move(); } //Compares all balls in a list in left window foreach (Ball A in listyBalls1) { foreach (Ball B in listyBalls1) { if (!(Ball.ReferenceEquals(A, B))) //Do NOT Compare to self { if (A.Equals(B)) //If the balls overlap then add to a temporary list { listyMiddle.Add(A); } } } } } lock (listyMiddle) { foreach (Ball item in listyMiddle) { listyBalls1.Remove(item); //remove balls that have touched } foreach (Ball item in listyMiddle) { listyBalls2.Add(item); } } //Clear lef drawer and move the balls and render the left drawer canvas1.Clear(); lock (listyBalls1) { foreach (Ball ball in listyBalls1) { ball.Render(canvas1); } } canvas1.AddText("Left Count: " + listyBalls1.Count, 15, 75, 550, 200, 30, Color.LawnGreen); canvas1.Render(); //Move the right list lock (listyBalls2) { foreach (Ball item in listyBalls2) { item.Move(); item.highlightFlag = false; foreach (Ball b1 in listyBalls2) { foreach (Ball b2 in listyBalls2) { if (!(Ball.ReferenceEquals(b1, b2))) { if (b1.Equals(b2)) { b1.highlightFlag = true; } } } } } canvas2.Clear(); foreach (Ball ball in listyBalls2) { ball.Render(canvas2); } } canvas2.AddText("Right Count: " + listyBalls2.Count, 15, 75, 550, 200, 30, Color.LawnGreen); canvas2.Render(); }
// Biased Grid Traverse Thread private void BiasedTraverse() { int steps = 0; CDrawer canvas = new CDrawer(WIDTH, HEIGHT); int[,] grid = new int[X_MAX, Y_MAX]; // 2D backing array of color intensity for the grid Point current = new Point(0, 0); Point previous = new Point(0, 0); // List of valid biased movements List <Point> nextPossiblePoint = new List <Point>() { current }; // List of all points not travelled to List <Point> HaveNotTraversed = new List <Point>(); canvas.Scale = BLOCKSIZE; // Initialization: each grid location with base color intensity // and include all points as not travelled to for (int x = 0; x < X_MAX; ++x) { for (int y = 0; y < Y_MAX; ++y) { grid[x, y] = BASE_RGB_VALUE; HaveNotTraversed.Add(new Point(x, y)); } } while (HaveNotTraversed.Count > 0) { ++steps; HaveNotTraversed.Remove(current); // Increment intensity of current color to max of 255 grid[current.X, current.Y] = grid[current.X, current.Y] + 25 > 255 ? 255 : grid[current.X, current.Y] + 25; // Draw previous point in yellow if (steps != 1) { canvas.SetBBScaledPixel(previous.X, previous.Y, Color.FromArgb(grid[previous.X, previous.Y], grid[previous.X, previous.Y], 0)); } // Draw current point in red canvas.SetBBScaledPixel(current.X, current.Y, Color.Red); previous = current; // Clear list and update biased travel directions and move nextPossiblePoint.Clear(); nextPossiblePoint = ClosestSpace(current, HaveNotTraversed); if (nextPossiblePoint.Count > 0) { current = nextPossiblePoint[_rnd.Next(0, nextPossiblePoint.Count)]; } } // Display number of steps to complete travel canvas.AddText(steps.ToString() + " Steps Taken", 25, Color.Blue); try { Invoke(new delVoidInt(UpdateUI), steps); } catch { System.Diagnostics.Trace.WriteLine("Target thread is dead"); } }
// Set up playing window public static void PlayWindow(ref CDrawer HangingPost, string title) { title = title.ToUpper(); int length = title.Length; LetterButtons(ref HangingPost); if (length <= 20) { int xpos = 300; int ypos = 200; foreach (char ch in title) { if (char.IsLetter(ch)) { HangingPost.AddText("_", 28, xpos, ypos, 28, 28, Color.Black); } else { HangingPost.AddText(ch.ToString(), 24, xpos, ypos - 4, 24, 24, Color.Black); } xpos += 28; } } else if (length < 35) { // Search for space in title close to index 15, and split string into 2 string line1, line2; int space_index = title.IndexOf(' ', 15); if (space_index > 20 || space_index == -1) { space_index = title.IndexOf(' ', 13); if (space_index > 20) { space_index = title.IndexOf(' ', 11); //This is worst case.... I think. } } line1 = title.Substring(0, space_index); line2 = title.Substring(space_index); int xpos = 300; int ypos1 = 200; int ypos2 = 260; foreach (char ch in line1) { if (char.IsLetter(ch)) { HangingPost.AddText("_", 28, xpos, ypos1, 28, 28, Color.Black); } else { HangingPost.AddText(ch.ToString(), 22, xpos, ypos1 - 4, 24, 24, Color.Black); } xpos += 28; } xpos = 300 - 28; foreach (char ch in line2) { if (char.IsLetter(ch)) { HangingPost.AddText("_", 28, xpos, ypos2, 28, 28, Color.Black); } else { HangingPost.AddText(ch.ToString(), 22, xpos, ypos2 - 4, 24, 24, Color.Black); } xpos += 28; } } else if (length <= 55) { string line1, line2, line3; int space_index1, space_index2; space_index1 = title.IndexOf(' ', 15); if (space_index1 > 20 || space_index1 == -1) { space_index1 = title.IndexOf(' ', 12); if (space_index1 > 20) { space_index1 = title.IndexOf(' ', 10); //This really should never happen.... } } space_index2 = title.IndexOf(' ', space_index1 + 20); if (space_index2 > space_index1 + 20) { space_index2 = title.IndexOf(' ', space_index1 + 15); if (space_index2 > space_index1 + 20) { space_index2 = title.IndexOf(' ', space_index1 + 10); } } line1 = title.Substring(0, space_index1); line2 = title.Substring(space_index1, space_index2 - space_index1); line3 = title.Substring(space_index2); int xpos = 300; int ypos1 = 180; int ypos2 = 240; int ypos3 = 300; foreach (char ch in line1) { if (char.IsLetter(ch)) { HangingPost.AddText("_", 28, xpos, ypos1, 28, 28, Color.Black); } else { HangingPost.AddText(ch.ToString(), 22, xpos, ypos1 - 4, 24, 24, Color.Black); } xpos += 28; } xpos = 300 - 28; foreach (char ch in line2) { if (char.IsLetter(ch)) { HangingPost.AddText("_", 28, xpos, ypos2, 28, 28, Color.Black); } else { HangingPost.AddText(ch.ToString(), 22, xpos, ypos2 - 4, 24, 24, Color.Black); } xpos += 28; } xpos = 300 - 28; foreach (char ch in line3) { if (char.IsLetter(ch)) { HangingPost.AddText("_", 28, xpos, ypos3, 28, 28, Color.Black); } else { HangingPost.AddText(ch.ToString(), 22, xpos, ypos3 - 4, 24, 24, Color.Black); } xpos += 28; } } HangingPost.Render(); }
public void GameThread() { Load(); List <Tree> _TreesToLightOnFire = new List <Tree>(); List <Entity> _RemoveEntities = new List <Entity>(); _Embers = new List <Ember>(); WIND = new Point(_RNG.Next(-5, 5), _RNG.Next(-5, 5)); while (RUN) { //--------------- WIND ------------------------- if (RANDOM_WIND) { if (_RNG.NextDouble() < 0.1) { Point NewWind = new Point(_RNG.Next(-1, 1), _RNG.Next(-1, 1)); WIND = new Point(WIND.X + NewWind.X, WIND.Y + NewWind.Y); } } _Canvas.AddText(String.Format("WIND: X: {0}, Y: {1}", WIND.X, WIND.Y), 10, 0, 10, 150, 10, Color.White); _Snapshot.Add(_Entities); //-------------- MAIN GAME LOGIC--------------------------------- foreach (Tree current in _Entities) { if (current.onFire) { //project a radius and determine if any tree is within its range /* * foreach(Tree other in _Entities) * { * //do not compare same tree * if (current.Equals(other) || other.onFire) * continue; * * * //if "other" tree is within distance of current tree * if (Tree.Distance(current, other) <= current.radiusOfFire/2) * { * //OTHER has a % chance of catching fire * if (_RNG.NextDouble() < 0.005) * { * _TreesToLightOnFire.Add(other); * } * } * } * */ // 0.5% chance to Spawn an "Ember" if (_RNG.NextDouble() < 0.05) { //spawn ember _Embers.Add(new Ember(current.pos)); } if (current.life <= 0) { _RemoveEntities.Add(current); } else { current.life = current.life - 1; } } } foreach (Ember e in _Embers) { e.Move(WIND); foreach (Tree t in _Entities) { //if tree is within distance of ember if (Tree.Distance(e, t) <= t.size) { //OTHER has a % chance of catching fire if (_RNG.NextDouble() < 0.05) { _TreesToLightOnFire.Add(t); _RemoveEntities.Add(e); } } if (e.life <= 0) { _EmbersToRemove.Add(e); } } } foreach (Tree t in _TreesToLightOnFire) { t.onFire = true; TREESONFIRE++; } foreach (Entity e in _RemoveEntities) { _Entities.Remove(e); } foreach (Ember e in _EmbersToRemove) { _Embers.Remove(e); } //Console.WriteLine("trees on fire {0}", TREESONFIRE); _TreesToLightOnFire.Clear(); _RemoveEntities.Clear(); _EmbersToRemove.Clear(); Thread.Sleep(100); Display(); } }
/// <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; } }
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; } } } }
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(); }
//********************************************************************* //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); } }
public void Render() { _canvas.AddCenteredEllipse((int)_point.X, (int)_point.Y, Radius * 2, Radius * 2, Color, 2, Color.White); //_canvas.AddText(GetCount.ToString(), 15, (int)_point.X - 30, (int)_point.Y - 30, 60, 60, Color.Black); _canvas.AddText(GetCount.ToString(), 20, new Rectangle(new Point(PointProperty.X - Radius, PointProperty.Y - Radius), new Size(Radius * 2, Radius * 2)), Color.Black); }
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(); }