c# 连连看 frmMain 代码.doc_第1页
c# 连连看 frmMain 代码.doc_第2页
c# 连连看 frmMain 代码.doc_第3页
c# 连连看 frmMain 代码.doc_第4页
c# 连连看 frmMain 代码.doc_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Threading;using System.Timers;namespace LLKAN public partial class frmMain : Form Game MyGame = new Game(); stdFunc MystdFunc = new stdFunc(); MapSelect MyMapSelect = new MapSelect(); string appPath = ; PlaySound spEarse; PlaySound spSelect; private int time = 100; private const int VALUE = 1; public int pn; private int score; private System.Windows.Forms.ProgressBar pBar; GameState gs = GameState.Start; public frmMain() InitializeComponent(); StartPosition = FormStartPosition.CenterScreen; private enum GameState Start, Play, End, Win /开始游戏 private void GameStart_Click(object sender, EventArgs e) LineTime.Enabled = true; LineTime.Start(); Graphics MyDraw = Pic1.CreateGraphics(); MyGame.GameStart(pn); DrawGame(MyDraw); / 在窗体内绘制游戏的图片 MyMapSelect.Clear(); /清除前面游戏的图片? if (LineTime.Enabled = true) progressBar1.Value = 100; time = 100; score = 0; label2.Text = score.ToString(); /开始/重新开始 private void button1_Click(object sender, EventArgs e) this.button1.Text = 重新开始; LineTime.Enabled = true; LineTime.Start(); Graphics MyDraw = Pic1.CreateGraphics(); if (comboBox1.Text = 天才级) pn = 49; else if (comboBox1.Text = 困难级) pn = 30; else if (comboBox1.Text = 普通级) pn = 25; else if (comboBox1.Text = 入门级) pn = 10; else pn = 5; MyGame.GameStart(pn); MyMapSelect.Clear(); /清除前面游戏的图片? DrawGame(MyDraw); / 在窗体内绘制游戏的图片 / if (LineTime.Enabled = true) / / MessageBox.Show(确定重新开始吗, 提示, MessageBoxButtons.OKCancel, MessageBoxIcon.Information); / progressBar1.Value = 100; time = 100; / score = 0; label2.Text = score.ToString(); / / 在窗体内绘制游戏的图片 / / private void DrawGame(Graphics MyDraw) if (MyGame.Playflag) for (int i = 0; i Game.Row; i+) for (int j = 0; j Game.Column; j+) if (MyGame.GamePicListi, j.State = 1) if (MyGame.GamePicListi, j.Selected) MyDraw.DrawImage(IL2.ImagesMyGame.GamePicListi, j.PicIndex, MyGame.GamePicListi, j.X, MyGame.GamePicListi, j.Y); else MyDraw.DrawImage(IL1.ImagesMyGame.GamePicListi, j.PicIndex, MyGame.GamePicListi, j.X, MyGame.GamePicListi, j.Y); else MyDraw.DrawImage(IL3.Images0, MyGame.GamePicListi, j.X, MyGame.GamePicListi, j.Y); private void Pic1_Paint(object sender, PaintEventArgs e) DrawGame(e.Graphics); /游戏过程中点击图片 private void Pic1_MouseClick(object sender, MouseEventArgs e) if (MyGame.Playflag) Point P = MystdFunc.GetGrid(e.X, e.Y); /如果点击在图片范围内 if (P.X != -1 & P.Y != -1 & P.X != 0 & P.X != Game.Row - 1 & P.Y != 0 & P.Y != Game.Column - 1) if (MyGame.GamePicListP.X, P.Y.Selected != true) MyMapSelect.SelectMap(P); MyGame.GamePicListP.X, P.Y.Select(); Graphics g = Pic1.CreateGraphics(); g.DrawImage(IL2.ImagesMyGame.GamePicListP.X, P.Y.PicIndex, MyGame.GamePicListP.X, P.Y.X, MyGame.GamePicListP.X, P.Y.Y); spSelect.Play(); / = 如果为第二次选择= if (MyMapSelect.GetFlag = -1) Point PL = MyMapSelect.PointX; / 如果两个图标可以消= if (MyGame.GamePicListP.X, P.Y.PicIndex = MyGame.GamePicListPL.X, PL.Y.PicIndex & MyGame.CheckPath(MyMapSelect.PointX, MyMapSelect.PointY, true) /消掉选择的两个图标 MyGame.DrawLine(g, Color.Blue); Thread.Sleep(100); g.DrawImage(IL3.Images0, MyGame.GamePicListP.X, P.Y.X, MyGame.GamePicListP.X, P.Y.Y); g.DrawImage(IL3.Images0, MyGame.GamePicListPL.X, PL.Y.X, MyGame.GamePicListPL.X, PL.Y.Y); MyGame.GamePicListP.X, P.Y.State = 2; MyGame.GamePicListPL.X, PL.Y.State = 2; progressBar1.Value+; score += 10; label2.Text = score.ToString(); spEarse.Play(); MyGame.DrawLine(g, Color.Black); MyMapSelect.Clear(); MyGame.CheckPlay(); if (MyGame.PlayWin) MessageBox.Show(恭喜你,你赢了!); MyGame.Playflag = false; LineTime.Start(); else /第一个变回原来状况 MyGame.GamePicListPL.X, PL.Y.Select(); g.DrawImage(IL1.ImagesMyGame.GamePicListPL.X, PL.Y.PicIndex, MyGame.GamePicListPL.X, PL.Y.X, MyGame.GamePicListPL.X, PL.Y.Y); /背景音乐 private void frmMain_Load(object sender, EventArgs e) appPath = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf(); spSelect = new PlaySound(appPath + Soundsselect.wav, select); spEarse = new PlaySound(appPath + Soundsearse.wav, earse); private void GamePause_Click(object sender, EventArgs e) /时间 private void LineTime_Tick(object sender, EventArgs e) time = time - VALUE; progressBar1.Value = time; if (progressBar1.Value = 0) time = 0; LineTime.Stop(); if (MessageBox.Show(你失败了,是否重新开始?, LLKAN, MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = DialogResult.OK) frmMain frm1 = new frmMain(); frm1.Show(); this.Hide(); if(MessageBox.Show(你失败了,是否重新开始?, LLKAN, MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = DialogResult.Cancel) Application .Exit(); score = 0; label2.Text = score.ToString(); /分数显示 private void label2_Click(object sender, EventArgs e) LineTime.Enabled = true; LineTime.Start(); Graphics MyDraw = Pic1.CreateGraphics(); MyGame.GameStart(pn); DrawGame(MyDraw); / 在窗体内绘制游戏的图片 MyMapSelect.Clear(); /清除前面游戏的图片? if (LineTime.Enabled = true) progressBar1.Value = 100; time = 100; score = 0; label2.Text = score.ToString(); /级别(关卡) private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e) /if (LineTime.Enabled = true) / / MessageBox.Show(确定重新开始吗, 提示, MessageBoxButtons.OKCancel, MessageBoxIcon.Information); / progressBar1.Value = 100; / time = 100; / score = 0; label2.Text = score.ToString(); /暂停/继续按钮 private void button2_Click(object sender, EventArgs e) if (this.button2.Text = 暂停) LineTime.Enabled = false; this.button2.Text = 继续; Pic1.Visible = false; else LineTime.Enabled = true; this.button2.Text = 暂停; Pic1.Visible = true; private void label4_Click(object sender, EventArgs e) /退出按钮 private void button3_Click(object sender, EventArgs e) if (MessageBox.Show(确认退出么, 操作提示, MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = DialogResult.OK) Application.Exit(); /菜单结束 private void GameExit_Click(object sender, EventArgs e) if (MessageBox.Show(确认退出么, 操作提示, MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = DialogResult.OK) Application.Exit(); /结束游戏 private void frmMain_FormClosing(object sender, FormClosingEventArgs e) Application.Exit(); private void groupBox2_Enter(object sender, EventArgs e) private void label3_Click(object sender, EventArgs e) /时间快慢 private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) switch (comboBox2.Text) case 很快: LineTime.Interval = 600; break; case 快: LineTime.Interval = 1000; break; case 一般: LineTime.Interval = 1200; break; case 慢: LineTime.Interval = 1500; break; default: LineTime.Interval = 2000; break; /if (LineTime.Enabled = true) / / MessageBox.Show(确定重新开始吗, 提示, MessageBoxButtons.OKCancel, MessageBoxIcon.Information); / progressBar1.Value = 100; / /time = 100; /score = 0; /label2.Text = score.ToStrin

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论