日期:2014-05-18  浏览次数:20777 次

c# 屌丝的游戏,是男人就坚持20秒
昨晚花了2个小时,今天花了4个小时完成的.就是自娱自乐,还有很多问题.自己看吧.
链接:http://download.csdn.net/detail/hlxcoo2007/4314240

C# code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace ManGame
{
    public partial class FMain : Form
    {
        public int[,] ballarray = new int[40, 40];
        public FMain()
        {
            InitializeComponent();
        }

        private bool _isStart = false;
        private bool isStart
        {
            get { return _isStart; }
            set { _isStart = value; }
        }

        private void tsmExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tsmChoose_Click(object sender, EventArgs e)
        {
            FrmDiffcultChoose _fchoose = new FrmDiffcultChoose(this);
            _fchoose.ShowDialog();
        }

        private void tsmAbout_Click(object sender, EventArgs e)
        {
            FrmAbout _about = new FrmAbout();
            _about.ShowDialog();
        }

        Timer _startTime;
        private void tsmNewGame_Click(object sender, EventArgs e)
        {
            setEnable(false);
            ts = 1;
            Graphics g = this.CreateGraphics();
            drawString(g, "1");
            _startTime = new Timer();
            _startTime.Interval = 1000;
            _startTime.Tick += new EventHandler(OnTick);
            _startTime.Start();
        }

        private void drawString(Graphics _g, string _s)
        {
            float px = this.ClientSize.Width / 2;
            float py = (this.ClientSize.Height / 2) - 40;
            StringFormat drawFormat = new StringFormat();
            drawFormat.Alignment = StringAlignment.Center;
            _g.DrawString(_s, new Font(this.Font.FontFamily, 72), new SolidBrush(Color.Red), px, py, drawFormat);
        }

        double OverTime = 0;
        int ts = 1;
        void OnTick(object sender, EventArgs e)
        {
            this.Refresh();
            Graphics g = this.CreateGraphics();
            ts += 1;
            drawString(g, ts.ToString());
            if (ts == 4)
            {
                this.Refresh();
                drawString(g, "翻滚吧,屌丝..");
            }
            if (ts == 5)
            {
                isStart = true;
                this.timer1.Start();
                Random r = new Random();
                for (int i = 1; i <= SaveParam.BallNum; i++)
                {
                    ballarray[i, 1] = +r.Next(10) + 5;
                    ballarray[i, 2] = +r.Next(10) + 5;
                    ballarray[i, 3] = +r.Next(10) + 5;
                    ballarray[i, 4] = +r.Next(10) + 5;
                }
                _startTime.Stop();
            }
        }

        private int x1;
        private int y1;
        protected override void OnMouseMove(MouseEventArgs m)
        {
            x1 = m.X;
            if (x1 + 40 >= this.Width)
            {
                x1 = this.Width - 25;
            }
            else if (x1 - 15 <= 0)
            {
                x1 = 15;
            }
            y1 = m.Y;
            if (y1 + 60 >= this.Height)
            {
                y1 = this.Height - 45;
            }
            else if (y1 - 60 <= 0)
            {
                y1 = 40;
            }
        }

        private void setEnable(bool _enable)
        {
            this.tsmAbout.Enabled = _enable;
            this.tsmChoose.Enabled = _enable;
            this.tsmNewGame.Enabled = _enable;
        }

        Rectangle _rect;
        bool ifOver = false;
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;