Skip to content

Commit

Permalink
* dev 7
Browse files Browse the repository at this point in the history
* documentation
  • Loading branch information
osamaz26 committed Feb 22, 2019
1 parent 804fad2 commit c92e9b5
Show file tree
Hide file tree
Showing 20 changed files with 454 additions and 3 deletions.
34 changes: 34 additions & 0 deletions src/oz222am_hangman/Models/Games/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

import oz222am_hangman.Models.Words.Word;

/**
* The type Game.
*/
public class Game {
private Word word;
private char[] chars;
private int failedTries = 0;
private int totalTires = 0;


/**
* Instantiates a new Game.
*
* @param word the word
*/
public Game(Word word) {
this.word = word;
prepare();
Expand All @@ -21,6 +29,12 @@ private void prepare() {
}
}

/**
* Verify boolean.
*
* @param c the c
* @return the boolean
*/
public boolean verify(char c) {
++totalTires;
boolean result = false;
Expand All @@ -38,6 +52,11 @@ public boolean verify(char c) {

}

/**
* Display string.
*
* @return the string
*/
public String display() {
StringBuilder result = new StringBuilder();
for (var character : chars) {
Expand All @@ -46,14 +65,29 @@ public String display() {
return result.toString();
}

/**
* Is solved boolean.
*
* @return the boolean
*/
public boolean isSolved() {
return String.valueOf(chars).equals(word.getValue());
}

/**
* Gets failed tries.
*
* @return the failed tries
*/
public int getFailedTries() {
return failedTries;
}

/**
* Gets total tires.
*
* @return the total tires
*/
public int getTotalTires() {
return totalTires;
}
Expand Down
60 changes: 60 additions & 0 deletions src/oz222am_hangman/Models/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,114 @@
import java.util.List;
import java.util.Map;

/**
* The type Items.
*
* @param <T> the type parameter
*/
public abstract class Items<T extends Model> {
private int index;
private Map<Integer, T> list;
private String path;

/**
* Instantiates a new Items.
*/
public Items() {
list = new HashMap<>();
}

/**
* Remove.
*
* @param id the id
* @throws Exception the exception
*/
public void remove(int id) throws Exception {
if (!list.containsKey(id)) {
throw new Exception("Option not found");
}
list.remove(id);
}

/**
* Add t.
*
* @param item the item
* @return the t
*/
public T add(T item) {
list.put(index++, item);
return item;
}

/**
* Add.
*
* @param items the items
*/
public void add(List<T> items) {
for (T item : items) {
list.put(item.getId(), item);
}
}


/**
* Gets values.
*
* @return the values
*/
public Collection<T> getValues() {
return list.values();
}

/**
* Gets size.
*
* @return the size
*/
public int getSize() {
return list.size();
}

/**
* Load.
*
* @throws Exception the exception
*/
public abstract void load() throws Exception;

/**
* Save.
*
* @throws Exception the exception
*/
public abstract void save() throws Exception;

/**
* Gets path.
*
* @return the path
*/
public String getPath() {
return path;
}

/**
* Sets path.
*
* @param path the path
*/
public void setPath(String path) {
this.path = path;
}

/**
* Is empty boolean.
*
* @return the boolean
*/
public boolean isEmpty() {
return list.isEmpty();
}
Expand Down
13 changes: 13 additions & 0 deletions src/oz222am_hangman/Models/Model.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
package oz222am_hangman.Models;

/**
* The type Model.
*/
public abstract class Model {
private int id;

/**
* Gets id.
*
* @return the id
*/
public int getId() {
return id;
}

/**
* Sets id.
*
* @param id the id
*/
public void setId(int id) {
this.id = id;
}
Expand Down
23 changes: 23 additions & 0 deletions src/oz222am_hangman/Models/Players/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,48 @@

import oz222am_hangman.Models.Model;

/**
* The type Player.
*/
public class Player extends Model {
private String name;


/**
* Instantiates a new Player.
*/
public Player() {

}

/**
* Gets name.
*
* @return the name
*/
public String getName() {
return name;
}

/**
* Sets name.
*
* @param name the name
* @throws Exception the exception
*/
public void setName(String name) throws Exception {
if (!validateName(name)) {
throw new Exception("invalid name");
}
this.name = name;
}

/**
* Validate name boolean.
*
* @param name the name
* @return the boolean
*/
public boolean validateName(String name) {
return !name.isEmpty();
}
Expand Down
13 changes: 13 additions & 0 deletions src/oz222am_hangman/Models/Players/Players.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
import java.util.Iterator;
import java.util.List;

/**
* The type Players.
*/
public class Players extends Items<Player> {

/**
* Instantiates a new Players.
*/
Players() {
super();
}
Expand Down Expand Up @@ -79,6 +85,13 @@ public void save() throws Exception {

}

/**
* Register player.
*
* @param name the name
* @return the player
* @throws Exception the exception
*/
public Player register(String name) throws Exception {
var player = new Player();
player.setName(name);
Expand Down
17 changes: 17 additions & 0 deletions src/oz222am_hangman/Models/Words/Word.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

import oz222am_hangman.Models.Model;

/**
* The type Word.
*/
public class Word extends Model {
private String value;

/**
* Instantiates a new Word.
*/
public Word() {

}
Expand All @@ -14,10 +20,21 @@ private boolean validateValue(String word) {
}


/**
* Gets value.
*
* @return the value
*/
public String getValue() {
return value;
}

/**
* Sets value.
*
* @param value the value
* @throws Exception the exception
*/
public void setValue(String value) throws Exception {
if (!validateValue(value)) {
throw new Exception("invalid word");
Expand Down
32 changes: 32 additions & 0 deletions src/oz222am_hangman/Models/Words/Words.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,27 @@
import java.util.List;
import java.util.Random;

/**
* The type Words.
*/
public class Words extends Items<Word> {
/**
* The Random.
*/
Random random = new Random();

/**
* Instantiates a new Words.
*/
public Words() {
super();
}

/**
* Instantiates a new Words.
*
* @param path the path
*/
public Words(String path) {
super();
setPath(path);
Expand All @@ -40,19 +54,37 @@ public void save() throws Exception {
bufferedWriter.close();
}

/**
* Add word.
*
* @param value the value
* @return the word
* @throws Exception the exception
*/
public Word add(String value) throws Exception {
var word = new Word();
word.setValue(value);
return super.add(word);
}

/**
* Pick word.
*
* @return the word
* @throws Exception the exception
*/
public Word pick() throws Exception {
if (isEmpty()) {
throw new Exception("Empty list");
}
return (Word) getValues().toArray()[random.nextInt(getSize())];
}

/**
* Get list.
*
* @return the list
*/
public List<Word> get() {
return null;
}
Expand Down
Loading

0 comments on commit c92e9b5

Please sign in to comment.