//[Make List] //extract the divisor as an integer.Using that divisor and the ScaledWidth and ScaledHeight of the CDrawer //use nested for() loops to generate all possible Points within the CDrawer window (based on the divisor increments) private void MakeList_Click(object sender, EventArgs e) { int divisor = (int)divisorUpDown.Value; //nested loops to generate all points in cdrawer for (int y = 0; y < drawer.ScaledHeight; y += divisor) //y vals { for (int x = 0; x < drawer.ScaledWidth; x += divisor) //x vals { ptr.Add(new Point(x, y)); } } //once list has been populated , clear the drawer drawer.Clear(); //itterate through list points while drawing fuchsia lines between all adjcent points for (int i = 1; i < ptr.Count; i++) { if (i != 1) { drawer.AddLine(ptr[i - 1].X, ptr[i - 1].Y, ptr[i].X, ptr[i].Y, Color.Fuchsia); } } //render drawn lines drawer.Render(); //display number of points in list ListButton.Text = $"List contains: {ptr.Count} points"; }
//occurs when the button is pressed //launches the difficulty selection screen, sets the difficulty private void StartButton_Click(object sender, EventArgs e) { // create difficulty modal and set difficulty var gameDifficulty = new GameDifficulty(); gameDifficulty.selection = _setting; // if ok was pressed if (DialogResult.OK == gameDifficulty.ShowDialog()) { // get difficulty from user _setting = gameDifficulty.selection; // load leaders from save LoadLeaders(_leaderBoardFileName[0]); // clear list and gdi make a list and initalize score to 0 _draw.Clear(); _lettersList.Clear(); GenList(); _scoreTotal = 0; score.Text = _scoreTotal.ToString(); // sets game to running, disable buttons and enable others _gameover = false; StartButton.Enabled = false; PauseButton.Enabled = true; EndBtn.Enabled = true; // make and start the thread threadAnimate = new Thread(new ThreadStart(Animation)); threadAnimate.IsBackground = true; threadAnimate.Start(); } }
private void UI_List_Butt_Click(object sender, EventArgs e) { pointList.Clear(); while (pointList.Count != ((canvas.ScaledWidth / (int)UI_NumUpDown.Value) * (canvas.ScaledHeight / (int)UI_NumUpDown.Value))) { Point newPoint = new Point(rng.Next(0, (canvas.ScaledWidth / (int)UI_NumUpDown.Value)) * (int)UI_NumUpDown.Value, rng.Next(0, (canvas.ScaledHeight / (int)UI_NumUpDown.Value)) * (int)UI_NumUpDown.Value); if (pointList.Count == 0) { pointList.Add(newPoint); } else { if (!pointList.Contains(newPoint)) { pointList.Add(newPoint); } } } canvas.Clear(); for (int i = 0; i < pointList.Count - 1; i++) { canvas.AddLine(pointList[i].X, pointList[i].Y, pointList[i + 1].X, pointList[i + 1].Y, Color.Magenta); } canvas.Render(); Text = "Made N Points"; UI_List_Butt.Text = "List contains: " + pointList.Count + " points"; }
//on button click provide a distinct set of shapes private void _btnDistinct_Click(object sender, EventArgs e) { shapes = shapes.Distinct().ToList(); _drawer.Clear(); render(); _drawer.Render(); }
private void B_Play_Click(object sender, EventArgs e) { //reset difficult, final score, and total ball dead int Level = 0; totalScore = 0; totalBallDead = 0; //open the SelectLvl dialog if (dlg_select.ShowDialog() == DialogResult.OK) { //get the difficult modeLVL = dlg_select.lvlSelection(); //check the chosen difficult and set the color for ball if (modeLVL == "Easy") { Level = 3; } else if (modeLVL == "Medium") { Level = 4; } else { Level = 5; } //check if canvas is null or not if (canvas == null) { canvas = new CDrawer(); } else { canvas.Clear(); } //create a random color ball and store it in array of ball location Randomize(Level); //draw balls Display(); B_Play.Enabled = false; Timer.Enabled = true; } }
// Main Menu Screen public static void MainMenu(ref CDrawer HangingPost) { bool play_game = false; Point click; HangingPost.Clear(); ////Draw hanged man, can use this for reference later //HangingPost.AddCenteredEllipse(270, 215, 50, 50, Color.Black); //head //HangingPost.AddLine(250, 215, 245, 285, Color.Black, 5); //torso //HangingPost.AddLine(250, 215, 230, 305, Color.Black, 5); //right arm //HangingPost.AddLine(250, 215, 270, 305, Color.Black, 5); //left arm //HangingPost.AddLine(245, 285, 230, 365, Color.Black, 5); //right leg //HangingPost.AddLine(245, 285, 265, 365, Color.Black, 5); //left leg ////Add peanut gallery //AddStickMan(60, 380, "Black", ref HangingPost, true); //AddStickMan(160, 420, "Black", ref HangingPost, true); //AddStickMan(300, 400, "Black", ref HangingPost, true); //AddStickMan(420, 420, "Black", ref HangingPost, true); //HangingPost.AddText("Let's Hang Someone!", 36, 0, 0, 800, 100, Color.DarkRed); //PG VERSION of Hangman HangingPost.AddCenteredEllipse(250, 245, 60, 60, Color.Empty, 5, Color.Black); //head HangingPost.AddLine(250, 275, 250, 350, Color.Black, 5); //torso HangingPost.AddLine(250, 275, 220, 360, Color.Black, 5); //left arm HangingPost.AddLine(250, 275, 280, 360, Color.Black, 5); //right arm HangingPost.AddLine(250, 350, 230, 460, Color.Black, 5); //left leg HangingPost.AddLine(250, 350, 270, 460, Color.Black, 5); //right leg HangingPost.AddText("Let's Play Hangman!", 36, 0, 0, 800, 100, Color.DarkRed); HangingPost.AddText("Click anywhere to begin...", 12, 200, 500, 800, 100); HangingPost.Render(); while (!play_game) { if (HangingPost.GetLastMouseLeftClick(out click)) { play_game = true; } } HangingPost.Clear(); //// Idle peanut gallery //AddStickMan(60, 380, "Black", ref HangingPost, false); //AddStickMan(160, 420, "Black", ref HangingPost, false); //AddStickMan(300, 400, "Black", ref HangingPost, false); //AddStickMan(420, 420, "Black", ref HangingPost, false); HangingPost.Render(); }
private void Animate(object ListOBalls) { //Quick and dirty erase everything (could get fancy and overwrite //existing balls with black just before move and redraw, but that's //probably premature optimization). if (!(ListOBalls is List <Ball> Balls)) { return; //What is this thing? } while (true) //Forevs, unless parent thread goes away. { canvas.Clear(); //My kingdom for a foreach with mutable list elements for (int i = 0; i < Balls.Count; ++i) { Ball b = Balls[i]; //Move first. That makes sure everything is on the canvas. b.Move();//This changes b! no other threads should be changing b, or I need to do more. canvas.AddCenteredEllipse((int)b.Location.X, (int)b.Location.Y, b.Size, b.Size, b.Color); } //Show the pretty thingees canvas.Render(); Thread.Sleep(delay); } }
public static void DrawWorldMap(Location CurrentLocation) { CDrawer Canvas = new CDrawer(1000, 1000); Canvas.Clear(); Canvas.Scale = 50; int[] cordarray = new int[2] { 0, 0 }; for (int row = 0; row < MapArray.GetLength(0); row++) { for (int columb = 0; columb < MapArray.GetLength(1); columb++) { foreach (Location locals in Locations) { if (locals.Coordinates.SequenceEqual(cordarray)) { Canvas.SetBBScaledPixel(row, columb, Color.Red); Canvas.AddText(locals.Name, 10, row, columb, 1, 1, Color.White); } if (CurrentLocation.Coordinates.SequenceEqual(cordarray)) { Canvas.SetBBScaledPixel(row, columb, Color.Green); } } cordarray[1]++; } cordarray[1] = 0; cordarray[0]++; } }
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]++; } }
private void Animate(object ListOShapes) { //Quick and dirty erase everything (could get fancy and overwrite //existing Shapes with black just before move and redraw, but that's //probably premature optimization). if (!(ListOShapes is List <Shape> Shapes)) { return; //What is this thing? } while (true) //Forevs, unless parent thread goes away. { if (cbErase.Checked) { canvas.Clear(); } //My kingdom for a foreach with mutable list elements lock (Shapes) {//Added because my event handlers could crossthread for (int i = 0; i < Shapes.Count; ++i) { Shape s = Shapes[i]; //Move first. That makes sure everything is on the canvas. s.Move();//This changes b! no other threads should be changing b, or I need to do more. s.Render(canvas); } } //Show the pretty thingees canvas.Render(); Thread.Sleep(delay); } }
private void Display() { _Canvas.Clear(); foreach (Tree e in _Entities) { if (DEBUG_FLAG) { if (e.onFire) { Color redtransparent; if (_RNG.Next(0, 100) < 50) { redtransparent = Color.FromArgb(40, Color.Red); } else { redtransparent = Color.FromArgb(40, Color.Orange); } _Canvas.AddCenteredEllipse(e.pos.X, e.pos.Y, e.radiusOfFire, e.radiusOfFire, redtransparent); } } _Canvas.AddCenteredEllipse(e.pos.X, e.pos.Y, e.size, e.size, e.color); } foreach (Ember e in _Embers) { _Canvas.AddCenteredEllipse(e.pos.X, e.pos.Y, e.size, e.size, e.color); } _Canvas.Render(); }
/// <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(); }
private void casio_Tick(object sender, EventArgs e) { Point vertex = new Point(); if (Canvas.GetLastMouseLeftClick(out vertex)) { Ball bola = new Ball(Canvas, vertex); foreach (Ball b in LBalls) { bola.MarkOverlap(b); } LBalls.Add(bola); } Canvas.Clear(); foreach (Ball b in LBalls) { b.Render(); } Canvas.Render(); if (Canvas.DrawerWindowSize.IsEmpty) { Application.Exit(); } }
//Take in a canvas and scale, draw all of the blocks public void Render(CDrawer canvas, int Size) { canvas.Clear(); for (int x = 0; x < XLength; x++) { for (int y = 0; y < YLength; y++) { //Ignore nulls and retainer blocks, don't need to render them if (grid[x, y] != null && !(grid[x, y] is RetainerBlock)) { //Centered point Point point = new Point(x * Size + (Size / 2), y * Size + (Size / 2)); //If free block, offset the point by Animation state if (grid[x, y] is FreeBlock && grid[x, y].life != Life.Dying) { point.Y += (Size / 10) * grid[x, y].AnimationState; //Move down 1/10 of the size, per AnimationState } //Get our side length, shrunk by death int sideLength = Size; if (grid[x, y].life == Life.Dying) { // (-10%) * State + Size sideLength = (-(Size / 10)) * grid[x, y].AnimationState + Size; //Shrink by 10% of size for every AnimationState } //Add every block using the point and size we just made canvas.AddCenteredRectangle(point.X, point.Y, sideLength, sideLength, grid[x, y].Colour, 1, Color.Black); } } } canvas.Render(); }
private void btnClear_Click(object sender, EventArgs e) { if (Canvas == null) { return; } Canvas.Clear(); }
private void BallTick_Tick(object sender, EventArgs e) { Point rightClick = new Point(-1, -1); Point leftClick = new Point(-1, -1); PropBall ball; canvas.Clear(); if (canvas.GetLastMouseRightClick(out rightClick)) { ball = new PropBall(rightClick, PropBall.BallColor.Purple); ballList.Add(ball); } if (canvas.GetLastMouseLeftClick(out leftClick)) { ball = new PropBall(leftClick, PropBall.BallColor.Orange); ballList.Add(ball); } for (int ballCount = 0; ballCount < ballList.Count(); ++ballCount) { foreach (PropBall ball2 in ballList) { if (!ball2.Equals(ballList[ballCount])) { if (ball2.GetColor != ballList[ballCount].GetColor) { ballList[ballCount].Love = ball2; } else { ballList[ballCount].Hate = ball2; } } } if (ballList[ballCount].Pos.X < 0 || ballList[ballCount].Pos.X > 800 || ballList[ballCount].Pos.Y < 0 || ballList[ballCount].Pos.Y > 600) { outBound.Add(ballList[ballCount]); } } foreach (PropBall outBall in outBound) { ballList.Remove(outBall); } foreach (PropBall mBall in ballList) { mBall.Render(canvas); } canvas.Render(); }
public void Render() { _canvas.Clear(); foreach (CTile tile in _hashTile) { tile.Render(_canvas); } //_canvas.Render(); }
private void buttonClear_Click(object sender, EventArgs e) { for (int x = 0; x < maxX; x++) { for (int y = 0; y < maxY; y++) { updated[x, y] = false; sandArray[x, y] = Type.empty; } } _Canvas.Clear(); }
//name: private void AnimateFallingLetters(Object objData) //purpose: Animates the movements of the letters as they flow through the CDrawer canvas //parameters: Object objData - object that is used to pass in data from main form. objData should be type List<fallingLetter> to work private void AnimateFallingLetters(Object objData) { CDrawer _canvas = new CDrawer(); //starts up a new canvas List <fallingLetter> listCopy = new List <fallingLetter>(); //initializes a fallingLetter list to be used in the background thread //ensures that passed in data is List<fallingLetter> if (objData is List <fallingLetter> ) { //copies the objData into a new list to be manipulated listCopy = (List <fallingLetter>)objData; //loop is used to run the game within, and to ensure that the gameover condition has not been breached while (gameOn) { //loop that is used to pause the game when pause boolean is set to true while (pauseGame) { Thread.Sleep(100); } //clears canvas _canvas.Clear(); //draws new letters to the creen for (int i = 0; i < listCopy.Count; i++) { _canvas.AddText(listCopy[i].letter.ToString(), 20, listCopy[i].xLocation, listCopy[i].yLocation, 40, 40, Color.Yellow); } //moves the letters down one MoveLetters(listCopy); //Passes the updated letter positioning back to the main program as the game is running try { Invoke(new delVoidListStruct(UpdateList), listCopy); } //if there is an error passing information then issue an error message box catch (Exception errListUpdate) { MessageBox.Show($"Error Updating List, Error Message: {errListUpdate}", "Error Message", MessageBoxButtons.OK); } //sleep controls the animation speed, for an amount determined by the trackbar in the showspeedmodeless Thread.Sleep(_animationSpeed); } } //if the game has ended this will display game over if (!gameOn) { _canvas.AddText("GAME OVER", 100, Color.Red); } }
/// <summary> /// balls will move with this /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _timer_Tick(object sender, EventArgs e) { //left click add ball sing point val if (_cDrawer.GetLastMouseLeftClick(out ctr)) { _balls.Add(new ball(ctr)); } //right click clear //clear collections and render gdi to show no shapes if (_cDrawer.GetLastMouseRightClick(out ctr)) { _balls.Clear(); _cDrawer.Clear(); _cDrawer.Render(); } //clear and call methods in respective loop _cDrawer.Clear(); //move balls in collection for (int i = 0; i < _balls.Count; i++) { _balls[i].MoveBall(_cDrawer); } //display every ball in lisy collection foreach (var item in _balls) { item.ShowBall(_cDrawer); } _cDrawer.Render(); //ball position in list //does for all balls for (int i = 0; i < _balls.Count; i++) { this.Text = _balls[i].ToString(); } }
private void Render() { drawSpace.Clear(); lock (ballList) { foreach (ball b in ballList) { b.Render(drawSpace); } } drawSpace.Render(); }
/// <summary> /// render the lights on gdi window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _timer_Tick(object sender, EventArgs e) { _cDrawer.Clear(); foreach (var item in _trekLampsList) { item.Tick(); } for (int i = 0; i < _trekLampsList.Count; i++) { _trekLampsList[i].RenderLamp(_cDrawer, i); } _cDrawer.Render(); }
private void Render() { _canvas.Clear(); foreach (LinkedList <LineSeg> lineSeg in _lineStack) { foreach (LineSeg line in lineSeg) { line.Render(_canvas); } } UpdateInfo(); }
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(); } }
// 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); } } } }
private void timer1_Tick(object sender, EventArgs e) { canvas.Clear(); foreach (Shape s in _shapes) { if (s is AniShape) { AniShape ani_s = (AniShape)s; ani_s.Tick(); } s.Render(canvas); } canvas.Render(); }
// give each member of _llStorage a rectangle, where they render it on the canvas. public void Render() { if (_llStorage.Count == 0) // don't try to render an empty collection { return; } float iRectWidth = (float)_canvas.m_ciWidth / _llStorage.Count; // this makes rectangle width fit canvas _canvas.Clear(); for (int i = 0; i < _llStorage.Count; i++) { // position each rectangle beside each other. Rectangle rRect = new Rectangle((int)(i * iRectWidth), 0, (int)iRectWidth, _canvas.m_ciHeight); this[i].Render(_canvas, rRect); // pass canvas and rect onto each generic's Render method. } _canvas.Render(); }
//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); } } } }
//****************************************************** //Timer Tick Event: Tick and re-render all shapes onto drawer. //****************************************************** private void timer1_Tick_1(object sender, EventArgs e) { //Clear drawer _drawer.Clear(); //Tick _shapes.ForEach(s => { if (s is IAnimate AniS) { AniS.Tick(); } }); //Render _shapes.ForEach(s => s.Render(_drawer)); _drawer.Render(); }
// give each member of _llStorage a rectangle, where they render it on the canvas. public void Render() { if (_llStorage.Count == 0) // don't try to render an empty collection { return; } int iRectWidth = _canvas.m_ciWidth / _llStorage.Count; // this makes rectangle width fit canvas int iCounter = 0; _canvas.Clear(); foreach (T t in _llStorage) // iterate over linked list { // position each rectangle beside each other. Rectangle rRect = new Rectangle(iCounter * iRectWidth, 0, iRectWidth, _canvas.m_ciHeight); t.Render(_canvas, rRect); // pass canvas and rect onto type's constrained Render method. ++iCounter; } _canvas.Render(); }