saintratchet
Lurker
Hi,
I'm developing a version of the Mastermind game as an Android app and I've hit a bit of a wall. I have the game coded out and I have an options menu set up using Shared Preferences but when certain options are selected and I click on play, the app stops working and cuts to a black screen accepting no new input.
The game works perfectly fine when I have selected the option for a 4 Peg code with 4, 5 or 6 colours but when I select a 6 Peg code it only works when I have selected 6 colours. When I select a 6 Peg code with 4 or 5 colours the app stalls as mentioned above.
Any help with this at all would be greatly appreciated, I've been stuck on this for a few days and can't wrap my head around what could be causing the issue.
Here is my onCreate method that takes in the preferences and loads up the necessary button images.
And here is the setColours method
Like I said, any help at all would be appreciated and if anyone needs to see any other classes or methods please just ask and I'd be more than happy to help.
Thanks.
I'm developing a version of the Mastermind game as an Android app and I've hit a bit of a wall. I have the game coded out and I have an options menu set up using Shared Preferences but when certain options are selected and I click on play, the app stops working and cuts to a black screen accepting no new input.
The game works perfectly fine when I have selected the option for a 4 Peg code with 4, 5 or 6 colours but when I select a 6 Peg code it only works when I have selected 6 colours. When I select a 6 Peg code with 4 or 5 colours the app stalls as mentioned above.
Any help with this at all would be greatly appreciated, I've been stuck on this for a few days and can't wrap my head around what could be causing the issue.
Here is my onCreate method that takes in the preferences and loads up the necessary button images.
Code:
MediaPlayer mp;
int codeLength;
int[] code = {0};
ImageButton orangeButton, purpleButton;
private static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); // SHARED PREFERENCES
boolean boo = SP.getBoolean("duplicates", false);
String str = SP.getString("pegs", "1");
String colour = SP.getString("colours", "4");
Log.w(TAG, "Peg number is: " + str + "and Colour number is: " + colour);
if(str.equalsIgnoreCase("1")){
setContentView(R.layout.activity_main);
}
else if(str.equalsIgnoreCase("2"))
setContentView(R.layout.game_6);
else
setContentView(R.layout.activity_main_test);
ImageButton redButton = (ImageButton) findViewById(R.id.redPeg);
redButton.setOnClickListener(this);
ImageButton greenButton = (ImageButton) findViewById(R.id.greenPeg);
greenButton.setOnClickListener(this);
ImageButton blueButton = (ImageButton) findViewById(R.id.bluePeg);
blueButton.setOnClickListener(this);
ImageButton yellowButton = (ImageButton) findViewById(R.id.yellowPeg);
yellowButton.setOnClickListener(this);
ImageButton codeButton = (ImageButton) findViewById(R.id.CodeButton);
codeButton.setOnClickListener(this);
Button lineButton = (Button) findViewById(R.id.LineButton);
lineButton.setOnClickListener(this);
purpleButton = (ImageButton) findViewById(R.id.purplePeg);
purpleButton.setOnClickListener(this);
orangeButton = (ImageButton) findViewById(R.id.orangePeg);
orangeButton.setOnClickListener(this);
setColourPegs(Integer.parseInt(colour));
Peg.pegFalse();
Code.setDuplicates(boo);
if(str.equalsIgnoreCase("2"))
codeLength = 6;
else
codeLength = 4;
Code.setColours(Integer.parseInt(colour));
Code.setCodeLength(codeLength);
Check.setCodeLength(codeLength);
code = Code.Generate();
}
And here is the setColours method
Code:
public void setColourPegs(int colour){
if(colour == 5){
purpleButton.setBackgroundColor(Color.parseColor("#ffffff"));
purpleButton.setImageResource(R.drawable.purple_peg2);
}
else if (colour == 6){
purpleButton.setBackgroundColor(Color.parseColor("#ffffff"));
purpleButton.setImageResource(R.drawable.purple_peg2);
orangeButton.setBackgroundColor(Color.parseColor("#ffffff"));
orangeButton.setImageResource(R.drawable.orange_peg2);
}
}
Like I said, any help at all would be appreciated and if anyone needs to see any other classes or methods please just ask and I'd be more than happy to help.
Thanks.
