//*****************************************************************************************************************************
//
// GameOperation.java Author: [name] Date: [date]
//
// Purpose: basic operations for matching game (lab 2)
//*****************************************************************************************************************************
import java.util.Random;
public class GameOperation
{
//declare variables (complete)
private Match current;
int a=0,b=0;
Random ran = new Random();
/*
* Constructor initializes variables to beginning of game
* -first is the first match of the game
*/
public GameOperation(Match first)
{
current = first;
a=0;
}
/* (complete)
* Update current match to the given match
*/
public void nextMatch(Match m)
{
current =m;
a++;
}
/* (complete)
* Return total matches played of the game
*/
public int getTotalMatches()
{
return a;
}
/* (complete)
* Return number of correct matches
*/
public int getCorrectMatches()
{
return b;
}
/* (complete)
* Return percentage of correct guesses to total guesses (as a percent, not as a decimal)
*/
public double getWinPercent()
{
return ((b*100)/a);
}
/* (complete)
* Return a random integer between 4 and 22 (decides next match)
*/
public int getNumber()
{
return ran.nextInt(18)+4;
}
/* (complete)
* Get filename of picture of current match
*/
public String getFileName()
{
return current.getFileName();
}
/*
* Return first choice of current match
*/
public String getFirst()
{
return current.getChoiceOne();
}
/* (complete)
* Return second choice of current match
*/
public String getSecond()
{
return current.getChoiceTwo();
}
/* (complete)
* Return third choice of current match
*/
public String getThird()
{
return current.getChoiceThree();
}
/* (complete)
* Return fourth choice of current match
*/
public String getFourth()
{
return current.getChoiceFour();
}
/* (complete)
* Determine if the given guess is equal to answer of the current match
* -update total matches played
* -return true if the guess is correct, false if not correct
*/
public boolean checkGuess(String guess)
{
if(current.getAnswer()==guess)
{
return true;
}
else
return false;
}
/* (complete)
* Correct guess, add to total correct guesses
*/
public void correct()
{
b++;
}
/* (complete)
* Create a match from the given values
* -return the newly created match
*/
public Match createMatch(String fileName, String choice1, String choice2, String choice3, String choice4, String answer)
{
Match xox = new Match(fileName, choice1, choice2, choice3, choice4, answer);
return xox;
}
}
Lab2 - Part Two
Wednesday, June 18, 2008
Posted by Admin at 10:39 AM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment