Time Machine - Divers - Programmation
Marsh Posté le 16-02-2025 à 12:57:00
Bonour, Voici le code de la Time Machine avec Ada. Le paquetage Ansi est de Hiboux. il permet de saisir 12 chiffres, la date et l'heure "202502161145" pour voyager dans le temps.
with Ada.Calendar;with Ada.Calendar.Formatting;use Ada.Calendar;with Sky.Ansi.Console;with Sky.Ansi.Windows;use Sky.Ansi.Console;with Ada.Characters.Handling;use Ada.Characters.Handling;with Text_Io;use Text_Io;procedure Main is package Windows is new Sky.Ansi.Windows(67, 240); use Windows; Past_Win : Window_Type := (30, 110, 3, 22, Single_Line_Frame, Green, Green); Present_Win : Window_Type := (33, 110, 3, 22, Single_Line_Frame, Yellow, Yellow); Future_Win : Window_Type := (36, 110, 3, 22, Single_Line_Frame, Red, Red); Start : Time := Clock; now : Time := Start; Target : Time := Now + 0.025; subtype Date_Str is String (1..8); subtype Hour_str is String (1..4); Date_Index : Natural := 1; Hour_Index : Natural := 1; type Part_Enum is (Date_part, Hour_part); task Time_Machine is entry Init; entry Receive(Char : in Character); entry Halt; end Time_Machine; function Part2date (Date : in Date_Str; Hour : in Hour_Str) return Time is Target : Time := Clock; begin Target := Time_Of(Year_Number'Value(Date(1..4)), Month_Number'Value(date(5..6)), Day_Number'Value(Date(7..8)), Duration'Value(hour(1..2))*3600.0+Duration'Value(Hour(3..4))*60.0); return Target; end Part2date; task body Time_Machine is Part : Part_Enum := Date_Part; Date : Date_Str := "19700101"; Hour : Hour_Str := "0000"; Edit : Boolean := False; Going : Boolean := False; Done : Boolean := False; begin Target := Part2date(Date, Hour); loop select accept Init; Sky.Ansi.Console.Clear_Screen; Draw_Window(Past_win); Draw_Window(Present_Win); Draw_Window(Future_Win); or when not Going => accept Receive(Char : in Character) do Edit := True; if Is_Digit(Char) then if Part = Date_part then Date(Date_Index+1) := Char; else Hour(Hour_Index) := Char; end if; if Hour_Index = 4 then Hour_Index := 1; Part := Date_Part; Edit := False; Start := Now; Going := True; Target := Part2date(Date, Hour); elsif Part = Hour_Part then Hour_Index := Hour_Index + 1; end if; if Date_Index = 8 then Date_Index := 0; Part := Hour_Part; elsif Part = Date_Part then Date_Index := Date_Index + 1; end if; end if; end Receive; or accept Halt; exit; or delay 0.0; Draw(Past_Win, 1, 1, White, To_Wide_String(Formatting.Image(Start))); Draw(Present_Win, 1, 1, White, To_Wide_String(Formatting.Image(now))); Draw(Future_Win, 1, 1, White, To_Wide_String(Formatting.Image(target))); if not Going then delay 0.05; Now := Now + 0.05; if Done then Target := now + 1.0; end if; else Going := not Going; Strat := Now; Now := Target; Target := now + 1.0; Done := True; end if; end select; end loop; end Time_Machine; Char : Character;begin Time_Machine.Init; loop Get_Immediate(Char); case Char is when Character'Val(27) => Time_Machine.Halt; New_Line; exit; when others => Time_Machine.Receive(Char); end case; end loop; end Main;
Affiche trois fenêtre : L'heure de départ L'heure courante L'heure de destination Result
+-----------------[X]+ |2025-02-16 11:54:10 | +--------------------+ +-----------------[X]+ |2025-02-16 11:54:13 | +--------------------+ +-----------------[X]+ |1970-01-01 00:00:00 | +--------------------+
Voir le paquetage Calendar pour les ilimites de timer.
Make sure you enter the(*)required information where indicate.HTML code is not allowed
Marsh Posté le 16-02-2025 à 12:57:00
Bonour,
Voici le code de la Time Machine avec Ada.
Le paquetage Ansi est de Hiboux.
il permet de saisir 12 chiffres, la date et l'heure "202502161145" pour voyager dans le temps.
Affiche trois fenêtre :
L'heure de départ
L'heure courante
L'heure de destination
Result
+-----------------[X]+
|2025-02-16 11:54:10 |
+--------------------+
+-----------------[X]+
|2025-02-16 11:54:13 |
+--------------------+
+-----------------[X]+
|1970-01-01 00:00:00 |
+--------------------+
Voir le paquetage Calendar pour les ilimites de timer.
Message édité par lady287 le 16-02-2025 à 13:55:54
---------------
Skywalker