Bonjour,
Je débute en perl et j'ai écris un petit programme pour m'amuser. Un programme qui génère les stats d'un personnage pour la première édition de DnD
QUESTIONS 1:
Je cherche un moyen de simplifier mon code, ou des astuces sur quoi faire et ne pas quoi faire. Je suis sur a 100% que je peut modifier les lignes (28 à 43 et 55 à 77) pour réduire la taille de mon programme pour que cela me donne un code plus propre.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 #!/usr/bin/perl #Creates stats for 1st and 2nd edition AD&D charaters or NPC's using "method 3" $range = 6; $minimum = 1; @StatsName = ("Strength", "Constitution", "Dexterity", "Intelligence", "Wisdom", "Charisma"); @Dices = ("Dice_1", "Dice_2", "Dice_3"); sub Random_Roll { int(rand($range)) + $minimum; } for ($Number_Stats = 1; $Number_Stats < 7; $Number_Stats++) { for ($count = 1; $count < 7; $count++) { $Dices[0] = Random_Roll {}; $Dices[1] = Random_Roll {}; $Dices[2] = Random_Roll {}; $Total_Dice = $Dices[0] + $Dices[1] + $Dices[2]; $arr[$count] = $Total_Dice; } $StatsHigh = $arr[1]; if ($StatsHigh < $arr[1]) { $StatsHigh = $arr[1]; } elsif ($StatsHigh < $arr[2]) { $StatsHigh = $arr[2]; } elsif ($StatsHigh < $arr[3]) { $StatsHigh = $arr[3]; } elsif ($StatsHigh < $arr[4]) { $StatsHigh = $arr[4]; } if ($StatsHigh > 17) { $range = 100; $StatsHigh = Random_Roll {}; } else { $StatsHigh = $StatsHigh; } if ($Number_Stats == 1) { print $StatsName[0], " = ", $StatsHigh, "\n"; } elsif ($Number_Stats == 2) { print $StatsName[1], " = ", $StatsHigh, "\n"; } elsif ($Number_Stats == 3) { print $StatsName[2], " = ", $StatsHigh, "\n"; } elsif ($Number_Stats == 4) { print $StatsName[3], " = ", $StatsHigh, "\n"; } elsif ($Number_Stats == 5) { print $StatsName[4], " = ", $StatsHigh, "\n"; } elsif ($Number_Stats == 6) { print $StatsName[5], " = ", $StatsHigh, "\n"; } }
Malheureusement je ne sais pas quoi faire, je vous demande de m'aider.
QUESTIONS 2:
Pour faire une pierre deux coups, je cherche comment afficher un paragraphe d'un fichier texte.
MON FICHIER TEXTE:
MON SCRIPT:Blood
* You now have a blood affliction *
Description: Blood et al. afflictions will cause a loss of 1 point each of strength and consitution per week until totally cured. Thus, chronic problems here will slowly wear the character away.
Duration: Terminal cases will take 1-12 weeks.
Bone
* You now have a bone affliction *
Description: Bone afflictions will cause a loss of 1 point each of strength and consitution per week until totally cured. Thus, chronic problems here will slowly wear the character away.
Duration: Terminal cases will take 1-12 weeks.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 sub Search { open (DISEASES, "Diseases.txt") or die "I couldn't get the file open: $!"; for $line (<DISEASES>) { if ($line =~ /?????/) { print $line; } } close DISEASES; }
Je cherche quoi marquer dans " if ($line =~ /?????/) " pour qu'il m'affiche:
Vous comprenez?* You now have a blood affliction *
Description: Blood et al. afflictions will cause a loss of 1 point each of strength and consitution per week until totally cured. Thus, chronic problems here will slowly wear the character away.
Duration: Terminal cases will take 1-12 weeks.
Merci!
Bonne fin de journée!
Partager