diff --git a/qualdev/TD Exceptions.ts b/qualdev/TD Exceptions.ts new file mode 100644 index 0000000000000000000000000000000000000000..02fed641b8da03ef2e461d3eac251618e3ce830c --- /dev/null +++ b/qualdev/TD Exceptions.ts @@ -0,0 +1,141 @@ +class NomVideError extends Error { + constructor(message = "La chaine nom est vide") { + super(message); + this.name = "NomVideError"; + } +} + +class PrenomVideError extends Error { + constructor(message = "La chaine prenom est vide") { + super(message); + this.name = "PrenomVideError"; + } +} + +class NomEtPrenomVideError extends Error { + constructor(message = "Les chaines nom et prenom sont vides") { + super(message); + this.name = "NomEtPrenomVideError"; + } +} + +function creeInitiales1(nom: string, prenom: string): string | Error { + if (nom.length === 0 && prenom.length !== 0) return new NomVideError; + else if (nom.length !== 0 && prenom.length === 0) return new PrenomVideError; + else if (nom.length === 0 && prenom.length === 0) return new NomEtPrenomVideError; + return nom[0].toUpperCase() + prenom[0].toUpperCase(); +} + +try { + creeInitiales1("", ""); +} catch (e) { + if (e instanceof NomVideError) { + console.log("La chaine nom est vide"); + } + else if (e instanceof PrenomVideError) { + console.log("La chaine prenom est vide"); + } + else if (e instanceof NomEtPrenomVideError) { + console.log("Les chaines nom et prenom sont vides"); + } + else { + console.log(e.message); + } +} finally { + console.log("Fin du programme"); +} + +// 2. celle des cha^ines vides + +// 7. Non, un seul type d'erreur suffi + +class ChaineVideError extends Error { + constructor(message = "Au moins une chaine est vide") { + super(message); + this.name = "ChaineVideError"; + } +} + +function creeInitiales(nom: string, prenom: string): string | Error { + if (nom.length === 0 || prenom.length === 0) return new ChaineVideError; + return nom[0].toUpperCase() + prenom[0].toUpperCase(); +} + +try { + creeInitiales("", ""); +} catch (e) { + if (e instanceof ChaineVideError) { + console.log("Au moins une chaine est vide"); + } + else { + console.log(e.message); + } +} finally { + console.log("Fin du programme"); +} + + +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Exercice 2 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + +class Etudiant { + INE: string; + nom: string; + prenom: string; +} + +let jean = new Etudiant(); +jean.nom = "jean"; +jean.prenom = "Valjean"; + +class INEError extends Error { + constructor(message = "Format incorrect") { + super(message); + this.name = "INEError"; + } +} + +function setINE(ine: string, objet: Etudiant): void { + let estCorrect = true; + let compteur = 0; + while ((compteur != ine.length) && estCorrect) { + if (compteur <= 9 && (ine[compteur] !== String(Number))) { + estCorrect = false; + } else if (compteur > 10 && (isLetter(ine[compteur]) === false)) { + estCorrect = false; + } else if (compteur === 10 && (ine[compteur] !== String(Number)) && isLetter(ine[compteur]) === false) { + estCorrect = false; + } + compteur++; + } + + if (estCorrect === false) { + throw INEError; + } + + objet.INE = ine; + console.log("C'est fait"); + +} + +function isLetter(c: string): boolean { + return (c >= "a" && c <= "z") || (c >= "A" && c <= "Z"); +} + + +try { + setINE("1010101010r", jean); +} catch (e) { + if (e instanceof INEError) { + console.log("Format incorrect"); + } + else { + console.log(e.message); + } +} finally { + console.log("Fin du programme"); +} + +console.log(jean.INE) + + + diff --git a/qualdev/TD_Debug.ts b/qualdev/TD_Debug.ts new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/.~lock.UML.odt# b/src/.~lock.UML.odt# new file mode 100644 index 0000000000000000000000000000000000000000..2788e4589ff320d19a3618927aaa4da865227a53 --- /dev/null +++ b/src/.~lock.UML.odt# @@ -0,0 +1 @@ +,e0088u,iutm-inf-f33-14,13.03.2024 08:58,file:///home/e0088u/.config/libreoffice/4; \ No newline at end of file diff --git a/src/TDEncapsulation.ts b/src/TDEncapsulation.ts new file mode 100644 index 0000000000000000000000000000000000000000..d4a2d7f75b189eb61378b9cebe57bfd12456a2d9 --- /dev/null +++ b/src/TDEncapsulation.ts @@ -0,0 +1,126 @@ +// Les pistes audio + +class Piste { + private _titre: string; + private _duree: number; + + constructor(titre: string, duree: number) { + this._titre = titre; + this._duree = duree; + } + + getTitre(): string { + return this._titre; + } + + setTitre(titre: string): void { + this._titre = titre; + } + + getDuree(): number { + return this._duree; + } + + egale(piste1: Piste, piste2: Piste): boolean { + if (piste1._duree === piste2._duree && piste1._titre === piste2._titre) { + return true; + } + return false; + } + + toString(): string { + return "La chanson " + this._titre + "dure " + this._duree + "." + } +} + +class Album { + private _titre: string; + private _nbPistes: number; + private _listePistes: Array<Piste>; + + setTitre(titre: string) { + this._titre = titre; + } + + getListe() { + return this._listePistes; + } + + setListe(pisteAAjouter: Piste, album: Album) { + album._listePistes.push(pisteAAjouter); + } + + estFini(): boolean { + if (this._listePistes.length === this._nbPistes) { + return true; + } + return false; + } + + contient(titreAChercher: string, pisteDemandee: Album): boolean { + for (let element of pisteDemandee.getListe()) { + if (element.getTitre() === titreAChercher) { + return true; + } + } + return false; + } + + ajouterPiste(album: Album, titre: Piste): void { + if (album._listePistes.length !== album._nbPistes) { + album._listePistes.push(titre); + + } + } + + dureeTotale(album: Album): number { + let temps = 0; + for (let element of album._listePistes) { + temps += element.getDuree(); + } + return temps; + } + + egale(album1: Album, album2: Album): boolean { + let existeTitreDifferent = true; + for (let element1 of album1._listePistes) { + for (let element2 of album2._listePistes) { + if (element1 === element2) { + existeTitreDifferent = false; + } + else { + existeTitreDifferent = true; + break; + } + } + } + return existeTitreDifferent; + } +} + +/* + _________________________________________________________________ +|Album | +|_________________________________________________________________| +|- titre: string | +|- nbPistes: int | +|- listePistes: Array<Piste> | +|_________________________________________________________________| +|+ getListe() | +|+ setListe(pisteAAjouter: Piste, album: Album) | +|+ estFini(): boolean | +|+ contient(titreAChercher: string, pisteDemandee: Album): boolean| +|+ ajouterPiste(album: Album): void | +|+ dureeTotale(album: Album): float | +|+ egale(album1: Album, album2: Album): boolean | +|_________________________________________________________________| +*/ + +let p1 = new Piste("t1", 230); +let p2 = new Piste("t2", 180); + +let d = new Album(); +d.setTitre("td"); +d.ajouterPiste(d, p1); +d.ajouterPiste(d, p2); + diff --git a/src/TDUML.ts b/src/TDUML.ts new file mode 100644 index 0000000000000000000000000000000000000000..c33304f3e2660053037233f37212e45e256d074c --- /dev/null +++ b/src/TDUML.ts @@ -0,0 +1,148 @@ +/* + _____________________________________________ +| | +|_____________________________________________| +| | +|_____________________________________________| +| | +|_____________________________________________| +*/ + +/* + ___________________________________________________ +|Ampoule | +|___________________________________________________| +|couleur : int | +|puissance : double | +|___________________________________________________| +|Ampoule(couleur: int = 0, puissance: int = 0): void| +|allumer(): void | +|eteindre(): void | +|getCouleur(): int | +|setCouleur(couleur: int): void | +|getPuissance(): double | +|setPuissance(puissance: double): void | +|toString(): string | +|___________________________________________________| +*/ + +class Timer { + periode: number; + etat: boolean; + + constructor() { + + } + + constructor1(periode: number) { + + } + + getPeriode(): number { + /* code */ + return 1; + } + + setPeriode(periode: number) { + + } + + activer(): void { + + } + + desactiver(): void { + + } + + utiliser(): void { + + } + + toString(): string { + return "Kartoffel" + } +} + + +/* + _____________________________________________ +|Point | +|_____________________________________________| +|x:float | +|y:float | +|_____________________________________________| +| | +|_____________________________________________| +*/ + +/* + ____________________________________________________________________________________________________ +|Cercle | +|____________________________________________________________________________________________________| +|rayon: int = 0 | +|centre: Point | +|____________________________________________________________________________________________________| +|pointDansCercle(cercle: Cercle, point: Point): boolean | +|rectangleDansCercle(coin1: Point, coin2: Point, coin3: Point, coin4: Point, cercle: Cercle): boolean| | +|chevauchement(coin1: Point, coin2: Point, coin3: Point, coin4: Point, cercle: Cercle): boolean | +|____________________________________________________________________________________________________| +*/ + +/* + _____________________________________________________ +|Temps | +|_____________________________________________________| +|heure:int | +|minute:int | +|second:int | +|_____________________________________________________| +|temps2Number(objet: Temps): int | +|number2Temps(temps: int): Temps | +|multiplieTemps(temps: Temps, multiplieur: int): Temps| +|multiplie(t: Temps, nb: int): void | +|vitesseMoyenne(temps: Temps, distance: float) | +|_____________________________________________________| +*/ + +/* + _____________________________________________ +|Caractere | +|_____________________________________________| +|carcAConserver:char = " " | +|_____________________________________________| +|estVoyelle(): boolean | +|nbVoyelles(message: string): int | +|_____________________________________________| +*/ + +/* + _____________________________________________ +|Rectangle | +|_____________________________________________| +|longueur:int = 1 | +|largeur:int = 1 | +|_____________________________________________| +|perimetre(): int | +|surface(): int | +|agrandir(multiple: int): void | +|afficherRectangle(rect: Rectangle) | +|_____________________________________________| +*/ + +/* + _____________________________________________ +|Reservoir | +|_____________________________________________| +|capacite: float | +|rempli: float | +|_____________________________________________| +|verse(quantite: float): float | +|puise(quantite: float): float | +|jauge():float | +|_____________________________________________| +*/ + + + +// Ajouter les constructeurs \ No newline at end of file diff --git a/src/TDclasses.ts b/src/TDclasses.ts index 264967c2baffa4944d884c628be4b2fefbf95ed7..78feb32d3ede9d58334860004235c6907cb26be5 100644 --- a/src/TDclasses.ts +++ b/src/TDclasses.ts @@ -47,10 +47,10 @@ function temps2Number(objet: Temps): number { return (objet.heure * 3600) + (objet.minute * 60) + objet.second; } -test = new Temps() -test.heure = 1 -test.minute = 30 -test.second = 5 +let test1 = new Temps() +test1.heure = 1 +test1.minute = 30 +test1.second = 5 //console.log(temps2Number(test)); @@ -64,8 +64,115 @@ function number2Temps(temps: number): Temps { return objet; } -console.log(number2Temps(5405)); +//console.log(number2Temps(6670)); function multiplieTemps(temps: Temps, multiplieur: number): Temps { return number2Temps(temps2Number(temps) * multiplieur); -} \ No newline at end of file +} + +// non, pointeur + +function multiplie(t: Temps, nb: number): void { + const t2 = multiplieTemps(t, nb) + t.heure = t2.heure; + t.minute = t2.minute; + t.second = t2.second; +} + +/* let i = 2; +multiplie(test1, i); +console.log(test1); */ + + +//??? + +function vitesseMoyenne(temps: Temps, distance: number) { + return temps2Number(temps) / distance; +} + +let vitesse = vitesseMoyenne(test1, 10); +console.log(vitesse); + +class Caractere { + caracAConserver = " "; + estVoyelle(): boolean { + if (this.caracAConserver === "a" || this.caracAConserver === "A" || this.caracAConserver === "e" || this.caracAConserver === "E" || this.caracAConserver === "i" || this.caracAConserver === "I" || this.caracAConserver === "o" || this.caracAConserver === "O" || this.caracAConserver === "u" || this.caracAConserver === "U" || this.caracAConserver === "y" || this.caracAConserver === "Y") { + return true; + }//RegExp + + return false; + } +} + +function nbVoyelles(message: string): number { + let lettre = new Caractere() + let compteur = 0; + for (let i = 0; i <= message.length; i++) { + lettre.caracAConserver = message[i]; + if (lettre.estVoyelle()) compteur += 1; + } + return compteur; +} + +console.log(nbVoyelles("potatoes")) + +class Rectangle { + longueur = 1; + largeur = 1; + perimetre(): number { + return 2 * this.longueur + 2 * this.largeur + } + surface(): number { + return this.longueur * this.largeur + } + agrandir(multiple: number): void { + this.longueur *= multiple; + this.largeur *= multiple; + } + static afficherRectangle(rect: Rectangle) { + console.log("largeur = ", rect.largeur, "longueur = ", rect.longueur) + } +} + +let carre = new Rectangle() +carre.largeur = 5; +carre.longueur = 5; +console.log(carre.perimetre(), carre.surface()) +carre.agrandir(3) +console.log(carre.largeur, carre.longueur) + +class Reservoir { + capacite: number + rempli: number + verse(quantite: number): number { + let surplus = 0; + if (this.rempli + quantite <= this.capacite) { + this.rempli += quantite + return surplus + } + surplus = this.rempli + quantite - this.capacite; + this.rempli = this.capacite; + return surplus; + } + puise(quantite: number): number { + let aEtePuise = 0; + if (this.rempli - quantite >= 0) { + this.rempli -= quantite; + return this.rempli; + } + let calcul = this.rempli - quantite; + while (calcul !== 0) { + aEtePuise += 1; + calcul += 1; + } + return quantite - aEtePuise; + } + jauge(): number { + return this.rempli; + } +} + +let bouteilleDEau = new Reservoir(); +bouteilleDEau.capacite = 100; +bouteilleDEau.rempli = 90; +console.log("Glouglou", bouteilleDEau.puise(4), bouteilleDEau.jauge(), bouteilleDEau.verse(1), bouteilleDEau.verse(20)) \ No newline at end of file diff --git a/src/UML.odt b/src/UML.odt new file mode 100644 index 0000000000000000000000000000000000000000..9721646898b16d6059efce6e49d4c492fd191666 Binary files /dev/null and b/src/UML.odt differ diff --git a/src/snake/app.css b/src/snake/app.css new file mode 100644 index 0000000000000000000000000000000000000000..9a956d3701994232423704aa51e2b90d24d832ac --- /dev/null +++ b/src/snake/app.css @@ -0,0 +1,5 @@ +#board { + width: 800px; + height: 800px; + background-color: #000; +} \ No newline at end of file diff --git a/src/snake/app.js b/src/snake/app.js new file mode 100644 index 0000000000000000000000000000000000000000..7471c3668c612de2e334b4a7a56923ed3d34d36d --- /dev/null +++ b/src/snake/app.js @@ -0,0 +1,61 @@ +const board = document.querySelector("#board"); + +let direction = { + x: 1, + y: 0, +}; + +let hasWon = false; +let hasLost = false; + +let startDate = new Date(); +let workingDate = new Date(); + +const snake = [ + {x: 40, y: 40}, + {x: 40, y: 41}, + {x: 40, y: 42}, + {x: 40, y: 43}, + {x: 40, y: 44}, + {x: 41, y: 44}, + {x: 42, y: 44}, + {x: 42, y: 45}, + {x: 42, y: 46}, + ]; + + function gestionTouchesAppuye(event) { + switch(event.key) { + case 'ArrowLeft': + console.log("Touche Gauche pressée"); + break; + case 'ArrowUp': + console.log("Touche Haut pressée"); + break; + case 'ArrowRight': + console.log("Touche Droite pressée"); + break; + case 'ArrowDown': + console.log("Touche Bas pressée"); + break; + } + } + + // Ajouter un écouteur d'événements pour détecter les touches pressées +document.addEventListener('keydown', gestionTouchesAppuye); + const context = board.getContext('2d'); + +setInterval(() => { + + console.log("tick"); + + + + + +// RESTE A FAIRE : +// gestion du snake +// gestion des bordures +// gestion de la direction +// gestion on mange une pomme + +}, 400); \ No newline at end of file diff --git a/src/snake/index.html b/src/snake/index.html new file mode 100644 index 0000000000000000000000000000000000000000..8449f21cad8e6270adbfac3a7a2b4c1cdc218ee0 --- /dev/null +++ b/src/snake/index.html @@ -0,0 +1,15 @@ +<html> + +<head> + <link rel="stylesheet" href="app.css"> +</head> + +<body> + <h1>Snake Game</h1> + <h2>Arrow to play</h2> + <canvas width="800" height="800" id="board"></canvas> + <script src="app.js"></script> + +</body> + +</html> \ No newline at end of file