中间件探索

This commit is contained in:
lichx 2024-04-08 21:04:47 +08:00
parent e0a212af0f
commit 3e81b973e9
15 changed files with 753 additions and 161 deletions

View File

@ -57,7 +57,19 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
foreach (var (x, y) in poss)
{
int type = Index[(x, y)].value;
if (!Index.Remove((x, y)))
if(Index.TryGetValue((x,y),out Node? node))
{
if (node.RNode != null)
node.RNode.LNode = node.LNode;
if(node.LNode!=null)
node.LNode.RNode = node.RNode;
if(node.DNode!=null)
node.DNode.UNode = node.UNode;
if(node.UNode!=null)
node.UNode.DNode = node.DNode;
Index.Remove((x, y));
}
else
throw new Exception("Val not Found in Index");
if (!board_Index[type].Remove((x, y)))
throw new Exception("Val not Found in board_Index");
@ -68,7 +80,15 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
public List<List<(int, int)>> get_tip((int, int) start)
{
throw new NotImplementedException();
List<List<(int, int)>> ans = new List<List<(int, int)>>();
if (board_Index.TryGetValue(Index[start].value, out var tip))
foreach (var pos in tip)
{
var (result, path) = test(start, pos);
if (result && path != null)
ans.Add(path);
}
return ans;
}
public int[,] make_board()
@ -78,7 +98,10 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
int[,]Bd = new int[height + 2, width + 2];
for (int i = 0; i < height + 2; i++)
for (int j = 0; j < width + 2; j++)
{
Bd[i, j] = -1;
Index.Add((j, i), new Node(j, i, -1));
}
int sum = width * height;
if (sum % 2 != 0)
@ -96,7 +119,7 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
index.Add((cur_width, cur_height));
else
board_Index.Add(Bd[cur_height, cur_width], new List<(int, int)> { (cur_width, cur_height) });
Index.Add((cur_width, cur_height), new Node(cur_width, cur_height, Bd[cur_height, cur_width]));
Index[(cur_width, cur_height)].value = Bd[cur_height, cur_width];
cur_width++;
if (cur_width > width)
{
@ -121,13 +144,162 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
public int[,] remake_board()
{
throw new NotImplementedException();
board_Index.Clear();
int[] temp_val_per_Image = (int[])Vals_per_Image.Clone();
var (width, height) = size;
int[,] Bd = new int[height + 2, width + 2];
for (int i = 0; i < height + 2; i++)
for (int j = 0; j < width + 2; j++)
Bd[i, j] = -1;
int last_val = -1;
foreach(var (index,node) in Index)
{
if(node.value==-1)
continue;
node.value = board_Funcs.getval(ref temp_val_per_Image, ref last_val, Etcs.Images_size());
Bd[node.y,node.x] = node.value;
if(board_Index.TryGetValue(node.value,out var list))
list.Add((node.x, node.y));
else
board_Index.Add(node.value, new List<(int, int)> { (node.x, node.y) });
}
return Bd;
}
public (bool, List<(int, int)>?) test((int, int) a, (int, int) b)
{
throw new NotImplementedException();
if(a==b)
return (false, null);
int xa, ya, xb, yb;
if (Index.TryGetValue(a, out var nodeA) && Index.TryGetValue(b, out var nodeB))
{
if (nodeA.value != nodeB.value)
return (false,null);
else
{
(xa, ya) = a;
(xb, yb) = b;
}
}
else
return (false, null);
Func<bool, int, int, int, bool> line_test = (bool x, int ct, int from, int to) =>
{//ct is x (x==true)left to right ///up to down ///Index must contain from or to ///只管中间
if (from > to)
(from, to) = (to, from);
if(ct==0||(ct == size.Item1+1&&!x)||(ct==size.Item2+1&&x))
return true;
if(x)
{
var node = Index[(0, ct)].RNode;
while(node!=null)
{
if (node.x > to)
return true;
if (node.x > from && node.x < to)
return false;
node = node.RNode;
}
return true;
}
else
{
var node = Index[(ct, 0)].DNode;
while (node != null)
{
if (node.y > to)
return true;
if (node.y > from && node.y < to)
return false;
node = node.DNode;
}
return true;
}
};
if (xa == xb)
if (line_test(false, xa, ya, yb))
return (true, new List<(int, int)> { a, b });
if (ya == yb)
if (line_test(true, ya, xa, xb))
return (true, new List<(int, int)> { a, b });
{//two line test
(int, int) extra_pa = (xa, yb);
(int, int) extra_pb = (xb, ya);
if (!Index.ContainsKey(extra_pa))
if (line_test(true, yb, xa, xb) && line_test(false, xa, ya, yb))
return (true, new List<(int, int)> { a, extra_pa, b });
if (!Index.ContainsKey(extra_pb))
if (line_test(true, ya, xa, xb) && line_test(false, xb, ya, yb))
return (true, new List<(int, int)> { a, extra_pb, b });
}
(int, int)[] squareA = new (int, int)[4];
(int, int)[] squareB = new (int, int)[4];//urdl
{//three line test
Func<Node, (int,int)[]> get_square = (Node node) =>
{
(int, int)[] result = new (int, int)[4];
result[0] = (node.UNode!.x, node.UNode!.value==-1? node.UNode!.y: node.UNode!.y + 1);
result[1] = (node.RNode!.value==-1? node.RNode!.x: node.RNode!.x - 1, node.RNode!.y);
result[2] = (node.DNode!.x, node.DNode!.value==-1? node.DNode!.y: node.DNode!.y - 1);
result[3] = (node.LNode!.value==-1? node.LNode!.x: node.LNode!.x + 1, node.LNode!.y);
return result;
};
squareA = get_square(nodeA);
squareB = get_square(nodeB);
Func<(int, int), (int, int), (bool, (int, int))> intersection = ((int, int) a, (int, int) b) =>//first small last big
{
if(a.Item1==a.Item2&&b.Item1==b.Item2&& a.Item1 == b.Item1)
return (false, (-1, -1));
if (a.Item1 > b.Item1)
(a, b) = (b, a);
if (a.Item2 < b.Item1)
return (false, (-1, -1));
if (a.Item2 > b.Item2)
return (true, (b.Item1, b.Item2));
return (true, (b.Item1, a.Item2));
};
var (throughx, xrange) = intersection((squareA[3].Item1, squareA[1].Item1), (squareB[3].Item1, squareB[1].Item1));
var (throughy, yrange) = intersection((squareA[0].Item2, squareA[2].Item2), (squareB[0].Item2, squareB[2].Item2));
Func<(int, int), int, List<int>> swing_check = ((int, int) range, int center) =>
{
List<int> result = new List<int>();
if (center < range.Item1)
{
for (int k = range.Item1; k <= range.Item2; k++)
result.Add(k);
return result;
}
if (center > range.Item2)
{
for (int k = range.Item2; k >= range.Item1; k--)
result.Add(k);
return result;
}
result.Add(center);
Func<int, bool> inrange = (int t) => t >= range.Item1 && t <= range.Item2;
bool go_on = true;
for (int i = 1; go_on; i++)
{
go_on = false;
if (go_on |= inrange(center + i))
result.Add(center + i);
if (go_on |= inrange(center - i))
result.Add(center - i);
}
return result;
};
if (throughx)
foreach (int i in swing_check(xrange, a.Item1))
if (line_test(false, i, a.Item2, b.Item2))
return (true, new List<(int, int)> { a, (i, a.Item2), (i, b.Item2), b });
if (throughy)
foreach (int i in swing_check(yrange, a.Item2))
if (line_test(true, i, a.Item1, b.Item1))
return (true, new List<(int, int)> { a, (a.Item1, i), (b.Item1, i), b });
}
return (false, null);
}
}
}

View File

@ -64,6 +64,7 @@ namespace CDSAE3_Lian_Lian_Kan
{10,100.0/3 }};
static int cus_height = 1, cus_width = 1;
public static System.Timers.Timer hunderd_millsecond_timer { get; set; } = new System.Timers.Timer(100) { AutoReset = true, Enabled = true };
public static Difficulty current_difficulty { get; set; } = Difficulty.normal;
public static Mode current_mode { get; set; }
public static Image trans_Image { get; set; } = Resources.trans;
@ -85,6 +86,7 @@ namespace CDSAE3_Lian_Lian_Kan
public static Color sel_Color { get; set; } = Color.FromArgb(0, 122, 204);
public static Color mouse_upper_color { get; set; } = Color.FromArgb(97, 97, 108);
public static Dictionary<string, List<string>> musics { get; set; } = new Dictionary<string, List<string>> { { "C418", new List<string> { "C418 - Beginning 2", "C418 - Floating Trees", "C418 - Moog City 2", "C418 - Mutation" } } };
public static Audio_res_manager audio_Res_Manager { get; set; } = new Audio_res_manager();
public static Song_Audio_processer song_Audio_Processer { get; set; } = new Song_Audio_processer();
public static Info_Audio_processer info_Audio_Processer { get; set; } = new Info_Audio_processer();
public static ResourceManager res_Manager { get; set; } = new ResourceManager("CDSAE3_Lian_Lian_Kan.Properties.Resources", typeof(Resources).Assembly);

View File

@ -16,7 +16,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
{
public partial class GameControl : UserControl, IGameControl
{
Board board = new Board();
IBoard board = new Graph_Board();
IGameMode? iGameMode;
Queue<((int, int), Single_Block)> queue = new Queue<((int, int), Single_Block)>();//y,x
bool do_search = false;
@ -24,13 +24,14 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
public GameControl()
{
InitializeComponent();
DoubleBuffered = true;
Etcs.game_form = this;
playPanel_set(board.make_board());
iGameMode = Etcs.game_mode_form;
}
void playPanel_set(int[,]bd)
void playPanel_set(int[,] bd)
{
playPanel.SuspendLayout();
playPanel_size_change();
for (int i = 0; i < playPanel.RowCount; i++)
for (int j = 0; j < playPanel.ColumnCount; j++)
@ -48,6 +49,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
playPanel.Controls.Add(x, j, i);
}
}
playPanel.ResumeLayout();
}
/// <summary>
/// 由form和to两个点获取方向
@ -76,7 +78,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
/// <param name="blocks"></param>
/// <param name="decrease"></param>
/// <returns></returns>
async Task set_PathAsync((int, int) point, Etcs.Direction direction, List<Single_Block> blocks, int wait_time,bool is_hint)
async Task set_PathAsync((int, int) point, Etcs.Direction direction, List<Single_Block> blocks, int wait_time, bool is_hint)
{
if (wait_time != 0)
@ -98,26 +100,26 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
{
case Etcs.Direction.up:
for (int i = from.Item2 - 1; i != to.Item2; i--)
await set_PathAsync((from.Item1, i), Etcs.Direction.up_down, blocks, wait_time,is_hint);
await set_PathAsync((from.Item1, i), Etcs.Direction.up_down, blocks, wait_time, is_hint);
break;
case Etcs.Direction.down:
for (int i = from.Item2 + 1; i != to.Item2; i++)
await set_PathAsync((from.Item1, i), Etcs.Direction.up_down, blocks, wait_time,is_hint);
await set_PathAsync((from.Item1, i), Etcs.Direction.up_down, blocks, wait_time, is_hint);
break;
case Etcs.Direction.right:
for (int i = from.Item1 + 1; i != to.Item1; i++)
await set_PathAsync((i, from.Item2), Etcs.Direction.left_right, blocks, wait_time,is_hint);
await set_PathAsync((i, from.Item2), Etcs.Direction.left_right, blocks, wait_time, is_hint);
break;
case Etcs.Direction.left:
for (int i = from.Item1 - 1; i != to.Item1; i--)
await set_PathAsync((i, from.Item2), Etcs.Direction.left_right, blocks, wait_time,is_hint);
await set_PathAsync((i, from.Item2), Etcs.Direction.left_right, blocks, wait_time, is_hint);
break;
}
if (include_end)
{
direction = ((int)direction & 3) > 0 ? (Etcs.Direction)((int)direction << 2) : (Etcs.Direction)((int)direction >> 2);
direction = direction | extra_Direction;
await set_PathAsync(to, direction, blocks, wait_time,is_hint);
await set_PathAsync(to, direction, blocks, wait_time, is_hint);
}
}
async Task path_drawerAsync(List<(int, int)> path, int wait_time, List<Single_Block> blocks, bool is_hint)
@ -125,18 +127,18 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
switch (path.Count)
{
case 2:
await to_path(path[0], path[1], false, Etcs.Direction.none, blocks, wait_time,is_hint);
await to_path(path[0], path[1], false, Etcs.Direction.none, blocks, wait_time, is_hint);
break;
case 3:
var extra_direction = get_Direction(path[1], path[2]);
await to_path(path[0], path[1], true, extra_direction, blocks, wait_time,is_hint);
await to_path(path[1], path[2], false, Etcs.Direction.none, blocks, wait_time,is_hint);
await to_path(path[0], path[1], true, extra_direction, blocks, wait_time, is_hint);
await to_path(path[1], path[2], false, Etcs.Direction.none, blocks, wait_time, is_hint);
break;
case 4:
Etcs.Direction extra_directionA = get_Direction(path[1], path[2]), extra_directionB = get_Direction(path[2], path[3]);
await to_path(path[0], path[1], true, extra_directionA, blocks, wait_time,is_hint);
await to_path(path[1], path[2], true, extra_directionB, blocks, wait_time,is_hint);
await to_path(path[2], path[3], false, Etcs.Direction.none, blocks, wait_time,is_hint);
await to_path(path[0], path[1], true, extra_directionA, blocks, wait_time, is_hint);
await to_path(path[1], path[2], true, extra_directionB, blocks, wait_time, is_hint);
await to_path(path[2], path[3], false, Etcs.Direction.none, blocks, wait_time, is_hint);
break;
}
@ -147,7 +149,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
return;
List<List<(int, int)>> paths = board.get_tip(queue.Peek().Item1);
foreach (var path in paths)
_ = path_drawerAsync(path, 0, hint_blocks,true);
_ = path_drawerAsync(path, 0, hint_blocks, true);
}
internal void de_set_tip()
{
@ -250,6 +252,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
public void Exchange_Handler(object? sender, EventArgs e)
{
int[,] bd = board.remake_board();
playPanel.SuspendLayout();
for (int i = 0; i < bd.GetLength(0); i++)
for (int j = 0; j < bd.GetLength(1); j++)
if (bd[i, j] == -1)
@ -260,6 +263,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
if (control != null && control is Single_Block single_Block)
single_Block.Re_create(bd[i, j], null, null, null);
}
playPanel.ResumeLayout();
}
public void Search_Handler(object? sender, SearchEventArgs e)

View File

@ -0,0 +1,70 @@
namespace CDSAE3_Lian_Lian_Kan.Forms
{
partial class Item
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
picture = new PictureBox();
Back_Picture = new Label();
((System.ComponentModel.ISupportInitialize)picture).BeginInit();
SuspendLayout();
//
// picture
//
picture.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
picture.Location = new Point(0, 0);
picture.Name = "picture";
picture.Size = new Size(70, 70);
picture.TabIndex = 1;
picture.TabStop = false;
//
// Back_Picture
//
Back_Picture.BackColor = Color.Gray;
Back_Picture.Location = new Point(0, 0);
Back_Picture.Name = "Back_Picture";
Back_Picture.Size = new Size(70, 70);
Back_Picture.TabIndex = 2;
//
// Item
//
AutoScaleDimensions = new SizeF(11F, 24F);
AutoScaleMode = AutoScaleMode.Font;
BackColor = Color.FromArgb(0, 0, 0, 0);
Controls.Add(picture);
Controls.Add(Back_Picture);
Name = "Item";
Size = new Size(70, 70);
((System.ComponentModel.ISupportInitialize)picture).EndInit();
ResumeLayout(false);
}
#endregion
private PictureBox picture;
private Label Back_Picture;
}
}

View File

@ -0,0 +1,39 @@
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.Windows.Forms;
namespace CDSAE3_Lian_Lian_Kan.Forms
{
public partial class Item : UserControl
{
(int,int) ori_size;
public Item()
{
InitializeComponent();
picture.Parent = Back_Picture;
}
public void Item_Init(Image image,(int,int) size,Color BackColor)
{
Back_Picture.BackColor = BackColor;
ori_size = size;
picture.Image = image;
picture.SizeMode = PictureBoxSizeMode.Zoom;
picture.BackColor = Color.Transparent;
Back_Picture.Size = new Size(Width, Height);
picture.Size = new Size(Width, Height);
set_progress(0);
}
public void set_progress(int height)
{
Size = new Size(ori_size.Item1, height);
picture.Location = new Point(0, -(70-height));
picture.Refresh();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -39,7 +39,7 @@
sp_button = new PictureBox();
search = new PictureBox();
exchange = new PictureBox();
search_time = new Label();
upper_search = new Item();
game_Panel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)back).BeginInit();
((System.ComponentModel.ISupportInitialize)sp_button).BeginInit();
@ -165,17 +165,13 @@
exchange.TabStop = false;
exchange.Click += exchange_Click;
//
// search_time
// upper_search
//
search_time.AutoSize = true;
search_time.BackColor = Color.FromArgb(249, 211, 171);
search_time.Font = new Font("Microsoft YaHei UI", 10F);
search_time.Location = new Point(413, 18);
search_time.Name = "search_time";
search_time.Size = new Size(36, 27);
search_time.TabIndex = 11;
search_time.Text = "00";
search_time.Visible = false;
upper_search.BackColor = Color.FromArgb(0, 0, 0, 0);
upper_search.Location = new Point(360, 31);
upper_search.Name = "upper_search";
upper_search.Size = new Size(70, 70);
upper_search.TabIndex = 12;
//
// Leisure_Mode
//
@ -183,7 +179,7 @@
AutoScaleMode = AutoScaleMode.Font;
BackColor = Color.FromArgb(249, 211, 171);
ClientSize = new Size(1439, 960);
Controls.Add(search_time);
Controls.Add(upper_search);
Controls.Add(exchange);
Controls.Add(search);
Controls.Add(sp_button);
@ -194,6 +190,7 @@
Controls.Add(energy_bar);
Controls.Add(back);
Controls.Add(game_Panel);
DoubleBuffered = true;
FormBorderStyle = FormBorderStyle.None;
Name = "Leisure_Mode";
Text = "Leisure_Mode";
@ -219,6 +216,6 @@
private PictureBox search;
private PictureBox exchange;
private GameControl gameControl;
private Label search_time;
private Item upper_search;
}
}

View File

@ -6,8 +6,10 @@ using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
using CDSAE3_Lian_Lian_Kan.Boards;
using CDSAE3_Lian_Lian_Kan.Properties;
namespace CDSAE3_Lian_Lian_Kan.Forms
{
@ -17,13 +19,39 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
{
Etcs.game_mode_form = this;
InitializeComponent();
timer = new System.Timers.Timer();
timer.Enabled = false;
timer.Interval = 1000;
timer.Elapsed += Timer_Tick;
upper_search.Item_Init(Resources.search, (70, 70),Color.FromArgb(253, 161, 60));
//Etcs.hunderd_millsecond_timer.Elapsed += hundred_millsecond_Timer_Tick;
time.Text = (left_time / 60).ToString().PadLeft(2, '0') + ":" + (left_time % 60).ToString().PadLeft(2, '0');
upper_search_ori_position = upper_search.Location;
timer = new System.Timers.Timer(1000);
timer.Elapsed += Timer_Tick;
timer.Enabled = true;
}
System.Timers.Timer timer;
int hundred_up_timer = 0;
//private void hundred_millsecond_Timer_Tick(object? sender, ElapsedEventArgs e)
//{
// if (_listening_timer)
// hundred_up_timer++;
// else
// return;
// //if(search_mode)
// //{
// // //down to up
// // //BeginInvoke(() => upper_search.Location = new Point(upper_search_ori_position.X, upper_search_ori_position.Y + (int)(70 * (search_left_time - hundred_up_timer * 0.1) / Etcs.search_left_time)));
// // //BeginInvoke(() => upper_search.set_progress(70-upper_search.Location.Y+upper_search_ori_position.Y));
// //}
// if (hundred_up_timer == 10)
// {
// BeginInvoke(() => upper_search.Location = new Point(upper_search_ori_position.X, upper_search_ori_position.Y + (int)(70 * (1 - ((search_left_time - hundred_up_timer * 0.1) / Etcs.search_left_time)))));
// BeginInvoke(() => upper_search.set_progress(70 - upper_search.Location.Y + upper_search_ori_position.Y));
// hundred_up_timer = 0;
// Timer_Tick(sender, e);
// }
//}
Point upper_search_ori_position;
int left_time = Etcs.left_time;
bool is_pause = true;
int cur_score = 0;
@ -32,7 +60,6 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
int search_left_time = 0;
bool search_mode = false;
Dictionary<int, double> decrease_per_level = Etcs.decrease_per_level;
private void Timer_Tick(object? sender, EventArgs e)
{
left_time--;
@ -42,11 +69,12 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
search_left_time--;
if (search_left_time < 0)
{
BeginInvoke(() => search_time.Visible = false);
search_mode = false;
gameControl.Search_Handler(this, new SearchEventArgs { set_search = false });
BeginInvoke(() => upper_search.set_progress(0));
}
BeginInvoke(() => search_time.Text = search_left_time.ToString().PadLeft(2, '0'));
BeginInvoke(() => upper_search.Location = new Point(upper_search_ori_position.X, upper_search_ori_position.Y + (int)(70 * (1 - ((search_left_time - hundred_up_timer * 0.1) / Etcs.search_left_time)))));
BeginInvoke(() => upper_search.set_progress(70 - upper_search.Location.Y + upper_search_ori_position.Y));
}
if (current_base <= 0)
{
@ -133,6 +161,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
{
Dispose();
Close();
//Etcs.hunderd_millsecond_timer.Elapsed -= hundred_millsecond_Timer_Tick;
timer.Close();
Etcs.form?.change_form(new Leisure_Mode_MenuForm());
}
@ -147,8 +176,6 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
gameControl.Search_Handler(this, new SearchEventArgs { set_search = true});
search_mode = true;
search_left_time = Etcs.search_left_time;
search_time.Text = search_left_time.ToString().PadLeft(2, '0');
search_time.Visible = true;
}
}
}

View File

@ -21,6 +21,7 @@ namespace CDSAE3_Lian_Lian_Kan
if (Etcs.game_form == null)
throw new Exception("game_form is null but try to make a new Single_Block");
Selected += Etcs.game_form.Selected_Handler;
}
public Single_Block(int image, Color default_backColor, Color select_Color, (int, int) pos)
{
@ -99,22 +100,24 @@ namespace CDSAE3_Lian_Lian_Kan
Image_change(Etcs.trans_Image);
direction = Etcs.Direction.none;
}
System.Timers.Timer? timer = null;
public void destroyAsync()
{
Image_change(Etcs.get_disappear_Images(block_id));
BackColor = Color.FromArgb(0, 0, 0, 0);
can_be_selected = false;
timer = new System.Timers.Timer();
timer.Interval = 500;
var timer = Etcs.hunderd_millsecond_timer;
timer_Eplased = 0;
timer.Elapsed += Image_Clear;
timer.Enabled = true;
}
object locker = new object();
int timer_Eplased = 0;
public void Image_Clear(object? sender, ElapsedEventArgs e)
{
timer?.Stop();
if(timer_Eplased++ > 5)
{
Image_change(Etcs.trans_Image);
Etcs.hunderd_millsecond_timer.Elapsed-= Image_Clear;
}
}
ConcurrentQueue<Image>images_queue = new ConcurrentQueue<Image>();
Thread? Image_setting_thread;
@ -126,9 +129,19 @@ namespace CDSAE3_Lian_Lian_Kan
Image_setting_thread = new Thread(() =>
{
while (images_queue.TryDequeue(out Image? image))
{
lock (image)
{
try
{
Image_set(image);
}
catch (Exception)
{
images_queue.Enqueue(image);
}
}
}
});
Image_setting_thread.Start();
}

View File

@ -0,0 +1,45 @@
namespace CDSAE3_Lian_Lian_Kan.Forms
{
partial class middle_parent
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
SuspendLayout();
//
// middle_parent
//
AutoScaleDimensions = new SizeF(11F, 24F);
AutoScaleMode = AutoScaleMode.Font;
BackColor = Color.Transparent;
Name = "middle_parent";
Size = new Size(40, 40);
ResumeLayout(false);
}
#endregion
}
}

View File

@ -0,0 +1,40 @@
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.Windows.Forms;
namespace CDSAE3_Lian_Lian_Kan.Forms
{
public partial class middle_parent : UserControl
{
public middle_parent()
{
InitializeComponent();
}
private Color _backColor = Etcs.def_Color;
private Color _frontColor = Etcs.mouse_upper_color;
public void set_progress(float progress, Color backColor, Color frontColor)
{
_backColor = backColor;
_frontColor = frontColor;
set_progress(progress);
}
public void set_progress(float progress)
{
SolidBrush upperBrush = new SolidBrush(_backColor);
SolidBrush lowerBrush = new SolidBrush(_frontColor);
Graphics formGraphics = CreateGraphics();
int wire = (int)((1-progress) * 40);
formGraphics.FillRectangle(upperBrush, new Rectangle(0, 0, 40, wire));
formGraphics.FillRectangle(lowerBrush, new Rectangle(0, wire, 40, 40));
upperBrush.Dispose();
lowerBrush.Dispose();
formGraphics.Dispose();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -10,25 +10,24 @@ namespace CDSAE3_Lian_Lian_Kan.Sound
{
internal class AudioPlayer : IDisposable
{
object source_obj;
MemoryStream sound;
MemoryStream ms;
Mp3FileReader ws;
BlockAlignReductionStream blockAlignReductionStream;
Wave16ToFloatProvider wave16ToFloatProvider;
WaveOutEvent waveOutEvent;
Action<string,AudioPlayer>? finished;
string file_name;
bool shutdown = false;
readonly byte[] source_obj;
readonly MemoryStream sound;
readonly MemoryStream ms;
readonly Mp3FileReader ws;
readonly BlockAlignReductionStream blockAlignReductionStream;
readonly Wave16ToFloatProvider wave16ToFloatProvider;
readonly WaveOutEvent waveOutEvent;
readonly Action<string,AudioPlayer>? finished;
readonly string file_name;
bool shuting_down = false;
internal int volume { get; set; }
internal AudioPlayer(string file_name, int volume)
{
this.file_name = file_name;
this.volume = volume;
file_name = file_name.Split('.').First().Replace(" ", "_").Replace("-", "_");
source_obj = Etcs.res_Manager.GetObject(file_name, Etcs.res_Culture)!;
sound = new MemoryStream((byte[])source_obj);
source_obj = Etcs.audio_Res_Manager.Get_Audio_Resources(file_name);
sound = new MemoryStream(source_obj);
ms = new MemoryStream(StreamToBytes(sound));
ws = new Mp3FileReader(ms);
blockAlignReductionStream = new BlockAlignReductionStream(ws);
@ -43,10 +42,9 @@ namespace CDSAE3_Lian_Lian_Kan.Sound
this.file_name = file_name;
this.volume = volume;
this.finished = finished;
file_name = file_name.Split('.').First().Replace(" ", "_").Replace("-", "_");
source_obj = Etcs.res_Manager.GetObject(file_name, Etcs.res_Culture)!;
sound = new MemoryStream((byte[])source_obj);
source_obj = Etcs.audio_Res_Manager.Get_Audio_Resources(file_name);
sound = new MemoryStream(source_obj);
ms = new MemoryStream(StreamToBytes(sound));
ws = new Mp3FileReader(ms);
blockAlignReductionStream = new BlockAlignReductionStream(ws);
@ -65,7 +63,7 @@ namespace CDSAE3_Lian_Lian_Kan.Sound
public void resume_song() => waveOutEvent.Play();
private void WaveOutEvent_PlaybackStopped(object? sender, StoppedEventArgs e)
{
if(shutdown) return;
if(shuting_down) return;
finished?.Invoke(file_name,this);
Dispose();
}
@ -77,13 +75,14 @@ namespace CDSAE3_Lian_Lian_Kan.Sound
public void Dispose()
{
shutdown = true;
shuting_down = true;
waveOutEvent.Stop();
sound.Dispose();
ms.Dispose();
//ws.Dispose();
//blockAlignReductionStream.Dispose();
ws.Dispose();
blockAlignReductionStream.Dispose();
waveOutEvent.Dispose();
GC.SuppressFinalize(this);
}
internal static byte[] StreamToBytes(Stream stream)
{

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CDSAE3_Lian_Lian_Kan.Sound
{
public class Audio_res_manager
{
Dictionary<string, byte[]> audio_res = new Dictionary<string, byte[]>();
internal byte[] Get_Audio_Resources(string name)
{
if(audio_res.TryGetValue(name, out byte[]? val))
return val;
object obj = Etcs.res_Manager.GetObject(name, Etcs.res_Culture)!;
byte[] res = (byte[])obj;
audio_res.Add(name, res);
return res;
}
internal void Clear_Audio_Resources()
{
audio_res.Clear();
}
}
}

View File

@ -12,92 +12,6 @@ namespace CDSAE3_Lian_Lian_Kan.Sound
{
public class Song_Audio_processer:IDisposable
{
//class Audio_File_Processor
//{
// private Wave16ToFloatProvider? wave16ToFloatProvider;
// private List<string> audioFiles = new List<string>();
// int next_song = 0;
// int volume = 90;
// internal void set_Albums(string s)=>audioFiles = Settings.musics.TryGetValue(s, out List<string>? val) ? val : new List<string>();
// internal Wave16ToFloatProvider get_next_song()
// {
// string name = audioFiles[next_song];
// next_song++;
// next_song %= audioFiles.Count;
// name = name.Split('.').First().Replace(" ","_").Replace("-","_");
// object obj = Settings.res_Manager.GetObject(name, Settings.res_Culture)!;
// MemoryStream sound = new MemoryStream((byte[])obj);
// MemoryStream ms = new MemoryStream(StreamToBytes(sound));
// var ws = new Mp3FileReader(ms);
// BlockAlignReductionStream blockAlignReductionStream = new BlockAlignReductionStream(ws);
// wave16ToFloatProvider = new Wave16ToFloatProvider(blockAlignReductionStream);
// wave16ToFloatProvider.Volume = volume / 100f;
// return wave16ToFloatProvider;
// }
// internal Wave16ToFloatProvider get_last_song()
// {
// next_song = (next_song - 2 + audioFiles.Count) % audioFiles.Count;
// return get_next_song();
// }
// internal void volume_change(int val)
// {
// volume = val;
// if(wave16ToFloatProvider != null)
// wave16ToFloatProvider.Volume = volume / 100f;
// }
// internal static byte[] StreamToBytes(Stream stream)
// {
// long originalPosition = 0;
// if (stream.CanSeek)
// {
// originalPosition = stream.Position;
// stream.Position = 0;
// }
// try
// {
// byte[] readBuffer = new byte[4096];
// int totalBytesRead = 0;
// int bytesRead;
// while ((bytesRead = stream.Read(readBuffer, totalBytesRead, readBuffer.Length - totalBytesRead)) > 0)
// {
// totalBytesRead += bytesRead;
// if (totalBytesRead == readBuffer.Length)
// {
// int nextByte = stream.ReadByte();
// if (nextByte != -1)
// {
// byte[] temp = new byte[readBuffer.Length * 2];
// Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length);
// Buffer.SetByte(temp, totalBytesRead, (byte)nextByte);
// readBuffer = temp;
// totalBytesRead++;
// }
// }
// }
// byte[] buffer = readBuffer;
// if (readBuffer.Length != totalBytesRead)
// {
// buffer = new byte[totalBytesRead];
// Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead);
// }
// return buffer;
// }
// finally
// {
// if (stream.CanSeek)
// {
// stream.Position = originalPosition;
// }
// }
// }
//}
AudioPlayer? audioPlayer;
private List<string> audioFiles = new List<string>();
int next_song = 1;
@ -141,7 +55,11 @@ namespace CDSAE3_Lian_Lian_Kan.Sound
}
audioPlayer.resume_song();
}
public void Dispose()=> audioPlayer?.Dispose();
public void Dispose()
{
audioPlayer?.Dispose();
GC.SuppressFinalize(this);
}
~Song_Audio_processer() => Dispose();
}
}