public void TestAddShape() { Drawing myDrawing = new Drawing(); Assert.AreEqual(0, myDrawing.Count); myDrawing.AddShape(new Rectangle()); myDrawing.AddShape(new Circle()); myDrawing.AddShape(new Line()); Assert.AreEqual(3, myDrawing.Count); }
public void TestAddShape() { Drawing myDrawing = new Drawing (); int count = myDrawing.ShapeCount; Assert.AreEqual (0, count, "Drawing should start with no shapes"); myDrawing.AddShape (new Rectangle ()); myDrawing.AddShape (new Rectangle ()); count = myDrawing.ShapeCount; Assert.AreEqual (2, count, "Adding two shapes should increase the count to 2"); }
public void TestCase() { Drawing myDrawing = new Drawing(); int count = myDrawing.ShapeCount; Assert.AreEqual(0, count, "Drawing should start with no shapess"); myDrawing.AddShape(new Shape()); myDrawing.AddShape(new Shape()); count = myDrawing.ShapeCount; Assert.AreEqual(2, count, "Drawing should have 2 shapess"); }
public void TestAddShape() { Drawing myDrawing = new Drawing(); int count = myDrawing.ShapeCount; Assert.AreEqual(0, count, "Drawing should start with no shapes"); myDrawing.AddShape(new Rectangle()); myDrawing.AddShape(new Rectangle()); count = myDrawing.ShapeCount; Assert.AreEqual(2, count, "Adding two shapes should increase the count to 2"); }
public void RemoveShapeTest() { Drawing drawing = new Drawing(); Rectangle s = new Rectangle(); drawing.AddShape(s); Rectangle sh = new Rectangle(Color.AliceBlue, 100, 100, 50, 50); drawing.AddShape(sh); Assert.AreEqual(2, drawing.ShapeCount); drawing.RemoveShape(sh); Assert.AreEqual(1, drawing.ShapeCount); Assert.False(sh.Selected); }
public void RemoveShapeTest() { Drawing myDrawing = new Drawing(); Shape[] s = { new Rectangle(Color.Red, 25, 25, 50, 50), new Rectangle(Color.Green, 25, 10, 50, 50), new Rectangle(Color.Blue, 10, 25, 50, 50) }; Point2D point = SwinGame.PointAt(26, 26); //no shape in list Assert.AreEqual(myDrawing.Count, 0); //can't be selected because no shape in list Assert.IsFalse(s[0].Selected); //add shape into list myDrawing.AddShape(s[0]); //1 shape in list Assert.AreEqual(myDrawing.Count, 1); myDrawing.SelectShapesAt(point); //select Assert.IsTrue(s[0].Selected); //remove shape from list myDrawing.RemoveShape(s[0]); //no shape in list because removed Assert.AreEqual(myDrawing.Count, 0); myDrawing.SelectShapesAt(point); //can't be selected at point Assert.IsFalse(s[0].Selected, "should be false"); }
public void TestSelectShape() { Drawing myDrawing = new Drawing(); Shape[] testShapes = { new Rectangle(Color.Red, 25, 25, 50, 50), new Rectangle(Color.Green, 25, 10, 50, 50), new Rectangle(Color.Blue, 10, 25, 50, 50) }; foreach(Shape s in testShapes) myDrawing.AddShape( s ); List<Shape> selected; Point2D point; point = SwinGame.PointAt( 70, 70 ); myDrawing.SelectShapesAt( point ); selected = myDrawing.SelectedShapes; CollectionAssert.Contains( selected, testShapes[0] ); Assert.AreEqual( 1, selected.Count ); point = SwinGame.PointAt( 70, 50 ); myDrawing.SelectShapesAt( point ); selected = myDrawing.SelectedShapes; CollectionAssert.Contains( selected, testShapes[0] ); CollectionAssert.Contains( selected, testShapes[1] ); Assert.AreEqual( 2, selected.Count ); }
public void TestSelectShape( ) { Drawing myDrawing = new Drawing(); Shape [] testShapes = { new Rectangle(Color.Red, 25, 25, 50, 50), new Rectangle(Color.Green, 25, 10, 50, 50), new Rectangle(Color.Blue, 10, 25, 50, 50) }; foreach (Shape s in testShapes) { myDrawing.AddShape(s); } List <Shape> Selected; Point2D point; point = SwinGame.PointAt(70, 70); myDrawing.SelectShapeAt(point); Selected = myDrawing.SelectedShape; CollectionAssert.Contains(Selected, testShapes [0]); Assert.AreEqual(1, Selected.Count); point = SwinGame.PointAt(70, 50); myDrawing.SelectShapeAt(point); Selected = myDrawing.SelectedShape; CollectionAssert.Contains(Selected, testShapes [0]); CollectionAssert.Contains(Selected, testShapes [1]); Assert.AreEqual(2, Selected.Count); }
public void TestRemoveShape( ) { Drawing myDrawing = new Drawing(); Shape[] testShapes = { new Rectangle(Color.Red, 25, 25, 50, 50), new Rectangle(Color.Green, 25, 10, 50, 50), new Rectangle(Color.Blue, 10, 25, 50, 50) }; Point2D point; List <Shape> selected; Shape shapeRemoved = testShapes [1]; foreach (Shape s in testShapes) { myDrawing.AddShape(s); } point = SwinGame.PointAt(25, 10); myDrawing.SelectShapeAt(point); selected = myDrawing.SelectedShape; Assert.AreEqual(3, myDrawing.ShapeCount); CollectionAssert.Contains(selected, shapeRemoved); myDrawing.RemoveShape(shapeRemoved); selected = myDrawing.SelectedShape; myDrawing.SelectShapeAt(point); Assert.AreEqual(2, myDrawing.ShapeCount); CollectionAssert.DoesNotContain(selected, shapeRemoved); }
public static void Main() { Drawing myDrawing = new Drawing(); //Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); SwinGame.ShowSwinGameSplashScreen(); //Run the game loop while (false == SwinGame.WindowCloseRequested()) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.White); SwinGame.DrawFramerate(0, 0); myDrawing.Draw(); //Draw onto the screen SwinGame.RefreshScreen(60); if (SwinGame.MouseClicked(MouseButton.LeftButton)) { SwinGame.FillCircle(Color.AliceBlue, 50, 50, 50); Shape myShape = new Shape(); myShape.X = SwinGame.MouseX(); myShape.Y = SwinGame.MouseY(); myDrawing.AddShape(myShape); } if (SwinGame.KeyTyped(KeyCode.vk_SPACE)) { SwinGame.GUISetBackgroundColor(SwinGame.RandomRGBColor(255)); } if (SwinGame.MouseClicked(MouseButton.RightButton)) { myDrawing.SelectShapesAt(SwinGame.MousePosition()); } if (SwinGame.KeyDown(KeyCode.vk_DELETE)) { foreach (Shape s in myDrawing.SelectedShapes) { myDrawing.RemoveShape(s); } } } }
public static void Main() { //Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); //SwinGame.ShowSwinGameSplashScreen(); Drawing myDrawing = new Drawing(); //Run the game loop while (false == SwinGame.WindowCloseRequested()) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); //Clear the screen and draw the framerate myDrawing.Draw(); SwinGame.DrawFramerate(0, 0); //Button Functions //spawn new shape if (SwinGame.MouseClicked(MouseButton.LeftButton)) { Shape s = new Shape(); s.X = SwinGame.MouseX(); s.Y = SwinGame.MouseY(); myDrawing.AddShape(s); } //randomise background color if (SwinGame.KeyTyped(KeyCode.SpaceKey)) { myDrawing.Background = SwinGame.RandomRGBColor(255); } //select if (SwinGame.MouseClicked(MouseButton.RightButton)) { myDrawing.SelectShapesAt(SwinGame.MousePosition()); } //delete selected if ((SwinGame.KeyTyped(KeyCode.DeleteKey)) || (SwinGame.KeyTyped(KeyCode.BackspaceKey))) { foreach (Shape selectedShape in myDrawing.SelectedShapes()) { myDrawing.RemoveShape(selectedShape); } } //Draw onto the screen SwinGame.RefreshScreen(60); } }
public static void Main() { //Open the game window SwinGame.OpenGraphicsWindow("DrawingProgram", 1600, 900); SwinGame.ShowSwinGameSplashScreen(); Drawing myDrawing = new Drawing(); //Run the game loop while (false == SwinGame.WindowCloseRequested()) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); if (SwinGame.MouseClicked(MouseButton.LeftButton)) { myDrawing.AddShape(new Shape((int)SwinGame.MousePosition().X, (int)SwinGame.MousePosition().Y)); } if (SwinGame.KeyDown(KeyCode.SpaceKey)) { myDrawing.Background = SwinGame.RandomRGBColor(255); } if (SwinGame.KeyDown(KeyCode.DeleteKey) || SwinGame.KeyDown(KeyCode.BackspaceKey)) { myDrawing.DeleteSelectedShapes(); } if (SwinGame.MouseClicked(MouseButton.RightButton)) { myDrawing.SelectShapesAt(SwinGame.MousePosition()); } //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.White); myDrawing.Draw(); SwinGame.DrawFramerate(0, 0); //Draw onto the screen SwinGame.RefreshScreen(60); } }
public void TestRemoveShape() { Drawing myDrawing = new Drawing (); Rectangle myShape1 = new Rectangle (Color.Red, 100, 100, 10, 50); Rectangle myShape2 = new Rectangle (Color.Green, 100, 100, 50, 50); Rectangle myShape3 = new Rectangle (Color.Blue, 100, 100, 50, 10); myDrawing.AddShape (myShape1); myDrawing.AddShape (myShape2); myDrawing.AddShape (myShape3); Point2D pt = SwinGame.PointAt (100, 100); Assert.AreEqual (3, myDrawing.ShapeCount); myDrawing.RemoveShape (myShape2); Assert.AreEqual (2, myDrawing.ShapeCount); myDrawing.SelectShapesAt(pt); Assert.IsFalse (myShape2.Selected); }
public static void Main() { //Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); SwinGame.ShowSwinGameSplashScreen(); //Shape myShape = new Shape(); Drawing myDrawing = new Drawing(); //Run the game loop while (false == SwinGame.WindowCloseRequested()) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); // If the user clicks the LeftButton on their mouse, set the shapes x, y to be at the mouse's position if (SwinGame.MouseClicked(MouseButton.LeftButton)) { myDrawing.AddShape(new Shape((int)SwinGame.MousePosition().X, (int)SwinGame.MousePosition().Y)); } if (SwinGame.MouseClicked(MouseButton.RightButton)) { myDrawing.SelectShapeAt(SwinGame.MousePosition()); } if (SwinGame.KeyTyped(KeyCode.SpaceKey)) { myDrawing.Background = SwinGame.RandomRGBColor(255); } if ((SwinGame.KeyTyped(KeyCode.DeleteKey)) | (SwinGame.KeyTyped(KeyCode.BackspaceKey))) { myDrawing.DeleteShapes(); } //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.White); myDrawing.Draw(); SwinGame.DrawFramerate(0, 0); //Draw onto the screen SwinGame.RefreshScreen(60); } }
public static void Main() { Drawing draw = new Drawing(); //Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); SwinGame.ShowSwinGameSplashScreen(); //Run the game loop while (SwinGame.WindowCloseRequested() == false) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.White); if (SwinGame.MouseClicked(MouseButton.LeftButton)) { Shape shape = new Shape(); shape.X = SwinGame.MouseX(); shape.Y = SwinGame.MouseY(); draw.AddShape(shape); } if (SwinGame.MouseClicked(MouseButton.RightButton)) { draw.SelectShapesAt(SwinGame.MousePosition()); } if (SwinGame.KeyTyped(KeyCode.vk_DELETE) || SwinGame.KeyTyped(KeyCode.vk_BACKSPACE)) { foreach (Shape shape in draw.SelectedShapes) { draw.RemoveShape(shape); } } if (SwinGame.KeyTyped(KeyCode.vk_SPACE)) { draw.Background = SwinGame.RandomRGBColor(255); } SwinGame.DrawFramerate(0, 0); //Draw onto the screen SwinGame.RefreshScreen(60); } }
public static void Main() { Drawing myDrawing = new Drawing(); ShapeKind KindToAdd = ShapeKind.Circle; //Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); SwinGame.ShowSwinGameSplashScreen(); //Run the game loop while (SwinGame.WindowCloseRequested() == false) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); //Clear the screen and myDrawing the framerate SwinGame.ClearScreen(Color.White); if (SwinGame.KeyTyped(KeyCode.vk_r)) { KindToAdd = ShapeKind.Rectangle; } else if (SwinGame.KeyTyped(KeyCode.vk_c)) { KindToAdd = ShapeKind.Circle; } else if (SwinGame.KeyTyped(KeyCode.vk_l)) { KindToAdd = ShapeKind.Line; } if (SwinGame.MouseClicked(MouseButton.LeftButton)) { Shape newShape; switch (KindToAdd) { case ShapeKind.Circle: newShape = new Circle(); break; case ShapeKind.Rectangle: newShape = new Rectangle(); break; case ShapeKind.Line: newShape = new Line(); break; default: newShape = new Rectangle(); break; } newShape.X = SwinGame.MouseX(); newShape.Y = SwinGame.MouseY(); myDrawing.AddShape(newShape); } if (SwinGame.MouseClicked(MouseButton.RightButton)) { myDrawing.SelectShapesAt(SwinGame.MousePosition()); } if (SwinGame.KeyTyped(KeyCode.vk_DELETE) || SwinGame.KeyTyped(KeyCode.vk_BACKSPACE)) { foreach (Shape shape in myDrawing.SelectedShapes) { myDrawing.RemoveShape(shape); } } if (SwinGame.KeyTyped(KeyCode.vk_SPACE)) { myDrawing.Background = SwinGame.RandomRGBColor(255); } myDrawing.Draw(); SwinGame.DrawFramerate(0, 0); //myDrawing onto the screen SwinGame.RefreshScreen(60); } }
public static void Main() { //Register shapes Shape.RegisterShape("Retangle", typeof(Rectangle)); Shape.RegisterShape("Circle", typeof(Circle)); Shape.RegisterShape("Line", typeof(Line)); //Open the game window SwinGame.OpenGraphicsWindow("DrawingProgram", 1600, 900); SwinGame.ShowSwinGameSplashScreen(); ShapeKind kindToAdd = ShapeKind.Circle; Drawing myDrawing = new Drawing(); //Run the game loop while (false == SwinGame.WindowCloseRequested()) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); if (SwinGame.MouseClicked(MouseButton.LeftButton)) { Shape newShape; int x = (int)SwinGame.MouseX(); int y = (int)SwinGame.MouseY(); if (kindToAdd == ShapeKind.Circle) { Circle newCircle = new Circle(); newShape = newCircle; } else if (kindToAdd == ShapeKind.Line) { Line newLine = new Line(); newShape = newLine; } else { Rectangle newRect = new Rectangle(); newShape = newRect; } newShape.X = x; newShape.Y = y; myDrawing.AddShape(newShape); } if (SwinGame.KeyDown(KeyCode.SKey)) { myDrawing.Save("C:\\Users\\Mikan\\Desktop\\TestDrawing.txt"); } if (SwinGame.KeyDown(KeyCode.OKey)) { myDrawing.Load("C:\\Users\\Mikan\\Desktop\\TestDrawing.txt"); } if (SwinGame.KeyDown(KeyCode.LKey)) { kindToAdd = ShapeKind.Line; } if (SwinGame.KeyDown(KeyCode.RKey)) { kindToAdd = ShapeKind.Rectangle; } if (SwinGame.KeyDown(KeyCode.CKey)) { kindToAdd = ShapeKind.Circle; } if (SwinGame.KeyDown(KeyCode.SpaceKey)) { myDrawing.Background = SwinGame.RandomRGBColor(255); } if (SwinGame.KeyDown(KeyCode.DeleteKey) || SwinGame.KeyDown(KeyCode.BackspaceKey)) { myDrawing.DeleteSelectedShapes(); } if (SwinGame.MouseClicked(MouseButton.RightButton)) { myDrawing.SelectShapesAt(SwinGame.MousePosition()); } //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.White); myDrawing.Draw(); SwinGame.DrawFramerate(0, 0); //Draw onto the screen SwinGame.RefreshScreen(60); } }
public static void Main() { //Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); SwinGame.ShowSwinGameSplashScreen(); //Shape myShape = new Shape(); Drawing myDrawing = new Drawing(); ShapeKind kindToAdd = ShapeKind.Circle; //Run the game loop while (false == SwinGame.WindowCloseRequested()) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); if (SwinGame.KeyTyped(KeyCode.RKey)) { kindToAdd = ShapeKind.Rectangle; } if (SwinGame.KeyTyped(KeyCode.CKey)) { kindToAdd = ShapeKind.Circle; } if (SwinGame.KeyTyped(KeyCode.LKey)) { kindToAdd = ShapeKind.Line; } // If the user clicks the LeftButton on their mouse, set the shapes x, y to be at the mouse's position if (SwinGame.MouseClicked(MouseButton.LeftButton)) { Shape newShape; float x = SwinGame.MouseX(); float y = SwinGame.MouseY(); if (kindToAdd == ShapeKind.Circle) { Circle newCircle = new Circle(); newShape = newCircle; } else if (kindToAdd == ShapeKind.Rectangle) { Rectangle newRect = new Rectangle(); newShape = newRect; } else { Line newLine = new Line(); newShape = newLine; } newShape.X = x; newShape.Y = y; myDrawing.AddShape(newShape); } if (SwinGame.MouseClicked(MouseButton.RightButton)) { myDrawing.SelectShapeAt(SwinGame.MousePosition()); } if (SwinGame.KeyTyped(KeyCode.SpaceKey)) { myDrawing.Background = SwinGame.RandomRGBColor(255); } if ((SwinGame.KeyTyped(KeyCode.DeleteKey)) | (SwinGame.KeyTyped(KeyCode.BackspaceKey))) { myDrawing.DeleteShapes(); } //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.White); myDrawing.Draw(); SwinGame.DrawFramerate(0, 0); //Draw onto the screen SwinGame.RefreshScreen(60); } }
public static void Main() { Drawing myDrawing = new Drawing(); ShapeKind kindToAdd = ShapeKind.Circle; //Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); SwinGame.ShowSwinGameSplashScreen(); //Run the game loop while (false == SwinGame.WindowCloseRequested()) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.White); SwinGame.DrawFramerate(0, 0); myDrawing.Draw(); //Draw onto the screen SwinGame.RefreshScreen(60); if (SwinGame.MouseClicked(MouseButton.LeftButton)) { Shape newShape; if (kindToAdd == ShapeKind.Circle) { Circle newCircle = new Circle(); newShape = newCircle; } else if (kindToAdd == ShapeKind.Line) { Line newLine = new Line(); newShape = newLine; } else { Rectangle newRect = new Rectangle(); newShape = newRect; } myDrawing.AddShape(newShape); } if (SwinGame.KeyTyped(KeyCode.vk_SPACE)) { SwinGame.GUISetBackgroundColor(SwinGame.RandomRGBColor(255)); } if (SwinGame.MouseClicked(MouseButton.RightButton)) { myDrawing.SelectShapesAt(SwinGame.MousePosition()); } if (SwinGame.KeyDown(KeyCode.vk_DELETE)) { foreach (Shape s in myDrawing.SelectedShapes) { myDrawing.RemoveShape(s); } } if (SwinGame.KeyDown(KeyCode.vk_r)) { kindToAdd = ShapeKind.Rectangle; } if (SwinGame.KeyDown(KeyCode.vk_c)) { kindToAdd = ShapeKind.Circle; } if (SwinGame.KeyDown(KeyCode.vk_l)) { kindToAdd = ShapeKind.Line; } } }
public static void Main() { ShapeKind kindToAdd; kindToAdd = ShapeKind.Rectangle; // Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); // SwinGame.ShowSwinGameSplashScreen(); Drawing drawing = new Drawing(); //Run the game loop while (false == SwinGame.WindowCloseRequested()) { // Fetch the next batch of UI interaction SwinGame.ProcessEvents(); // Clear the screen and draw the framerate SwinGame.ClearScreen(drawing.Background); SwinGame.DrawFramerate(0, 0); // Sets shape type based on user input if (Input.KeyTyped(KeyCode.RKey)) { kindToAdd = ShapeKind.Rectangle; } else if (Input.KeyTyped(KeyCode.CKey)) { kindToAdd = ShapeKind.Circle; } else if (Input.KeyTyped(KeyCode.LKey)) { kindToAdd = ShapeKind.Line; } // Sets shapes position from mouse click if (Input.MouseClicked(MouseButton.LeftButton)) { Shape myShape; if (kindToAdd == ShapeKind.Circle) { myShape = new Circle(); } else if (kindToAdd == ShapeKind.Rectangle) { myShape = new Rectangle(); } else { myShape = new Line(); } myShape.X = SwinGame.MouseX(); myShape.Y = SwinGame.MouseY(); drawing.AddShape(myShape); } if (Input.KeyTyped(KeyCode.SpaceKey)) { drawing.Background = SwinGame.RandomRGBColor(255); } if (Input.MouseClicked(MouseButton.RightButton)) { drawing.SelectShapesAt(SwinGame.MousePosition()); } if (Input.KeyTyped(KeyCode.DeleteKey)) { drawing.RemoveShapes(); } if (Input.KeyTyped(KeyCode.SKey)) { drawing.Save(@"C:\Testing\TestDrawing.txt"); } if (Input.KeyTyped(KeyCode.OKey)) { drawing.Load(@"C:\Testing\TestDrawing.txt"); } drawing.Draw(); // Draw onto the screen SwinGame.RefreshScreen(60); } }
public static void Main() { SwinGame.OpenAudio(); SwinGame.OpenGraphicsWindow("GameMain", 800, 600); SwinGame.ShowSwinGameSplashScreen(); Drawing myDrawing = new Drawing(); ShapeKind KindtoAdd = ShapeKind.Circle; while (false == SwinGame.WindowCloseRequested()) { SwinGame.ProcessEvents(); SwinGame.ClearScreen(Color.White); SwinGame.DrawFramerate(0, 0); myDrawing.Draw(); if (Input.KeyTyped(KeyCode.vk_r)) { KindtoAdd = ShapeKind.Rectangle; } if (Input.KeyTyped(KeyCode.vk_c)) { KindtoAdd = ShapeKind.Circle; } if (Input.KeyTyped(KeyCode.vk_l)) { KindtoAdd = ShapeKind.Line; } Point2D mouseLocation = SwinGame.MousePosition(); if (SwinGameSDK.Input.MouseClicked(MouseButton.LeftButton)) { /*Shape myShape = new Shape(); * myShape.Color = SwinGame.RandomRGBColor (255); * myShape.X = SwinGame.MouseX(); * myShape.Y = SwinGame.MouseY(); * myDrawing.AddShape (myShape);*/ Shape newShape = default(Shape); if (KindtoAdd == ShapeKind.Circle) { Circle newCircle = new Circle(); newCircle.X = SwinGame.MouseX(); newCircle.Y = SwinGame.MouseY(); newShape = newCircle; } else if (KindtoAdd == ShapeKind.Rectangle) { Rectangle newRect = new Rectangle(); newRect.X = SwinGame.MouseX(); newRect.Y = SwinGame.MouseY(); newShape = newRect; } else if (KindtoAdd == ShapeKind.Line) { Line newLine = new Line(); newLine.X = SwinGame.MouseX(); newLine.Y = SwinGame.MouseY(); newShape = newLine; } myDrawing.AddShape(newShape); } if (SwinGame.MouseClicked(MouseButton.RightButton)) { myDrawing.SelectShapeAt(SwinGame.MousePosition()); } if (SwinGame.KeyTyped(KeyCode.vk_DELETE)) { List <Shape> selected = myDrawing.SelectedShape; foreach (Shape s in selected) { myDrawing.RemoveShape(s); } } //if (myShape.IsAt (mouseLocation)) //{ if (SwinGame.KeyTyped(KeyCode.vk_SPACE)) { myDrawing.Mybackground = SwinGame.RandomRGBColor(255); } //} SwinGame.DrawFramerate(0, 0); SwinGame.RefreshScreen(); } //End the audio SwinGame.CloseAudio(); //Close any resources we were using SwinGame.ReleaseAllResources(); }
public static void Main() { //Start the audio system so sound can be played SwinGame.OpenAudio(); //Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); SwinGame.ShowSwinGameSplashScreen(); //Run the game loop Drawing myDrawing = new Drawing(); ShapeKind KindToAdd = new ShapeKind(); KindToAdd = ShapeKind.Circle; while (false == SwinGame.WindowCloseRequested()) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.White); myDrawing.Draw(); SwinGame.DrawFramerate(0, 0); // Adds shape if left click if (SwinGame.MouseClicked(MouseButton.LeftButton)) { Shape newShape; if (KindToAdd == ShapeKind.Circle) { Circle newCircle = new Circle(); newCircle.PosX = SwinGame.MouseX(); newCircle.PosY = SwinGame.MouseY(); newShape = newCircle; } else if (KindToAdd == ShapeKind.Rectangle) { Rectangle newRect = new Rectangle(); newRect.PosX = SwinGame.MouseX(); newRect.PosY = SwinGame.MouseY(); newShape = newRect; } else { Line newLine = new Line(); newLine.PosX = SwinGame.MouseX() - 40; newLine.PosY = SwinGame.MouseY(); newLine.PosXEnd = SwinGame.MouseX() + 40; newLine.PosYEnd = SwinGame.MouseY(); newShape = newLine; } myDrawing.AddShape(newShape); } // Selects || Deselects shape if (SwinGame.MouseClicked(MouseButton.RightButton)) { myDrawing.SelectShapesAt(SwinGame.MousePosition()); } // Deletes selected shapes if ((SwinGame.KeyDown(KeyCode.BackspaceKey)) || (SwinGame.KeyDown(KeyCode.DeleteKey))) { myDrawing.RemoveShapes(); } // Changes background color if space pressed. if (SwinGame.KeyDown(KeyCode.SpaceKey)) { myDrawing.Background = SwinGame.RandomColor(); } //Press R change KindToAdd to Rectangle if (SwinGame.KeyDown(KeyCode.RKey)) { KindToAdd = ShapeKind.Rectangle; } //Press C KindToAdd to change to Circle if (SwinGame.KeyDown(KeyCode.CKey)) { KindToAdd = ShapeKind.Circle; } //Press L KindToAdd to change to Line if (SwinGame.KeyDown(KeyCode.LKey)) { KindToAdd = ShapeKind.Line; } if (SwinGame.KeyDown(KeyCode.SKey)) { myDrawing.Save("ShapeSaveFile.txt"); } if (SwinGame.KeyDown(KeyCode.OKey)) { try { myDrawing.Load("ShapeSaveFile.txt"); } catch (Exception e) { Console.WriteLine("Error loading file: {0}", e.Message); } } SwinGame.RefreshScreen(60); } }
public static void Main() { ShapeKind kindToAdd = ShapeKind.Circle; //Start the audio system so sound can be played SwinGame.OpenAudio(); //Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); // SwinGame.ShowSwinGameSplashScreen(); Drawing myDrawing = new Drawing (); //Run the game loop while(false == SwinGame.WindowCloseRequested()) { if (SwinGame.KeyTyped (KeyCode.vk_r)) { kindToAdd = ShapeKind.Rectangle; } if (SwinGame.KeyTyped (KeyCode.vk_c)) { kindToAdd = ShapeKind.Circle; } if (SwinGame.KeyTyped (KeyCode.vk_l)) { kindToAdd = ShapeKind.Line; } //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.White); //Change location of shape if (SwinGame.MouseClicked(MouseButton.LeftButton)) { Shape newShape; if (kindToAdd == ShapeKind.Circle) { Circle newCircle = new Circle (); newShape = newCircle; } else if (kindToAdd == ShapeKind.Rectangle) { Rectangle newRect = new Rectangle (); newShape = newRect; } else { Line newLine = new Line (); newShape = newLine; } newShape.X = SwinGame.MouseX (); newShape.Y = SwinGame.MouseY (); myDrawing.AddShape (newShape); } if (SwinGame.MouseClicked (MouseButton.RightButton)) { myDrawing.SelectShapesAt (SwinGame.MousePosition ()); } //Check if mouse is within shape bounds and spacebar pressed //If true change color of shape to random RGB color if (SwinGame.KeyTyped(KeyCode.vk_SPACE)) { myDrawing.BackgroundColor = SwinGame.RandomRGBColor (255); } if ((SwinGame.KeyTyped (KeyCode.vk_DELETE)) || (SwinGame.KeyTyped (KeyCode.vk_BACKSPACE))) { foreach (Shape s in myDrawing.SelectedShapes) { myDrawing.RemoveShape (s); } } SwinGame.DrawFramerate(0,0); myDrawing.Draw (); //Draw onto the screen SwinGame.RefreshScreen(); } //End the audio SwinGame.CloseAudio(); //Close any resources we were using SwinGame.ReleaseAllResources(); }
public static void Main() { // REGISTER SHAPES: Shape.RegisterShape("Rectangle", typeof(Rectangle)); Shape.RegisterShape("Circle", typeof(Circle)); Shape.RegisterShape("Line", typeof(Line)); // LOCAL VARIABLES: Drawing drawing = new Drawing(); ShapeKind kindToAdd = ShapeKind.Circle; SwinGame.OpenGraphicsWindow("GameMain", 800, 600); SwinGame.ShowSwinGameSplashScreen(); // GAME LOOP: while (SwinGame.WindowCloseRequested() == false) { // Fetch the next batch of UI interaction: SwinGame.ProcessEvents(); // Clear the screen and draw the framerate: SwinGame.ClearScreen(Color.White); // HANDLE INPUT: // Background Color: if (SwinGame.KeyTyped(KeyCode.SpaceKey)) { drawing.Background = SwinGame.RandomRGBColor(255); } // Rectangle: if (SwinGame.KeyTyped(KeyCode.RKey)) { kindToAdd = ShapeKind.Rectangle; } // Circle: if (SwinGame.KeyTyped(KeyCode.CKey)) { kindToAdd = ShapeKind.Circle; } // Line: if (SwinGame.KeyTyped(KeyCode.LKey)) { kindToAdd = ShapeKind.Line; } // Draw: if (SwinGame.MouseClicked(MouseButton.LeftButton)) { // New Shape is created (by default as a Rectangle) Shape newShape = new Rectangle(); // Switch statement reads from ShapeKind enum, and draws // currently selected Shape Type: switch (kindToAdd) { case ShapeKind.Circle: Circle newCircle = new Circle(); newShape = newCircle; break; case ShapeKind.Rectangle: Rectangle newRect = new Rectangle(); newShape = newRect; break; case ShapeKind.Line: Line newLine = new Line(); newShape = newLine; break; } // Apply Mouse Pointer position to Shape's x & y: newShape.X = SwinGame.MouseX(); newShape.Y = SwinGame.MouseY(); drawing.AddShape(newShape); } // Select Shapes at Mouse Position when RMB is clicked: if (SwinGame.MouseClicked(MouseButton.RightButton)) { drawing.SelectShapesAt(SwinGame.MousePosition()); } // Delete Selected Shapes when Backspace key is typed: if (SwinGame.KeyTyped(KeyCode.BackspaceKey)) { drawing.DeleteSelectedShapes(); } // Save all Shapes when S key is typed: if (SwinGame.KeyTyped(KeyCode.SKey)) { try { drawing.Save("Users/andru/Desktop/TestDrawing.txt"); } catch (Exception e) { Console.Error.WriteLine("Error saving to file: {0}", e.Message); } } // Open from Text File when O key is typed: if (SwinGame.KeyTyped(KeyCode.OKey)) { try { drawing.Load("//Users/andru/Desktop/TestDrawing.txt"); } catch (Exception e) { Console.Error.WriteLine("Error loading file: {0}", e.Message); } } // Draw Assets in drawing Object: drawing.Draw(); // Draw Assets on screen: SwinGame.DrawFramerate(0, 0); // Draw onto the screen: SwinGame.RefreshScreen(60); } }
public static void Main() { Shape.RegisterShape("Rectangle", typeof(Rectangle)); Shape.RegisterShape("Circle", typeof(Circle)); Shape.RegisterShape("Line", typeof(Line)); //Start the audio system so sound can be played // SwinGame.OpenAudio(); //Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); // SwinGame.ShowSwinGameSplashScreen(); ShapeKind kindToAdd = ShapeKind.Circle; Drawing mydrawing = new Drawing(); do { mydrawing.FreeList(); SwinGame.ClearScreen(Color.White); SwinGame.DrawFramerate(0, 0); SwinGame.RefreshScreen(); /*Shape s = new Shape ();*/ //Run the game loop while (!SwinGame.WindowCloseRequested()) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.White); SwinGame.DrawFramerate(0, 0); Random rand = new Random(); Shape s = default(Shape); mydrawing.Draw(); if (Input.KeyTyped(KeyCode.vk_r)) { kindToAdd = ShapeKind.Rectangle; } if (Input.KeyTyped(KeyCode.vk_c)) { kindToAdd = ShapeKind.Circle; } if (Input.KeyTyped(KeyCode.vk_l)) { kindToAdd = ShapeKind.Line; } if (Input.KeyTyped(KeyCode.vk_s)) { mydrawing.Save("File.txt"); } if (Input.KeyDown(KeyCode.vk_KP_ENTER)) { try { mydrawing.Load("File.txt"); } catch (Exception e) { Console.Error.WriteLine("Error loading file:{0}", e.Message); } } if (SwinGame.MouseClicked(MouseButton.LeftButton)) { //code written before inheritance // s.X = SwinGame.MouseX (); // s.Y = SwinGame.MouseY (); // done previously when abstract is not done-> // ->Shape newShape = new Shape (); switch (kindToAdd) { case ShapeKind.Circle: Circle newCircle = new Circle(); newCircle.X = SwinGame.MouseX(); newCircle.Y = SwinGame.MouseY(); newCircle.Radius = (int)(rand.NextDouble() * 100); Console.WriteLine("(" + newCircle.X + "," + newCircle.Y + ")"); s = newCircle; break; case ShapeKind.Rectangle: Rectangle newRect = new Rectangle(); newRect.Width = (int)(rand.NextDouble() * 400); newRect.Height = (int)(rand.NextDouble() * 400); newRect.X = SwinGame.MouseX() - newRect.Width / 2; newRect.Y = SwinGame.MouseY() - newRect.Height / 2; Console.WriteLine("(" + newRect.X + "," + newRect.Y + ")"); s = newRect; break; case ShapeKind.Line: Line newLine = new Line(); newLine.X = SwinGame.MouseX(); newLine.Y = SwinGame.MouseY(); // //center of the program is about (400,300) newLine.XEnd = (int)(rand.NextDouble() * 800); newLine.YEnd = (int)(rand.NextDouble() * 600); s = newLine; break; default: break; } mydrawing.AddShape(s); } if (Input.KeyDown(KeyCode.vk_SPACE)) { mydrawing.BackgroundColor = SwinGame.RandomRGBColor(255); } if (SwinGame.MouseClicked(MouseButton.RightButton)) { mydrawing.SelectShapesAt(SwinGame.MousePosition()); //done previously when abstract is not done // if (s is Rectangle) // (s as Rectangle).DrawOutline (); // if (s is Circle) // (s as Circle).DrawOutline (); // else if (s is Line) // (s as Line).DrawOutline (); } foreach (Shape Shapes in mydrawing.SelectedShapes) { if (Input.KeyTyped(KeyCode.vk_BACKSPACE) || Input.KeyTyped(KeyCode.vk_DELETE)) { mydrawing.RemoveShape(Shapes); // if (s is Rectangle) // (s as Rectangle).DrawOutline (); // if (s is Circle) // (s as Circle).DrawOutline (); // else if (s is Line) // (s as Line).DrawOutline (); } } //Draw onto the screen SwinGame.RefreshScreen(); } //End the audio SwinGame.CloseAudio(); //Close any resources we were using SwinGame.ReleaseAllResources(); }while(Input.KeyTyped(KeyCode.vk_z)); }
public static void Main() { //Register shapes Shape.RegisterShape("Rectangle", typeof(Rectangle)); Shape.RegisterShape("Circle", typeof(Circle)); Shape.RegisterShape("Line", typeof(Line)); //Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); SwinGame.ShowSwinGameSplashScreen(); //Shape myShape = new Shape(); Drawing myDrawing = new Drawing(); ShapeKind kindToAdd = ShapeKind.Circle; //Run the game loop while (false == SwinGame.WindowCloseRequested()) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); string _path = @"C:\Users\Klim\Documents\Code\5.3D\TestDrawing.txt"; if (SwinGame.KeyTyped(KeyCode.SKey)) { myDrawing.Save(_path); } if (SwinGame.KeyTyped(KeyCode.OKey)) { try { myDrawing.Load(_path); } catch (Exception e) { Console.Error.WriteLine("Error loadingfile: {0}", e.Message); } } if (SwinGame.KeyTyped(KeyCode.RKey)) { kindToAdd = ShapeKind.Rectangle; } if (SwinGame.KeyTyped(KeyCode.CKey)) { kindToAdd = ShapeKind.Circle; } if (SwinGame.KeyTyped(KeyCode.LKey)) { kindToAdd = ShapeKind.Line; } // If the user clicks the LeftButton on their mouse, set the shapes x, y to be at the mouse's position if (SwinGame.MouseClicked(MouseButton.LeftButton)) { Shape newShape; float x = SwinGame.MouseX(); float y = SwinGame.MouseY(); if (kindToAdd == ShapeKind.Circle) { Circle newCircle = new Circle(); newShape = newCircle; } else if (kindToAdd == ShapeKind.Rectangle) { Rectangle newRect = new Rectangle(); newShape = newRect; } else { Line newLine = new Line(); newShape = newLine; } newShape.X = x; newShape.Y = y; myDrawing.AddShape(newShape); } if (SwinGame.MouseClicked(MouseButton.RightButton)) { myDrawing.SelectShapeAt(SwinGame.MousePosition()); } if (SwinGame.KeyTyped(KeyCode.SpaceKey)) { myDrawing.Background = SwinGame.RandomRGBColor(255); } if ((SwinGame.KeyTyped(KeyCode.DeleteKey)) | (SwinGame.KeyTyped(KeyCode.BackspaceKey))) { myDrawing.DeleteShapes(); } //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.White); myDrawing.Draw(); SwinGame.DrawFramerate(0, 0); //Draw onto the screen SwinGame.RefreshScreen(60); } }
public static void Main() { ShapeKind kindToAdd = ShapeKind.Circle; Drawing drawing = new Drawing(); //Open the game window Core.OpenGraphicsWindow("GameMain", 768, 600); do { if (Core.MouseClicked(MouseButton.RightButton)) { if (Core.MouseClicked(MouseButton.RightButton)) { drawing.SelectedShapesAt(Core.MousePosition()); drawing.Draw(); } } if (Core.MouseClicked(MouseButton.LeftButton)) { Point2D cur_pos = Core.MousePosition(); Shape newShape; if (kindToAdd == ShapeKind.Rectangle) { newShape = new Rectangle(Color.Green, cur_pos.X, cur_pos.Y, 100, 100); drawing.AddShape(newShape); } if (kindToAdd == ShapeKind.Circle) { newShape = new Circle(Color.Blue, cur_pos.X, cur_pos.Y, 50); drawing.AddShape(newShape); } if (kindToAdd == ShapeKind.Line) { newShape = new Line(Color.Red, cur_pos.X, cur_pos.Y); drawing.AddShape(newShape); } drawing.Draw(); } if (Core.KeyTyped(KeyCode.vk_SPACE)) { drawing.backgroundColor = Shape.getRandomColor(); Core.ClearScreen(drawing.backgroundColor); drawing.Draw(); } if (Core.KeyTyped(KeyCode.vk_DELETE) || Core.KeyTyped(KeyCode.vk_BACKSPACE)) { foreach (Shape s in drawing.SelectedShape) { drawing.RemoveShape(s); } drawing.Draw(); } if (Core.KeyTyped(KeyCode.vk_r)) { kindToAdd = ShapeKind.Rectangle; } if (Core.KeyTyped(KeyCode.vk_c)) { kindToAdd = ShapeKind.Circle; } if (Core.KeyTyped(KeyCode.vk_l)) { kindToAdd = ShapeKind.Line; } Core.ProcessEvents(); Core.RefreshScreen(); Core.ProcessEvents(); } while(!Core.WindowCloseRequested()); }