?? frmmain.cs
字號:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
namespace PushBox
{
public partial class frmMain : Form
{
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
public frmMain()
{
InitializeComponent();
}
private System.Collections.ArrayList MapArrayList = new System.Collections.ArrayList();
enum enumMap
{
地板,箱子目地的,墻,箱子,空,紅箱子
}
private string RenImage = null;
enumMap[] enumMapArray = new enumMap[225];
enumMap[] Undo1MapArray = new enumMap[255];
private Point Ren1Locate = new Point();
private string MapType = "standard";
private Sound sMusic = null;
private Sound sPushBox = null;
private Sound sCantBox = null;
public int Level = 1;
private Label LBox = new Label();
private Label LAim = new Label();
private Label Ldown1 = new Label();
private Label Ldown2 = new Label();
private Label Lleft1 = new Label();
private Label Lleft2 = new Label();
private Label LLu = new Label();
private Label LREDBOX = new Label();
private Label Lright1 = new Label();
private Label Lright2 = new Label();
private Label Lup1 = new Label();
private Label Lup2 = new Label();
private Label LWall = new Label();
private Node[] b;
int[] luArray;
int RenWeiZhi = 0;
/// <summary>
/// 讀Ini文件
/// </summary>
/// <param name="section"></param>
/// <param name="key"></param>
/// <param name="def"></param>
/// <param name="FileName"></param>
/// <returns></returns>
public string ReadString(string section, string key, string def, string FileName)
{
StringBuilder temp = new StringBuilder(1024);
GetPrivateProfileString(section, key, def, temp, 1024, FileName);
return temp.ToString();
}
/// <summary>
/// 是否通過當前關
/// </summary>
/// <returns></returns>
private bool WinBool()
{
bool win = true;
for (int i = 0; i < 225; i++)
{
if (enumMapArray[i] == enumMap.箱子目地的)
{
win = false;
}
}
return win;
}
/// <summary>
/// 地表構造
/// </summary>
private void DiBiao()
{
for (int i = 0; i < 225; i++)
{
PictureBox p = new PictureBox();
p.BackColor = Color.Black;
p.SizeMode = PictureBoxSizeMode.StretchImage;
p.Size = new Size(30, 30);
p.Top = int.Parse((i / 15).ToString()) * 30;
p.Left = (i - int.Parse((i / 15).ToString()) * 15) * 30;
p.Visible = true;
p.Parent = panel1;
MapArrayList.Add(p);
}
}
/// <summary>
/// 顯示地圖
/// </summary>
/// <param name="FileName"></param>
private void ShowMap(string FileName)
{
撤消ToolStripMenuItem.Enabled = false;
toolStripButton5.Enabled = false;
this.Text = "推箱子 【★-第" + Level.ToString() + "關-★】";
for (int i = 0; i < 225; i++)
{
switch (ReadString("Game", "PBox" + i.ToString(), "", Application.StartupPath + "\\Level\\" + FileName))
{
case "Wall":
enumMapArray[i] = enumMap.墻;
((PictureBox)MapArrayList[i]).Image = LWall.Image;
break;
case "null":
enumMapArray[i] = enumMap.空;
((PictureBox)MapArrayList[i]).Image = null;
break;
case "Box":
enumMapArray[i] = enumMap.箱子;
((PictureBox)MapArrayList[i]).Image = LBox.Image;
((PictureBox)MapArrayList[i]).MouseEnter += new EventHandler(P_MouseEnter);
((PictureBox)MapArrayList[i]).MouseLeave += new EventHandler(P_MouseLeave);
((PictureBox)MapArrayList[i]).Click += new EventHandler(P_Click);
break;
case "People":
enumMapArray[i] = enumMap.地板;
((PictureBox)MapArrayList[i]).Image = LLu.Image;
((PictureBox)MapArrayList[i]).MouseEnter += new EventHandler(P_MouseEnter);
((PictureBox)MapArrayList[i]).MouseLeave += new EventHandler(P_MouseLeave);
((PictureBox)MapArrayList[i]).Click += new EventHandler(P_Click);
pbRen.Top = int.Parse((i / 15).ToString()) * 30;
pbRen.Left = (i - int.Parse((i / 15).ToString()) * 15) * 30;
pbRen.Image = LLu.Image;
RenImage = "down1.BMP";
break;
case "Aim":
enumMapArray[i] = enumMap.箱子目地的;
((PictureBox)MapArrayList[i]).Image = LAim.Image;
((PictureBox)MapArrayList[i]).MouseEnter += new EventHandler(P_MouseEnter);
((PictureBox)MapArrayList[i]).MouseLeave += new EventHandler(P_MouseLeave);
((PictureBox)MapArrayList[i]).Click += new EventHandler(P_Click);
break;
case "Lu":
enumMapArray[i] = enumMap.地板;
((PictureBox)MapArrayList[i]).Image = LLu.Image;
((PictureBox)MapArrayList[i]).MouseEnter += new EventHandler(P_MouseEnter);
((PictureBox)MapArrayList[i]).MouseLeave += new EventHandler(P_MouseLeave);
((PictureBox)MapArrayList[i]).Click += new EventHandler(P_Click);
break;
}
}
timer1.Enabled = true;
}
/// <summary>
/// 加載地圖類型
/// </summary>
/// <param name="mapDir"></param>
private void LoadMapType(string mapDir)
{
LAim.Image = new Bitmap(Application.StartupPath + "\\" + mapDir + "\\Aim.BMP");
LBox.Image = new Bitmap(Application.StartupPath + "\\" + mapDir + "\\Box.bmp");
Ldown1.Image = new Bitmap(Application.StartupPath + "\\" + mapDir + "\\down1.BMP");
Ldown2.Image = new Bitmap(Application.StartupPath + "\\" + mapDir + "\\down2.BMP");
Lleft1.Image = new Bitmap(Application.StartupPath + "\\" + mapDir + "\\left1.BMP");
Lleft2.Image = new Bitmap(Application.StartupPath + "\\" + mapDir + "\\left2.BMP");
LLu.Image = new Bitmap(Application.StartupPath + "\\" + mapDir + "\\Lu.BMP");
LREDBOX.Image = new Bitmap(Application.StartupPath + "\\" + mapDir + "\\REDBOX.BMP");
Lright1.Image = new Bitmap(Application.StartupPath + "\\" + mapDir + "\\right1.bmp");
Lright2.Image = new Bitmap(Application.StartupPath + "\\" + mapDir + "\\right2.bmp");
Lup1.Image = new Bitmap(Application.StartupPath + "\\" + mapDir + "\\up1.BMP");
Lup2.Image = new Bitmap(Application.StartupPath + "\\" + mapDir + "\\up2.BMP");
LWall.Image = new Bitmap(Application.StartupPath + "\\" + mapDir + "\\Wall.BMP");
}
/// <summary>
/// 改變地圖類型
/// </summary>
private void ChangeMapType()
{
for (int i = 0; i < 225; i++)
{
switch (enumMapArray[i])
{
case enumMap.地板:
((PictureBox)MapArrayList[i]).Image = LLu.Image;
break;
case enumMap.紅箱子:
((PictureBox)MapArrayList[i]).Image = LREDBOX.Image;
break;
case enumMap.空:
((PictureBox)MapArrayList[i]).Image = null;
break;
case enumMap.墻:
((PictureBox)MapArrayList[i]).Image = LWall.Image;
break;
case enumMap.箱子:
((PictureBox)MapArrayList[i]).Image = LBox.Image;
break;
case enumMap.箱子目地的:
((PictureBox)MapArrayList[i]).Image = LAim.Image;
break;
}
}
pbRen.Image = Ldown1.Image;
}
private void MouseFindLu()
{
b = new Node[225];
for (int i = 0; i < 225; i++)
{
b[i] = new Node();
b[i].X = i - int.Parse((i / 15).ToString()) * 15;
b[i].Y = int.Parse((i / 15).ToString());
}
}
private void frmMain_Load(object sender, EventArgs e)
{
DiBiao();
MouseFindLu();
LoadMapType(MapType);
ShowMap("Level1.hmap");
sPushBox = new Sound(this);
sMusic = new Sound(this);
sCantBox = new Sound(this);
sMusic.Load(Application.StartupPath + "\\music.mp3");
sPushBox.Load(Application.StartupPath + "\\PushBox.Wav");
sCantBox.Load(Application.StartupPath + "\\CantMove.wav");
開啟ToolStripMenuItem_Click(null, null);
this.Size = new Size(456, 535);
this.Top = 0;
}
private void timer1_Tick(object sender, EventArgs e)
{
switch (RenImage)
{
case "down1.BMP":
pbRen.Image = Ldown2.Image;
RenImage = "down2.BMP";
break;
case "down2.BMP":
pbRen.Image = Ldown1.Image;
RenImage = "down1.BMP";
break;
case "left1.BMP":
pbRen.Image = Lleft2.Image;
RenImage = "left2.BMP";
break;
case "left2.BMP":
pbRen.Image = Lleft1.Image;
RenImage = "left1.BMP";
break;
case "right1.BMP":
pbRen.Image = Lright2.Image;
RenImage = "right2.BMP";
break;
case "right2.BMP":
pbRen.Image = Lright1.Image;
RenImage = "right1.BMP";
break;
case "up1.BMP":
pbRen.Image = Lup2.Image;
RenImage = "up2.BMP";
break;
case "up2.BMP":
pbRen.Image = Lup1.Image;
RenImage = "up1.BMP";
break;
}
}
private void frmMain_KeyDown(object sender, KeyEventArgs e)
{
Point lcation = pbRen.Location;
switch (e.KeyCode)
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -