加了一堆东西 推送!!

This commit is contained in:
lichx 2024-04-02 21:57:04 +08:00
parent b2c833c6cb
commit 5b1d474cfd
28 changed files with 649 additions and 538 deletions

View File

@ -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<int, List<(int, int)>> board_Index { get; } = new Dictionary<int, List<(int, int)>>();
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<temp_val_per_Image.Length;i++)
if (temp_val_per_Image[i]!=0)
{
k = i;
break;
}
temp_val_per_Image[k]--;
return k;
}
int t = rand.Next(0, types);
if (temp_val_per_Image[t] == 0 || t == last_val)
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)
for (; temp_val_per_Image[i] <= 0 || i == last_val; i %= types)
i++;
temp_val_per_Image[i]--;
last_val = i;
@ -100,9 +106,9 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs
cur_width = 1;
}
}
return;
return Bd;
}
public void remake_board()
public int[,] remake_board()
{
board_Index.Clear();
var rand = new Random();
@ -151,6 +157,7 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs
else
board_Index.Add(Bd[i, j], new List<(int, int)> { (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<int>> swing_check = ((int, int) range) =>
Func<(int, int), int, List<int>> swing_check = ((int, int) range, int center) =>
{
int mid = (range.Item2 - range.Item1) / 2 + range.Item1;
bool swing = true;//up true
List<int> ans = new List<int> { mid };
for (int i = 1; ;)
List<int> result = new List<int>();
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<int, bool> inrange = (int t) => t >= range.Item1 && t <= range.Item2;
bool go_on = true;
for (int i = 1; go_on; i++)
{
go_on = false;
if (go_on |= inrange(center + i))
result.Add(center + i);
if (go_on |= inrange(center - i))
result.Add(center - i);
}
return result;
};
if (throughx)
foreach (int i in swing_check(xrange))
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<List<(int,int)>> get_tip((int, int) start)
internal List<List<(int, int)>> get_tip((int, int) start)
{
List<List<(int, int)>> ans = new List<List<(int, int)>>();
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; }
}
}

View File

@ -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);
}
}

View File

@ -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<int, double> decrease_per_level = new Dictionary<int, double> {
{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<string, List<string>> musics { get; set; } = new Dictionary<string, List<string>> { { "C418", new List<string> { "C418 - Beginning 2", "C418 - Floating Trees", "C418 - Moog City 2", "C418 - Mutation" } } };
public static Audio_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;
}
}

View File

@ -1,94 +0,0 @@
namespace CDSAE3_Lian_Lian_Kan.Forms
{
partial class Audio_player
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
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;
}
}

View File

@ -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();
}
}
}

View File

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

View File

@ -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
/// <param name="from">起始点</param>
/// <param name="to">终点</param>
/// <returns></returns>
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;
}
/// <summary>
/// 设置单个点方向
@ -77,7 +76,7 @@ namespace CDSAE3_Lian_Lian_Kan.Forms
/// <param name="blocks"></param>
/// <param name="decrease"></param>
/// <returns></returns>
async Task set_PathAsync((int, int) point, Settings.Direction direction, List<Single_Block> blocks, int wait_time,bool is_hint)
async Task set_PathAsync((int, int) point, Etcs.Direction direction, List<Single_Block> blocks, int wait_time,bool is_hint)
{
if (wait_time != 0)
@ -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<Single_Block> 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<Single_Block> 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)

View File

@ -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;
}
}

View File

@ -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<int, double> decrease_per_level = Settings.decrease_per_level;
Dictionary<int, double> 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;
}
}
}

View File

@ -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());
}
}
}

View File

@ -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";

View File

@ -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();
}
}
}

View File

@ -42,6 +42,8 @@
picture.TabIndex = 0;
picture.TabStop = false;
picture.Click += picture_Click;
picture.MouseEnter += picture_MouseEnter;
picture.MouseLeave += picture_MouseLeave;
//
// Single_Block
//

View File

@ -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

View File

@ -90,6 +90,86 @@ namespace CDSAE3_Lian_Lian_Kan.Properties {
}
}
/// <summary>
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] breakA1 {
get {
object obj = ResourceManager.GetObject("breakA1", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] breakA2 {
get {
object obj = ResourceManager.GetObject("breakA2", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] breakA3 {
get {
object obj = ResourceManager.GetObject("breakA3", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] breakA4 {
get {
object obj = ResourceManager.GetObject("breakA4", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] breakA5 {
get {
object obj = ResourceManager.GetObject("breakA5", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] breakA6 {
get {
object obj = ResourceManager.GetObject("breakA6", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] breakA7 {
get {
object obj = ResourceManager.GetObject("breakA7", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] breakA8 {
get {
object obj = ResourceManager.GetObject("breakA8", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>

View File

@ -307,4 +307,28 @@
<data name="next" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\next.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="breakA1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\breakA1.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="breakA2" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\breakA2.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="breakA3" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\breakA3.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="breakA4" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\breakA4.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="breakA5" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\breakA5.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="breakA6" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\breakA6.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="breakA7" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\breakA7.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="breakA8" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\breakA8.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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<string,AudioPlayer>? 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<string,AudioPlayer> 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;
}
}
}
}
}

View File

@ -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<string> audioFiles = new List<string>();
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<string>? val) ? val : new List<string>();
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());
}
/// <summary>
/// 切换音乐
/// </summary>
/// <param name="waveChannel32"></param>
private void waveOutEvent_Provider(Wave16ToFloatProvider wave16ToFloatProvider)
{
songOutputDevice.Stop();
songOutputDevice.Dispose();
songOutputDevice = new WaveOutEvent();
songOutputDevice.Init(wave16ToFloatProvider);
songOutputDevice.PlaybackStopped += OnPlaybackStopped;
}
/// <summary>
/// 调整音乐音量
/// </summary>
/// <param name="val">音量大小 1-100</param>
public void volume_change(int val)=> audio_File_Processor.volume_change(val);
public List<string> 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();
}
}
}

View File

@ -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;
}
}
}

View File

@ -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<string> audioFiles = new List<string>();
// int next_song = 0;
// int volume = 90;
// internal void set_Albums(string s)=>audioFiles = Settings.musics.TryGetValue(s, out List<string>? val) ? val : new List<string>();
// internal Wave16ToFloatProvider get_next_song()
// {
// string name = audioFiles[next_song];
// next_song++;
// next_song %= audioFiles.Count;
// name = name.Split('.').First().Replace(" ","_").Replace("-","_");
// object obj = Settings.res_Manager.GetObject(name, Settings.res_Culture)!;
// MemoryStream sound = new MemoryStream((byte[])obj);
// MemoryStream ms = new MemoryStream(StreamToBytes(sound));
// var ws = new Mp3FileReader(ms);
// BlockAlignReductionStream blockAlignReductionStream = new BlockAlignReductionStream(ws);
// wave16ToFloatProvider = new Wave16ToFloatProvider(blockAlignReductionStream);
// wave16ToFloatProvider.Volume = volume / 100f;
// return wave16ToFloatProvider;
// }
// internal Wave16ToFloatProvider get_last_song()
// {
// next_song = (next_song - 2 + audioFiles.Count) % audioFiles.Count;
// return get_next_song();
// }
// internal void volume_change(int val)
// {
// volume = val;
// if(wave16ToFloatProvider != null)
// wave16ToFloatProvider.Volume = volume / 100f;
// }
// internal static byte[] StreamToBytes(Stream stream)
// {
// long originalPosition = 0;
// if (stream.CanSeek)
// {
// originalPosition = stream.Position;
// stream.Position = 0;
// }
// try
// {
// byte[] readBuffer = new byte[4096];
// int totalBytesRead = 0;
// int bytesRead;
// while ((bytesRead = stream.Read(readBuffer, totalBytesRead, readBuffer.Length - totalBytesRead)) > 0)
// {
// totalBytesRead += bytesRead;
// if (totalBytesRead == readBuffer.Length)
// {
// int nextByte = stream.ReadByte();
// if (nextByte != -1)
// {
// byte[] temp = new byte[readBuffer.Length * 2];
// Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length);
// Buffer.SetByte(temp, totalBytesRead, (byte)nextByte);
// readBuffer = temp;
// totalBytesRead++;
// }
// }
// }
// byte[] buffer = readBuffer;
// if (readBuffer.Length != totalBytesRead)
// {
// buffer = new byte[totalBytesRead];
// Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead);
// }
// return buffer;
// }
// finally
// {
// if (stream.CanSeek)
// {
// stream.Position = originalPosition;
// }
// }
// }
//}
AudioPlayer? audioPlayer;
private List<string> audioFiles = new List<string>();
int next_song = 1;
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;
}
/// <summary>
/// 调整音乐音量
/// </summary>
/// <param name="val">音量大小 1-100</param>
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();
}
}