From 3e81b973e96752451313986207483697bf8f069f Mon Sep 17 00:00:00 2001 From: lichx Date: Mon, 8 Apr 2024 21:04:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E9=97=B4=E4=BB=B6=E6=8E=A2=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CDSAE3_Lian_Lian_Kan/Boards/Graph_Board.cs | 184 +++++++++++++++++- CDSAE3_Lian_Lian_Kan/Etcs.cs | 2 + CDSAE3_Lian_Lian_Kan/Forms/GameControl.cs | 42 ++-- CDSAE3_Lian_Lian_Kan/Forms/Item.Designer.cs | 70 +++++++ CDSAE3_Lian_Lian_Kan/Forms/Item.cs | 39 ++++ CDSAE3_Lian_Lian_Kan/Forms/Item.resx | 120 ++++++++++++ .../Forms/Leisure_Mode.Designer.cs | 23 +-- CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs | 45 ++++- CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs | 27 ++- .../Forms/middle_parent.Designer.cs | 45 +++++ CDSAE3_Lian_Lian_Kan/Forms/middle_parent.cs | 40 ++++ CDSAE3_Lian_Lian_Kan/Forms/middle_parent.resx | 120 ++++++++++++ CDSAE3_Lian_Lian_Kan/Sound/AudioPlayer.cs | 39 ++-- .../Sound/Audio_res_manager.cs | 26 +++ .../Sound/Song_Audio_processer.cs | 92 +-------- 15 files changed, 753 insertions(+), 161 deletions(-) create mode 100644 CDSAE3_Lian_Lian_Kan/Forms/Item.Designer.cs create mode 100644 CDSAE3_Lian_Lian_Kan/Forms/Item.cs create mode 100644 CDSAE3_Lian_Lian_Kan/Forms/Item.resx create mode 100644 CDSAE3_Lian_Lian_Kan/Forms/middle_parent.Designer.cs create mode 100644 CDSAE3_Lian_Lian_Kan/Forms/middle_parent.cs create mode 100644 CDSAE3_Lian_Lian_Kan/Forms/middle_parent.resx create mode 100644 CDSAE3_Lian_Lian_Kan/Sound/Audio_res_manager.cs diff --git a/CDSAE3_Lian_Lian_Kan/Boards/Graph_Board.cs b/CDSAE3_Lian_Lian_Kan/Boards/Graph_Board.cs index 7f9e833..db1e986 100644 --- a/CDSAE3_Lian_Lian_Kan/Boards/Graph_Board.cs +++ b/CDSAE3_Lian_Lian_Kan/Boards/Graph_Board.cs @@ -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> get_tip((int, int) start) { - throw new NotImplementedException(); + List> ans = new List>(); + 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 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 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> swing_check = ((int, int) range, int center) => + { + List result = new List(); + 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 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); + + } } } diff --git a/CDSAE3_Lian_Lian_Kan/Etcs.cs b/CDSAE3_Lian_Lian_Kan/Etcs.cs index c79a7ce..f00e8ce 100644 --- a/CDSAE3_Lian_Lian_Kan/Etcs.cs +++ b/CDSAE3_Lian_Lian_Kan/Etcs.cs @@ -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> musics { get; set; } = new Dictionary> { { "C418", new List { "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); diff --git a/CDSAE3_Lian_Lian_Kan/Forms/GameControl.cs b/CDSAE3_Lian_Lian_Kan/Forms/GameControl.cs index 440920c..f9eab78 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/GameControl.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/GameControl.cs @@ -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(); } /// /// 由form和to两个点获取方向 @@ -76,7 +78,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms /// /// /// - async Task set_PathAsync((int, int) point, Etcs.Direction direction, List blocks, int wait_time,bool is_hint) + async Task set_PathAsync((int, int) point, Etcs.Direction direction, List 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 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> 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() { @@ -169,7 +171,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms if (do_search) { de_set_tip(); - set_tip(); + set_tip(); } break; case 1: @@ -188,7 +190,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms if (do_search) { de_set_tip(); - set_tip(); + set_tip(); } queue.Enqueue((e.position, sender)); sendera.deselect(); @@ -204,7 +206,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms break; case 1: if (queue.Peek().Item1 == e.position) - { + { queue.Dequeue(); if (do_search) 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) diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Item.Designer.cs b/CDSAE3_Lian_Lian_Kan/Forms/Item.Designer.cs new file mode 100644 index 0000000..bebe6f8 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Forms/Item.Designer.cs @@ -0,0 +1,70 @@ +namespace CDSAE3_Lian_Lian_Kan.Forms +{ + partial class Item + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region 组件设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要修改 + /// 使用代码编辑器修改此方法的内容。 + /// + 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; + } +} diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Item.cs b/CDSAE3_Lian_Lian_Kan/Forms/Item.cs new file mode 100644 index 0000000..38a264e --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Forms/Item.cs @@ -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(); + } + } +} diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Item.resx b/CDSAE3_Lian_Lian_Kan/Forms/Item.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Forms/Item.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.Designer.cs b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.Designer.cs index 5c64879..09e6972 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.Designer.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs index 256d5f1..1a022f4 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs @@ -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 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; } } } diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs b/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs index 7fe97e9..6abaa6a 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs @@ -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(); - Image_change(Etcs.trans_Image); + if(timer_Eplased++ > 5) + { + Image_change(Etcs.trans_Image); + Etcs.hunderd_millsecond_timer.Elapsed-= Image_Clear; + } } ConcurrentQueueimages_queue = new ConcurrentQueue(); Thread? Image_setting_thread; @@ -127,7 +130,17 @@ namespace CDSAE3_Lian_Lian_Kan { while (images_queue.TryDequeue(out Image? image)) { - Image_set(image); + lock (image) + { + try + { + Image_set(image); + } + catch (Exception) + { + images_queue.Enqueue(image); + } + } } }); Image_setting_thread.Start(); diff --git a/CDSAE3_Lian_Lian_Kan/Forms/middle_parent.Designer.cs b/CDSAE3_Lian_Lian_Kan/Forms/middle_parent.Designer.cs new file mode 100644 index 0000000..0ef6061 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Forms/middle_parent.Designer.cs @@ -0,0 +1,45 @@ +namespace CDSAE3_Lian_Lian_Kan.Forms +{ + partial class middle_parent + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region 组件设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要修改 + /// 使用代码编辑器修改此方法的内容。 + /// + 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 + } +} diff --git a/CDSAE3_Lian_Lian_Kan/Forms/middle_parent.cs b/CDSAE3_Lian_Lian_Kan/Forms/middle_parent.cs new file mode 100644 index 0000000..72fd31b --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Forms/middle_parent.cs @@ -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(); + } + } +} diff --git a/CDSAE3_Lian_Lian_Kan/Forms/middle_parent.resx b/CDSAE3_Lian_Lian_Kan/Forms/middle_parent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Forms/middle_parent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CDSAE3_Lian_Lian_Kan/Sound/AudioPlayer.cs b/CDSAE3_Lian_Lian_Kan/Sound/AudioPlayer.cs index 21ee553..15ba863 100644 --- a/CDSAE3_Lian_Lian_Kan/Sound/AudioPlayer.cs +++ b/CDSAE3_Lian_Lian_Kan/Sound/AudioPlayer.cs @@ -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? 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? 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) { diff --git a/CDSAE3_Lian_Lian_Kan/Sound/Audio_res_manager.cs b/CDSAE3_Lian_Lian_Kan/Sound/Audio_res_manager.cs new file mode 100644 index 0000000..978cc1e --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Sound/Audio_res_manager.cs @@ -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 audio_res = new Dictionary(); + 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(); + } + } +} diff --git a/CDSAE3_Lian_Lian_Kan/Sound/Song_Audio_processer.cs b/CDSAE3_Lian_Lian_Kan/Sound/Song_Audio_processer.cs index 6828a17..5f872db 100644 --- a/CDSAE3_Lian_Lian_Kan/Sound/Song_Audio_processer.cs +++ b/CDSAE3_Lian_Lian_Kan/Sound/Song_Audio_processer.cs @@ -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 audioFiles = new List(); - // int next_song = 0; - // int volume = 90; - // internal void set_Albums(string s)=>audioFiles = Settings.musics.TryGetValue(s, out List? val) ? val : new List(); - // 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 audioFiles = new List(); 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(); } }