Skip to content

Commit

Permalink
#80 issue. Refactoring and commenting code
Browse files Browse the repository at this point in the history
  • Loading branch information
grambas committed Dec 11, 2017
1 parent 8bcfe04 commit c99398d
Show file tree
Hide file tree
Showing 33 changed files with 1,090 additions and 1,002 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

915 changes: 466 additions & 449 deletions application/.idea/workspace.xml

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions application/app/src/main/java/isdp/guess_a_song/StartScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import isdp.guess_a_song.ui.EditProfile;
import isdp.guess_a_song.ui.JoinGame;
import isdp.guess_a_song.ui.MusicLibrary;
import isdp.guess_a_song.ui.experimental.GameCreationTab;
import isdp.guess_a_song.ui.roomcreation._1HostGame;
import isdp.guess_a_song.ui.roomcreation._4GameRoom;

Expand All @@ -28,7 +27,6 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_start_screen);



/********************************************
* Check and Grand storage access permission
*******************************************/
Expand All @@ -52,9 +50,8 @@ protected void onCreate(Bundle savedInstanceState) {
startActivity(intent);
finish();
}


}

/**
* Storage permission stuff
*
Expand All @@ -73,7 +70,7 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
//SYNC DB SONGS
ContentResolver contentResolver = getContentResolver();
DatabaseHandler db = new DatabaseHandler(this);
MusicLibrary.syncSongToDB(contentResolver,db);
MusicLibrary.syncSongToDB(contentResolver, db);
} else {
Toast.makeText(this, "No Permission Granted. Restart App!", Toast.LENGTH_SHORT).show();
finish();
Expand All @@ -82,6 +79,8 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
}
}
}

//BUTTONS ACTION
public void hostGame(View v) {
Intent intent = new Intent(this, _1HostGame.class);
startActivity(intent);
Expand All @@ -96,6 +95,7 @@ public void MusicLibrary(View v) {
Intent intent = new Intent(this, MusicLibrary.class);
startActivity(intent);
}

public void GameRoomActivity(View v) {
Intent intent = new Intent(this, _4GameRoom.class);
startActivity(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import isdp.guess_a_song.model.Answer;
import isdp.guess_a_song.model.Question;
import isdp.guess_a_song.model.Song;
import isdp.guess_a_song.utils.Constants;

/**
* Created on 10/9/2017, 2:29 PM
Expand All @@ -17,36 +18,36 @@

/**
* This is an answer generator for songs
*
* @Author Mindaugas Milius
*/


public class AnswersGenerator {

/**
*
* @param db
* @param s
* @param type game type (guess Artist or Title)
* @return Full Question object with answers
* @see Question
*/
public static Question generate(DatabaseHandler db, Song s,int type){
public static Question generate(DatabaseHandler db, Song s, int type) {

Answer temp_ans;

List<Song> answer_songs = db.getRandomSongs(s);

ArrayList<Answer> tempAns = new ArrayList<Answer>();
for(int i=0;i<3;i++){
Log.d("AnswersGenerator",answer_songs.get(i).toString());
temp_ans = new Answer(answer_songs.get(i).songToAnswer(type),false);
for (int i = 0; i < 3; i++) {
if (Constants.DEBUG_MODE){Log.d(Constants.LOGT, answer_songs.get(i).toString());}
temp_ans = new Answer(answer_songs.get(i).songToAnswer(type), false);
tempAns.add(temp_ans);
}

tempAns.add(new Answer(s.songToAnswer(type),true));
Question result = new Question(tempAns,type,s);
tempAns.add(new Answer(s.songToAnswer(type), true));
Question result = new Question(tempAns, type, s);

return result;
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public class HostGame extends Observable {
Settings settings;
List<Question> questions;
HashMap<String, UserProfile> players;
HashMap<Integer, Set<String>> already_answered;

//Score score

int status;
int currentIndex;
Expand All @@ -48,8 +45,7 @@ public static HostGame getInstance() {
private HostGame() {
status = Constants.GAME_STATUS_STARTED;
currentIndex = 0;
// scoreMap = null;
players = new HashMap<String,UserProfile>();
players = new HashMap<String, UserProfile>();

questions = null;
settings = null;
Expand All @@ -60,52 +56,47 @@ public int getAns_amount() {
return ans_amount;
}

public void setAns_amount(int ans_amount) {
this.ans_amount = ans_amount;
setChanged();
notifyObservers();
}


public void setCurrentIndex(int currentIndex) {
this.currentIndex = currentIndex;
}

/**
* Methdod to start a game after all game
* creation steps are done and all players joined
* into the room
*/
public void start(){
status = Constants.GAME_STATUS_STARTED;
public void start() {
status = Constants.GAME_STATUS_STARTED;
}

public boolean next_q(){
public boolean next_q() {
ans_amount = 0;
if (currentIndex == questions.size()-1 ) {
if (currentIndex == questions.size() - 1) {
return false;
}
currentIndex++;
setChanged();
notifyObservers();
return true;
}
public void pause(){
status = Constants.GAME_STATUS_PAUSE;

public void pause() {
status = Constants.GAME_STATUS_PAUSE;
}

public Question getCurrentQuestion(){
public Question getCurrentQuestion() {
return questions.get(currentIndex);
}

public int getCurrentIndex(){
public int getCurrentIndex() {
return currentIndex;
}
public String showScore(){

/**
* Function to display current score.
* @return current score as string . Not sorted
*/
public String showScore() {
String scoreString = "Score: \n";
//TODO add sorting
for (UserProfile value : players.values()) {
scoreString += (value.getName() +" : " + value.getScore()+ "\n");
scoreString += (value.getName() + " : " + value.getScore() + "\n");
}
return scoreString;
}
Expand All @@ -115,9 +106,9 @@ public ArrayList<String> showScoreList() {
int score = -1;
for (UserProfile value : players.values()) {

//This should sort the list...using Queue as datastructure might be a better idea...probably
//This should sort the list...using Queue as data structure might be a better idea...probably
if (value.getScore() > score) {
scores.add(0,value.getName() +" : " + value.getScore());
scores.add(0, value.getName() + " : " + value.getScore());
score = value.getScore();
} else {
scores.add(value.getName() + " : " + value.getScore());
Expand All @@ -126,11 +117,10 @@ public ArrayList<String> showScoreList() {
return scores;
}

public void end(){
status = Constants.GAME_STATUS_FINISHED;
public void end() {
status = Constants.GAME_STATUS_FINISHED;
}


public Settings getSettings() {
return settings;
}
Expand All @@ -147,29 +137,41 @@ public void setQuestions(List<Question> questions) {
this.questions = questions;
}

public HashMap<String, UserProfile> getPlayers() {
public HashMap<String, UserProfile> getPlayers() {
return players;
}

public void setPlayers( List<UserProfile> players) {
public void setPlayers(List<UserProfile> players) {
for (UserProfile record : players) {
if(record.isAuth()){
this.players.put(record.getUuid(),record);
if (record.isAuth()) {
this.players.put(record.getUuid(), record);
}
}
}
public void addPlayers( UserProfile player) {
players.put(player.getUuid(),player);

public void addPlayers(UserProfile player) {
players.put(player.getUuid(), player);
}

public boolean processAnswer(String player,int guess,int guess_index){
/**
* Function to calculate points after Player guess
* This function also checks if user is already guessed
* for current question and if so, it won't give points
* for that questions twice.
* @param player
* @param guess
* @param guess_index
* @return true or false if player is already guessed for current question
*/

public boolean processAnswer(String player, int guess, int guess_index) {
boolean result = true;
Log.d(Constants.LOGT, "processAnswer: "+ player);
if(currentIndex == guess_index && players.containsKey(player)){
if(getCurrentQuestion().isNotAnswered(player,guess)){
if( getCurrentQuestion().isCorrect(guess)){
if (Constants.DEBUG_MODE){Log.d(Constants.LOGT, "processAnswer: " + player);}
if (currentIndex == guess_index && players.containsKey(player)) {
if (getCurrentQuestion().isNotAnswered(player, guess)) {
if (getCurrentQuestion().isCorrect(guess)) {
players.get(player).addScore(Constants.REWARD_CORRECT);
}else{
} else {
//decrement?
players.get(player).addScore(Constants.REWARD_WRONG);
}
Expand All @@ -178,40 +180,45 @@ public boolean processAnswer(String player,int guess,int guess_index){
notifyObservers();
}

}else{
result = false;
} else {
result = false;
}
return result;
return result;
}

public int getStatus() {
return status;
}

public void setStatus(int status) {
Log.d(Constants.LOGT, "Game Status changed from "+ this.status + " to "+ status);
if (Constants.DEBUG_MODE){Log.d(Constants.LOGT, "Game Status changed from " + this.status + " to " + status);}
this.status = status;
setChanged();
notifyObservers();
}

public String getHumanStatus(){
if (status == Constants.GAME_STATUS_STARTED){
/**
* Display Game status for user in words
* @return
*/
public String getHumanStatus() {
if (status == Constants.GAME_STATUS_STARTED) {
return "Started";
}else if(status == Constants.GAME_STATUS_FINISHED){
} else if (status == Constants.GAME_STATUS_FINISHED) {
return "Finished";
}else if(status == Constants.GAME_STATUS_ON_QUESTION){
} else if (status == Constants.GAME_STATUS_ON_QUESTION) {
return "On question";
}else if(status == Constants.GAME_STATUS_PAUSE){
} else if (status == Constants.GAME_STATUS_PAUSE) {
return "Paused";
}else if(status == Constants.GAME_STATUS_TIME_OVER){
} else if (status == Constants.GAME_STATUS_TIME_OVER) {
return "Time over";
}else if(status == Constants.GAME_STATUS_READY){
} else if (status == Constants.GAME_STATUS_READY) {
return "Ready";
}else{
} else {
return "not defined";
}
}

@Override
public String toString() {
return "HostGame{" +
Expand Down
Loading

0 comments on commit c99398d

Please sign in to comment.