public void TestConstructor() { Rectangle s = new Rectangle (Color.Red, 50, 50, 100, 100); Assert.IsTrue (s.IsAt (SwinGame.PointAt (50, 50))); Assert.IsTrue (s.IsAt (SwinGame.PointAt (150, 50))); Assert.IsTrue (s.IsAt (SwinGame.PointAt (50, 150))); Assert.IsTrue (s.IsAt (SwinGame.PointAt (150, 150))); Assert.IsTrue (s.Color == Color.Red); }
public void TestShapeAtWhenMoved() { Rectangle s = new Rectangle (); s.X = 25; s.Y = 25; Assert.IsTrue (s.IsAt (SwinGame.PointAt (50, 50))); s.X = 100; s.Y = 100; Assert.IsFalse (s.IsAt (SwinGame.PointAt (50, 50))); }
public void TestShapeValue() { Rectangle s = new Rectangle (); Assert.IsFalse (s.Selected); s.Selected = true; Assert.IsTrue (s.Selected); }
public void TestShapeAt() { Rectangle s = new Rectangle (); s.X = 25; s.Y = 25; s.Width = 50; s.Height = 50; Assert.IsTrue (s.IsAt (SwinGame.PointAt (50, 50))); Assert.IsTrue (s.IsAt (SwinGame.PointAt (25, 25))); Assert.IsFalse (s.IsAt (SwinGame.PointAt (10, 50))); Assert.IsFalse (s.IsAt (SwinGame.PointAt (50, 10))); }
public void TestShapeAtWhenResized() { Rectangle s = new Rectangle (); s.X = 25; s.Y = 25; s.Width = 50; s.Height = 50; Assert.IsTrue (s.IsAt (SwinGame.PointAt (75, 75))); s.Width = 25; s.Height = 25; Assert.IsFalse (s.IsAt (SwinGame.PointAt (75, 75))); }
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() { 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(); }