Beispiel #1
0
        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 );
        }
Beispiel #2
0
        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");
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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();
        }
Beispiel #5
0
        public void TestInitialiseWithColor()
        {
            Drawing d = new Drawing (Color.Red);

            Assert.IsTrue (d.BackgroundColor == Color.Red);
        }
Beispiel #6
0
        public void TestDefaultInitialisation()
        {
            Drawing d = new Drawing();

            Assert.IsTrue (d.BackgroundColor == Color.White);
        }