コード例 #1
0
        //Allows for clicks
        private void timer1_Tick(object sender, EventArgs e)
        {
            Point ptClick;

            if (canvas.GetLastMouseLeftClick(out ptClick))
            {
                canvas.AddCenteredEllipse(ptClick.X, ptClick.Y, circleSize, circleSize, customCol);
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: ManuMathews/Backup-USB
        public void timer1_Tick(object sender, EventArgs e)
        {
            Point newCirclePoint;

            if (true == drawingBoard.GetLastMouseLeftClick(out newCirclePoint))
            {
                drawingBoard.AddEllipse(newCirclePoint.X - (circleSize / 2), newCirclePoint.Y - (circleSize / 2), circleSize, circleSize, circleColor);
            }
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        // Button Constructor/Controller; User selects button and returns a char
        static char SelectLetter(ref CDrawer HangingPost)
        {
            char  selection = ' ';
            Point click;
            bool  valid_click = false;
            int   counter     = 0;
            // Generate buttons
            var button = new Button[26];                //create array of class Button

            for (int i = 0; i < 26; i++)
            {
                button[i]       = new Button();         //construct new Button for each element in array
                button[i].alpha = (char)(i + 65);
                if (i < 13)
                {
                    button[i].xMin_coord = 250 + counter * 40;
                    button[i].xMax_coord = button[i].xMin_coord + 30;
                    button[i].yMin_coord = 10;
                    button[i].yMax_coord = 40;
                }
                else
                {
                    button[i].xMin_coord = 250 + counter * 40;
                    button[i].xMax_coord = button[i].xMin_coord + 30;
                    button[i].yMin_coord = 50;
                    button[i].yMax_coord = 80;
                }
                counter++;
                if (counter >= 13)
                {
                    counter = 0;
                }
            }
            while (!valid_click)
            {
                if (HangingPost.GetLastMouseLeftClick(out click))
                {
                    for (int i = 0; i < 26; i++)
                    {
                        int xmin = button[i].xMin_coord;
                        int xmax = button[i].xMax_coord;
                        int ymin = button[i].yMin_coord;
                        int ymax = button[i].yMax_coord;
                        if (click.X > xmin && click.X < xmax && click.Y > ymin && click.Y < ymax)
                        {
                            HangingPost.AddLine(xmin, ymin, xmax, ymax, Color.Red, 2);
                            HangingPost.AddLine(xmax, ymin, xmin, ymax, Color.Red, 2);
                            HangingPost.Render();
                            selection   = button[i].alpha;
                            valid_click = true;
                        }
                    }
                }
            }
            return(selection);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: PhongNguyen512/Block
        static void Main(string[] args)
        {
            //program information
            Console.WriteLine("Instruction:");
            Console.WriteLine("Left click to create a RED BLOCK");
            Console.WriteLine("Right click to create a YELLOW BLOCK");
            Console.WriteLine("Right click on exist BLOCK to DELETE it\n");
            Console.WriteLine("RED BLOCK will fall to the bottom");
            Console.WriteLine("YELLOW BLOCK will stay solid in the click location");

            //initial constant variables
            const int blockSize = 50;

            const int windowX = 1000;
            const int windowY = 1000;

            const int blockX = windowX / blockSize;
            const int blockY = windowY / blockSize;

            //initial point for clicking left or right
            Point currentPos = new Point();

            CDrawer canvas = new CDrawer(windowX, windowY, false);

            if (blockSize >= 10)
            {
                GridManager gm = new GridManager(blockX, blockY, blockSize, canvas);

                do
                {
                    //add grid if left click or right click
                    if (canvas.GetLastMouseLeftClick(out currentPos))
                    {
                        gm.AddLeft(currentPos);
                    }
                    if (canvas.GetLastMouseRightClick(out currentPos))
                    {
                        gm.AddRight(currentPos);
                    }

                    gm.Render(canvas);
                    gm.Falling();

                    //for TESTING ONLY
                    //gm.ShowAll(canvas);
                    Thread.Sleep(10);
                } while (true);
            }
            else
            {
                Console.WriteLine("Block size must be greater than or equal 10");
            }
            Console.ReadKey();
        }
コード例 #6
0
ファイル: Drawings.cs プロジェクト: sjc17/CNT-Hangman
        // 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();
        }
コード例 #7
0
        // occurs on evey mouse click
        // draw thred based on where you clicked in gdi window
        // amount of pixels drawn baed on trackbar value
        // call wander method to to start drawing
        // set to backgground
        private void timer1_Tick(object sender, EventArgs e)
        {
            Point      click;                         // start thred on mouse click
            WanderData wanderdata = new WanderData(); // varaible for struct

            // draw thred based on where you clicked in gdi window
            if (_draw.GetLastMouseLeftClick(out click))
            {
                wanderdata.pCount    = trackBar1.Value;
                wanderdata.x         = click.X;
                wanderdata.y         = click.Y;
                _wander              = new Thread(new ParameterizedThreadStart(Wander));
                _wander.IsBackground = true;
                _wander.Start(wanderdata);
            }
        }
コード例 #8
0
        //runs everytime when pressed
        // when enabled draw on moseclick with desied shape
        private void timer1_Tick(object sender, EventArgs e)
        {
            Point click;                                 // tracks mouse clicks to draw shape

            _draw.GetLastMouseLeftClick(out click);      // draw on mouse click

            if (_bColorSet && _shape)
            {
                if (_iShape == 1)
                {
                    if (_borderCheck)
                    {
                        _draw.AddCenteredRectangle(click.X, click.Y, 50, 50, _color, 2, Color.White);
                        _draw.Render();
                    }
                    else
                    {
                        _draw.AddCenteredRectangle(click.X, click.Y, 50, 50, _color);
                        _draw.Render();
                    }
                }
                if (_iShape == 0)
                {
                    if (_borderCheck)
                    {
                        _draw.AddCenteredEllipse(click.X, click.Y, 50, 50, _color, 2, Color.White);
                        _draw.Render();
                    }
                    else
                    {
                        _draw.AddCenteredEllipse(click.X, click.Y, 50, 50, _color);
                        _draw.Render();
                    }
                }
            }
            else
            {
                if (!_borderCheck && !_shape)
                {
                    MessageBox.Show("Error: Properties have not been set.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #9
0
        private void _Timer_Tick(object sender, EventArgs e)
        {
            Point p;

            if (canvas.GetLastMouseLeftClick(out p))
            {
                BallList.Add(new Ball(p));
            }
            else if (canvas.GetLastMouseRightClick(out p))
            {
                BallList.Clear();
            }
            canvas.Clear();
            for (int i = 0; i < BallList.Count; i++)
            {
                BallList[i].MoveBall(canvas);
                BallList[i].ShowBall(canvas);
                this.Text = BallList[i].ToString();
            }
            canvas.Render();
        }
コード例 #10
0
        //when game is started, constantly checking score and balls status
        private void timer1_Tick(object sender, EventArgs e)
        {
            Point point = new Point();

            //if the user clicks left mouse
            if (_canvas.GetLastMouseLeftClick(out point))
            {
                //getting the score for that instance of how many balls are killed
                score += Pick(ballArray, _canvas);
                //update the score in the form
                Invoke(new DelVoidInt(setScore), score);

                //if all the balls are killed, game is done
                if (Ballalive(ballArray) == 0)
                {
                    _canvas.AddText("Game Over!", 50);
                    //enable the play button agian
                    Invoke(new DelVoidVoid(enableButton));
                    //make new high score form
                    HighScore hs = new HighScore();
                    //if user wants to store the name for the game play
                    if (hs.ShowDialog() == DialogResult.OK)
                    {
                        string name = hs.GetUserName;

                        //write the name, level, and score into the file name highscore.txt
                        try
                        {
                            StreamWriter sw = new StreamWriter("HighScore.txt", true);
                            sw.WriteLine(name + "," + level + "," + score);
                            sw.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error!");
                        }
                    }
                }
            }
        }
コード例 #11
0
        //occurs every 100ms once the game has started
        // calls Alive balls to check for a game over
        // check for mouse clicks,update upon evey new mouse click
        private void timer1_Tick(object sender, EventArgs e)
        {
            // exeute when no balls are left in gdi window
            if (AliveBalls() == 0)
            {
                // stop timer, enable user to play again, dispaly game over msg
                timer1.Stop();
                PlayButton.Enabled = true;
                _draw.AddText("Game over", 60, Color.White);

                // call score to keep tarck of players curent score
                ScoreBoard();
            }

            //if a fresh mouse click is detected, call Drop for that location, total up the score and call StepDown
            else if (_draw.GetLastMouseLeftClick(out _mouseClick))
            {
                _scoreTotal += Pick();
                FallDown();
                scoreLabel.Text = _scoreTotal.ToString();
            }
        }
コード例 #12
0
        /// <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();
            }
        }
コード例 #13
0
        private void TimerClick_Tick(object sender, EventArgs e)
        {
            Point    newClick = new Point(-1, -1);
            ICA3Ball newBall;


            if (canvas.GetLastMouseLeftClick(out newClick))
            {
                newBall = new ICA3Ball(canvas, newClick);
                canvas.Clear();
                for (int ballIndex = 0; ballIndex < ballList.Count(); ++ballIndex)
                {
                    ballList[ballIndex].MarkOverlap(newBall);
                }
                ballList.Add(newBall);

                foreach (ICA3Ball ball in ballList)
                {
                    ball.Render();
                }
                canvas.Render();
            }
        }
コード例 #14
0
        private void casio_Tick(object sender, EventArgs e)
        {
            //Tick all FBalls in list
            foreach (FBall fb in LBalls)
            {
                fb.Tick();
            }

            //IF user clicks mouse, create newpoint and random number
            Point vertex = new Point();

            if (Canvas.GetLastMouseLeftClick(out vertex))
            {
                Draw(vertex, Color.FromArgb(rand.Next(50, 255), rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)));
            }
            else if (Canvas.GetLastMouseRightClick(out vertex))
            {
                //create black circles from top left
                Draw(new Point(0, 0), Color.Black);
            }

            //clear then render all FBalls
            Canvas.Clear();
            foreach (FBall fb in LBalls)
            {
                fb.Render();
            }

            //show all FBalls on CDrawer canvas
            Canvas.Render();

            //check if canvas is closed
            if (Canvas.DrawerWindowSize.IsEmpty)
            {
                Application.Exit();
            }
        }
コード例 #15
0
        static void Main(string[] args)
        {
            //intializing
            Color       objColor       = new Color();
            List <info> structureslist = new List <info>();
            CDrawer     canvas         = new CDrawer();
            Point       location       = new Point(200, 200);
            info        infoN;
            string      filename;
            Shape       shape = Shape.Circle;
            int         i     = 0;

            Options(ref canvas);                                // Open Menu

            while (true)                                        // go into while loop unless it fails
            {
                if (canvas.GetLastMouseLeftClick(out location)) //catch mouse click point
                {
                    //change shape information depends on click location
                    if (location.X > 20 && location.X < 70 && location.Y > 40 && location.Y < 90)
                    {
                        objColor = Color.Red;
                    }

                    else if (location.X > 80 && location.X < 170 && location.Y > 20 && location.Y < 90)
                    {
                        objColor = Color.Green;
                    }

                    else if (location.X > 180 && location.X < 270 && location.Y > 40 && location.Y < 90)
                    {
                        objColor = Color.Blue;
                    }

                    else if (location.X > 280 && location.X < 350 && location.Y > 40 && location.Y < 90)
                    {
                        shape = Shape.Circle;
                    }

                    else if (location.X > 360 && location.X < 450 && location.Y > 40 && location.Y < 90)
                    {
                        shape = Shape.Squre;
                    }

                    else if (location.X > 460 && location.X < 510 && location.Y > 40 && location.Y < 90)
                    {
                        shape = Shape.Star;
                    }

                    else if (location.X > 520 && location.X < 590 && location.Y > 40 && location.Y < 90) //Save option
                    {
                        Console.Write("Enter your filename: ");                                          //choosing saving file name
                        filename = Console.ReadLine();

                        StreamWriter swOutputFile = new StreamWriter(filename);
                        //save shape information each line
                        foreach (info item in structureslist)
                        {
                            swOutputFile.WriteLine("{0},{1},{2},{3}", item._shape, item._shapeColor, item.XLocation, item.YLocatoin);
                        }
                        swOutputFile.Close(); //save
                    }


                    else if (location.X > 600 && location.X < 670 && location.Y > 40 && location.Y < 90) //Load Option
                    {
                        Console.Write("Enter your filename: ");                                          // choose loading file name
                        filename = Console.ReadLine();

                        //initializing for load variables
                        StreamReader  swInputFile;
                        List <string> LoadList = new List <string>();
                        string        text;
                        try // catch error while opening file
                        {
                            swInputFile = new StreamReader(filename);
                            while ((text = swInputFile.ReadLine()) != null)
                            {
                                string[] text2;
                                text2 = text.Split(',');
                                info infoO;
                                infoO._shapeColor = Color.Red;
                                infoO._shape      = Shape.Circle;
                                infoO.XLocation   = 0;
                                infoO.YLocatoin   = 0;
                                switch (text2[0]) //check shape type
                                {
                                case "Cirlce": { infoO._shape = Shape.Circle; break; }

                                case "Square": { infoO._shape = Shape.Squre; break; }

                                case "Star": { infoO._shape = Shape.Star; break; }
                                }
                                switch (text2[1])//check shape color
                                {
                                case "Color [Red]": { infoO._shapeColor = Color.Red; break; }

                                case "Color [Green]": { infoO._shapeColor = Color.Green; break; }

                                case "Color [Blue]": { infoO._shapeColor = Color.Blue; break; }
                                }
                                infoO.XLocation = Convert.ToInt64(text2[2]); //check shape X location
                                infoO.YLocatoin = Convert.ToInt64(text2[3]); //check shape Y location
                                structureslist.Add(infoO);                   //add on to list to save information

                                foreach (info item in structureslist)        //Call information on to GDI drawer from list
                                {
                                    switch (item._shape)
                                    {
                                    case Shape.Circle:
                                    {
                                        if (item._shapeColor == Color.Red)
                                        {
                                            canvas.AddCenteredEllipse((int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Red);
                                        }
                                        else if (item._shapeColor == Color.Green)
                                        {
                                            canvas.AddCenteredEllipse((int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Green);
                                        }
                                        else if (item._shapeColor == Color.Blue)
                                        {
                                            canvas.AddCenteredEllipse((int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Blue);
                                        }
                                        break;
                                    }

                                    case Shape.Squre:
                                    {
                                        if (item._shapeColor == Color.Red)
                                        {
                                            canvas.AddCenteredRectangle((int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Red);
                                        }
                                        else if (item._shapeColor == Color.Green)
                                        {
                                            canvas.AddCenteredRectangle((int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Green);
                                        }
                                        else if (item._shapeColor == Color.Blue)
                                        {
                                            canvas.AddCenteredRectangle((int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Blue);
                                        }
                                        break;
                                    }

                                    case Shape.Star:
                                    {
                                        if (item._shapeColor == Color.Red)
                                        {
                                            canvas.AddText("S", 20, (int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Red);
                                        }
                                        else if (item._shapeColor == Color.Green)
                                        {
                                            canvas.AddText("S", 20, (int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Green);
                                        }
                                        else if (item._shapeColor == Color.Blue)
                                        {
                                            canvas.AddText("S", 20, (int)item.XLocation, (int)item.YLocatoin, 20, 20, Color.Blue);
                                        }
                                        break;
                                    }
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error, the error was {0}", e);
                        }
                    }

                    else if (location.X > 680 && location.X < 750 && location.Y > 40 && location.Y < 90)
                    {
                        canvas.Clear();      // clear GDI drawer
                        Options(ref canvas); //Recall menu
                    }
                    else //If mouse click location is out of menu area draw the shapes
                    {
                        switch (shape)//Goes into diffrent options depends on the shape
                        {
                        case Shape.Circle:
                        {
                            canvas.AddCenteredEllipse(location, 20, 20, objColor);
                            infoN._shape      = shape;
                            infoN._shapeColor = objColor;
                            infoN.XLocation   = location.X;
                            infoN.YLocatoin   = location.Y;
                            structureslist.Add(infoN);

                            break;
                        }

                        case Shape.Squre:
                        {
                            canvas.AddCenteredRectangle(location, 20, 20, objColor);
                            infoN._shape      = shape;
                            infoN._shapeColor = objColor;
                            infoN.XLocation   = location.X;
                            infoN.YLocatoin   = location.Y;
                            structureslist.Add(infoN);
                            break;
                        }

                        case Shape.Star:
                        {
                            canvas.AddText("S", 20, location.X, location.Y, 20, 30, objColor);
                            infoN._shape      = shape;
                            infoN._shapeColor = objColor;
                            infoN.XLocation   = location.X;
                            infoN.YLocatoin   = location.Y;
                            structureslist.Add(infoN);
                            break;
                        }
                        }
                    }
                }
            }
        }
コード例 #16
0
ファイル: Form1.cs プロジェクト: ManuMathews/Backup-USB
 private void btn_StartDraw_Click(object sender, EventArgs e)
 {
     drawer.GetLastMouseLeftClick(out clickCoordinates);
     drawer.AddEllipse((clickCoordinates.X - (size / 2)), (clickCoordinates.Y - (size / 2)), size, size, color);
 }
コード例 #17
0
        static void Main(string[] args)
        {
            CDrawer dr = new CDrawer();

            dr.BBColour = Color.White;
            Random rnd = new Random();

            dr.Scale = 20; // adjust scale to test ScaledWidth/ScaledHeight

            // Disable continuous update
            dr.ContinuousUpdate = false;
            // perform lengthy/high object count operation
            for (int i = 0; i < 1000; ++i)
            {
                dr.AddEllipse(rnd.Next(dr.ScaledWidth), rnd.Next(dr.ScaledHeight), 1, 1, RandColor.GetColor());
                dr.Render(); // tell drawer to show now, all elements have been added
            }


            int iNum = 0;

            iNum++;



            Point pCoord;          // coords to accept mouse click pos
            int   iNumClicks  = 0; // count number of clicks accepted
            int   iFalseAlarm = 0; // count the number of poll calls

            do
            {
                bool bRes = dr.GetLastMouseLeftClick(out pCoord); // poll
                if (bRes)                                         // new coords?
                {
                    ++iNumClicks;
                    dr.AddEllipse(pCoord.X - 10, pCoord.Y - 10, 20, 20);
                }
                else
                {
                    iFalseAlarm++;                      // not new coords
                }
            }while (iNumClicks < 10);

            Console.WriteLine("Checked for coordinates " + iFalseAlarm.ToString() + " times!");


            Console.ReadKey();

            /*
             * {
             *  FileStream foo = new FileStream("snot", FileMode.Create);
             *  MemoryStream ms = new MemoryStream();
             *  BinaryFormatter bf = new BinaryFormatter();
             *
             *  SThing temp = new SThing();
             *  temp.i = 42;
             *
             *  bf.Serialize(ms, temp);
             *  foo.Write(ms.GetBuffer(), 0, (int)ms.Length);
             *  foo.Close();
             * }
             *
             * {
             *  FileStream foo = new FileStream("snot", FileMode.Open);
             *  BinaryFormatter bf = new BinaryFormatter();
             *
             *  object o = bf.Deserialize(foo);
             *  if (o is SThing)
             *  {
             *      SThing temp = (SThing)o;
             *      Console.WriteLine (temp.i.ToString());
             *  }
             * }
             *
             * Console.ReadKey();
             */
        }
コード例 #18
0
        static void Main(string[] args)
        {
            bool gameOver = false;      // Exit the Game
            bool gameExit = false;      // Exit the Program
            bool start    = false;      // Start the Game

            // Instance of random.
            Random rand = new Random();

            //x ball position
            int iX = 3;
            //y ball position
            int iY = rand.Next(2, 115);

            //amount ball moves in x direction for every loop
            int iXVelocity = 3;

            //amount ball moves in y direction for every loop
            int iYVelocity = 3;

            // Game score
            int score = 0;

            // Ball speed delay
            int ballSpeed = 120;

            //create a drawer window
            CDrawer Canvas = new CDrawer();

            Canvas.Scale = 5;

            // coordinates.
            Point coord;

            // Mouse position in Canvas
            int mouseYPos = 70;


            //loop until the ball leaves the visible window
            while (((iX < 160) || (iX > 0)) && !gameExit)
            {
                while (gameOver == false)
                {
                    // Erase the old ball and paddle.
                    Canvas.Clear();

                    // If left mouse click start the game.
                    if (Canvas.GetLastMouseLeftClick(out coord))
                    {
                        start = true;
                    }

                    // if start is true start the game.
                    if (start)
                    {
                        // Get the mouse position in the canva and scale it to 5.
                        if (Canvas.GetLastMousePosition(out coord))
                        {
                            mouseYPos = (coord.Y / 5) - 5;
                        }

                        // Add the paddle.
                        Canvas.AddRectangle(0, mouseYPos, 1, 10, Color.Red);

                        //draw the new ball
                        Canvas.AddEllipse(iX, iY, 2, 2);

                        //time delay to slow down the ball
                        System.Threading.Thread.Sleep(ballSpeed);

                        // If mouse is on paddle position bounce back.
                        if ((iY - 9) <= mouseYPos && (iY + 1) >= mouseYPos && iX <= 2)
                        {
                            // Reverse speed position (goes opposite way).
                            iXVelocity = -iXVelocity;
                            iYVelocity = -iYVelocity;

                            // increment the ball speed.
                            ballSpeed = ballSpeed <= 20 ? 1 : ballSpeed - 20;

                            // increment score.
                            score++;
                        }

                        // Increment the position with the velocity.
                        iX += iXVelocity;
                        iY += iYVelocity;

                        //check for bouncing off of the lower edge of the window
                        if ((iY > 118) || (iY < 0))
                        {
                            //reverse the y velocity (ball goes up)
                            iYVelocity = -iYVelocity;
                        }

                        // If ball position is greater than 160 reverse the X velocity (ball goes left).
                        if (iX > 160)
                        {
                            iXVelocity = -iXVelocity;
                        }

                        // If ball position is less than 0 game is over.
                        if (iX < 0)
                        {
                            gameOver = true;
                        }
                    }
                }

                // Erase the old ball and paddle.
                Canvas.Clear();

                // Display the final score and option buttons to play again and quit the game.
                Canvas.AddText($"Final Score: {score}", 36, Color.Gray);
                Canvas.AddText("Play Again", 12, 85, 84, 30, 45, Color.Green);
                Canvas.AddText("Quit", 12, 120, 84, 30, 45, Color.Gray);
                Canvas.AddRectangle(87, 103, 25, 8, Color.Empty, 1, Color.Green);
                Canvas.AddRectangle(122, 103, 25, 8, Color.Empty, 1, Color.Gray);
                while (gameOver == true)
                {
                    if (Canvas.GetLastMouseLeftRelease(out coord))
                    {
                        Console.WriteLine("Click!");
                    }
                    // If play again button is click start the game.
                    if (Canvas.GetLastMouseLeftClick(out coord) && (coord.X >= 435 && coord.X <= 560) && (coord.Y >= 515 && coord.Y <= 555))
                    {
                        // Initialize ball position and speed.
                        iX         = 3;
                        iY         = rand.Next(2, 115);
                        iXVelocity = 3;
                        iYVelocity = 3;
                        ballSpeed  = 120;
                        score      = 0;

                        // Start the game.
                        gameOver = false;
                        start    = true;
                    }

                    // If quit button is click quit the game.
                    if (Canvas.GetLastMouseLeftClick(out coord) && (coord.X >= 610 && coord.X <= 735) && (coord.Y >= 515 && coord.Y <= 555))
                    {
                        // Exit the game.
                        gameExit = true;
                        gameOver = false;
                    }
                }
            }
        }
コード例 #19
0
        /// <summary>
        /// the main event for game code
        /// does everything needed for game to run
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Timer_Tick(object sender, EventArgs e)
        {
            Point pt;

            missile.boomRadius = boomTrackBar.Value;
            labelBommVal.Text  = boomTrackBar.Value.ToString();

            //add enemy missiles to list and update label
            if (foemissiles.Count < missilesUpDown.Value)
            {
                missile newMissile = new missile();
                foemissiles.Add(newMissile);
                missilsIN += 1;
            }

            //colilsion check
            List <missile> colided = friendlyMissile.Intersect(foemissiles).ToList();

            //remove all colided missiles
            //also update score and update counter for removed missiles
            foreach (missile item in colided)
            {
                while (foemissiles.Remove(item))
                {
                    score += 100;
                    gone  += 1;
                }
            }

            //remove any missiles outside of boundaries
            friendlyMissile.RemoveAll(missile.Explosion);
            missile.Loading = true;
            foemissiles.RemoveAll(missile.boundaryCheckLeftRIght);

            // if missile reaches bottom of gdi lives --
            if (foemissiles.RemoveAll(missile.BoundaryCheckUpDown) >= 1)
            {
                lives -= 1;
            }

            // and a "bunker" where frindly misslies spawn
            CDrawer.AddCenteredRectangle(CDrawer.ScaledWidth / 2, CDrawer.ScaledHeight, 30, 30, Color.Green);
            CDrawer.AddText($"Lives {lives} Score {score}", 60, Color.Cyan);

            // update labels
            labelmissIN.Text    = missilsIN.ToString();
            labelDestroyed.Text = gone.ToString();
            labelFriend.Text    = friendlyIN.ToString();
            labelKD.Text        = KD.ToString();

            //update k/d ratio as long as there is at least 1 missle on screen
            if (friendlyIN > 0)
            {
                KD = (double)Math.Round(Convert.ToDecimal((missilsIN / friendlyIN)), 2);
            }

            missile.Loading = false;//start rending in missiles and effects

            //movment for enemy missiles
            foreach (missile item in foemissiles)
            {
                item.move();
                item.DrawMissiles();
            }

            //movment for friendly missiles
            foreach (missile item in friendlyMissile)
            {
                //bool for friend?
                item.move();
                item.DrawMissiles();
            }

            //on a left click spawn a friendly missile and update label
            if (CDrawer.GetLastMouseLeftClick(out pt))
            {
                friendlyMissile.Add(new missile(pt));
                friendlyIN++;
            }

            //when adjusting timerinterval stop the game
            //adjust interval and resume game
            if (timer1.Enabled)
            {
                timer1.Stop();
            }
            this.timer1.Interval = (int)intervalUpDown.Value;
            timer1.Start();

            //if a game over happens
            //set game over state, stop the timer
            //and display game over text
            if (currentState == eGameState.Over)
            {
                currentState   = eGameState.Unstarted;
                timer1.Enabled = false;
                timer1.Stop();
                missile.Loading = true;
                CDrawer.AddText("GAME OVER", 60, Color.Cyan);
                missile.Loading = false;
            }

            //if lives 0 game is over
            if (lives == 0)
            {
                currentState = eGameState.Over;
            }
        }