Сделать стены в игре "Лабиринт"
Код:
namespace Catacombs
{
public partial class Menu : Form
{
bool right;
bool left;
bool up;
bool down;
public Menu()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
//делаем 1 блок осязаемым
if (player.Right > block.Left-3 && player.Bottom > block.Top && player.Top < block.Bottom) { right = false; }
if (player.Left < block.Right+3 && player.Bottom > block.Top && player.Top < block.Bottom) { left = false; }
if (player.Bottom > block.Top-3 && player.Left < block.Right && player.Right > block.Left) { down = false; }
if (player.Top < block.Bottom+3 && player.Left < block.Right && player.Right > block.Left) { up = false; }
if (right == true) {player.Left += 3;}
if (left == true) { player.Left -= 3; }
if (up == true) { player.Top -= 3; }
if (down == true) { player.Top += 3; }
}
private void Menu_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode ==Keys.Right) { right = true; }
if (e.KeyCode == Keys.Left) { left = true; }
if (e.KeyCode == Keys.Up) { up = true; }
if (e.KeyCode == Keys.Down) { down = true; }
}
private void Menu_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right) { right = false; }
if (e.KeyCode == Keys.Left) { left = false; }
if (e.KeyCode == Keys.Up) { up = false; }
if (e.KeyCode == Keys.Down) { down = false; }
}
}
}
{
public partial class Menu : Form
{
bool right;
bool left;
bool up;
bool down;
public Menu()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
//делаем 1 блок осязаемым
if (player.Right > block.Left-3 && player.Bottom > block.Top && player.Top < block.Bottom) { right = false; }
if (player.Left < block.Right+3 && player.Bottom > block.Top && player.Top < block.Bottom) { left = false; }
if (player.Bottom > block.Top-3 && player.Left < block.Right && player.Right > block.Left) { down = false; }
if (player.Top < block.Bottom+3 && player.Left < block.Right && player.Right > block.Left) { up = false; }
if (right == true) {player.Left += 3;}
if (left == true) { player.Left -= 3; }
if (up == true) { player.Top -= 3; }
if (down == true) { player.Top += 3; }
}
private void Menu_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode ==Keys.Right) { right = true; }
if (e.KeyCode == Keys.Left) { left = true; }
if (e.KeyCode == Keys.Up) { up = true; }
if (e.KeyCode == Keys.Down) { down = true; }
}
private void Menu_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right) { right = false; }
if (e.KeyCode == Keys.Left) { left = false; }
if (e.KeyCode == Keys.Up) { up = false; }
if (e.KeyCode == Keys.Down) { down = false; }
}
}
}
Нужно, что-бы не стены думали, а сам курсор-лабиринта определял, что у нево на пути
Для этово нужно проверять ход (Right-Left-Up-Down) перед курсором-лабиринта.
un2008Csharp.dll - нужно добавить к проекту Как ссылку
Все PictureBox Size 13x13, кроме лабиринта(в данном случаи 402x402) зависит от настроек генератора лабиринтов.
Код:
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.VisualBasic.Devices;
using un2008Csharp;
namespace SimpleMaze
{
public partial class Form1 : Form
{
int int_corX;
int int_corY;
string str_MemArrow;
Computer My = new Computer();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int_corX = picCursor.Left;
int_corY = picCursor.Top;
NumLockOffOn();
Buza.ShowMove(picMaze, picControlMove, picCursor);
}
private void NumLockOffOn()
{
if (My.Keyboard.NumLock)
{
picNumLock.BackColor = Color.Green;
}
else
{
picNumLock.BackColor = Color.Red;
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Up:
case Keys.NumPad8:
int_corY -= 1;
str_MemArrow = "AU";
break;
case Keys.Down:
case Keys.NumPad2:
int_corY += 1;
str_MemArrow = "AD";
break;
case Keys.Left:
case Keys.NumPad4:
int_corX -= 1;
str_MemArrow = "AL";
break;
case Keys.Right:
case Keys.NumPad6:
int_corX += 1;
str_MemArrow = "AR";
break;
case Keys.NumLock:
NumLockOffOn();
return;
}
picCursor.Location = new Point(int_corX, int_corY);
Buza.ShowMove(picMaze, picControlMove, picCursor);
}
private void picControlMove_Paint(object sender, PaintEventArgs e)
{
Bitmap M_bm = new Bitmap(picMask.Image);
Bitmap C_bm = new Bitmap(picControlMove.Image);
if (Buza.CompareImage(M_bm, C_bm) == Buza.CompareResult.unPixelMismatch)
{
switch (str_MemArrow)
{
case "AU":
int_corY += 1;
break;
case "AD":
int_corY -= 1;
break;
case "AL":
int_corX += 1;
break;
case "AR":
int_corX -= 1;
break;
}
}
picCursor.Location = new Point(int_corX, int_corY);
}
}
}
using System.Drawing;
using System.Windows.Forms;
using Microsoft.VisualBasic.Devices;
using un2008Csharp;
namespace SimpleMaze
{
public partial class Form1 : Form
{
int int_corX;
int int_corY;
string str_MemArrow;
Computer My = new Computer();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int_corX = picCursor.Left;
int_corY = picCursor.Top;
NumLockOffOn();
Buza.ShowMove(picMaze, picControlMove, picCursor);
}
private void NumLockOffOn()
{
if (My.Keyboard.NumLock)
{
picNumLock.BackColor = Color.Green;
}
else
{
picNumLock.BackColor = Color.Red;
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Up:
case Keys.NumPad8:
int_corY -= 1;
str_MemArrow = "AU";
break;
case Keys.Down:
case Keys.NumPad2:
int_corY += 1;
str_MemArrow = "AD";
break;
case Keys.Left:
case Keys.NumPad4:
int_corX -= 1;
str_MemArrow = "AL";
break;
case Keys.Right:
case Keys.NumPad6:
int_corX += 1;
str_MemArrow = "AR";
break;
case Keys.NumLock:
NumLockOffOn();
return;
}
picCursor.Location = new Point(int_corX, int_corY);
Buza.ShowMove(picMaze, picControlMove, picCursor);
}
private void picControlMove_Paint(object sender, PaintEventArgs e)
{
Bitmap M_bm = new Bitmap(picMask.Image);
Bitmap C_bm = new Bitmap(picControlMove.Image);
if (Buza.CompareImage(M_bm, C_bm) == Buza.CompareResult.unPixelMismatch)
{
switch (str_MemArrow)
{
case "AU":
int_corY += 1;
break;
case "AD":
int_corY -= 1;
break;
case "AL":
int_corX += 1;
break;
case "AR":
int_corX -= 1;
break;
}
}
picCursor.Location = new Point(int_corX, int_corY);
}
}
}