This repository has been archived on 2024-06-21. You can view files and clone it, but cannot push or open issues or pull requests.
CDSAE3/CDSAE3_Lian_Lian_Kan/Forms/Challenge_Mode.cs

432 lines
17 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using CDSAE3_Lian_Lian_Kan.Extensions;
using CDSAE3_Lian_Lian_Kan.Forms.Interface;
using CDSAE3_Lian_Lian_Kan.Sound;
using System.Drawing.Drawing2D;
using System.Text;
using System.Timers;
using Timer = System.Timers.Timer;
namespace CDSAE3_Lian_Lian_Kan.Forms
{
public partial class Challenge_Mode : Form, IGameMode
{
GameControl gameControl;
public Challenge_Mode()
{
InitializeComponent();
timer = new Timer { Interval = 100, AutoReset = true, Enabled = false };
timer.Elapsed += TimerTick;
Etcs.current_difficulty = Etcs.Difficulty.challenge;
Etcs.loadFinished = false;
gameControl = new GameControl((t) => Challenge_Mode_LoadAsync(this, new EventArgs()));
game_Panel.Controls.Add(gameControl);
gameControl.Dock = DockStyle.Fill;
}
Timer timer;
double curTime = 0;
private int Score
{
get
{
return score;
}
set
{
if (value > score)
AddScoreLabel(value - score);
else
SubScoreLabel(score - value);
score = value;
SetScoreLabel();
}
}
Thread? scoreSetThread;
private void SetScoreLabel()
{
if (scoreSetThread != null && scoreSetThread.IsAlive)
scoreSetThread.Interrupt();
scoreSetThread = new Thread(() =>
{
StringBuilder target = new StringBuilder(score.ToString().PadLeft(6, '0'));
StringBuilder src = new StringBuilder(scoreLabel.Text);
List<string> duration = new();
while (src.ToString() != target.ToString())
{
for (int i = 0; i < src.Length; i++)
{
if (src[i] != target[i])
{
if (target[i] > src[i])
{
if (target[i] - src[i] <= 5)
src[i]++;
else
src[i] = (char)((Convert.ToInt32(src[i] + 9)) % 10 + '0');
}
else
{
if (src[i] - target[i] <= 5)
src[i]--;
else
src[i] = (char)((Convert.ToInt32(src[i] + 11)) % 10 + '0');
}
}
}
duration.Add(src.ToString());
}
try
{
for (int i = 0; i < duration.Count; i++)
{
BeginInvoke(() => scoreLabel.Text = duration[i]);
Thread.Sleep(50);
}
}
catch (ThreadInterruptedException) { }
});
scoreSetThread.Start();
}
private int score = 0;
private void TimerTick(object? sender, ElapsedEventArgs e)
{
curTime += 0.1;
timeLine.set_progress(curTime / 136);
}
private async void Challenge_Mode_LoadAsync(object sender, EventArgs e)
{
bool loopStop = false;
PausePanel.BringToFront();
int oriSongVolume = Etcs.Song_Volume;
{
while (Etcs.Song_Volume != 0)
{
Etcs.Song_Volume = Math.Max(Etcs.Song_Volume - 7, 0);
Etcs.song_Audio_Processer.volume_change(Etcs.Song_Volume);
await Task.Delay(100);
}
}
{
Action<string, AudioPlayer> loopPlay = null!;
loopPlay = (s, player) =>
{
if (!loopStop)
Etcs.song_Audio_Processer.set_song("Ambient", 50, loopPlay);
};
Etcs.info_Audio_Processer.playMusicClip("Ambient", 50, loopPlay);
Label label = new Label { TextAlign = ContentAlignment.MiddleCenter, Font = new Font("Microsoft YaHei UI", 20F), ForeColor = Color.White, BackColor = Color.FromArgb(0, 0, 0, 0), AutoSize = false, Size = new Size(1220, 55), Location = new Point(110, 330) };
Controls.Add(label);
label.BringToFront();
string[] strings = { "你也许意识到了", "连连看的实现并不如其规则那样简单", "忙碌的CLR处理着数以千计的事件", "委托,反射,线程冲突不断发生在各处", "代码的堆叠已经到达极限", "这是最后的连连看,集中精力,不要犯错,在歌曲结束前击败它" };
//4* 7 28s 18s in game 10s
for (int i = 0; i < 6; i++)
{
label.Text = strings[i];
Etcs.info_Audio_Processer.playMusicClip("Message", 60);
await Task.Delay(4000);
if (i == 2)
{
loopStop = true;
while (Etcs.Song_Volume != 0)
{
Etcs.Song_Volume = Math.Max(Etcs.Song_Volume - 7, 0);
Etcs.song_Audio_Processer.volume_change(Etcs.Song_Volume);
await Task.Delay(100);
}
Etcs.song_Audio_Processer.pause_song();
Etcs.song_Audio_Processer.set_albums("Tatsh");
Etcs.song_Audio_Processer.set_song(Etcs.song_Audio_Processer.get_next_song());
timer.Enabled = true;
Thread thread = new Thread(async () =>
{
for (int n = 0; n < 8; n++)
{
Etcs.Song_Volume += 7;
Etcs.song_Audio_Processer.volume_change(Etcs.Song_Volume);
await Task.Delay(500);
}
await Task.Delay(9000);
foreach (var item in new Label[] { , , })
Invoke(() => item.Visible = true);
});
thread.Start();
}
}
_pauseAllow = true;
label.SendToBack();
label.Visible = false;
label.Dispose();
}
PausePanel.Visible = false;
Etcs.song_Audio_Processer.SongFinished += Song_Audio_Processer_SongFinished;
ShowAudioVisualizer();
}
private async void Song_Audio_Processer_SongFinished(Sound.Song_Audio_processer s, Sound.SongFinishedEventArgs e)
{
timer.Stop();
if (finished)
return;
foreach (var item in new Label[] { , , })
item.Visible = false;
PausePanel.Visible = true;
PausePanel.BackgroundImage = Properties.Resources.trans;
for (int i = 0; i < 200; i += 10)
{
Color animRed = Color.FromArgb(i, 0, 0);
game_Panel.BackColor = animRed;
PausePanel.BackColor = animRed;
await Task.Delay(10);
}
PausePanel.BringToFront();
for (int i = 200; i < 255; i += 10)
{
Color animRed = Color.FromArgb(i, 0, 0);
PausePanel.BackColor = animRed;
await Task.Delay(10);
}
Etcs.info_Audio_Processer.playMusicClip("failed");
Finished_Handler(this, new FinishArgs { finishType = FinishArgs.FinishType.Time_out });
}
int cur_score = 0;
bool finished = false;
public void Finished_Handler(object sender, FinishArgs e)
{
BeginInvoke(async () =>
{
finished = true;
switch (e.finishType)
{
case FinishArgs.FinishType.All_done:
timer.Stop();
new Thread(() =>
{
while (Etcs.Song_Volume != 0)
{
Etcs.Song_Volume = Math.Max(Etcs.Song_Volume - 7, 0);
Etcs.song_Audio_Processer.volume_change(Etcs.Song_Volume);
Thread.Sleep(500);
}
Etcs.song_Audio_Processer.pause_song();
}).Start();
foreach (var item in new Label[] { , , })
item.Visible = false;
PausePanel.Visible = true;
PausePanel.BackgroundImage = Properties.Resources.trans;
for (int i = 0; i < 200; i += 10)
{
Color animRed = Color.FromArgb(i, i, i);
game_Panel.BackColor = animRed;
PausePanel.BackColor = animRed;
await Task.Delay(10);
}
PausePanel.BringToFront();
for (int i = 200; i < 260; i += 10)
{
Color animRed = Color.FromArgb(i, i, i);
PausePanel.BackColor = animRed;
await Task.Delay(10);
}
Label label = new Label { TextAlign = ContentAlignment.MiddleCenter, Font = new Font("Microsoft YaHei UI", 20F), ForeColor = Color.White, BackColor = Color.FromArgb(0, 0, 0, 0), AutoSize = false, Size = new Size(1220, 55), Location = new Point(110, 330) };
string[] strings = { "Mission Accomplish", "下次再见", "The End" };
for (int i = 0; i < strings.Length; i++)
{
label.Text = strings[i];
Etcs.info_Audio_Processer.playMusicClip("Message", 60);
}
label.Visible = false;
label.Dispose();
Form form = new FinishedMessageBox(score, (int)curTime);
form.FormClosed += ((sender, args) =>
{
Dispose();
Close();
Etcs.form?.change_form(Etcs.charts, false, null, null);
});
form.ShowDialog();
break;
case FinishArgs.FinishType.Time_out:
退_Click(this, new EventArgs());
break;
}
});
}
private bool _pauseState = false;
private bool search_mode;
private int search_left_use_time;
/// <summary>
/// 需要测试!!
/// </summary>
private bool _pauseAllow = false;
private void DoPause()
{
if (!_pauseAllow)
return;
timer.Enabled = false;
Etcs.song_Audio_Processer.pause_song();
_pauseState = true;
Bitmap bit = new Bitmap(Width, Height);
Graphics g = Graphics.FromImage(bit);
g.CompositingQuality = CompositingQuality.HighQuality;
g.CopyFromScreen(Etcs.form!.Left + 5, Etcs.form!.Top + 43, 0, 0, new Size(Width, Height));
PausePanel.BringToFront();
Rectangle rectangle = new Rectangle(0, 0, bit.Width, bit.Height);
PausePanel.BackgroundImage = bit.GaussianBlur();
PausePanel.Visible = true;
GC.Collect();
}
private void DePause()
{
Etcs.song_Audio_Processer.resume_song();
_pauseState = false;
timer.Enabled = true;
PausePanel.Visible = false;
PausePanel.SendToBack();
}
public void TogglePause()
{
if (_pauseState)
DePause();
else
DoPause();
}
private void ShowAudioVisualizer()
{
Form audioVisualizer = new AudioVisualizer.MainWindow();
audioVisualizer.TopLevel = false;
audioVisualizer.Dock = DockStyle.Fill;
AudioVisualizerPanel.Controls.Add(audioVisualizer);
audioVisualizer.Show();
}
private void _Click(object sender, EventArgs e)
{
DePause();
}
private void 退_Click(object sender, EventArgs e)
{
Dispose();
Close();
Etcs.hunderd_millsecond_timer.Elapsed -= TimerTick;
Etcs.gameMenuForm!.playFormToMenu();
}
private void CanClickLabel_MouseEnter(object sender, EventArgs e)
{
(sender as Label)!.BackColor = Color.FromArgb(100, 100, 100);
}
private void CanClickLabel_MouseLeave(object sender, EventArgs e)
{
(sender as Label)!.BackColor = Color.FromArgb(0, 0, 0, 0);
}
public void De_pause(object sender, EventArgs e) { }
public void Score_Change(object sender, ChangeScoreArgs e)
{
if (e.add)
{
new Thread(() => Score += e.score).Start();
if (search_mode)
{
search_left_use_time--;
if (search_left_use_time == 0)
{
search_mode = false;
gameControl.Search_Handler(this, new SearchEventArgs { set_search = false });
}
}
}
else
new Thread(() => Score = Math.Max(0, Score - e.score)).Start();
}
Thread? ScoreChange;
public void AddScoreLabel(int score)
{
if (ScoreChange != null && ScoreChange.IsAlive)
ScoreChange.Interrupt();
ScoreChange = new Thread(() =>
{
try
{
BeginInvoke(() => scoreChangeLabel.Text = "+" + score);
BeginInvoke(() => scoreChangeLabel.ForeColor = Color.FromArgb(0, 255, 0));
BeginInvoke(() => scoreChangeLabel.Visible = true);
for (int i = 255; i > 0; i -= 20)
{
BeginInvoke(() => scoreChangeLabel.ForeColor = Color.FromArgb(0, i, 0));
Thread.Sleep(80);
}
BeginInvoke(() => scoreChangeLabel.Visible = false);
}
catch (ThreadInterruptedException) { return; }
});
ScoreChange.Start();
}
public void SubScoreLabel(int score)
{
if (ScoreChange != null && ScoreChange.IsAlive)
ScoreChange.Interrupt();
ScoreChange = new Thread(() =>
{
try
{
BeginInvoke(() => scoreChangeLabel.Text = "-" + score);
BeginInvoke(() => scoreChangeLabel.ForeColor = Color.FromArgb(255, 0, 0));
BeginInvoke(() => scoreChangeLabel.Visible = true);
for (int i = 255; i > 0; i -= 20)
{
BeginInvoke(() => scoreChangeLabel.ForeColor = Color.FromArgb(i, 0, 0));
Thread.Sleep(80);
}
BeginInvoke(() => scoreChangeLabel.Visible = false);
}
catch (ThreadInterruptedException) { return; }
});
ScoreChange.Start();
}
public void SetTheme()
{
Etcs.current_block_theme = Etcs.Theme.code;
Etcs.gameModeForm = this;
}
private void DoSearch()
{
gameControl.Search_Handler(this, new SearchEventArgs { set_search = true });
search_mode = true;
search_left_use_time = 3;
}
private void DoRemake()
{
Task.Run(() => gameControl.Exchange_Handler(this, new EventArgs()));
}
public void GetGift_Handler(object sender, GiftArgs e)
{
Etcs.info_Audio_Processer.playMusicClip("HitSong");
switch (e.giftType)
{
case GiftArgs.GiftType.Search:
DoSearch();
break;
case GiftArgs.GiftType.ReMake:
DoRemake();
break;
}
}
public void Back()
{
TogglePause();
}
}
}