diff --git a/CDSAE3_Lian_Lian_Kan/Board_funcs/Board.cs b/CDSAE3_Lian_Lian_Kan/Board_funcs/Board.cs index 4650b01..2a4a22a 100644 --- a/CDSAE3_Lian_Lian_Kan/Board_funcs/Board.cs +++ b/CDSAE3_Lian_Lian_Kan/Board_funcs/Board.cs @@ -8,9 +8,9 @@ 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 partial class Board:IBoard { - public int[,] Bd { get; set; } = { { } };//y,x + private int[,] Bd = { { } };//y,x public Dictionary> board_Index { get; } = new Dictionary>(); public int[] Vals_per_Image { get; set; } = { }; public int total; @@ -24,13 +24,13 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs { total = value; if (total == 0) - Settings.game_mode_form?.Finished_Handler(this, new Forms.FinishArgs { finish_Type = Forms.FinishArgs.Finish_Type.All_done }); + Etcs.game_mode_form?.Finished_Handler(this, new Forms.FinishArgs { finish_Type = Forms.FinishArgs.Finish_Type.All_done }); } } - public void make_board() + public int[,] make_board() { var rand = new Random(); - size = Settings.get_length_width(); + size = Etcs.get_length_width(); var (width, height) = size; Bd = new int[height + 2, width + 2]; for (int i = 0; i < height + 2; i++) @@ -40,7 +40,7 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs if (sum % 2 != 0) sum--; total = sum; - int types = Settings.Images_size(); + int types = Etcs.Images_size(); Vals_per_Image = new int[types]; int single = sum / types; for (int k = sum; k > 0; k -= 2) @@ -68,15 +68,21 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs } if (not_zero <= 1) { - int k = temp_val_per_Image.Single(x => x != 0); + int k = 0; + for(int i=0;i { (j, i) }); } + return Bd; } public (bool, List<(int, int)>?) test((int, int) a, (int, int) b)//x,y { @@ -274,31 +281,36 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs }; 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) => + Func<(int, int), int, List> swing_check = ((int, int) range, int center) => { - int mid = (range.Item2 - range.Item1) / 2 + range.Item1; - bool swing = true;//up true - List ans = new List { mid }; - for (int i = 1; ;) + List result = new List(); + if (center < range.Item1) { - 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; + for (int k = range.Item1; k <= range.Item2; k++) + result.Add(k); + return result; } - return ans; + 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)) + foreach (int i in swing_check(xrange, a.Item1)) 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 }); @@ -306,7 +318,7 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs return (true, new List<(int, int)> { a, (i, a.Item2), (i, b.Item2), b }); if (throughy) - foreach (int i in swing_check(yrange)) + foreach (int i in swing_check(yrange, a.Item2)) 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 }); @@ -315,9 +327,7 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs } return (false, null); } - - - internal void decrease(params (int, int)[] poss) + public void decrease(params (int, int)[] poss) { foreach (var (x, y) in poss) { @@ -329,20 +339,19 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs } } - internal List> get_tip((int, int) start) + internal List> get_tip((int, int) start) { List> ans = new List>(); - if(board_Index.TryGetValue( Bd[start.Item2, start.Item1], out var tip)) + 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) + if (result && path != null) ans.Add(path); } return ans; } - public (int, int) size { get; set; }//width,height - public Settings.Mode mode { get; set; } + public Etcs.Mode mode { get; set; } } } diff --git a/CDSAE3_Lian_Lian_Kan/Board_funcs/IBoard.cs b/CDSAE3_Lian_Lian_Kan/Board_funcs/IBoard.cs new file mode 100644 index 0000000..c096ccf --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Board_funcs/IBoard.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CDSAE3_Lian_Lian_Kan.Board_funcs +{ + internal interface IBoard + { + public int[,] make_board(); + public int[,] remake_board(); + public (bool, List<(int, int)>?) test((int, int) a, (int, int) b); + public void decrease(params (int, int)[] poss); + + + + } +} diff --git a/CDSAE3_Lian_Lian_Kan/Settings.cs b/CDSAE3_Lian_Lian_Kan/Etcs.cs similarity index 89% rename from CDSAE3_Lian_Lian_Kan/Settings.cs rename to CDSAE3_Lian_Lian_Kan/Etcs.cs index ad2c9ed..cc58c02 100644 --- a/CDSAE3_Lian_Lian_Kan/Settings.cs +++ b/CDSAE3_Lian_Lian_Kan/Etcs.cs @@ -11,7 +11,7 @@ using CDSAE3_Lian_Lian_Kan.Properties; using CDSAE3_Lian_Lian_Kan.Sound; namespace CDSAE3_Lian_Lian_Kan { - public static class Settings + public static class Etcs { public static int left_time { get; set; } = 180; public static int search_left_time { get; set; } = 20; @@ -46,6 +46,11 @@ namespace CDSAE3_Lian_Lian_Kan down_left_right = 14, up_down_left_right = 15 } + public enum break_music + { + breakA, + breakB + } public static Dictionary decrease_per_level = new Dictionary { {1,100.0/60 }, {2,100.0/45 }, @@ -78,9 +83,14 @@ namespace CDSAE3_Lian_Lian_Kan 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 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_processer audio_Processer { get; set; } = new Audio_processer(); + 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); public static CultureInfo res_Culture { get; set; } = new CultureInfo("en-US"); + public static int Song_Volume { get; set; } = 70; + public static int Info_Volume { get; set; } = 70; + } } diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Audio_player.Designer.cs b/CDSAE3_Lian_Lian_Kan/Forms/Audio_player.Designer.cs deleted file mode 100644 index 869ca37..0000000 --- a/CDSAE3_Lian_Lian_Kan/Forms/Audio_player.Designer.cs +++ /dev/null @@ -1,94 +0,0 @@ -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 deleted file mode 100644 index bb669a7..0000000 --- a/CDSAE3_Lian_Lian_Kan/Forms/Audio_player.cs +++ /dev/null @@ -1,55 +0,0 @@ -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 deleted file mode 100644 index af32865..0000000 --- a/CDSAE3_Lian_Lian_Kan/Forms/Audio_player.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 07bb3cf..637acea 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/GameControl.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/GameControl.cs @@ -24,27 +24,26 @@ namespace CDSAE3_Lian_Lian_Kan.Forms public GameControl() { InitializeComponent(); - board.make_board(); - Settings.game_form = this; - playPanel_set(); - iGameMode = Settings.game_mode_form; + + Etcs.game_form = this; + playPanel_set(board.make_board()); + iGameMode = Etcs.game_mode_form; } - void playPanel_set() + void playPanel_set(int[,]bd) { - int[,] bd = board.Bd; playPanel_size_change(); for (int i = 0; i < playPanel.RowCount; i++) for (int j = 0; j < playPanel.ColumnCount; j++) { if (bd[i, j] == -1) { - var x = new Single_Block(Settings.trans_Image, (j, i)); + var x = new Single_Block(Etcs.trans_Image, (j, i)); x.Dock = DockStyle.Fill; playPanel.Controls.Add(x, j, i); } else { - var x = new Single_Block(bd[i, j], Settings.def_Color, Settings.sel_Color, (j, i)); + var x = new Single_Block(bd[i, j], Etcs.def_Color, Etcs.sel_Color, (j, i)); x.Dock = DockStyle.Fill; playPanel.Controls.Add(x, j, i); } @@ -56,18 +55,18 @@ namespace CDSAE3_Lian_Lian_Kan.Forms /// 起始点 /// 终点 /// - Settings.Direction get_Direction((int, int) from, (int, int) to) //x,y + Etcs.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; + return Etcs.Direction.up; else - return Settings.Direction.down; + return Etcs.Direction.down; else if (from.Item1 > to.Item1) - return Settings.Direction.left; + return Etcs.Direction.left; else - return Settings.Direction.right; + return Etcs.Direction.right; } /// /// 设置单个点方向 @@ -77,7 +76,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms /// /// /// - async Task set_PathAsync((int, int) point, Settings.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) @@ -92,31 +91,31 @@ namespace CDSAE3_Lian_Lian_Kan.Forms 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) + async Task to_path((int, int) from, (int, int) to, bool include_end, Etcs.Direction extra_Direction, List blocks, int wait_time, bool is_hint) { var direction = get_Direction(from, to); switch (direction) { - case Settings.Direction.up: + case Etcs.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); + await set_PathAsync((from.Item1, i), Etcs.Direction.up_down, blocks, wait_time,is_hint); break; - case Settings.Direction.down: + case Etcs.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); + await set_PathAsync((from.Item1, i), Etcs.Direction.up_down, blocks, wait_time,is_hint); break; - case Settings.Direction.right: + case Etcs.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); + await set_PathAsync((i, from.Item2), Etcs.Direction.left_right, blocks, wait_time,is_hint); break; - case Settings.Direction.left: + case Etcs.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); + await set_PathAsync((i, from.Item2), Etcs.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 = ((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); } @@ -126,18 +125,18 @@ namespace CDSAE3_Lian_Lian_Kan.Forms switch (path.Count) { case 2: - await to_path(path[0], path[1], false, Settings.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, Settings.Direction.none, blocks, wait_time,is_hint); + await to_path(path[1], path[2], false, Etcs.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]); + 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, Settings.Direction.none, blocks, wait_time,is_hint); + await to_path(path[2], path[3], false, Etcs.Direction.none, blocks, wait_time,is_hint); break; } @@ -225,6 +224,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms return; 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); + Etcs.info_Audio_Processer.play_random_break_soundScape(); if (controlA != null && controlB != null && controlA is Single_Block single_BlockA && controlB is Single_Block single_BlockB) { single_BlockA.destroyAsync(); @@ -250,8 +250,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms } public void Exchange_Handler(object? sender, EventArgs e) { - board.remake_board(); - int[,] bd = board.Bd; + int[,] bd = board.remake_board(); for (int i = 0; i < bd.GetLength(0); i++) for (int j = 0; j < bd.GetLength(1); j++) if (bd[i, j] == -1) diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.Designer.cs b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.Designer.cs index b914374..5c64879 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.Designer.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.Designer.cs @@ -39,6 +39,7 @@ sp_button = new PictureBox(); search = new PictureBox(); exchange = new PictureBox(); + search_time = new Label(); game_Panel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)back).BeginInit(); ((System.ComponentModel.ISupportInitialize)sp_button).BeginInit(); @@ -164,12 +165,25 @@ exchange.TabStop = false; exchange.Click += exchange_Click; // + // search_time + // + 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; + // // Leisure_Mode // AutoScaleDimensions = new SizeF(11F, 24F); AutoScaleMode = AutoScaleMode.Font; BackColor = Color.FromArgb(249, 211, 171); ClientSize = new Size(1439, 960); + Controls.Add(search_time); Controls.Add(exchange); Controls.Add(search); Controls.Add(sp_button); @@ -205,5 +219,6 @@ private PictureBox search; private PictureBox exchange; private GameControl gameControl; + private Label search_time; } } \ 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 5c569b2..ec7f1f4 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode.cs @@ -15,7 +15,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms { public Leisure_Mode() { - Settings.game_mode_form = this; + Etcs.game_mode_form = this; InitializeComponent(); timer = new System.Timers.Timer(); timer.Enabled = false; @@ -24,14 +24,14 @@ namespace CDSAE3_Lian_Lian_Kan.Forms time.Text = (left_time / 60).ToString().PadLeft(2, '0') + ":" + (left_time % 60).ToString().PadLeft(2, '0'); } System.Timers.Timer timer; - int left_time = Settings.left_time; + int left_time = Etcs.left_time; bool is_pause = true; 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; + Dictionary decrease_per_level = Etcs.decrease_per_level; private void Timer_Tick(object? sender, EventArgs e) { @@ -42,9 +42,11 @@ 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(() => search_time.Text = search_left_time.ToString().PadLeft(2, '0')); } if (current_base <= 0) { @@ -129,10 +131,10 @@ namespace CDSAE3_Lian_Lian_Kan.Forms private void back_Click(object sender, EventArgs e) { - Close(); Dispose(); + Close(); timer.Close(); - Settings.form?.change_form(new Leisure_Mode_MenuForm()); + Etcs.form?.change_form(new Leisure_Mode_MenuForm()); } private void exchange_Click(object sender, EventArgs e) @@ -144,7 +146,9 @@ namespace CDSAE3_Lian_Lian_Kan.Forms { gameControl.Search_Handler(this, new SearchEventArgs { set_search = true}); search_mode = true; - search_left_time = Settings.search_left_time; + 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/Leisure_Mode_MenuForm.cs b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode_MenuForm.cs index 38677b0..28f2f7f 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode_MenuForm.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/Leisure_Mode_MenuForm.cs @@ -15,13 +15,13 @@ namespace CDSAE3_Lian_Lian_Kan.Forms public Leisure_Mode_MenuForm() { InitializeComponent(); - Settings.audio_Processer.next_song(); - Settings.audio_Processer.resume_song(); + Etcs.song_Audio_Processer.set_albums("C418"); + Etcs.song_Audio_Processer.set_song(Etcs.song_Audio_Processer.get_next_song()); } private void start_Game_Click(object sender, EventArgs e) { - Settings.form?.change_form(new Leisure_Mode()); + Etcs.form?.change_form(new Leisure_Mode()); } } } diff --git a/CDSAE3_Lian_Lian_Kan/Forms/MainForm.Designer.cs b/CDSAE3_Lian_Lian_Kan/Forms/MainForm.Designer.cs index 6e3a2c9..eb856b3 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/MainForm.Designer.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/MainForm.Designer.cs @@ -46,6 +46,7 @@ AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1440, 960); Controls.Add(MainPanel); + DoubleBuffered = true; MaximumSize = new Size(1462, 1016); MinimumSize = new Size(1462, 1016); Name = "LianLianKan"; diff --git a/CDSAE3_Lian_Lian_Kan/Forms/MainForm.cs b/CDSAE3_Lian_Lian_Kan/Forms/MainForm.cs index e9344fe..3773e35 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/MainForm.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/MainForm.cs @@ -9,7 +9,7 @@ namespace CDSAE3_Lian_Lian_Kan InitializeComponent(); current_form = this; change_form(new Leisure_Mode_MenuForm()); - Settings.form = this; + Etcs.form = this; } Form current_form; public void change_form(Form form) @@ -21,8 +21,8 @@ namespace CDSAE3_Lian_Lian_Kan form.TopLevel = false; form.Dock = DockStyle.Fill; MainPanel.Controls.Add(form); - GC.Collect(); form.Show(); + GC.Collect(); } } } diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.Designer.cs b/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.Designer.cs index 54cbae8..babd49f 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.Designer.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.Designer.cs @@ -42,6 +42,8 @@ picture.TabIndex = 0; picture.TabStop = false; picture.Click += picture_Click; + picture.MouseEnter += picture_MouseEnter; + picture.MouseLeave += picture_MouseLeave; // // Single_Block // diff --git a/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs b/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs index f8c3400..e13816d 100644 --- a/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs +++ b/CDSAE3_Lian_Lian_Kan/Forms/Single_Block.cs @@ -17,24 +17,24 @@ namespace CDSAE3_Lian_Lian_Kan public Single_Block() { InitializeComponent(); - if (Settings.game_form == null) + if (Etcs.game_form == null) throw new Exception("game_form is null but try to make a new Single_Block"); - Selected += Settings.game_form.Selected_Handler; + Selected += Etcs.game_form.Selected_Handler; } public Single_Block(int image, Color default_backColor, Color select_Color, (int, int) pos) { block_id = image; position = pos; InitializeComponent(); - Image_change(Settings.get_block_Image(image)); + Image_change(Etcs.get_block_Image(image)); picture.SizeMode = PictureBoxSizeMode.Zoom; nor_color = default_backColor; sel_color = select_Color; BackColor = default_backColor; picture.BackColor = default_backColor; - if (Settings.game_form == null) + if (Etcs.game_form == null) throw new Exception("game_form is null but try to make a new Single_Block"); - Selected += Settings.game_form.Selected_Handler; + Selected += Etcs.game_form.Selected_Handler; } public Single_Block(Image image, (int, int) pos) @@ -44,13 +44,16 @@ namespace CDSAE3_Lian_Lian_Kan picture.SizeMode = PictureBoxSizeMode.Zoom; BackColor = Color.FromArgb(0, 0, 0, 0); can_be_selected = false; - if (Settings.game_form == null) + if (Etcs.game_form == null) throw new Exception("game_form is null but try to make a new Single_Block"); - Selected += Settings.game_form.Selected_Handler; + Selected += Etcs.game_form.Selected_Handler; + + } int block_id; Color nor_color; Color sel_color; + Color mouse_upper_color = Etcs.mouse_upper_color; public bool selected { get; set; } = false; bool can_be_selected = true; public (int, int) position { get; set; }//height,width @@ -79,26 +82,26 @@ namespace CDSAE3_Lian_Lian_Kan selected = false; BackColor = nor_color; } - Settings.Direction direction = Settings.Direction.none; - public void hint_path(Settings.Direction direction) + Etcs.Direction direction = Etcs.Direction.none; + public void hint_path(Etcs.Direction direction) { this.direction |= direction; - Image_change(Settings.get_tip_direction_Image(this.direction)); + Image_change(Etcs.get_tip_direction_Image(this.direction)); } - public void to_path(Settings.Direction direction) + public void to_path(Etcs.Direction direction) { - Image_change(Settings.get_direction_Image(direction)); - direction = Settings.Direction.none; + Image_change(Etcs.get_direction_Image(direction)); + direction = Etcs.Direction.none; } public void de_path() { - Image_change(Settings.trans_Image); - direction = Settings.Direction.none; + Image_change(Etcs.trans_Image); + direction = Etcs.Direction.none; } System.Timers.Timer? timer = null; public void destroyAsync() { - Image_change(Settings.get_disappear_Images(block_id)); + Image_change(Etcs.get_disappear_Images(block_id)); BackColor = Color.FromArgb(0, 0, 0, 0); can_be_selected = false; timer = new System.Timers.Timer(); @@ -110,20 +113,24 @@ namespace CDSAE3_Lian_Lian_Kan public void Image_Clear(object? sender, ElapsedEventArgs e) { timer?.Stop(); - Image_change(Settings.trans_Image); + Image_change(Etcs.trans_Image); } public void Image_change(Image new_image) + { + + } + private void Image_set(Image image) { try { lock (locker) { - picture.Image = new_image; + picture.Image = image; } } - catch(Exception) + catch (Exception) { - Image_change(new_image); + Image_change(image); } } public void Re_create(int image, Color? default_backColor, Color? select_Color, (int, int)? pos) @@ -131,14 +138,29 @@ namespace CDSAE3_Lian_Lian_Kan if (block_id == image) return; block_id = image; - Image_change(Settings.get_block_Image(image)); + Image_change(Etcs.get_block_Image(image)); if (default_backColor != null) nor_color = (Color)default_backColor; - if(select_Color != null) + if (select_Color != null) sel_color = (Color)select_Color; if (pos != null) position = ((int, int))pos; } + + private void picture_MouseEnter(object sender, EventArgs e) + { + if(!can_be_selected || selected) + return; + BackColor = mouse_upper_color; + } + + private void picture_MouseLeave(object sender, EventArgs e) + { + if (!can_be_selected || selected) + return; + BackColor = nor_color; + } + 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 61578d7..f51f194 100644 --- a/CDSAE3_Lian_Lian_Kan/Properties/Resources.Designer.cs +++ b/CDSAE3_Lian_Lian_Kan/Properties/Resources.Designer.cs @@ -90,6 +90,86 @@ namespace CDSAE3_Lian_Lian_Kan.Properties { } } + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] breakA1 { + get { + object obj = ResourceManager.GetObject("breakA1", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] breakA2 { + get { + object obj = ResourceManager.GetObject("breakA2", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] breakA3 { + get { + object obj = ResourceManager.GetObject("breakA3", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] breakA4 { + get { + object obj = ResourceManager.GetObject("breakA4", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] breakA5 { + get { + object obj = ResourceManager.GetObject("breakA5", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] breakA6 { + get { + object obj = ResourceManager.GetObject("breakA6", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] breakA7 { + get { + object obj = ResourceManager.GetObject("breakA7", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] breakA8 { + get { + object obj = ResourceManager.GetObject("breakA8", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// 查找 System.Byte[] 类型的本地化资源。 /// diff --git a/CDSAE3_Lian_Lian_Kan/Properties/Resources.resx b/CDSAE3_Lian_Lian_Kan/Properties/Resources.resx index 025799b..0469aca 100644 --- a/CDSAE3_Lian_Lian_Kan/Properties/Resources.resx +++ b/CDSAE3_Lian_Lian_Kan/Properties/Resources.resx @@ -307,4 +307,28 @@ ..\Resources\next.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\breakA1.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\breakA2.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\breakA3.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\breakA4.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\breakA5.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\breakA6.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\breakA7.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\breakA8.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/CDSAE3_Lian_Lian_Kan/Resources/breakA1.mp3 b/CDSAE3_Lian_Lian_Kan/Resources/breakA1.mp3 new file mode 100644 index 0000000..b1aecda Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/breakA1.mp3 differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/breakA2.mp3 b/CDSAE3_Lian_Lian_Kan/Resources/breakA2.mp3 new file mode 100644 index 0000000..ab8414b Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/breakA2.mp3 differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/breakA3.mp3 b/CDSAE3_Lian_Lian_Kan/Resources/breakA3.mp3 new file mode 100644 index 0000000..1949636 Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/breakA3.mp3 differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/breakA4.mp3 b/CDSAE3_Lian_Lian_Kan/Resources/breakA4.mp3 new file mode 100644 index 0000000..10d7ffb Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/breakA4.mp3 differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/breakA5.mp3 b/CDSAE3_Lian_Lian_Kan/Resources/breakA5.mp3 new file mode 100644 index 0000000..a9c530a Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/breakA5.mp3 differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/breakA6.mp3 b/CDSAE3_Lian_Lian_Kan/Resources/breakA6.mp3 new file mode 100644 index 0000000..268496d Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/breakA6.mp3 differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/breakA7.mp3 b/CDSAE3_Lian_Lian_Kan/Resources/breakA7.mp3 new file mode 100644 index 0000000..60b91c6 Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/breakA7.mp3 differ diff --git a/CDSAE3_Lian_Lian_Kan/Resources/breakA8.mp3 b/CDSAE3_Lian_Lian_Kan/Resources/breakA8.mp3 new file mode 100644 index 0000000..c67e371 Binary files /dev/null and b/CDSAE3_Lian_Lian_Kan/Resources/breakA8.mp3 differ diff --git a/CDSAE3_Lian_Lian_Kan/Sound/AudioPlayer.cs b/CDSAE3_Lian_Lian_Kan/Sound/AudioPlayer.cs new file mode 100644 index 0000000..21ee553 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Sound/AudioPlayer.cs @@ -0,0 +1,141 @@ +using NAudio.Wave; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +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; + 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); + ms = new MemoryStream(StreamToBytes(sound)); + ws = new Mp3FileReader(ms); + blockAlignReductionStream = new BlockAlignReductionStream(ws); + wave16ToFloatProvider = new Wave16ToFloatProvider(blockAlignReductionStream); + wave16ToFloatProvider.Volume = volume / 100f; + waveOutEvent = new WaveOutEvent(); + waveOutEvent.Init(wave16ToFloatProvider); + waveOutEvent.PlaybackStopped += WaveOutEvent_PlaybackStopped; + } + internal AudioPlayer(string file_name, int volume, Action finished) + { + 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); + ms = new MemoryStream(StreamToBytes(sound)); + ws = new Mp3FileReader(ms); + blockAlignReductionStream = new BlockAlignReductionStream(ws); + wave16ToFloatProvider = new Wave16ToFloatProvider(blockAlignReductionStream); + wave16ToFloatProvider.Volume = volume / 100f; + waveOutEvent = new WaveOutEvent(); + waveOutEvent.Init(wave16ToFloatProvider); + waveOutEvent.PlaybackStopped += WaveOutEvent_PlaybackStopped; + } + public void volume_change(int val) + { + volume = val; + wave16ToFloatProvider.Volume = volume / 100f; + } + public void pause_song() => waveOutEvent.Pause(); + public void resume_song() => waveOutEvent.Play(); + private void WaveOutEvent_PlaybackStopped(object? sender, StoppedEventArgs e) + { + if(shutdown) return; + finished?.Invoke(file_name,this); + Dispose(); + } + + ~AudioPlayer() + { + Dispose(); + } + + public void Dispose() + { + shutdown = true; + waveOutEvent.Stop(); + sound.Dispose(); + ms.Dispose(); + //ws.Dispose(); + //blockAlignReductionStream.Dispose(); + waveOutEvent.Dispose(); + } + 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; + } + } + } + + } +} diff --git a/CDSAE3_Lian_Lian_Kan/Sound/Audio_processer.cs b/CDSAE3_Lian_Lian_Kan/Sound/Audio_processer.cs deleted file mode 100644 index d487cda..0000000 --- a/CDSAE3_Lian_Lian_Kan/Sound/Audio_processer.cs +++ /dev/null @@ -1,164 +0,0 @@ -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(); - } - } -} diff --git a/CDSAE3_Lian_Lian_Kan/Sound/Info_Audio_processer.cs b/CDSAE3_Lian_Lian_Kan/Sound/Info_Audio_processer.cs new file mode 100644 index 0000000..073b473 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Sound/Info_Audio_processer.cs @@ -0,0 +1,71 @@ +using NAudio.Wave; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace CDSAE3_Lian_Lian_Kan.Sound +{ + public class Info_Audio_processer + { + Etcs.break_music soundScape_version = Etcs.break_music.breakA; + public int soundScape_volume { get; set; } = 90; + string last_break_soundScape = ""; + Random random = new Random(); + class Info_file_processer + { } + + internal void set_SoundScape_version(Etcs.break_music version) => soundScape_version = version; + internal void play_random_break_soundScape() + { + Task.Run(() => + { + void finished(string s,AudioPlayer audioPlayer) + { + audioPlayer.Dispose(); + } + AudioPlayer audioPlayer = new AudioPlayer(get_random_break_soundScape(), soundScape_volume,finished); + audioPlayer.resume_song(); + //object obj = Settings.res_Manager.GetObject(get_random_break_soundScape(), Settings.res_Culture)!; + //var infoOutputDevice = new WaveOutEvent(); + //using (var sound = new MemoryStream((byte[])obj)) + //using (var ms = new MemoryStream(StreamToBytes(sound))) + //using (var ws = new Mp3FileReader(ms)) + //using (var blockAlignReductionStream = new BlockAlignReductionStream(ws)) + //{ + // var wave16ToFloatProvider = new Wave16ToFloatProvider(blockAlignReductionStream); + // wave16ToFloatProvider.Volume = soundScape_volume / 100f; + // infoOutputDevice.Init(wave16ToFloatProvider); + // infoOutputDevice.PlaybackStopped += InfoOutputDevice_PlaybackStopped; + // infoOutputDevice.Play(); + //} + }); + } + + private string get_random_break_soundScape() + { + string name; + for (; ; ) + { + name = soundScape_version switch + { + Etcs.break_music.breakA => "breakA" + (random.Next(1, 9)).ToString(), + Etcs.break_music.breakB => throw new NotImplementedException(), + _ => "breakA" + (random.Next(0, 9)).ToString() + }; + if (name != last_break_soundScape) + break; + } + return name; + //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 = soundScape_volume / 100f; + //return wave16ToFloatProvider; + } + } +} diff --git a/CDSAE3_Lian_Lian_Kan/Sound/Song_Audio_processer.cs b/CDSAE3_Lian_Lian_Kan/Sound/Song_Audio_processer.cs new file mode 100644 index 0000000..6828a17 --- /dev/null +++ b/CDSAE3_Lian_Lian_Kan/Sound/Song_Audio_processer.cs @@ -0,0 +1,147 @@ +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 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; + private void OnPlaybackStopped(string s,object? obj) + { + set_song(get_next_song()); + } + public void pause_song()=> audioPlayer?.pause_song(); + public void resume_song()=> audioPlayer?.resume_song(); + public string get_next_song() + { + string name = audioFiles[next_song]; + next_song++; + next_song %= audioFiles.Count; + return name; + } + + /// + /// 调整音乐音量 + /// + /// 音量大小 1-100 + public void volume_change(int val)=> audioPlayer?.volume_change(val); + public void set_albums(string s) + { + var result = Etcs.musics.Where(x => x.Key == s).ToList(); + if (result.Count == 0) + throw new Exception("no such album"); + audioFiles = result.First().Value; + } + public void set_song(string s) + { + audioPlayer?.Dispose(); + try + { + audioPlayer = new AudioPlayer(s, Etcs.Song_Volume, OnPlaybackStopped); + } + catch (Exception e) + { + MessageBox.Show($"failed to play {s}\n{e.Message}"); + return; + } + audioPlayer.resume_song(); + } + public void Dispose()=> audioPlayer?.Dispose(); + ~Song_Audio_processer() => Dispose(); + } +}