Skip to content

Commit

Permalink
Updated to 0.2.1
Browse files Browse the repository at this point in the history
- New feature: Highlight songs which name contain non-ASCII character(s) and bonus songs (#1)
- Fixed other known issues
  • Loading branch information
Misaka12456 committed Jan 1, 2025
1 parent 6155245 commit 9341ed3
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 93 deletions.
6 changes: 3 additions & 3 deletions ChuNiZiMu/ChuNiZiMu.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<Platforms>x64;arm64</Platforms>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishAot>true</PublishAot>
<Version>0.2.0</Version>
<Version>0.2.1</Version>
<Company>Misaka Castle</Company>
<Copyright>(C)Copyright 2018-2024 Misaka Castle and Project Chunizimu contributors. All rights reserved.</Copyright>
<Copyright>(C)Copyright 2018-2025 Misaka Castle and Project Chunizimu contributors. All rights reserved.</Copyright>
</PropertyGroup>

</Project>
</Project>
34 changes: 6 additions & 28 deletions ChuNiZiMu/Models/Song.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ public class Song
/// <summary>
/// 该曲目是否为Bonus曲目。
/// </summary>
bool BonusSong = false;
public bool IsBonusSong { get; set; }

/// <summary>
/// 该曲目是否含有ascii字符以外的元素。
/// </summary>
bool Non_ASCII_Characters = false;
public bool IsNonASCIICharacters { get; init; }

/// <summary>
/// 该曲目是否受到特殊效果影响。
/// </summary>
bool Affected = false;
public bool Affected { get; init; }

/// <summary>
/// 该曲目当前已揭露的曲名。(初始状态下为全问号;如果设置了<c>revealSpacesInitially = true</c>,则初始状态下除空格外的字符均为问号)
Expand All @@ -40,14 +42,7 @@ public Song(string title, bool revealSpacesInitially = false)
{
FullSecretSongTitle = title;
HiddenSongTitle = new char[title.Length];
for (int i = 0 ; i < title.Length; i++) // 检测是否包括非ascii字符
{
if (!Char.IsAscii(title[i]))
{
this.Non_ASCII_Characters = true;
break;
}
}
IsNonASCIICharacters = title.Any(t => !char.IsAscii(t));
if (revealSpacesInitially)
{
for (int i = 0; i < title.Length; i++)
Expand Down Expand Up @@ -118,23 +113,6 @@ public void RevealAll()
HiddenSongTitle = FullSecretSongTitle.ToCharArray();
}

public void SetBonusFlag()
{
this.BonusSong = true;
}

public bool CheckBonusFlag()
{
return this.BonusSong;
}
public void SetAffectedFlag(bool flag)
{
this.Affected = flag;
}
public bool CheckNonAscii()
{
return this.Non_ASCII_Characters;
}
public override string ToString()
{
if (!HiddenSongTitle.Contains('?'))
Expand Down
143 changes: 81 additions & 62 deletions ChuNiZiMu/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,26 @@ public static void Main(string[] args)
"<no options> \tStart the game session.");
return;
}

if (args.Length > 0)
{
Console.Error.WriteLine($"Unknown argument: {args[0]}.\n" +
"Use chunizimu --help to show help message.");
"Use chunizimu --help to show help message.");
return;
}

GameInit(args);
}

private static void GameInit(string[] args)
{
ConsolePlus.SetTitle("音游开字母(Chu Ni Zi Mu) - 根据已揭露(Reveal)的字符盲猜音游曲名");
Console.Clear();
Console.WriteLine("Welcome to Chu Ni Zi Mu, a tiny utility to manage the game which to guess the song name by the revealed characters in the song title.");
Console.WriteLine("Do you want to reveal spaces initially? This settings can only be set once before the game session starts. (y/N)");
bool revealSpacesInitially = (Console.ReadLine() ?? string.Empty).Trim().ToLower() == "y";
Console.WriteLine("To start the game session, please init the songs pool by input the song name once per line, and input a blank line or EOF to start the game session:");
var songs = new List<Song>();
Console.Clear();
Console.WriteLine("Welcome to Chu Ni Zi Mu, a tiny utility to manage the game which to guess the song name by the revealed characters in the song title.");
Console.WriteLine("Do you want to reveal spaces initially? This settings can only be set once before the game session starts. (y/N)");
bool revealSpacesInitially = (Console.ReadLine() ?? string.Empty).Trim().ToLower() == "y";
Console.WriteLine("To start the game session, please init the songs pool by input the song name once per line, and input a blank line or EOF to start the game session:");
var songs = new List<Song>();
while (true)
{
string? songName = Console.ReadLine();
Expand All @@ -46,72 +48,81 @@ private static void GameInit(string[] args)
Console.Error.Write("Please at least input 2 songs to start the game session.");
continue;
}

break;
}

songs.Add(new Song(songName, revealSpacesInitially));
}

Console.WriteLine("Show correct answers during every round in the game session (for reference)?\n" +
"This should be set true when and ONLY when just using this tool as a game backend manager, instead of a game player. (Y/n)");
bool showCorrectAnswers = (Console.ReadLine() ?? string.Empty).Trim().ToLower() != "n";
Console.WriteLine("Add the revealed letter EVEN THOUGH the letter doesn't exist in any song title?\n" +

Console.WriteLine("Add the revealed letter EVEN THOUGH the letter doesn't exist in any song title?\n" +
"By enabling this feature, the revealed letter list will act better as a hint list, which was widely used in the real game chat before. (Y/n)");
bool preserveAnyRevealedLetter = (Console.ReadLine() ?? string.Empty).Trim().ToLower() != "n";

Console.WriteLine("Is there a Bonus track set? Bonus tracks will be highlighted in a special color. (y/N)");
bool bonusSetFlag = (Console.ReadLine() ?? string.Empty).Trim().ToLower() == "y";
while (bonusSetFlag)
bool bonusSetFlag = (Console.ReadLine() ?? string.Empty).Trim().Equals("y", StringComparison.CurrentCultureIgnoreCase);
if (bonusSetFlag)
{
Console.WriteLine("Please enter the Bonus track number and input a blank line or EOF to finish");
string? bonusString = Console.ReadLine();
if (bonusString == null ||bonusString.Length ==0)
while (true)
{
Console.WriteLine("If you want to confirm that you don't set the bonus, please enter the enter again to confirm.");
string? confirmString = Console.ReadLine();
if (confirmString == null||confirmString.Length == 0)
Console.WriteLine("Please enter the Bonus track number and input a blank line or EOF to finish");
string? bonusString = Console.ReadLine();
if (string.IsNullOrEmpty(bonusString))
{
break;
Console.WriteLine("If you want to confirm that you don't set the bonus, please enter the enter again to confirm.");
string? confirmString = Console.ReadLine();
if (string.IsNullOrEmpty(confirmString))
{
break;
}
}
}
else
{
Regex regex = new Regex("[^0-9]+$");
if (regex.IsMatch(bonusString))
{
Console.WriteLine("Error: You entered a character other than a number, please press enter key to re-enter");
continue;
}
else
{
int[] bonusList = Array.ConvertAll<string, int>(bonusString.Split(" "),s => int.Parse(s));
foreach (int bonusIndex in bonusList)
Regex regex = new Regex("[^0-9]+$");
if (regex.IsMatch(bonusString))
{
Console.WriteLine("Error: You entered a character other than a number, please press enter key to re-enter");
continue;
}
else
{
if(bonusIndex > songs.Count)
int[] bonusList = Array.ConvertAll(bonusString.Split(" "), int.Parse);
foreach (int bonusIndex in bonusList)
{
continue;
if (bonusIndex > songs.Count)
{
continue;
}

songs[bonusIndex - 1].IsBonusSong = true;
}
songs[bonusIndex - 1].SetBonusFlag();
}

break;
}
break;
}
}
}
}



Console.WriteLine("Please check the following song list for the game session:");
for (int i = 0; i < songs.Count; i++)
{
Console.WriteLine($"[{i + 1}] {songs[i].FullSecretSongTitle}");
}

Console.WriteLine("And the initial state of the game session:");
for (int i = 0; i < songs.Count; i++)
{
Console.WriteLine($"[{i + 1}] {new string(songs[i].HiddenSongTitle)}");
}

Console.WriteLine($"If check correct, press any key to start the game session. ({songs.Count} songs)");
Console.ReadKey(true);

GameMain(songs, revealSpacesInitially, showCorrectAnswers, preserveAnyRevealedLetter);
}

Expand All @@ -121,13 +132,14 @@ private static void GameMain(IReadOnlyList<Song> songs, bool revealSpacesInitial
var revealedChars = new HashSet<string>();
if (revealSpacesInitially) revealedChars.Add("<空格>");
var stopwatch = Stopwatch.StartNew();
for (int round = 1; ; round++)
for (int round = 1;; round++)
{
Console.ResetColor();
Console.Clear();
ConsolePlus.SetTitle($"Chu Ni Zi Mu - Round {(gameFinished ? "Final" : round)}");

#region Game Main Songs Panel

Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"已开:{string.Join(' ', revealedChars)}");
Console.ResetColor();
Expand All @@ -137,36 +149,33 @@ private static void GameMain(IReadOnlyList<Song> songs, bool revealSpacesInitial
var song = songs[i];
if (song.ToString() == song.FullSecretSongTitle)
{
if(song.CheckBonusFlag())
{
Console.ForegroundColor = ConsoleColor.Magenta; // bonus completed
}
else
{
Console.ForegroundColor = ConsoleColor.Green; // normal completed
}
Console.ForegroundColor = song.IsBonusSong ? ConsoleColor.Magenta : ConsoleColor.Green; // check ? bonus completed : normal completed

Console.WriteLine($"[{i + 1}] {song.FullSecretSongTitle}");
Console.ResetColor();
}
else
{
if(song.CheckNonAscii())
{
Console.ForegroundColor = ConsoleColor.Blue;
}
else if (song.CheckBonusFlag())
{
Console.ForegroundColor = ConsoleColor.Magenta;
}
Console.Write($"[{i + 1}] ");
Console.ResetColor();
Console.WriteLine($"{new string(song.HiddenSongTitle)}");
//Console.WriteLine($"[{i + 1}] {new string(song.HiddenSongTitle)}");
}
if (song.IsNonASCIICharacters)
{
Console.ForegroundColor = ConsoleColor.Blue;
}
else if (song.IsBonusSong)
{
Console.ForegroundColor = ConsoleColor.Magenta;
}

Console.Write($"[{i + 1}] ");
Console.ResetColor();
Console.WriteLine($"{new string(song.HiddenSongTitle)}");
//Console.WriteLine($"[{i + 1}] {new string(song.HiddenSongTitle)}");
}
}

#endregion

#region Game Finish logics

if (gameFinished)
{
Console.BackgroundColor = ConsoleColor.DarkBlue;
Expand All @@ -181,9 +190,11 @@ private static void GameMain(IReadOnlyList<Song> songs, bool revealSpacesInitial
Console.ResetColor();
return;
}

#endregion

#region Correct Answer Show logic

if (showCorrectAnswers)
{
Console.WriteLine();
Expand All @@ -193,9 +204,11 @@ private static void GameMain(IReadOnlyList<Song> songs, bool revealSpacesInitial
Console.WriteLine($"[{i + 1}] {songs[i].FullSecretSongTitle}");
}
}

#endregion

#region Game Menu and Input logics

Console.BackgroundColor = ConsoleColor.DarkBlue;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("<single char> - reveal, :d <num> - directly complete a song, :q - quit");
Expand All @@ -221,31 +234,37 @@ private static void GameMain(IReadOnlyList<Song> songs, bool revealSpacesInitial
Console.ReadKey(true);
continue;
}

char letter = option[0];
var revealResult = songs.Select(song => song.RevealLetter(letter)).ToList();
if (revealResult.All(result => result == RevealResult.AlreadyCompleted))
{
gameFinished = true;
continue; // directly continue to show the game final result
}

string shownLetter = letter == ' ' ? "<空格>" : letter.ToString();
if (revealedChars.Contains(letter.ToString()) || (letter == ' ' && revealedChars.Contains("<空格>")))
{
Console.WriteLine($"The letter {shownLetter} has already been revealed. Any key continue.");
Console.ReadKey(true);
continue;
}

if (revealResult.All(result => result != RevealResult.Success) && revealResult.Any(result => result == RevealResult.NotInTitle))
{
// 没有成功的记录,并且至少有一个报错“不在标题中”
Console.WriteLine($"The letter {shownLetter} is not in any song title. Any key continue.");
Console.ReadKey(true);
if (preserveAnyRevealedLetter) revealedChars.Add(shownLetter);
continue;
}
}

revealedChars.Add(shownLetter);
}

#endregion

}
}
}

0 comments on commit 9341ed3

Please sign in to comment.