diff --git a/CDSAE3_Lian_Lian_Kan/Board_funcs/Board.cs b/CDSAE3_Lian_Lian_Kan/Board_funcs/Board.cs index 9abf9e9..4650b01 100644 --- a/CDSAE3_Lian_Lian_Kan/Board_funcs/Board.cs +++ b/CDSAE3_Lian_Lian_Kan/Board_funcs/Board.cs @@ -5,25 +5,28 @@ using System.Text; 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 { public partial class Board { - public Board() { - } - public int[,]? Bd { get; set; } = null;//y,x - public int[]? vals_per_Image = null; + public int[,] Bd { get; set; } = { { } };//y,x + public Dictionary> board_Index { get; } = new Dictionary>(); + public int[] Vals_per_Image { get; set; } = { }; public int total; - public int Total { get + public int Total + { + get { return total; - } + } set { total = value; - if(total == 0) + if (total == 0) Settings.game_mode_form?.Finished_Handler(this, new Forms.FinishArgs { finish_Type = Forms.FinishArgs.Finish_Type.All_done }); - } } + } + } public void make_board() { var rand = new Random(); @@ -38,68 +41,139 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs sum--; total = sum; int types = Settings.Images_size(); - vals_per_Image = new int[types]; - int single = sum/types; - for(int k = sum; k>0; k-=2) + 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) + if (Vals_per_Image[t] >= 1.5 * single) { k += 2; continue; } - vals_per_Image[t]+=2; + Vals_per_Image[t] += 2; } int cur_width = 1, cur_height = 1; - var temp_val_per_Image = (int[])vals_per_Image.Clone(); + var temp_val_per_Image = (int[])Vals_per_Image.Clone(); + int last_val = -1; Func getval = () => { - int t = rand.Next(0, types); - if (temp_val_per_Image[t] == 0) + 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 i = (t + 1)%types; - for (; temp_val_per_Image[i] == 0; i %= types) + 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 { (cur_width, cur_height) }); cur_width++; if (cur_width > width) - { + { cur_height++; cur_width = 1; } } return; } - public (bool,List<(int,int)>?) test((int,int) a,(int,int) b)//x,y + public void remake_board() + { + board_Index.Clear(); + var rand = new Random(); + int[] temp_val_per_Image = (int[])Vals_per_Image.Clone(); + int types = Vals_per_Image.Length; + int height = Bd.GetLength(0); + int width = Bd.GetLength(1); + 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 = 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(); + if (board_Index.TryGetValue(Bd[i, j], out var index)) + index.Add((j, i)); + else + board_Index.Add(Bd[i, j], new List<(int, int)> { (j, i) }); + } + } + public (bool, List<(int, int)>?) test((int, int) a, (int, int) b)//x,y { bool reverse = false; if (a == b) - return (false,null); - if (Bd?[a.Item2, a.Item1] != Bd?[b.Item2, b.Item1]) - return (false,null); + return (false, null); + if (Bd[a.Item2, a.Item1] != Bd[b.Item2, b.Item1]) + return (false, null); var (xa, ya) = a; var (xb, yb) = b; - Func line_test = (bool x,int ct,int from,int to) => + Func line_test = (bool x, int ct, int from, int to) => {//ct is x (x==true)left to right ///up to down if (from > to) (from, to) = (to, from); if (x) { for (int i = from + 1; i < to; i++) - if (Bd?[ct, i] != -1) + if (Bd[ct, i] != -1) return false; } else for (int i = from + 1; i < to; i++) - if (Bd?[i, ct] != -1) + if (Bd[i, ct] != -1) return false; return true; }; @@ -115,9 +189,9 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs HashSet<(int, int)> reachableA = new HashSet<(int, int)>(), reachableB = new HashSet<(int, int)>(); Func<(int, int), HashSet<(int, int)>, bool> check_insert = ((int, int) pos, HashSet<(int, int)> insert) =>//x,y { - if (pos.Item1 < 0 || pos.Item2 < 0 || pos.Item1 >= Bd?.GetLength(1) || pos.Item2 >= Bd?.GetLength(0)) + if (pos.Item1 < 0 || pos.Item2 < 0 || pos.Item1 >= Bd.GetLength(1) || pos.Item2 >= Bd.GetLength(0)) return false; - if (Bd?[pos.Item2, pos.Item1] == -1) + if (Bd[pos.Item2, pos.Item1] == -1) { insert.Add(pos); return true; @@ -182,33 +256,57 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs if (find_ans) return (true, new List<(int, int)> { a, (pax, pay), b }); if (reachableA.Count > reachableB.Count) - { + { (a, b) = (b, a); reverse = true; } } {//three line test - Func<(int, int), (int, int), (bool, (int, int))> intersection = ((int, int) a, (int, int) b) => + Func<(int, int), (int, int), (bool, (int, int))> intersection = ((int, int) a, (int, int) b) =>//first small last big { 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, 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), List> swing_check = ((int, int) range) => + { + int mid = (range.Item2 - range.Item1) / 2 + range.Item1; + bool swing = true;//up true + List ans = new List { mid }; + for (int i = 1; ;) + { + int t; + if (swing) + t = mid + i; + else + { + t = mid - i; + i++; + } + swing = !swing; + if (t >= range.Item1 && t <= range.Item2) + ans.Add(t); + else + break; + } + return ans; + }; if (throughx) - for (int i = xrange.Item1; i <= xrange.Item2; i++) + foreach (int i in swing_check(xrange)) if (line_test(false, i, a.Item2, b.Item2)) if (reverse) return (true, new List<(int, int)> { b, (i, b.Item2), (i, a.Item2), a }); else return (true, new List<(int, int)> { a, (i, a.Item2), (i, b.Item2), b }); + if (throughy) - for (int i = yrange.Item1; i <= yrange.Item2; i++) + foreach (int i in swing_check(yrange)) if (line_test(true, i, a.Item1, b.Item1)) if (reverse) return (true, new List<(int, int)> { b, (b.Item1, i), (a.Item1, i), a }); @@ -217,6 +315,33 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs } return (false, null); } + + + internal void decrease(params (int, int)[] poss) + { + foreach (var (x, y) in poss) + { + int type = Bd[y, x]; + Bd[y, x] = -1; + if (!board_Index[type].Remove((x, y))) + throw new Exception("Val not Found in board_Index"); + Vals_per_Image[type]--; + } + } + + internal List> get_tip((int, int) start) + { + List> ans = new List>(); + if(board_Index.TryGetValue( Bd[start.Item2, start.Item1], 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, int) size { get; set; }//width,height public Settings.Mode mode { get; set; } } diff --git a/CDSAE3_Lian_Lian_Kan/CDSAE3_Lian_Lian_Kan.csproj b/CDSAE3_Lian_Lian_Kan/CDSAE3_Lian_Lian_Kan.csproj index af03d74..043993c 100644 --- a/CDSAE3_Lian_Lian_Kan/CDSAE3_Lian_Lian_Kan.csproj +++ b/CDSAE3_Lian_Lian_Kan/CDSAE3_Lian_Lian_Kan.csproj @@ -8,6 +8,10 @@ enable + + + + True diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Audio_player.Designer.cs b/CDSAE3_Lian_Lian_Kan/Forms/Audio_player.Designer.cs new file mode 100644 index 0000000..869ca37 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Forms/Audio_player.Designer.cs @@ -0,0 +1,94 @@ +namespace CDSAE3_Lian_Lian_Kan.Forms +{ + partial class Audio_player + { + /// + /// 必需的设计器变量。 + /// + 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() + { + sp_Button = new PictureBox(); + last = new PictureBox(); + next = new PictureBox(); + ((System.ComponentModel.ISupportInitialize)sp_Button).BeginInit(); + ((System.ComponentModel.ISupportInitialize)last).BeginInit(); + ((System.ComponentModel.ISupportInitialize)next).BeginInit(); + SuspendLayout(); + // + // sp_Button + // + sp_Button.Image = Properties.Resources.pause; + sp_Button.Location = new Point(368, 114); + sp_Button.Name = "sp_Button"; + sp_Button.Size = new Size(70, 70); + sp_Button.SizeMode = PictureBoxSizeMode.Zoom; + sp_Button.TabIndex = 0; + sp_Button.TabStop = false; + sp_Button.Click += sp_Button_Click; + // + // last + // + last.Image = Properties.Resources.last; + last.Location = new Point(199, 114); + last.Name = "last"; + last.Size = new Size(70, 70); + last.SizeMode = PictureBoxSizeMode.Zoom; + last.TabIndex = 1; + last.TabStop = false; + last.Click += last_Click; + // + // next + // + next.Image = Properties.Resources.next; + next.Location = new Point(536, 114); + next.Name = "next"; + next.Size = new Size(70, 70); + next.SizeMode = PictureBoxSizeMode.Zoom; + next.TabIndex = 2; + next.TabStop = false; + next.Click += next_Click; + // + // Audio_player + // + AutoScaleDimensions = new SizeF(11F, 24F); + AutoScaleMode = AutoScaleMode.Font; + BackColor = Color.White; + Controls.Add(next); + Controls.Add(last); + Controls.Add(sp_Button); + Name = "Audio_player"; + Size = new Size(873, 323); + ((System.ComponentModel.ISupportInitialize)sp_Button).EndInit(); + ((System.ComponentModel.ISupportInitialize)last).EndInit(); + ((System.ComponentModel.ISupportInitialize)next).EndInit(); + ResumeLayout(false); + } + + #endregion + + private PictureBox sp_Button; + private PictureBox last; + private PictureBox next; + } +} diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Audio_player.cs b/CDSAE3_Lian_Lian_Kan/Forms/Audio_player.cs new file mode 100644 index 0000000..bb669a7 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Forms/Audio_player.cs @@ -0,0 +1,55 @@ +using CDSAE3_Lian_Lian_Kan; +using CDSAE3_Lian_Lian_Kan.Properties; +using NAudio.Wave; +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; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; + +namespace CDSAE3_Lian_Lian_Kan.Forms +{ + public partial class Audio_player : UserControl + { + public Audio_player() + { + InitializeComponent(); + } + bool play_state = false; + private void sp_Button_Click(object sender, EventArgs e) + { + if (!play_state) + play(); + else + pause(); + play_state = !play_state; + } + private void play() + { + Settings.audio_Processer.resume_song(); + sp_Button.Image = Resources.pause; + } + private void pause() + { + Settings.audio_Processer.pause_song(); + sp_Button.Image = Resources.play_buttton; + } + + private void last_Click(object sender, EventArgs e) + { + Settings.audio_Processer.last_song(); + play(); + } + + private void next_Click(object sender, EventArgs e) + { + Settings.audio_Processer.next_song(); + play(); + } + } +} diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Audio_player.resx b/CDSAE3_Lian_Lian_Kan/Forms/Audio_player.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Forms/Audio_player.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/GameControl.cs b/CDSAE3_Lian_Lian_Kan/Forms/GameControl.cs index b4c6ffa..07bb3cf 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/GameControl.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/GameControl.cs @@ -5,6 +5,7 @@ using System.ComponentModel; using System.ComponentModel.Design; using System.Data; using System.Drawing; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -13,10 +14,13 @@ using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; namespace CDSAE3_Lian_Lian_Kan.Forms { - public partial class GameControl : UserControl, IBeSelected + public partial class GameControl : UserControl, IGameControl { Board board = new Board(); - IGameMode iGameMode; + IGameMode? iGameMode; + Queue<((int, int), Single_Block)> queue = new Queue<((int, int), Single_Block)>();//y,x + bool do_search = false; + List hint_blocks = new List(); public GameControl() { InitializeComponent(); @@ -27,16 +31,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms } void playPanel_set() { - int[,] bd; - if (board.Bd == null) - { - board.make_board(); - bd = board.Bd ?? new int[0, 0]; - if (bd.Length == 0) - throw new Exception("bd is null"); - } - else - bd = board.Bd; + int[,] bd = board.Bd; playPanel_size_change(); for (int i = 0; i < playPanel.RowCount; i++) for (int j = 0; j < playPanel.ColumnCount; j++) @@ -55,18 +50,128 @@ namespace CDSAE3_Lian_Lian_Kan.Forms } } } - Queue<((int, int), Single_Block)> queue = new Queue<((int, int), Single_Block)>();//y,x + /// + /// 由form和to两个点获取方向 + /// + /// 起始点 + /// 终点 + /// + Settings.Direction get_Direction((int, int) from, (int, int) to) //x,y + { + if (from.Item1 == to.Item1) + if (from.Item2 > to.Item2) + return Settings.Direction.up; + else + return Settings.Direction.down; + else + if (from.Item1 > to.Item1) + return Settings.Direction.left; + else + return Settings.Direction.right; + } + /// + /// 设置单个点方向 + /// + /// + /// + /// + /// + /// + async Task set_PathAsync((int, int) point, Settings.Direction direction, List blocks, int wait_time,bool is_hint) + { + + if (wait_time != 0) + await Task.Delay(wait_time); + Control? control = playPanel.GetControlFromPosition(point.Item1, point.Item2); + if (control != null && control is Single_Block single_Block) + { + if (is_hint) + single_Block.hint_path(direction); + else + single_Block.to_path(direction); + blocks.Add(single_Block); + } + } + async Task to_path((int, int) from, (int, int) to, bool include_end, Settings.Direction extra_Direction, List blocks, int wait_time, bool is_hint) + { + var direction = get_Direction(from, to); + switch (direction) + { + case Settings.Direction.up: + for (int i = from.Item2 - 1; i != to.Item2; i--) + await set_PathAsync((from.Item1, i), Settings.Direction.up_down, blocks, wait_time,is_hint); + break; + case Settings.Direction.down: + for (int i = from.Item2 + 1; i != to.Item2; i++) + await set_PathAsync((from.Item1, i), Settings.Direction.up_down, blocks, wait_time,is_hint); + break; + case Settings.Direction.right: + for (int i = from.Item1 + 1; i != to.Item1; i++) + await set_PathAsync((i, from.Item2), Settings.Direction.left_right, blocks, wait_time,is_hint); + break; + case Settings.Direction.left: + for (int i = from.Item1 - 1; i != to.Item1; i--) + await set_PathAsync((i, from.Item2), Settings.Direction.left_right, blocks, wait_time,is_hint); + break; + } + if (include_end) + { + direction = ((int)direction & 3) > 0 ? (Settings.Direction)((int)direction << 2) : (Settings.Direction)((int)direction >> 2); + direction = direction | extra_Direction; + 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) + { + switch (path.Count) + { + case 2: + await to_path(path[0], path[1], false, Settings.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, Settings.Direction.none, blocks, wait_time,is_hint); + break; + case 4: + Settings.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, Settings.Direction.none, blocks, wait_time,is_hint); + break; + } + + } + internal void set_tip() + { + if (queue.Count != 1) + return; + List> paths = board.get_tip(queue.Peek().Item1); + foreach (var path in paths) + _ = path_drawerAsync(path, 0, hint_blocks,true); + } + internal void de_set_tip() + { + foreach (var control in hint_blocks) + control.de_path(); + hint_blocks.Clear(); + } public void Selected_Handler(Single_Block sender, SelectedEventArgs e) { Task.Run(() => { - iGameMode.De_pause(this, e); + iGameMode?.De_pause(this, e); if (e.be_selected) { switch (queue.Count) { case 0: queue.Enqueue((e.position, sender)); + if (do_search) + { + de_set_tip(); + set_tip(); + } break; case 1: var (posa, sendera) = queue.Dequeue(); @@ -74,15 +179,18 @@ namespace CDSAE3_Lian_Lian_Kan.Forms var (could, path) = board.test(posa, posb); if (could) { + board.decrease(posa, posb); _ = Block_ClearAsync(path); while (queue.Count() > 0) queue.Dequeue(); - if (board.Bd is null) throw new Exception("No usable board. How come?"); - board.Bd[posa.Item2, posa.Item1] = -1; - board.Bd[posb.Item2, posb.Item1] = -1; } else { + if (do_search) + { + de_set_tip(); + set_tip(); + } queue.Enqueue((e.position, sender)); sendera.deselect(); } @@ -97,86 +205,25 @@ namespace CDSAE3_Lian_Lian_Kan.Forms break; case 1: if (queue.Peek().Item1 == e.position) + { queue.Dequeue(); + if (do_search) + de_set_tip(); + } break; } } }); } - async Task Block_ClearAsync(List<(int, int)>? path) { - List paths = new List(); + if (do_search == true) + foreach (Single_Block single_Block in hint_blocks) + single_Block.de_path(); + List blocks = new List(); if (path == null) return; - Func<(int, int), (int, int), Settings.Direction> get_Direction = ((int, int) from, (int, int) to) =>//x,y - { - if (from.Item1 == to.Item1) - if (from.Item2 > to.Item2) - return Settings.Direction.up; - else - return Settings.Direction.down; - else - if (from.Item1 > to.Item1) - return Settings.Direction.left; - else - return Settings.Direction.right; - }; - Func<(int, int), Settings.Direction, Task> set_Path = async ((int, int) point, Settings.Direction direction) => - { - await Task.Delay(20); - Control? control = playPanel.GetControlFromPosition(point.Item1, point.Item2); - if (control != null && control is Single_Block single_Block) - { - single_Block.to_path(direction); - paths.Add(single_Block); - } - }; - Func<(int, int), (int, int), bool, Settings.Direction, Task> to_path = async ((int, int) from, (int, int) to, bool include_end, Settings.Direction extra_Direction) => - { - var direction = get_Direction(from, to); - switch (direction) - { - case Settings.Direction.up: - for (int i = from.Item2 - 1; i != to.Item2; i--) - await set_Path((from.Item1, i), Settings.Direction.up_down); - break; - case Settings.Direction.down: - for (int i = from.Item2 + 1; i != to.Item2; i++) - await set_Path((from.Item1, i), Settings.Direction.up_down); - break; - case Settings.Direction.right: - for (int i = from.Item1 + 1; i != to.Item1; i++) - await set_Path((i, from.Item2), Settings.Direction.left_right); - break; - case Settings.Direction.left: - for (int i = from.Item1 - 1; i != to.Item1; i--) - await set_Path((i, from.Item2), Settings.Direction.left_right); - break; - } - if (include_end) - { - direction = direction | extra_Direction; - await set_Path(to, direction); - } - }; - switch (path.Count) - { - case 2: - await to_path(path[0], path[1], false, 0); - break; - case 3: - var extra_direction = get_Direction(path[1], path[2]); - await to_path(path[0], path[1], true, extra_direction); - await to_path(path[1], path[2], false, Settings.Direction.none); - break; - case 4: - Settings.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); - await to_path(path[1], path[2], true, extra_directionB); - await to_path(path[2], path[3], false, Settings.Direction.none); - break; - } + await path_drawerAsync(path, 20, blocks, false); Control? controlA = playPanel.GetControlFromPosition(path[0].Item1, path[0].Item2), controlB = playPanel.GetControlFromPosition(path.Last().Item1, path.Last().Item2); if (controlA != null && controlB != null && controlA is Single_Block single_BlockA && controlB is Single_Block single_BlockB) { @@ -184,12 +231,11 @@ namespace CDSAE3_Lian_Lian_Kan.Forms single_BlockB.destroyAsync(); } await Task.Delay(200); - foreach (var control in paths) + foreach (var control in blocks) control.de_path(); - iGameMode.Score_Add(this, new AddScoreArgs { score = (paths.Count + 2)*10 }); + iGameMode?.Score_Add(this, new AddScoreArgs { score = (blocks.Count + 2) * 10 }); board.Total -= 2; } - void playPanel_size_change() { var (width, height) = board.size; @@ -202,5 +248,34 @@ namespace CDSAE3_Lian_Lian_Kan.Forms for (int i = 0; i < height + 1; i++) playPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); } + public void Exchange_Handler(object? sender, EventArgs e) + { + board.remake_board(); + int[,] bd = board.Bd; + for (int i = 0; i < bd.GetLength(0); i++) + for (int j = 0; j < bd.GetLength(1); j++) + if (bd[i, j] == -1) + continue; + else + { + Control? control = playPanel.GetControlFromPosition(j, i); + if (control != null && control is Single_Block single_Block) + single_Block.Re_create(bd[i, j], null, null, null); + } + } + + public void Search_Handler(object? sender, SearchEventArgs e) + { + if (e.set_search) + { + do_search = true; + set_tip(); + } + else + { + do_search = false; + de_set_tip(); + } + } } } diff --git a/CDSAE3_Lian_Lian_Kan/Forms/IBeSelected.cs b/CDSAE3_Lian_Lian_Kan/Forms/IBeSelected.cs index 3e79dad..429f528 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/IBeSelected.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/IBeSelected.cs @@ -6,8 +6,14 @@ using System.Threading.Tasks; namespace CDSAE3_Lian_Lian_Kan.Forms { - public interface IBeSelected + public interface IGameControl { public void Selected_Handler(Single_Block sender, SelectedEventArgs e); + public void Exchange_Handler(object? sender, EventArgs e); + public void Search_Handler(object? sender, SearchEventArgs e); + } + public class SearchEventArgs:EventArgs + { + public bool set_search { get; set; } = false;//true : search } } diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.Designer.cs b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.Designer.cs index a9e2bb6..b914374 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.Designer.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.Designer.cs @@ -150,6 +150,7 @@ search.SizeMode = PictureBoxSizeMode.Zoom; search.TabIndex = 9; search.TabStop = false; + search.Click += search_Click; // // exchange // @@ -161,6 +162,7 @@ exchange.SizeMode = PictureBoxSizeMode.Zoom; exchange.TabIndex = 10; exchange.TabStop = false; + exchange.Click += exchange_Click; // // Leisure_Mode // diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs index 1f49264..5c569b2 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs @@ -29,15 +29,26 @@ namespace CDSAE3_Lian_Lian_Kan.Forms int cur_score = 0; int factor_val = 1; int current_base = 0; - + int search_left_time = 0; + bool search_mode = false; Dictionary decrease_per_level = Settings.decrease_per_level; + private void Timer_Tick(object? sender, EventArgs e) { left_time--; BeginInvoke(() => time.Text = (left_time / 60).ToString().PadLeft(2, '0') + ":" + (left_time % 60).ToString().PadLeft(2, '0')); + if(search_mode) + { + search_left_time--; + if (search_left_time < 0) + { + search_mode = false; + gameControl.Search_Handler(this, new SearchEventArgs { set_search = false }); + } + } if (current_base <= 0) { - if(factor_val>1) + if (factor_val > 1) { current_base = 100; factor_val--; @@ -70,9 +81,9 @@ namespace CDSAE3_Lian_Lian_Kan.Forms { cur_score += e.score * factor_val; current_base += e.score; - while(current_base>100) + while (current_base > 100) { - if(factor_val>=10) + if (factor_val >= 10) { factor_val = 10; current_base = 100; @@ -83,7 +94,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms factor_val++; } } - BeginInvoke(()=>factor.Text = "x" + factor_val.ToString()); + BeginInvoke(() => factor.Text = "x" + factor_val.ToString()); BeginInvoke(() => energy_bar.Value = current_base); BeginInvoke(() => score.Text = cur_score.ToString()); } @@ -123,5 +134,17 @@ namespace CDSAE3_Lian_Lian_Kan.Forms timer.Close(); Settings.form?.change_form(new Leisure_Mode_MenuForm()); } + + private void exchange_Click(object sender, EventArgs e) + { + Task.Run(() => gameControl.Exchange_Handler(this, new EventArgs())); + } + + private void search_Click(object sender, EventArgs e) + { + gameControl.Search_Handler(this, new SearchEventArgs { set_search = true}); + search_mode = true; + search_left_time = Settings.search_left_time; + } } } diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode_MenuForm.cs b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode_MenuForm.cs index d252e36..38677b0 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode_MenuForm.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode_MenuForm.cs @@ -15,6 +15,8 @@ namespace CDSAE3_Lian_Lian_Kan.Forms public Leisure_Mode_MenuForm() { InitializeComponent(); + Settings.audio_Processer.next_song(); + Settings.audio_Processer.resume_song(); } private void start_Game_Click(object sender, EventArgs e) diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs b/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs index 02861f1..f8c3400 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs @@ -79,13 +79,21 @@ namespace CDSAE3_Lian_Lian_Kan selected = false; BackColor = nor_color; } + 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)); + } public void to_path(Settings.Direction direction) - {//TODO tube Image - Image_change(Settings.get_block_Image(0)); + { + Image_change(Settings.get_direction_Image(direction)); + direction = Settings.Direction.none; } public void de_path() { Image_change(Settings.trans_Image); + direction = Settings.Direction.none; } System.Timers.Timer? timer = null; public void destroyAsync() @@ -98,7 +106,7 @@ namespace CDSAE3_Lian_Lian_Kan timer.Elapsed += Image_Clear; timer.Enabled = true; } - Object locker = new object(); + object locker = new object(); public void Image_Clear(object? sender, ElapsedEventArgs e) { timer?.Stop(); @@ -116,9 +124,21 @@ namespace CDSAE3_Lian_Lian_Kan catch(Exception) { Image_change(new_image); - //Console.WriteLine("test"); } } + 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; + } public event SelectedEventHandler Selected; } public class SelectedEventArgs : EventArgs diff --git a/CDSAE3_Lian_Lian_Kan/Properties/Resources.Designer.cs b/CDSAE3_Lian_Lian_Kan/Properties/Resources.Designer.cs index 0ff9122..61578d7 100644 --- a/CDSAE3_Lian_Lian_Kan/Properties/Resources.Designer.cs +++ b/CDSAE3_Lian_Lian_Kan/Properties/Resources.Designer.cs @@ -90,6 +90,46 @@ namespace CDSAE3_Lian_Lian_Kan.Properties { } } + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] C418___Beginning_2 { + get { + object obj = ResourceManager.GetObject("C418___Beginning_2", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] C418___Floating_Trees { + get { + object obj = ResourceManager.GetObject("C418___Floating_Trees", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] C418___Moog_City_2 { + get { + object obj = ResourceManager.GetObject("C418___Moog_City_2", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] C418___Mutation { + get { + object obj = ResourceManager.GetObject("C418___Mutation", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// @@ -290,6 +330,16 @@ namespace CDSAE3_Lian_Lian_Kan.Properties { } } + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap last { + get { + object obj = ResourceManager.GetObject("last", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// @@ -310,6 +360,16 @@ namespace CDSAE3_Lian_Lian_Kan.Properties { } } + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap next { + get { + object obj = ResourceManager.GetObject("next", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// @@ -370,6 +430,156 @@ namespace CDSAE3_Lian_Lian_Kan.Properties { } } + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_d { + get { + object obj = ResourceManager.GetObject("tip_d", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_dl { + get { + object obj = ResourceManager.GetObject("tip_dl", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_dlr { + get { + object obj = ResourceManager.GetObject("tip_dlr", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_dr { + get { + object obj = ResourceManager.GetObject("tip_dr", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_l { + get { + object obj = ResourceManager.GetObject("tip_l", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_lr { + get { + object obj = ResourceManager.GetObject("tip_lr", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_r { + get { + object obj = ResourceManager.GetObject("tip_r", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_u { + get { + object obj = ResourceManager.GetObject("tip_u", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_ud { + get { + object obj = ResourceManager.GetObject("tip_ud", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_udl { + get { + object obj = ResourceManager.GetObject("tip_udl", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_udlr { + get { + object obj = ResourceManager.GetObject("tip_udlr", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_udr { + get { + object obj = ResourceManager.GetObject("tip_udr", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_ul { + get { + object obj = ResourceManager.GetObject("tip_ul", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_ulr { + get { + object obj = ResourceManager.GetObject("tip_ulr", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap tip_ur { + get { + object obj = ResourceManager.GetObject("tip_ur", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// @@ -410,6 +620,16 @@ namespace CDSAE3_Lian_Lian_Kan.Properties { } } + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap udlr { + get { + object obj = ResourceManager.GetObject("udlr", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// @@ -450,16 +670,6 @@ namespace CDSAE3_Lian_Lian_Kan.Properties { } } - /// - /// 查找 System.Drawing.Bitmap 类型的本地化资源。 - /// - internal static System.Drawing.Bitmap urdl { - get { - object obj = ResourceManager.GetObject("urdl", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// diff --git a/CDSAE3_Lian_Lian_Kan/Properties/Resources.resx b/CDSAE3_Lian_Lian_Kan/Properties/Resources.resx index 08ffef0..025799b 100644 --- a/CDSAE3_Lian_Lian_Kan/Properties/Resources.resx +++ b/CDSAE3_Lian_Lian_Kan/Properties/Resources.resx @@ -229,6 +229,9 @@ ..\Resources\udl.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\udlr.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\udr.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -241,7 +244,67 @@ ..\Resources\ur.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\urdl.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\tip_d.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tip_dl.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tip_dlr.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tip_dr.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tip_l.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tip_lr.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tip_r.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tip_u.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tip_ud.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tip_udl.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tip_udlr.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tip_udr.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tip_ul.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tip_ulr.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tip_ur.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\C418 - Beginning 2.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\C418 - Floating Trees.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\C418 - Moog City 2.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\C418 - Mutation.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\last.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\next.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/CDSAE3_Lian_Lian_Kan/Resources/C418 - Beginning 2.mp3 b/CDSAE3_Lian_Lian_Kan/Resources/C418 - Beginning 2.mp3 new file mode 100644 index 0000000..869f63c Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/C418 - Beginning 2.mp3 differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/C418 - Floating Trees.mp3 b/CDSAE3_Lian_Lian_Kan/Resources/C418 - Floating Trees.mp3 new file mode 100644 index 0000000..dd8b7e9 Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/C418 - Floating Trees.mp3 differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/C418 - Moog City 2.mp3 b/CDSAE3_Lian_Lian_Kan/Resources/C418 - Moog City 2.mp3 new file mode 100644 index 0000000..ff1e375 Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/C418 - Moog City 2.mp3 differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/C418 - Mutation.mp3 b/CDSAE3_Lian_Lian_Kan/Resources/C418 - Mutation.mp3 new file mode 100644 index 0000000..a46d0d1 Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/C418 - Mutation.mp3 differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/last.png b/CDSAE3_Lian_Lian_Kan/Resources/last.png new file mode 100644 index 0000000..cf3c92b Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/last.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/next.png b/CDSAE3_Lian_Lian_Kan/Resources/next.png new file mode 100644 index 0000000..97e93cc Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/next.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_d.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_d.png new file mode 100644 index 0000000..c90223c Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_d.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_dl.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_dl.png new file mode 100644 index 0000000..f9369bf Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_dl.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_dlr.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_dlr.png new file mode 100644 index 0000000..e98c76f Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_dlr.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_dr.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_dr.png new file mode 100644 index 0000000..444e4ca Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_dr.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_l.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_l.png new file mode 100644 index 0000000..4660260 Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_l.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_lr.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_lr.png new file mode 100644 index 0000000..2f0ef11 Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_lr.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_r.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_r.png new file mode 100644 index 0000000..b8d0171 Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_r.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_u.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_u.png new file mode 100644 index 0000000..d4a4993 Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_u.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_ud.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_ud.png new file mode 100644 index 0000000..8dea150 Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_ud.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_udl.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_udl.png new file mode 100644 index 0000000..9eea70b Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_udl.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_udlr.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_udlr.png new file mode 100644 index 0000000..899317a Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_udlr.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_udr.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_udr.png new file mode 100644 index 0000000..1e8d08c Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_udr.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_ul.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_ul.png new file mode 100644 index 0000000..ca9bbce Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_ul.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_ulr.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_ulr.png new file mode 100644 index 0000000..9a962de Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_ulr.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/tip_ur.png b/CDSAE3_Lian_Lian_Kan/Resources/tip_ur.png new file mode 100644 index 0000000..5556b2f Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/tip_ur.png differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/urdl.png b/CDSAE3_Lian_Lian_Kan/Resources/udlr.png similarity index 100% rename from CDSAE3_Lian_Lian_Kan/Resources/urdl.png rename to CDSAE3_Lian_Lian_Kan/Resources/udlr.png diff --git a/CDSAE3_Lian_Lian_Kan/Settings.cs b/CDSAE3_Lian_Lian_Kan/Settings.cs index 9760574..ad2c9ed 100644 --- a/CDSAE3_Lian_Lian_Kan/Settings.cs +++ b/CDSAE3_Lian_Lian_Kan/Settings.cs @@ -1,16 +1,21 @@ using System; using System.Collections.Generic; +using System.Globalization; 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.Forms; using CDSAE3_Lian_Lian_Kan.Properties; +using CDSAE3_Lian_Lian_Kan.Sound; namespace CDSAE3_Lian_Lian_Kan { - public class Settings + public static class Settings { public static int left_time { get; set; } = 180; + public static int search_left_time { get; set; } = 20; + public enum Difficulty { easy = 0, @@ -34,7 +39,12 @@ namespace CDSAE3_Lian_Lian_Kan up_right = 3, up_left = 9, down_right = 6, - down_left = 12 + down_left = 12, + up_down_right = 7, + up_down_left = 13, + up_left_right = 11, + down_left_right = 14, + up_down_left_right = 15 } public static Dictionary decrease_per_level = new Dictionary { {1,100.0/60 }, @@ -49,20 +59,28 @@ namespace CDSAE3_Lian_Lian_Kan {10,100.0/3 }}; static int cus_height = 1, cus_width = 1; - public static Difficulty current_difficulty { get; set; } = Difficulty.easy; + 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; public static (int, int) get_length_width() => current_difficulty != Difficulty.custom ? (7 * (1 + (int)current_difficulty), 4 * (1 + (int)current_difficulty)) : (cus_width,cus_height); public static List block_Images { get; set; } = new List { Resources.Apple, Resources.Banana, Resources.Beetroot, Resources.Cherry, Resources.Corn, Resources.Eggplant, Resources.Grape, Resources.Pear, Resources.Strawberry, Resources.Watermelon }; public static List disappear_Images { get; set; } = new List { Resources.Gapple, Resources.Gbanana, Resources.Gbeetroot, Resources.Gcherry, Resources.Gcorn, Resources.Geggplant, Resources.Ggrape, Resources.Gpear, Resources.Gstrawberry, Resources.Gwatermelon }; + public static List direction_Images { get; set; } = new List { Resources.trans, Resources.u, Resources.r , Resources.ur, Resources.d, Resources.ud, Resources.dr, Resources.udr, Resources.l, Resources.ul, Resources.lr, Resources.ulr, Resources.dl, Resources.udl, Resources.dlr, Resources.udlr}; + public static List tip_direction_Image { get; set; } = new List { Resources.trans, Resources.tip_u, Resources.tip_r, Resources.tip_ur, Resources.tip_d, Resources.tip_ud, Resources.tip_dr, Resources.tip_udr, Resources.tip_l, Resources.tip_ul, Resources.tip_lr, Resources.tip_ulr, Resources.tip_dl, Resources.tip_udl, Resources.tip_dlr, Resources.tip_udlr }; public static Image get_block_Image(int t) => block_Images[t]; public static Image get_disappear_Images(int t) => disappear_Images[t]; + public static Image get_direction_Image(Direction direction) => direction_Images[(int)direction]; public static int Images_size() => current_mode switch { Mode.fruit => 10, _ => 0, }; + internal static Image get_tip_direction_Image(Direction direction) => tip_direction_Image[(int)direction]; public static LianLianKan? form { get; set; } - public static IBeSelected? game_form{ get; set; }//gameBoard + public static IGameControl? game_form{ get; set; }//gameBoard public static IGameMode? game_mode_form { get; set; }//entireGame public static Board board { get; set; } = new Board(); public static Color def_Color { get; set; } = Color.FromArgb(0, 0, 0, 0); public static Color sel_Color { get; set; } = Color.FromArgb(0, 122, 204); + 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_processer audio_Processer { get; set; } = new Audio_processer(); + public static ResourceManager res_Manager { get; set; } = new ResourceManager("CDSAE3_Lian_Lian_Kan.Properties.Resources", typeof(Resources).Assembly); + public static CultureInfo res_Culture { get; set; } = new CultureInfo("en-US"); } } diff --git a/CDSAE3_Lian_Lian_Kan/Sound/Audio_processer.cs b/CDSAE3_Lian_Lian_Kan/Sound/Audio_processer.cs new file mode 100644 index 0000000..d487cda --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Sound/Audio_processer.cs @@ -0,0 +1,164 @@ +using NAudio.Wave; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Resources; +using System.Text; +using System.Threading.Tasks; +using CDSAE3_Lian_Lian_Kan.Properties; +using NAudio.Wave.SampleProviders; +namespace CDSAE3_Lian_Lian_Kan.Sound +{ + public class Audio_processer + { + class Audio_File_Processor + { + private WaveChannel32? volumeStream; + private List audioFiles = new List(); + string base_path; + int next_song = 0; + int volume = 90; + public Audio_File_Processor() + { + base_path = AppDomain.CurrentDomain.BaseDirectory; + } + internal void set_Albums(string s)=>audioFiles = Settings.musics.TryGetValue(s, out List? val) ? val : new List(); + internal Wave16ToFloatProvider get_next_song() + { + volumeStream?.Close(); + 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 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(volumeStream != null) + volumeStream.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; + } + } + } + ~Audio_File_Processor() + { + volumeStream?.Close(); + } + + } + private WaveOutEvent songOutputDevice; + private WaveOutEvent infoOutputDevice; + Audio_File_Processor audio_File_Processor = new Audio_File_Processor(); + public Audio_processer() + { + songOutputDevice = new WaveOutEvent(); + infoOutputDevice = new WaveOutEvent(); + set_albums(get_albums().First()); + } + private void OnPlaybackStopped(object? sender, StoppedEventArgs e) + { + next_song(); + resume_song(); + } + public void pause_song()=>songOutputDevice.Pause(); + public void resume_song()=>songOutputDevice.Play(); + public void last_song() + { + waveOutEvent_Provider(audio_File_Processor.get_last_song()); + } + public void next_song() + { + waveOutEvent_Provider(audio_File_Processor.get_next_song()); + } + /// + /// 切换音乐 + /// + /// + private void waveOutEvent_Provider(Wave16ToFloatProvider wave16ToFloatProvider) + { + + songOutputDevice.Stop(); + songOutputDevice.Dispose(); + songOutputDevice = new WaveOutEvent(); + songOutputDevice.Init(wave16ToFloatProvider); + songOutputDevice.PlaybackStopped += OnPlaybackStopped; + } + /// + /// 调整音乐音量 + /// + /// 音量大小 1-100 + public void volume_change(int val)=> audio_File_Processor.volume_change(val); + public List get_albums() => Settings.musics.Select(x => x.Key).ToList(); + public void set_albums(string s) + { + audio_File_Processor.set_Albums(s); + } + ~Audio_processer() + { + songOutputDevice.Dispose(); + infoOutputDevice.Dispose(); + } + } +}