2024-03-22 17:03:01 +08:00
|
|
|
|
using CDSAE3_Lian_Lian_Kan.Forms;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Timers;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace CDSAE3_Lian_Lian_Kan
|
|
|
|
|
{
|
|
|
|
|
public partial class Single_Block : UserControl
|
|
|
|
|
{
|
|
|
|
|
public Single_Block()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
if (Settings.game_form == null)
|
|
|
|
|
throw new Exception("game_form is null but try to make a new Single_Block");
|
|
|
|
|
Selected += Settings.game_form.Selected_Handler;
|
|
|
|
|
}
|
|
|
|
|
public Single_Block(int image, Color default_backColor, Color select_Color, (int, int) pos)
|
|
|
|
|
{
|
|
|
|
|
block_id = image;
|
|
|
|
|
position = pos;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
Image_change(Settings.get_block_Image(image));
|
|
|
|
|
picture.SizeMode = PictureBoxSizeMode.Zoom;
|
|
|
|
|
nor_color = default_backColor;
|
|
|
|
|
sel_color = select_Color;
|
|
|
|
|
BackColor = default_backColor;
|
|
|
|
|
picture.BackColor = default_backColor;
|
|
|
|
|
if (Settings.game_form == null)
|
|
|
|
|
throw new Exception("game_form is null but try to make a new Single_Block");
|
|
|
|
|
Selected += Settings.game_form.Selected_Handler;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public Single_Block(Image image, (int, int) pos)
|
|
|
|
|
{
|
|
|
|
|
position = pos;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
picture.SizeMode = PictureBoxSizeMode.Zoom;
|
|
|
|
|
BackColor = Color.FromArgb(0, 0, 0, 0);
|
|
|
|
|
can_be_selected = false;
|
|
|
|
|
if (Settings.game_form == null)
|
|
|
|
|
throw new Exception("game_form is null but try to make a new Single_Block");
|
|
|
|
|
Selected += Settings.game_form.Selected_Handler;
|
|
|
|
|
}
|
|
|
|
|
int block_id;
|
|
|
|
|
Color nor_color;
|
|
|
|
|
Color sel_color;
|
|
|
|
|
public bool selected { get; set; } = false;
|
|
|
|
|
bool can_be_selected = true;
|
|
|
|
|
public (int, int) position { get; set; }//height,width
|
|
|
|
|
private void picture_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!can_be_selected)
|
|
|
|
|
return;
|
|
|
|
|
if (selected)
|
|
|
|
|
{
|
|
|
|
|
deselect();
|
|
|
|
|
Selected.Invoke(this, new SelectedEventArgs(position, false));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
select();
|
|
|
|
|
Selected.Invoke(this, new SelectedEventArgs(position, true));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void select()
|
|
|
|
|
{
|
|
|
|
|
selected = true;
|
|
|
|
|
BackColor = sel_color;
|
|
|
|
|
}
|
|
|
|
|
public void deselect()
|
|
|
|
|
{
|
|
|
|
|
selected = false;
|
|
|
|
|
BackColor = nor_color;
|
|
|
|
|
}
|
2024-03-29 14:18:38 +08:00
|
|
|
|
Settings.Direction direction = Settings.Direction.none;
|
|
|
|
|
public void hint_path(Settings.Direction direction)
|
|
|
|
|
{
|
|
|
|
|
this.direction |= direction;
|
|
|
|
|
Image_change(Settings.get_tip_direction_Image(this.direction));
|
|
|
|
|
}
|
2024-03-22 17:03:01 +08:00
|
|
|
|
public void to_path(Settings.Direction direction)
|
2024-03-29 14:18:38 +08:00
|
|
|
|
{
|
|
|
|
|
Image_change(Settings.get_direction_Image(direction));
|
|
|
|
|
direction = Settings.Direction.none;
|
2024-03-22 17:03:01 +08:00
|
|
|
|
}
|
|
|
|
|
public void de_path()
|
|
|
|
|
{
|
|
|
|
|
Image_change(Settings.trans_Image);
|
2024-03-29 14:18:38 +08:00
|
|
|
|
direction = Settings.Direction.none;
|
2024-03-22 17:03:01 +08:00
|
|
|
|
}
|
|
|
|
|
System.Timers.Timer? timer = null;
|
|
|
|
|
public void destroyAsync()
|
|
|
|
|
{
|
|
|
|
|
Image_change(Settings.get_disappear_Images(block_id));
|
|
|
|
|
BackColor = Color.FromArgb(0, 0, 0, 0);
|
|
|
|
|
can_be_selected = false;
|
|
|
|
|
timer = new System.Timers.Timer();
|
|
|
|
|
timer.Interval = 500;
|
|
|
|
|
timer.Elapsed += Image_Clear;
|
|
|
|
|
timer.Enabled = true;
|
|
|
|
|
}
|
2024-03-29 14:18:38 +08:00
|
|
|
|
object locker = new object();
|
2024-03-22 17:03:01 +08:00
|
|
|
|
public void Image_Clear(object? sender, ElapsedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
timer?.Stop();
|
|
|
|
|
Image_change(Settings.trans_Image);
|
|
|
|
|
}
|
|
|
|
|
public void Image_change(Image new_image)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
lock (locker)
|
|
|
|
|
{
|
|
|
|
|
picture.Image = new_image;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(Exception)
|
|
|
|
|
{
|
|
|
|
|
Image_change(new_image);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-29 14:18:38 +08:00
|
|
|
|
public void Re_create(int image, Color? default_backColor, Color? select_Color, (int, int)? pos)
|
|
|
|
|
{
|
|
|
|
|
if (block_id == image)
|
|
|
|
|
return;
|
|
|
|
|
block_id = image;
|
|
|
|
|
Image_change(Settings.get_block_Image(image));
|
|
|
|
|
if (default_backColor != null)
|
|
|
|
|
nor_color = (Color)default_backColor;
|
|
|
|
|
if(select_Color != null)
|
|
|
|
|
sel_color = (Color)select_Color;
|
|
|
|
|
if (pos != null)
|
|
|
|
|
position = ((int, int))pos;
|
|
|
|
|
}
|
2024-03-22 17:03:01 +08:00
|
|
|
|
public event SelectedEventHandler Selected;
|
|
|
|
|
}
|
|
|
|
|
public class SelectedEventArgs : EventArgs
|
|
|
|
|
{
|
|
|
|
|
public SelectedEventArgs((int, int) pos, bool sel)//width,height sel for be_selected
|
|
|
|
|
{
|
|
|
|
|
position = pos;
|
|
|
|
|
be_selected = sel;
|
|
|
|
|
}
|
|
|
|
|
public (int, int) position { get; set; }//height,width
|
|
|
|
|
public bool be_selected { get; set; }
|
|
|
|
|
}
|
|
|
|
|
public delegate void SelectedEventHandler(Single_Block sender, SelectedEventArgs e);
|
|
|
|
|
}
|