Exemplo n.º 1
0
        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()
        {
            //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);
            }
        }
Exemplo n.º 3
0
        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);
                }
                if (SwinGame.KeyTyped(KeyCode.vk_s))
                {
                    myDrawing.Save("./drawing.txt");
                }
                if (SwinGame.KeyTyped(KeyCode.vk_o))
                {
                    try {
                        myDrawing.Load("./drawing.txt");
                    } catch (Exception e) {
                        Console.Error.WriteLine("Error loading file: {0}", e.Message);
                    }
                }
                myDrawing.Draw();
                SwinGame.DrawFramerate(0, 0);

                //myDrawing onto the screen
                SwinGame.RefreshScreen(60);
            }
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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);
            }
        }