From f25fba888739b8076864e4b023964a046ce593f7 Mon Sep 17 00:00:00 2001
From: Julie CONTE <jconte@ippon.fr>
Date: Mon, 17 Aug 2020 19:03:54 +0200
Subject: [PATCH] Initial version

---
 ugly-trivia/.gitlab-ci.yml                    |  11 ++
 ugly-trivia/README.md                         |  11 ++
 ugly-trivia/pom.xml                           |  39 ++++
 .../games/trivia/runner/GameRunner.java       |  36 ++++
 .../adaptionsoft/games/uglytrivia/Game.java   | 169 ++++++++++++++++++
 .../adaptionsoft/games/trivia/SomeTest.java   |  13 ++
 6 files changed, 279 insertions(+)
 create mode 100644 ugly-trivia/.gitlab-ci.yml
 create mode 100644 ugly-trivia/README.md
 create mode 100644 ugly-trivia/pom.xml
 create mode 100644 ugly-trivia/src/main/java/com/adaptionsoft/games/trivia/runner/GameRunner.java
 create mode 100644 ugly-trivia/src/main/java/com/adaptionsoft/games/uglytrivia/Game.java
 create mode 100644 ugly-trivia/src/test/java/com/adaptionsoft/games/trivia/SomeTest.java

diff --git a/ugly-trivia/.gitlab-ci.yml b/ugly-trivia/.gitlab-ci.yml
new file mode 100644
index 00000000..b7ddbe51
--- /dev/null
+++ b/ugly-trivia/.gitlab-ci.yml
@@ -0,0 +1,11 @@
+package-ugly-trivia:
+  variables:
+    PROJECT_FOLDER: "ugly-trivia"
+  extends: .java
+  only:
+    refs:
+      - master
+      - merge_requests
+    changes:
+      - ".gitlab-common-ci.yml"
+      - "ugly-trivia/**/*"
diff --git a/ugly-trivia/README.md b/ugly-trivia/README.md
new file mode 100644
index 00000000..7b33ed15
--- /dev/null
+++ b/ugly-trivia/README.md
@@ -0,0 +1,11 @@
+# String calculator
+
+Revue d'[UglyTrivia](/uglyTrivia). 
+
+Dans le cadre d'un programme de mentoring interne (BlackBelt) Julie a fait une résolution du kata ugly trivia. Pendant ce live, Julie et Colin (son mentor) vont faire une revue de cette résolution.
+
+-   **Auteurs** : Colin DAMON et Julie CONTE
+-   **Date** : 19/09/2020
+-   **Langage** : Java
+-   **Niveau** : Moyen
+-   **Replay** : 
diff --git a/ugly-trivia/pom.xml b/ugly-trivia/pom.xml
new file mode 100644
index 00000000..f9de2335
--- /dev/null
+++ b/ugly-trivia/pom.xml
@@ -0,0 +1,39 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>com.adaptionsoft.games</groupId>
+    <artifactId>uglytrivia</artifactId>
+    <packaging>jar</packaging>
+    <version>1.0-SNAPSHOT</version>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.8.2</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <version>2.5</version>
+                <configuration>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.3.2</version>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/ugly-trivia/src/main/java/com/adaptionsoft/games/trivia/runner/GameRunner.java b/ugly-trivia/src/main/java/com/adaptionsoft/games/trivia/runner/GameRunner.java
new file mode 100644
index 00000000..ed99a9ae
--- /dev/null
+++ b/ugly-trivia/src/main/java/com/adaptionsoft/games/trivia/runner/GameRunner.java
@@ -0,0 +1,36 @@
+
+package com.adaptionsoft.games.trivia.runner;
+import java.util.Random;
+
+import com.adaptionsoft.games.uglytrivia.Game;
+
+
+public class GameRunner {
+
+	private static boolean notAWinner;
+
+	public static void main(String[] args) {
+		Game aGame = new Game();
+		
+		aGame.add("Chet");
+		aGame.add("Pat");
+		aGame.add("Sue");
+		
+		Random rand = new Random();
+	
+		do {
+			
+			aGame.roll(rand.nextInt(5) + 1);
+			
+			if (rand.nextInt(9) == 7) {
+				notAWinner = aGame.wrongAnswer();
+			} else {
+				notAWinner = aGame.wasCorrectlyAnswered();
+			}
+			
+			
+			
+		} while (notAWinner);
+		
+	}
+}
diff --git a/ugly-trivia/src/main/java/com/adaptionsoft/games/uglytrivia/Game.java b/ugly-trivia/src/main/java/com/adaptionsoft/games/uglytrivia/Game.java
new file mode 100644
index 00000000..f4a3db5a
--- /dev/null
+++ b/ugly-trivia/src/main/java/com/adaptionsoft/games/uglytrivia/Game.java
@@ -0,0 +1,169 @@
+package com.adaptionsoft.games.uglytrivia;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+
+public class Game {
+    ArrayList players = new ArrayList();
+    int[] places = new int[6];
+    int[] purses  = new int[6];
+    boolean[] inPenaltyBox  = new boolean[6];
+    
+    LinkedList popQuestions = new LinkedList();
+    LinkedList scienceQuestions = new LinkedList();
+    LinkedList sportsQuestions = new LinkedList();
+    LinkedList rockQuestions = new LinkedList();
+    
+    int currentPlayer = 0;
+    boolean isGettingOutOfPenaltyBox;
+    
+    public  Game(){
+    	for (int i = 0; i < 50; i++) {
+			popQuestions.addLast("Pop Question " + i);
+			scienceQuestions.addLast(("Science Question " + i));
+			sportsQuestions.addLast(("Sports Question " + i));
+			rockQuestions.addLast(createRockQuestion(i));
+    	}
+    }
+
+	public String createRockQuestion(int index){
+		return "Rock Question " + index;
+	}
+	
+	public boolean isPlayable() {
+		return (howManyPlayers() >= 2);
+	}
+
+	public boolean add(String playerName) {
+		
+		
+	    players.add(playerName);
+	    places[howManyPlayers()] = 0;
+	    purses[howManyPlayers()] = 0;
+	    inPenaltyBox[howManyPlayers()] = false;
+	    
+	    System.out.println(playerName + " was added");
+	    System.out.println("They are player number " + players.size());
+		return true;
+	}
+	
+	public int howManyPlayers() {
+		return players.size();
+	}
+
+	public void roll(int roll) {
+		System.out.println(players.get(currentPlayer) + " is the current player");
+		System.out.println("They have rolled a " + roll);
+		
+		if (inPenaltyBox[currentPlayer]) {
+			if (roll % 2 != 0) {
+				isGettingOutOfPenaltyBox = true;
+				
+				System.out.println(players.get(currentPlayer) + " is getting out of the penalty box");
+				places[currentPlayer] = places[currentPlayer] + roll;
+				if (places[currentPlayer] > 11) places[currentPlayer] = places[currentPlayer] - 12;
+				
+				System.out.println(players.get(currentPlayer) 
+						+ "'s new location is " 
+						+ places[currentPlayer]);
+				System.out.println("The category is " + currentCategory());
+				askQuestion();
+			} else {
+				System.out.println(players.get(currentPlayer) + " is not getting out of the penalty box");
+				isGettingOutOfPenaltyBox = false;
+				}
+			
+		} else {
+		
+			places[currentPlayer] = places[currentPlayer] + roll;
+			if (places[currentPlayer] > 11) places[currentPlayer] = places[currentPlayer] - 12;
+			
+			System.out.println(players.get(currentPlayer) 
+					+ "'s new location is " 
+					+ places[currentPlayer]);
+			System.out.println("The category is " + currentCategory());
+			askQuestion();
+		}
+		
+	}
+
+	private void askQuestion() {
+		if (currentCategory() == "Pop")
+			System.out.println(popQuestions.removeFirst());
+		if (currentCategory() == "Science")
+			System.out.println(scienceQuestions.removeFirst());
+		if (currentCategory() == "Sports")
+			System.out.println(sportsQuestions.removeFirst());
+		if (currentCategory() == "Rock")
+			System.out.println(rockQuestions.removeFirst());		
+	}
+	
+	
+	private String currentCategory() {
+		if (places[currentPlayer] == 0) return "Pop";
+		if (places[currentPlayer] == 4) return "Pop";
+		if (places[currentPlayer] == 8) return "Pop";
+		if (places[currentPlayer] == 1) return "Science";
+		if (places[currentPlayer] == 5) return "Science";
+		if (places[currentPlayer] == 9) return "Science";
+		if (places[currentPlayer] == 2) return "Sports";
+		if (places[currentPlayer] == 6) return "Sports";
+		if (places[currentPlayer] == 10) return "Sports";
+		return "Rock";
+	}
+
+	public boolean wasCorrectlyAnswered() {
+		if (inPenaltyBox[currentPlayer]){
+			if (isGettingOutOfPenaltyBox) {
+				System.out.println("Answer was correct!!!!");
+				purses[currentPlayer]++;
+				System.out.println(players.get(currentPlayer) 
+						+ " now has "
+						+ purses[currentPlayer]
+						+ " Gold Coins.");
+				
+				boolean winner = didPlayerWin();
+				currentPlayer++;
+				if (currentPlayer == players.size()) currentPlayer = 0;
+				
+				return winner;
+			} else {
+				currentPlayer++;
+				if (currentPlayer == players.size()) currentPlayer = 0;
+				return true;
+			}
+			
+			
+			
+		} else {
+		
+			System.out.println("Answer was corrent!!!!");
+			purses[currentPlayer]++;
+			System.out.println(players.get(currentPlayer) 
+					+ " now has "
+					+ purses[currentPlayer]
+					+ " Gold Coins.");
+			
+			boolean winner = didPlayerWin();
+			currentPlayer++;
+			if (currentPlayer == players.size()) currentPlayer = 0;
+			
+			return winner;
+		}
+	}
+	
+	public boolean wrongAnswer(){
+		System.out.println("Question was incorrectly answered");
+		System.out.println(players.get(currentPlayer)+ " was sent to the penalty box");
+		inPenaltyBox[currentPlayer] = true;
+		
+		currentPlayer++;
+		if (currentPlayer == players.size()) currentPlayer = 0;
+		return true;
+	}
+
+
+	private boolean didPlayerWin() {
+		return !(purses[currentPlayer] == 6);
+	}
+}
diff --git a/ugly-trivia/src/test/java/com/adaptionsoft/games/trivia/SomeTest.java b/ugly-trivia/src/test/java/com/adaptionsoft/games/trivia/SomeTest.java
new file mode 100644
index 00000000..6c8c4149
--- /dev/null
+++ b/ugly-trivia/src/test/java/com/adaptionsoft/games/trivia/SomeTest.java
@@ -0,0 +1,13 @@
+package com.adaptionsoft.games.trivia;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class SomeTest {
+
+	@Test
+	public void true_is_true() throws Exception {
+		assertTrue(false);
+	}
+}
-- 
GitLab