Comment supprimer des doublons d'un tableau en pascal
Fermé
pcforever01
Messages postés52Date d'inscriptionlundi 30 août 2010StatutMembreDernière intervention 2 décembre 2012
-
2 déc. 2012 à 16:05
Bonjour,
je n'arrive pas à supprimer des doublons, dans la procédure ajouterjoueurs voici mon code si quelqu'un sais m'aider ;)
program jeux;
uses crt;
const maxScores = 10; { borne tableau physique scores }
maxJoueurs = 20; { borne tableau physique scores }
scoreMin = 0; scoreMax = 10000; { pour valider score }
optionMin =0;optionMax =5;
type Joueur = record
nick : string;
score: integer;
end;
type TpJoueurs = array[1..maxJoueurs] of Joueur;
var Joueurs: TpJoueurs;
var nbjoueurs : integer;
type TpScores = array [1..maxScores] of Joueur;
var scores : TpScores;
var nbScores :integer;
procedure pause; { pour chaque étape, avant de revenir au menu }
begin
writeln;
write('appuyez sur une touche pour continuer ... ');
readkey
end;
function choixMenu(optMin : integer; optMax : integer) : integer; { montrer les actions possibles et saisir le choix }
var choix:integer;
begin
repeat
clrscr;
writeln('MENU');
writeln('====');
writeln('1. initialiser jeu');
writeln('2. ajouter joueur');
writeln('3. lister les joueurs');
writeln('4. encoder score');
writeln('5. afficher hall of fame');
writeln;
writeln('0. quitter');
writeln;
write(' votre choix => ');
readln(choix);
choixMenu := choix;
until choix in [optMin..optMax];
pause;
end;
procedure initialiserJeu(var scores: TpScores ;var joueurs : TpJoueurs); { à faire avant toute chose }
var ok:boolean;
reponse : char;
ind:integer;
begin
clrscr;
ok:=true;
writeln('initialisation');
writeln('--------------');
writeln;
write('toutes les donnees seront perdues ! continuer (o/n) ? ');
readln(reponse);
while not ((lowercase(reponse) = 'n')or (ok = false) ) do begin
if(reponse = 'o') then begin
for ind := 1 to maxScores do
begin
scores[ind].score:=0;
scores[ind].nick:='';
end;
for ind := 1 to maxJoueurs do
begin
joueurs[ind].score:=0;
joueurs[ind].nick:='';
end;
ok := false;
end
else begin
clrscr;
write('reponse incorrecte continuer l''initialisation (o/n) ? ');
readln(reponse);
end;
end;
pause;
end;
begin
clrscr;
writeln('ajout de joueur');
writeln('---------------');
indice1:=1;
indice:=0;
doublon := false;
if not ( nb = maxJoueurs) then
begin
write('joueur ', nb+1, '/', maxJoueurs, ' ... nickname : ');
readln(nickName);
nb := nb + 1;
for indice:= nb downto indice1 do begin
if nickname = joueurs[indice].nick then doublon:=true
end;
end
else if doublon = true then begin
writeln('veuillez choisir un autre nicname');
readln(nickName);
nb := nb+1;
end
else begin joueurs[nb].nick := nickName;
writeln;
writeln('joueur ajoute ...');
writeln('son numero de joueur est ', nb,'nick',joueurs[nb].nick );
end;
pause;
end;
function traiterChoixMenu():boolean;
var fin:boolean;
begin
fin:= false;
case choixMenu(optionMin, optionMax) of
1 : initialiserJeu(scores,joueurs);
2 : ajouterJoueur(nbJoueurs,joueurs);