raku

My Raku Scripts Collection
git clone https://fab.ddns.me.uk/stagit/raku
Log | Files | Refs | README

typing.raku (1138B)


      1 #!/usr/bin/env raku
      2 
      3 # 1. 単語リストの準備
      4 my $dict-path = "/usr/share/dict/british";
      5 my @words;
      6 
      7 if $dict-path.IO.e && $dict-path.IO.f {
      8     # ファイルが存在する場合:5〜10文字の単語を抽出
      9     @words = $dict-path.IO.lines.grep({ 5 <= .chars <= 10 });
     10 }
     11 
     12 # ファイルがない、または中身が空だった場合のフォールバック
     13 if !@words {
     14     say "Note: Using default word list.";
     15     @words = <raku openbsd perl terminal coding coffee apple>;
     16 }
     17 
     18 # 2. ゲーム開始
     19 say "=== OpenBSD Typing Game ===";
     20 say "Words loaded: {@words.elems}";
     21 say "Press Enter to start (Ctrl+C to quit)...";
     22 get;
     23 
     24 my $total = 5;
     25 my $score = 0;
     26 my $start-time = now;
     27 
     28 for @words.pick($total) -> $target {
     29     say "\n[Type this] : $target";
     30     print "> "; # 入力プロンプト
     31     
     32     my $input = get;
     33     
     34     if $input eq $target {
     35         say "✨ Correct!";
     36         $score++;
     37     } else {
     38         say "❌ Wrong... (The word was: $target)";
     39     }
     40 }
     41 
     42 # 3. 結果表示
     43 my $duration = now - $start-time;
     44 say "\n" ~ "=" x 20;
     45 say "Result: $score / $total";
     46 say "Time  : {$duration.round(0.01)}s";
     47 say "=" x 20;