Portfolio Code | Clement Colmerauer
Repositories
Site
Kata refactoring
Code
Commits
Branches
Tags
Search
Tree:
2fce22c
Branches
Tags
master
Kata refactoring
build
reports
jacoco
test
html
re.forestier.edu.rpg
UpdatePlayer.java.html
corrigé
Clement COLMERAUER
commited
2fce22c
at 2024-10-07 10:30:57
UpdatePlayer.java.html
Blame
History
Raw
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="fr"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>UpdatePlayer.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">kata</a> > <a href="index.source.html" class="el_package">re.forestier.edu.rpg</a> > <span class="el_source">UpdatePlayer.java</span></div><h1>UpdatePlayer.java</h1><pre class="source lang-java linenums">package re.forestier.edu.rpg; import java.util.HashMap; import java.util.Random; <span class="fc" id="L6">public class UpdatePlayer {</span> <span class="fc" id="L8"> private final static String[] objectList = {"Lookout Ring : Prevents surprise attacks","Scroll of Stupidity : INT-2 when applied to an enemy", "Draupnir : Increases XP gained by 100%", "Magic Charm : Magic +10 for 5 rounds", "Rune Staff of Curse : May burn your ennemies... Or yourself. Who knows?", "Combat Edge : Well, that's an edge", "Holy Elixir : Recover your HP"</span> }; public static HashMap<String, HashMap<Integer, HashMap<String, Integer>>> abilitiesPerTypeAndLevel() { <span class="fc" id="L12"> HashMap<String, HashMap<Integer, HashMap<String, Integer>>> abilitiesPerTypeAndLevel = new HashMap<>();</span> <span class="fc" id="L14"> HashMap<Integer, HashMap<String, Integer>> adventurerMap = new HashMap<>();</span> <span class="fc" id="L15"> HashMap<String, Integer> adventurerLevel1 = new HashMap<>();</span> <span class="fc" id="L16"> adventurerLevel1.put("INT", 1);</span> <span class="fc" id="L17"> adventurerLevel1.put("DEF", 1);</span> <span class="fc" id="L18"> adventurerLevel1.put("ATK", 3);</span> <span class="fc" id="L19"> adventurerLevel1.put("CHA", 2);</span> <span class="fc" id="L20"> adventurerMap.put(1, adventurerLevel1);</span> <span class="fc" id="L22"> HashMap<String, Integer> adventurerLevel2 = new HashMap<>();</span> <span class="fc" id="L23"> adventurerLevel1.put("INT", 2);</span> <span class="fc" id="L24"> adventurerLevel1.put("CHA", 3);</span> <span class="fc" id="L25"> adventurerMap.put(2, adventurerLevel2);</span> <span class="fc" id="L27"> HashMap<String, Integer> adventurerLevel3 = new HashMap<>();</span> <span class="fc" id="L28"> adventurerLevel3.put("ATK", 5);</span> <span class="fc" id="L29"> adventurerLevel3.put("ALC", 1);</span> <span class="fc" id="L30"> adventurerMap.put(3, adventurerLevel3);</span> <span class="fc" id="L32"> HashMap<String, Integer> adventurerLevel4 = new HashMap<>();</span> <span class="fc" id="L33"> adventurerLevel4.put("DEF", 3);</span> <span class="fc" id="L34"> adventurerMap.put(4, adventurerLevel4);</span> <span class="fc" id="L36"> HashMap<String, Integer> adventurerLevel5 = new HashMap<>();</span> <span class="fc" id="L37"> adventurerLevel5.put("VIS", 1);</span> <span class="fc" id="L38"> adventurerLevel5.put("DEF", 4);</span> <span class="fc" id="L39"> adventurerMap.put(5, adventurerLevel5);</span> <span class="fc" id="L41"> abilitiesPerTypeAndLevel.put("ADVENTURER", adventurerMap);</span> <span class="fc" id="L44"> HashMap<Integer, HashMap<String, Integer>> archerMap = new HashMap<>();</span> <span class="fc" id="L45"> HashMap<String, Integer> archerLevel1 = new HashMap<>();</span> <span class="fc" id="L46"> archerLevel1.put("INT", 1);</span> <span class="fc" id="L47"> archerLevel1.put("ATK", 3);</span> <span class="fc" id="L48"> archerLevel1.put("CHA", 1);</span> <span class="fc" id="L49"> archerLevel1.put("VIS", 3);</span> <span class="fc" id="L50"> archerMap.put(1, archerLevel1);</span> <span class="fc" id="L52"> HashMap<String, Integer> archerLevel2 = new HashMap<>();</span> <span class="fc" id="L53"> archerLevel2.put("DEF", 1);</span> <span class="fc" id="L54"> archerLevel2.put("CHA", 2);</span> <span class="fc" id="L55"> archerMap.put(2, archerLevel2);</span> <span class="fc" id="L57"> HashMap<String, Integer> archerLevel3 = new HashMap<>();</span> <span class="fc" id="L58"> archerLevel3.put("ATK", 3);</span> <span class="fc" id="L59"> archerMap.put(3, archerLevel3);</span> <span class="fc" id="L61"> HashMap<String, Integer> archerLevel4 = new HashMap<>();</span> <span class="fc" id="L62"> archerLevel4.put("DEF", 2);</span> <span class="fc" id="L63"> archerMap.put(4, archerLevel4);</span> <span class="fc" id="L65"> HashMap<String, Integer> archerLevel5 = new HashMap<>();</span> <span class="fc" id="L66"> archerLevel5.put("ATK", 4);</span> <span class="fc" id="L67"> archerMap.put(5, archerLevel5);</span> <span class="fc" id="L69"> abilitiesPerTypeAndLevel.put("ARCHER", archerMap);</span> <span class="fc" id="L72"> HashMap<Integer, HashMap<String, Integer>> dwarf = new HashMap<>();</span> <span class="fc" id="L73"> HashMap<String, Integer> dwarfLevel1 = new HashMap<>();</span> <span class="fc" id="L74"> dwarfLevel1.put("ALC", 4);</span> <span class="fc" id="L75"> dwarfLevel1.put("INT", 1);</span> <span class="fc" id="L76"> dwarfLevel1.put("ATK", 3);</span> <span class="fc" id="L77"> dwarf.put(1, dwarfLevel1);</span> <span class="fc" id="L79"> HashMap<String, Integer> dwarfLevel2 = new HashMap<>();</span> <span class="fc" id="L80"> dwarfLevel2.put("DEF", 1);</span> <span class="fc" id="L81"> dwarfLevel2.put("ALC", 5);</span> <span class="fc" id="L82"> dwarf.put(2, dwarfLevel2);</span> <span class="fc" id="L84"> HashMap<String, Integer> dwarfLevel3 = new HashMap<>();</span> <span class="fc" id="L85"> dwarfLevel3.put("ATK", 4);</span> <span class="fc" id="L86"> dwarf.put(3, dwarfLevel3);</span> <span class="fc" id="L88"> HashMap<String, Integer> dwarfLevel4 = new HashMap<>();</span> <span class="fc" id="L89"> dwarfLevel4.put("DEF", 2);</span> <span class="fc" id="L90"> dwarf.put(4, dwarfLevel4);</span> <span class="fc" id="L92"> HashMap<String, Integer> dwarfLevel5 = new HashMap<>();</span> <span class="fc" id="L93"> dwarfLevel5.put("CHA", 1);</span> <span class="fc" id="L94"> dwarf.put(5, dwarfLevel5);</span> <span class="fc" id="L96"> abilitiesPerTypeAndLevel.put("DWARF", dwarf);</span> <span class="fc" id="L98"> return abilitiesPerTypeAndLevel;</span> } public static boolean addXp(Player player, int xp) { <span class="fc" id="L102"> int currentLevel = player.retrieveLevel();</span> <span class="fc" id="L103"> player.setXp(player.getXp()+xp);</span> <span class="fc" id="L104"> int newLevel = player.retrieveLevel();</span> <span class="fc bfc" id="L106" title="All 2 branches covered."> if (newLevel != currentLevel) {</span> // Player leveled-up! // Give a random object ; <span class="fc" id="L110"> Random random = new Random();</span> <span class="fc" id="L111"> player.inventory.add(objectList[random.nextInt(objectList.length - 0) + 0]);</span> // Add/upgrade abilities to player <span class="fc" id="L114"> HashMap<String, Integer> abilities = abilitiesPerTypeAndLevel().get(player.getAvatarClass()).get(newLevel);</span> <span class="fc" id="L115"> abilities.forEach((ability, level) -> {</span> <span class="fc" id="L116"> player.abilities.put(ability, abilities.get(ability));</span> <span class="fc" id="L117"> });</span> <span class="fc" id="L118"> return true;</span> } <span class="fc" id="L120"> return false;</span> } // majFinDeTour met à jour les points de vie public static void majFinDeTour(Player player) { <span class="fc bfc" id="L127" title="All 2 branches covered."> if(player.getCurrentHealthPoints() == 0) {</span> <span class="fc" id="L128"> System.out.println("Le joueur est KO !");</span> <span class="fc" id="L129"> return;</span> } <span class="fc bfc" id="L132" title="All 2 branches covered."> if(player.getCurrentHealthPoints() < player.getHealthPoints()/2) {</span> <span class="fc bfc" id="L133" title="All 2 branches covered."> if(!player.getAvatarClass().equals("ADVENTURER")) {</span> <span class="fc bfc" id="L134" title="All 2 branches covered."> if(player.getAvatarClass().equals("DWARF")) {</span> <span class="fc bfc" id="L135" title="All 2 branches covered."> if(player.inventory.contains("Holy Elixir")) {</span> <span class="fc" id="L136"> player.setCurrentHealthPoints(player.getCurrentHealthPoints()+1);</span> } <span class="fc" id="L138"> player.setCurrentHealthPoints(player.getCurrentHealthPoints()+1);</span> } <span class="fc bfc" id="L142" title="All 2 branches covered."> if(player.getAvatarClass().equals("ARCHER")) {</span> <span class="fc" id="L143"> player.setCurrentHealthPoints(player.getCurrentHealthPoints()+1);</span> <span class="fc bfc" id="L144" title="All 2 branches covered."> if(player.inventory.contains("Magic Bow")) {</span> <span class="fc" id="L145"> player.setCurrentHealthPoints(player.getCurrentHealthPoints()+player.getCurrentHealthPoints()/8-1);</span> } } } else { <span class="fc" id="L149"> player.setCurrentHealthPoints(player.getCurrentHealthPoints()+2);</span> <span class="fc bfc" id="L150" title="All 2 branches covered."> if(player.retrieveLevel() < 3) {</span> <span class="fc" id="L151"> player.setCurrentHealthPoints(player.getCurrentHealthPoints()-1);</span> } } } else { <span class="fc bfc" id="L156" title="All 2 branches covered."> if(player.getCurrentHealthPoints() >= player.getHealthPoints()) {</span> <span class="fc" id="L157"> player.setCurrentHealthPoints(player.getHealthPoints());</span> <span class="fc" id="L158"> return;</span> } } <span class="fc" id="L161"> }</span> } </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.11.202310140853</span></div></body></html>