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.IO; using System.Media; namespace 拼图 { public partial class Form3 : Form { public static int a; //定义b接收用户输入的总步数 public static int b; private System.Windows.Forms.PictureBox[,]t; public Form3() { InitializeComponent(); } /// <summary> /// 窗体加载事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form3_Load(object sender, EventArgs e) { string[] path = Directory.GetFiles(@"背景音乐", "*.wav");
class Player
{
private string Pcommand;
private bool isOpen; [DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, int bla); /// <summary>
/// Not much to conctruct here
/// </summary>
public Player()
{
} /// <summary>
/// Stops currently playing audio file
/// </summary>
public void Close()
{
Pcommand = "close MediaFile";
mciSendString(Pcommand, null, 0, 0);
isOpen = false;
} /// <summary>
/// Opens audio file to play
/// </summary>
/// <param name="sFileName">This is the audio file's path and filename</param>
public void Open(string sFileName)
{
Pcommand = "open \"" + sFileName + "\" type mpegvideo alias MediaFile";
mciSendString(Pcommand, null, 0, 0);
isOpen = true;
} /// <summary>
/// Plays selected audio file
/// </summary>
/// <param name="loop">If True,audio file will repeat</param>
public void Play(bool loop)
{
if (isOpen)
{
Pcommand = "play MediaFile";
if (loop)
Pcommand += " REPEAT";
mciSendString(Pcommand, null, 0, 0);
}
} /// <summary>
/// Pauses currently playing audio file
/// </summary>
public void Pause()
{
Pcommand = "pause MediaFile";
mciSendString(Pcommand, null, 0, 0);
} /// <summary>
/// Returns the current status player: playing,paused,stopped etc.
/// </summary>
public string Status()
{
int i = 128;
System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(i);
mciSendString("status MediaFile mode", stringBuilder, i, 0);
return stringBuilder.ToString();
}
}
if (checkbox1.Checked)
mciSendString("play temp_alias repeat", null, 0, 0);
else
mciSendString("stop temp_alias repeat", null, 0, 0);
这位朋友 你给的解答 我试了试 它提示没有mcisendstring这个单词 能在详细点么 麻烦了
这位朋友 你给的解答 我试了试 它提示没有mcisendstring这个单词 能在详细点么 麻烦了这个说不通啊,如果提示这个,那么你原来的代码也应该会出问题才对呀。可是你的代码里也有对mciSendString的调用并且还好用。
这位朋友 你给的解答 我试了试 它提示没有mcisendstring这个单词 能在详细点么 麻烦了这个说不通啊,如果提示这个,那么你原来的代码也应该会出问题才对呀。可是你的代码里也有对mciSendString的调用并且还好用。
我直接把我的游戏代码发上来 给你看看 指导指导我 可是这里显示只能回复3次 我不能再回复了 你能先教我怎么用这个论坛
这位朋友 你给的解答 我试了试 它提示没有mcisendstring这个单词 能在详细点么 麻烦了这个说不通啊,如果提示这个,那么你原来的代码也应该会出问题才对呀。可是你的代码里也有对mciSendString的调用并且还好用。
我直接把我的游戏代码发上来 给你看看 指导指导我 可是这里显示只能回复3次 我不能再回复了 你能先教我怎么用这个论坛我记得是,连续回复不能回复3次。你这不连续的应该没事吧? 如果没办法,那你给我发私信吧。点我的头像,进去到我的页面,那里有发私信的按钮。
这位朋友 你给的解答 我试了试 它提示没有mcisendstring这个单词 能在详细点么 麻烦了这个说不通啊,如果提示这个,那么你原来的代码也应该会出问题才对呀。可是你的代码里也有对mciSendString的调用并且还好用。
我直接把我的游戏代码发上来 给你看看 指导指导我 可是这里显示只能回复3次 我不能再回复了 你能先教我怎么用这个论坛我记得是,连续回复不能回复3次。你这不连续的应该没事吧? 如果没办法,那你给我发私信吧。点我的头像,进去到我的页面,那里有发私信的按钮。
那好 我试试 我把我的代码发给上来给你看看 麻烦了
我在国外,百度贴吧上不去,还是传到CSDN吧。
我在国外,百度贴吧上不去,还是传到CSDN吧。 我想麻烦您帮我看看怎么添加两个功能 一个是 控制背景音乐的开和关 还有个是 这个游戏运行一次就会错误 我找了找 好像是开始按钮事件里面出错了 麻烦您给我指导一下。 昨天在忙朋友生病的事一直没时间。拜托您了。 代码在下面
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.IO;
using System.Media;
namespace 拼图
{
public partial class Form3 : Form
{
public static int a;
//定义b接收用户输入的总步数
public static int b;
private System.Windows.Forms.PictureBox[,]t;
public Form3()
{
InitializeComponent();
}
/// <summary>
/// 窗体加载事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form3_Load(object sender, EventArgs e)
{
string[] path = Directory.GetFiles(@"背景音乐", "*.wav");
SoundPlayer sp = new SoundPlayer();
sp.SoundLocation = path[0];
sp.Play();
//隐藏认输按钮事件
btnFinish.Enabled = false;
t = new PictureBox[3, 3] { { pictureBox1, pictureBox2, pictureBox3 }, { pictureBox4, pictureBox5, pictureBox6 }, { pictureBox7, pictureBox8, pictureBox9 } }; for (int i = 0; i <= 2; i++)
{
for (int j = 0; j <= 2; j++)
{
t[i, j].Enabled = false;
}
}
}
/// <summary>
/// 点击第一张图片事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox1_Click(object sender, EventArgs e)
{
b++;
label2.Text = b.ToString();
if (pictureBox2.Image == null)
{
pictureBox2.Image = pictureBox1.Image;
pictureBox1.Image = null;
}
else if (pictureBox4.Image == null)
{
pictureBox4.Image = pictureBox1.Image;
pictureBox1.Image = null;
} }
/// <summary>
/// 点击第二张图片事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox2_Click(object sender, EventArgs e)
{
b++;
label2.Text = b.ToString();
if (pictureBox1.Image == null)
{
pictureBox1.Image = pictureBox2.Image;
pictureBox2.Image = null;
}
else if (pictureBox3.Image == null)
{
pictureBox3.Image = pictureBox2.Image;
pictureBox2.Image = null;
}
else if (pictureBox5.Image == null)
{
pictureBox5.Image = pictureBox2.Image;
pictureBox2.Image = null;
}
}
/// <summary>
/// 点击第三张图片事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox3_Click(object sender, EventArgs e)
{
b++;
label2.Text = b.ToString();
if (pictureBox2.Image == null)
{
pictureBox2.Image = pictureBox3.Image;
pictureBox3.Image = null;
}
else if (pictureBox6.Image == null)
{
pictureBox6.Image = pictureBox3.Image;
pictureBox3.Image = null;
}
}
/// <summary>
/// 点击第四张图片事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox4_Click(object sender, EventArgs e)
{
b++;
label2.Text = b.ToString();
if (pictureBox1.Image == null)
{
pictureBox1.Image = pictureBox4.Image;
pictureBox4.Image = null;
}
else if (pictureBox5.Image == null)
{
pictureBox5.Image = pictureBox4.Image;
pictureBox4.Image = null;
}
else if (pictureBox7.Image == null)
{
pictureBox7.Image = pictureBox4.Image;
pictureBox4.Image = null;
}
}
/// <summary>
/// 点击第六张事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox6_Click(object sender, EventArgs e)
{
b++;
label2.Text = b.ToString();
if (pictureBox5.Image == null)
{
pictureBox5.Image = pictureBox6.Image;
pictureBox6.Image = null;
}
else if (pictureBox3.Image == null)
{
pictureBox3.Image = pictureBox6.Image;
pictureBox6.Image = null;
}
else if (pictureBox9.Image == null)
{
pictureBox9.Image = pictureBox6.Image;
pictureBox6.Image = null;
}
}
/// 点击第五张图片事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox5_Click(object sender, EventArgs e)
{
b++;
label2.Text = b.ToString();
if (pictureBox2.Image == null)
{
pictureBox2.Image = pictureBox5.Image;
pictureBox5.Image = null;
}
else if (pictureBox4.Image == null)
{
pictureBox4.Image = pictureBox5.Image;
pictureBox5.Image = null;
}
else if (pictureBox6.Image == null)
{
pictureBox6.Image = pictureBox5.Image;
pictureBox5.Image = null;
}
else if (pictureBox8.Image == null)
{
pictureBox8.Image = pictureBox5.Image;
pictureBox5.Image = null;
}
}
/// <summary>
/// 点击第七张图片事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox7_Click(object sender, EventArgs e)
{
b++;
label2.Text = b.ToString();
if (pictureBox4.Image == null)
{
pictureBox4.Image = pictureBox7.Image;
pictureBox7.Image = null;
}
else if (pictureBox8.Image == null)
{
pictureBox8.Image = pictureBox7.Image;
pictureBox7.Image = null;
}
}
/// <summary>
/// 点击第九张图片事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox9_Click(object sender, EventArgs e)
{
b++;
label2.Text = b.ToString();
if (pictureBox8.Image == null)
{
pictureBox8.Image = pictureBox9.Image;
pictureBox9.Image = null;
}
else if (pictureBox6.Image == null)
{
pictureBox6.Image = pictureBox9.Image;
pictureBox9.Image = null;
}
}
/// <summary>
/// 点击第八张事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox8_Click(object sender, EventArgs e)
{
b++;
label2.Text = b.ToString();
if (pictureBox5.Image == null)
{
pictureBox5.Image = pictureBox8.Image;
pictureBox8.Image = null;
}
else if (pictureBox9.Image == null)
{
pictureBox9.Image = pictureBox8.Image;
pictureBox8.Image = null;
}
else if (pictureBox7.Image == null)
{
pictureBox7.Image = pictureBox8.Image;
pictureBox8.Image = null;
}
}
/// <summary>
/// 更改标签的属性
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void label2_TextChanged(object sender, EventArgs e)
{
try
{
if (int.Parse(label2.Text) >= 10000)
{
MessageBox.Show("你已经超过了游戏所限定的最大步数,欢迎再来!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
}
catch { }
}
/// <summary>
/// 开始按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
//总分数为零
label2.Text = "0";
b = 0;
btnFinish.Enabled = true;
pictureBox9.Image = pictureBox18.Image;
a = a + 1;
for (int m = 0; m <= 2; m++)
{
for (int n = 0; n <= 2; n++)
{
t[m, n].Enabled = true;
}
}
ss:
switch (a)
{
case 1:
{
Clipboard.SetImage(pictureBox1.Image);
pictureBox1.Image = pictureBox5.Image;
pictureBox5.Image = Clipboard.GetImage();
Clipboard.Clear();
Clipboard.SetImage(pictureBox2.Image);
pictureBox2.Image = pictureBox4.Image;
pictureBox4.Image = Clipboard.GetImage();
Clipboard.Clear();
Clipboard.SetImage(pictureBox3.Image);
pictureBox3.Image = pictureBox8.Image;
pictureBox8.Image = Clipboard.GetImage();
Clipboard.Clear();
btnBegin.Enabled = false;
break;
}
case 2:
{
Clipboard.SetImage(pictureBox1.Image);
pictureBox1.Image = pictureBox6.Image;
pictureBox6.Image = Clipboard.GetImage();
Clipboard.Clear();
Clipboard.SetImage(pictureBox2.Image);
pictureBox2.Image = pictureBox8.Image;
pictureBox8.Image = Clipboard.GetImage();
Clipboard.Clear();
Clipboard.SetImage(pictureBox3.Image);
pictureBox3.Image = pictureBox5.Image;
pictureBox5.Image = Clipboard.GetImage();
Clipboard.Clear();
btnBegin.Enabled = false;
break;
}
case 3:
{
Clipboard.SetImage(pictureBox2.Image);
pictureBox2.Image = pictureBox5.Image;
pictureBox5.Image = Clipboard.GetImage();
Clipboard.Clear();
Clipboard.SetImage(pictureBox4.Image);
pictureBox4.Image = pictureBox6.Image;
pictureBox6.Image = Clipboard.GetImage();
Clipboard.Clear();
Clipboard.SetImage(pictureBox3.Image);
pictureBox3.Image = pictureBox8.Image;
pictureBox8.Image = Clipboard.GetImage();
Clipboard.Clear();
btnBegin.Enabled = false;
break;
}
case 4:
{
Clipboard.SetImage(pictureBox1.Image);
pictureBox1.Image = pictureBox8.Image;
pictureBox8.Image = Clipboard.GetImage();
Clipboard.Clear();
Clipboard.SetImage(pictureBox3.Image);
pictureBox3.Image = pictureBox5.Image;
pictureBox5.Image = Clipboard.GetImage();
Clipboard.Clear();
Clipboard.SetImage(pictureBox6.Image);
pictureBox6.Image = pictureBox9.Image;
pictureBox9.Image = Clipboard.GetImage();
Clipboard.Clear();
btnBegin.Enabled = false;
break;
}
default:
{
a = 1;
goto ss;
}
}
}
我已经打包传在自己的资源里面了去了 另外您给我的代码我运行不了 不知道是为什么 希望您能把我解决这两个问题 最好注释一下 我是新手有些地方不懂 希望您能体谅一下 多多包涵。 http://download.csdn.net/detail/spfarm/8359253 音乐播放的我加上了。
图片丢失的我查到了原因,但是希望你自己解决。
我已经打包传在自己的资源里面了去了 另外您给我的代码我运行不了 不知道是为什么 希望您能把我解决这两个问题 最好注释一下 我是新手有些地方不懂 希望您能体谅一下 多多包涵。 http://download.csdn.net/detail/spfarm/8359253 音乐播放的我加上了。
图片丢失的我查到了原因,但是希望你自己解决。
麻烦您了 但是您给我的地址 它提示资源不存在 不知道是为什么 多谢您帮我找到原因 我会自己解决的 多谢