diff --git a/CDSAE3_Lian_Lian_Kan/Board_funcs/Board.cs b/CDSAE3_Lian_Lian_Kan/Boards/Board.cs similarity index 77% rename from CDSAE3_Lian_Lian_Kan/Board_funcs/Board.cs rename to CDSAE3_Lian_Lian_Kan/Boards/Board.cs index 2a4a22a..1ebe695 100644 --- a/CDSAE3_Lian_Lian_Kan/Board_funcs/Board.cs +++ b/CDSAE3_Lian_Lian_Kan/Boards/Board.cs @@ -6,15 +6,15 @@ using System.Threading.Tasks; using System.Xml; using CDSAE3_Lian_Lian_Kan; using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar; -namespace CDSAE3_Lian_Lian_Kan.Board_funcs +namespace CDSAE3_Lian_Lian_Kan.Boards { public partial class Board:IBoard { private int[,] Bd = { { } };//y,x - public Dictionary> board_Index { get; } = new Dictionary>(); - public int[] Vals_per_Image { get; set; } = { }; - public int total; - public int Total + private Dictionary> board_Index = new Dictionary>(); + private int[] Vals_per_Image { get; set; } = Array.Empty(); + private int total; + private int Total { get { @@ -23,13 +23,13 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs set { total = value; - if (total == 0) + if (Total == 0) Etcs.game_mode_form?.Finished_Handler(this, new Forms.FinishArgs { finish_Type = Forms.FinishArgs.Finish_Type.All_done }); } } - public int[,] make_board() + private Board_funcs board_Funcs = new Board_funcs(); + public int[,] make_board()//Size from Etcs.get_length_width() { - var rand = new Random(); size = Etcs.get_length_width(); var (width, height) = size; Bd = new int[height + 2, width + 2]; @@ -41,60 +41,13 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs sum--; total = sum; int types = Etcs.Images_size(); - Vals_per_Image = new int[types]; - int single = sum / types; - for (int k = sum; k > 0; k -= 2) - { - int t = rand.Next(0, types); - if (Vals_per_Image[t] >= 1.5 * single) - { - k += 2; - continue; - } - Vals_per_Image[t] += 2; - } + Vals_per_Image = board_Funcs.get_vals_per_image(Total, types); + int last_val = -1; int cur_width = 1, cur_height = 1; var temp_val_per_Image = (int[])Vals_per_Image.Clone(); - int last_val = -1; - Func getval = () => - { - int not_zero = 0; - foreach (int x in temp_val_per_Image) - if (x != 0) - { - not_zero++; - if (not_zero > 1) - break; - } - if (not_zero <= 1) - { - int k = 0; - for(int i=0;i getval = () => - { - int not_zero = 0; - foreach (int x in temp_val_per_Image) - if (x != 0) - { - not_zero++; - if (not_zero > 1) - break; - } - if (not_zero <= 1) - { - int k = temp_val_per_Image.Single(x => x != 0); - temp_val_per_Image[k]--; - return k; - } - int t = rand.Next(0, types); - if (temp_val_per_Image[t] == 0 || t == last_val) - { - int i = (t + 1) % types; - for (; temp_val_per_Image[i] == 0 || i == last_val; i %= types) - i++; - temp_val_per_Image[i]--; - last_val = i; - return i; - } - temp_val_per_Image[t]--; - last_val = t; - return t; - }; for (int i = 0; i < height; i++) for (int j = 0; j < width; j++) if (Bd[i, j] != -1) { - Bd[i, j] = getval(); + Bd[i, j] = board_Funcs.getval(ref temp_val_per_Image, ref last_val, types); if (board_Index.TryGetValue(Bd[i, j], out var index)) index.Add((j, i)); else @@ -336,10 +259,10 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs if (!board_Index[type].Remove((x, y))) throw new Exception("Val not Found in board_Index"); Vals_per_Image[type]--; + Total--; } } - - internal List> get_tip((int, int) start) + public List> get_tip((int, int) start) { List> ans = new List>(); if (board_Index.TryGetValue(Bd[start.Item2, start.Item1], out var tip)) @@ -352,6 +275,5 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs return ans; } public (int, int) size { get; set; }//width,height - public Etcs.Mode mode { get; set; } } } diff --git a/CDSAE3_Lian_Lian_Kan/Boards/Board_funcs.cs b/CDSAE3_Lian_Lian_Kan/Boards/Board_funcs.cs new file mode 100644 index 0000000..5c74545 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Boards/Board_funcs.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CDSAE3_Lian_Lian_Kan.Boards +{ + internal class Board_funcs + { + private Random random = new Random(); + internal int getval(ref int[] temp_val_per_Image,ref int last_val,int types) + { + int not_zero = 0; + foreach (int x in temp_val_per_Image) + if (x != 0) + { + not_zero++; + if (not_zero > 1) + break; + } + if (not_zero <= 1) + { + int k = 0; + for (int i = 0; i < temp_val_per_Image.Length; i++) + if (temp_val_per_Image[i] != 0) + { + k = i; + break; + } + temp_val_per_Image[k]--; + return k; + } + int t = random.Next(0, types); + if (temp_val_per_Image[t] <= 0 || t == last_val) + { + int i = (t + 1) % types; + for (; temp_val_per_Image[i] <= 0 || i == last_val; i %= types) + i++; + temp_val_per_Image[i]--; + last_val = i; + return i; + } + temp_val_per_Image[t]--; + last_val = t; + return t; + } + internal int[] get_vals_per_image(int total,int type_num) + { + int[] vals_per_Image= new int[type_num]; + int single = total / type_num; + for (int k = total; k > 0; k -= 2) + { + int t = random.Next(0, type_num); + if (vals_per_Image[t] >= 1.5 * single) + { + k += 2; + continue; + } + vals_per_Image[t] += 2; + } + return vals_per_Image; + } + } +} diff --git a/CDSAE3_Lian_Lian_Kan/Boards/Graph_Board.cs b/CDSAE3_Lian_Lian_Kan/Boards/Graph_Board.cs new file mode 100644 index 0000000..7f9e833 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Boards/Graph_Board.cs @@ -0,0 +1,133 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CDSAE3_Lian_Lian_Kan.Boards +{ + internal class Graph_Board : IBoard + { + class Node + { + public Node? LNode, RNode, UNode, DNode; + public int x, y; + public int value; + public Node(int x, int y, int value) + { + this.x = x; + this.y = y; + this.value = value; + LNode = RNode = UNode = DNode = null; + } + + public Node(Node? lNode, Node? rNode, Node? uNode, Node? dNode, int x, int y, int value) + { + LNode = lNode; + RNode = rNode; + UNode = uNode; + DNode = dNode; + this.x = x; + this.y = y; + this.value = value; + } + } + public (int, int) size { get; set; }//width,height + Dictionary<(int,int),Node>Index = new Dictionary<(int,int), Node>();//width,height + private Dictionary> board_Index = new Dictionary>(); + Board_funcs board_Funcs = new Board_funcs(); + private int total; + private int Total + { + get + { + return total; + } + set + { + total = value; + if (Total == 0) + Etcs.game_mode_form?.Finished_Handler(this, new Forms.FinishArgs { finish_Type = Forms.FinishArgs.Finish_Type.All_done }); + } + } + private int[] Vals_per_Image { get; set; } = Array.Empty(); + + public void decrease(params (int, int)[] poss) + { + foreach (var (x, y) in poss) + { + int type = Index[(x, y)].value; + if (!Index.Remove((x, y))) + throw new Exception("Val not Found in Index"); + if (!board_Index[type].Remove((x, y))) + throw new Exception("Val not Found in board_Index"); + Vals_per_Image[type]--; + Total--; + } + } + + public List> get_tip((int, int) start) + { + throw new NotImplementedException(); + } + + public int[,] make_board() + { + size = Etcs.get_length_width(); + 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 sum = width * height; + if (sum % 2 != 0) + sum--; + total = sum; + int types = Etcs.Images_size(); + Vals_per_Image = board_Funcs.get_vals_per_image(Total, types); + int last_val = -1; + int cur_width = 1, cur_height = 1; + var temp_val_per_Image = (int[])Vals_per_Image.Clone(); + for (int i = 0; i < sum; i++) + { + Bd[cur_height, cur_width] = board_Funcs.getval(ref temp_val_per_Image, ref last_val, types); + if (board_Index.TryGetValue(Bd[cur_height, cur_width], out var index)) + 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])); + cur_width++; + if (cur_width > width) + { + cur_height++; + cur_width = 1; + } + } + foreach(var (index,node)in Index) + { + if (Index.TryGetValue((node.x - 1, node.y), out var lnode)) + node.LNode = lnode; + if (Index.TryGetValue((node.x + 1, node.y), out var rnode)) + node.RNode = rnode; + if (Index.TryGetValue((node.x, node.y - 1), out var unode)) + node.UNode = unode; + if (Index.TryGetValue((node.x, node.y + 1), out var dnode)) + node.DNode = dnode; + Index[index] = node; + } + return Bd; + } + + public int[,] remake_board() + { + + throw new NotImplementedException(); + } + + public (bool, List<(int, int)>?) test((int, int) a, (int, int) b) + { + throw new NotImplementedException(); + } + } +} diff --git a/CDSAE3_Lian_Lian_Kan/Board_funcs/IBoard.cs b/CDSAE3_Lian_Lian_Kan/Boards/IBoard.cs similarity index 69% rename from CDSAE3_Lian_Lian_Kan/Board_funcs/IBoard.cs rename to CDSAE3_Lian_Lian_Kan/Boards/IBoard.cs index c096ccf..40b7462 100644 --- a/CDSAE3_Lian_Lian_Kan/Board_funcs/IBoard.cs +++ b/CDSAE3_Lian_Lian_Kan/Boards/IBoard.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace CDSAE3_Lian_Lian_Kan.Board_funcs +namespace CDSAE3_Lian_Lian_Kan.Boards { internal interface IBoard { @@ -12,8 +12,7 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs public int[,] remake_board(); public (bool, List<(int, int)>?) test((int, int) a, (int, int) b); public void decrease(params (int, int)[] poss); - - - + public List> get_tip((int, int) start); + public (int, int) size { get; set; }//width,height } } diff --git a/CDSAE3_Lian_Lian_Kan/Etcs.cs b/CDSAE3_Lian_Lian_Kan/Etcs.cs index cc58c02..c79a7ce 100644 --- a/CDSAE3_Lian_Lian_Kan/Etcs.cs +++ b/CDSAE3_Lian_Lian_Kan/Etcs.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Resources; using System.Text; using System.Threading.Tasks; -using CDSAE3_Lian_Lian_Kan.Board_funcs; +using CDSAE3_Lian_Lian_Kan.Boards; using CDSAE3_Lian_Lian_Kan.Forms; using CDSAE3_Lian_Lian_Kan.Properties; using CDSAE3_Lian_Lian_Kan.Sound; diff --git a/CDSAE3_Lian_Lian_Kan/Forms/GameControl.cs b/CDSAE3_Lian_Lian_Kan/Forms/GameControl.cs index 637acea..440920c 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/GameControl.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/GameControl.cs @@ -1,4 +1,4 @@ -using CDSAE3_Lian_Lian_Kan.Board_funcs; +using CDSAE3_Lian_Lian_Kan.Boards; using System; using System.Collections.Generic; using System.ComponentModel; @@ -234,7 +234,6 @@ namespace CDSAE3_Lian_Lian_Kan.Forms foreach (var control in blocks) control.de_path(); iGameMode?.Score_Add(this, new AddScoreArgs { score = (blocks.Count + 2) * 10 }); - board.Total -= 2; } void playPanel_size_change() { diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs index ec7f1f4..256d5f1 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -using CDSAE3_Lian_Lian_Kan.Board_funcs; +using CDSAE3_Lian_Lian_Kan.Boards; namespace CDSAE3_Lian_Lian_Kan.Forms { diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Setting.Designer.cs b/CDSAE3_Lian_Lian_Kan/Forms/Setting.Designer.cs new file mode 100644 index 0000000..f550f32 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Forms/Setting.Designer.cs @@ -0,0 +1,45 @@ +namespace CDSAE3_Lian_Lian_Kan.Forms +{ + partial class Setting + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + SuspendLayout(); + // + // Setting + // + AutoScaleDimensions = new SizeF(11F, 24F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(756, 571); + Name = "Setting"; + Text = "Setting"; + ResumeLayout(false); + } + + #endregion + } +} \ No newline at end of file diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Setting.cs b/CDSAE3_Lian_Lian_Kan/Forms/Setting.cs new file mode 100644 index 0000000..687ceb9 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Forms/Setting.cs @@ -0,0 +1,20 @@ +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 Setting : Form + { + public Setting() + { + InitializeComponent(); + } + } +} diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Setting.resx b/CDSAE3_Lian_Lian_Kan/Forms/Setting.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Forms/Setting.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/Single_Block.cs b/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs index e13816d..7fe97e9 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs @@ -1,5 +1,6 @@ using CDSAE3_Lian_Lian_Kan.Forms; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -115,9 +116,22 @@ namespace CDSAE3_Lian_Lian_Kan timer?.Stop(); Image_change(Etcs.trans_Image); } + ConcurrentQueueimages_queue = new ConcurrentQueue(); + Thread? Image_setting_thread; public void Image_change(Image new_image) { - + images_queue.Enqueue(new_image); + if(Image_setting_thread == null || !Image_setting_thread.IsAlive) + { + Image_setting_thread = new Thread(() => + { + while (images_queue.TryDequeue(out Image? image)) + { + Image_set(image); + } + }); + Image_setting_thread.Start(); + } } private void Image_set(Image image) {