C#完整实现消消乐

C#课程设计作业,花了两天时间,其中抠图找图都花了大半天(后悔以前没去学PS,后悔莫及,所以最后做出来自己都看不下去的粗糙,不过只能这样了)
第一天上午:构思整个的大体框架,要实现的功能
第一天下午:找图,抠图,找资源,地图的绘制
第二天上午:被搜索联通块以及方块的消除难住了,后面参考了一些才解决主要核心的,包括判断相邻,执行交换,消除,执行下落,利用了3个Timer组件
第二天下午:技能体系,充值体系,修修改改,勉强做出来了

(一)课程作业:C#消消乐完整实现
利用 C#winform 实现了消消乐游戏的制作 开发环境 VS2015,SQL sever 2008,
实现功能:
1.登录,注册窗口
2.主界面消消乐的实现
3.技能体系:3个技能
4.充值体系
5.背包功能的实现
6.闯关功能的实现
(二)主要窗体
1.登录,注册
在这里插入图片描述
在这里插入图片描述
2.主界面
在这里插入图片描述
3.充值界面,教学界面
在这里插入图片描述
在这里插入图片描述
(三)各窗体核心代码
1.登录,注册

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Media;

namespace KillGame
{
   
    public partial class Login : Form
    {
   
        public Login()
        {
   
            InitializeComponent();
            
        }

        private void button1_Click(object sender, EventArgs e)//登录
        {
   
            if(checkBox1 .Checked ==true)
            {
   
                if (textBox1.Text.Trim() == "123456" && textBox2.Text.Trim() == "123456")
                {
   
                    string sname = "老师";
                    startProgress(progressBar1);
                    this.Hide();
                    Game game = new KillGame.Game(sname);
                    game.Show();

                }
                else
                {
   
                    MessageBox.Show("登录失败,超级用户账号密码都是123456,再试试");
                }
            }
            else
            {
   
                string id = textBox1.Text.Trim().ToString();
                string pwd = textBox2.Text.Trim().ToString();
                if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "")
                {
   
                    MessageBox.Show("请输入账号或密码!");
                    return;
                }
                SqlConnection conn = new SqlConnection(@"Data Source=(local);Initial Catalog=MBook;Persist Security Info=True;User ID=sa;Password='zdllxf211215'");
                string strselect = "select Name from TUser where id='" + textBox1.Text.Trim().ToString() + "'and pwd='" + textBox2.Text.Trim().ToString() + "'";
                SqlCommand cmd = new SqlCommand(strselect, conn);
                conn.Open();
                string name = cmd.ExecuteScalar().ToString();
                if (name != null)
                {
   
                    startProgress(progressBar1);
                    this.Hide();
                    Game game = new KillGame.Game(name);
                    game.Show();

                }
                else
                {
   
                    MessageBox.Show("登录失败!");
                }
            }
           
          
        }

        private void button2_Click(object sender, EventArgs e)//取消
        {
   
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)//注册
        {
   
            Logon logon = new Logon();
            logon.Show();
        }
        public void SetCursor(Bitmap cursor, Point hotPoint)//自定义光标
        {
   
            int hotX = hotPoint.X;
            int hotY = hotPoint.Y;
            Bitmap myNewCursor = new Bitmap(cursor.Width * 2 - hotX, cursor.Height * 2 - hotY);
            Graphics g = Graphics.FromImage(myNewCursor);
            g.Clear(Color.FromArgb(0, 0, 0, 0));
            g.DrawImage(cursor, cursor.Width - hotX, cursor.Height - hotY, cursor.Width,
            cursor.Height);
            this.Cursor = new Cursor(myNewCursor.GetHicon());
            g.Dispose();
            myNewCursor.Dispose();
        }
        private void startProgress(ProgressBar pBar1)
        {
   
            pBar1.Visible = true;// 显示进度条控件.
            pBar1.Minimum = 1;// 设置进度条最小值.
            pBar1.Maximum = 15;// 设置进度条最大值.
            pBar1.Value = 1;// 设置进度条初始值
            pBar1.Step = 1;// 设置每次增加的步长
                           //创建Graphics对象
            Graphics g = pBar1.CreateGraphics();
            for (int x = 1; x <= 15; x++)
            {
   
                //执行PerformStep()函数
                pBar1.PerformStep();
                string str = Math.Round((100 * x / 15.0), 2).ToString("#0.00 ") + "%";
                Font font = new Font("Times New Roman", (float)10, FontStyle.Regular);
                PointF pt = new PointF(pBar1.Width / 2 - 17, pBar1.Height / 2 - 7);
                g.DrawString(str, font, Brushes.Black , pt);
                //每次循环让程序休眠300毫秒
                System.Threading.Thread.Sleep(300);
            }
            pBar1.Visible = false;
            //MessageBox.Show("success!");
        }

        private void Login_Load(object sender, EventArgs e)//窗体加载
        {
   

            SoundPlayer bm = new SoundPlayer("Music\\bj.wav");//背景音乐
            bm.PlayLooping();
            Bitmap a = (Bitmap)Bitmap.FromFile("Image\\mouse.png");
            SetCursor(a, new Point(0, 0));

        }
    }
}

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

namespace KillGame
{
   
    public partial class Logon : Form
    {
   
        public Logon()
        {
   
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)//注册
        {
   
            if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "" || textBox4.Text.Trim()=="")
            {
   
                MessageBox.Show("请输入完整信息!");
                return;
            }
            if(textBox2 .Text .Trim ()==textBox3 .Text .Trim())
            {
   
                SqlConnection conn = new SqlConnection(@"Data Source=(local);Initial Catalog=MBook;Persist Security Info=True;User ID=sa;Password='zdllxf211215'");
                string strselect = "insert into TUser values('" + textBox1.Text.Trim() + "','" + textBox4.Text.Trim() + "','" + textBox2.Text.Trim() + "')";
                SqlCommand cmd = new SqlCommand(strselect
  • 46
    点赞
  • 143
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值