Ok so I finally sat down and started working on my Simon Says game on Android. I feel like I'm going in a pretty bad direction atm but I'm not too commited yet. Here's what I've got so far, along with an explanation:
I run entirely off of a single Activity atm, is this bad?
Code
private int level;
private Vector<Integer> sequence;
private Vector<Integer> playerSequence;
private Random randomInt;
private boolean gameOver;
private TextView txtView;
private Button btnRed;
private Button btnGreen;
private Button btnBlue;
private Button btnYellow;
Most of these are self explanatory, the textview is for testing purposes atm though. My layouts are xml configured.
My onCreate():
Code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
level = 0;
sequence = new Vector<Integer>();
playerSequence = new Vector<Integer>();
gameOver = false;
txtView = (TextView)findViewById(R.id.txtView);
btnRed = (Button)findViewById(R.id.redButton);
btnBlue = (Button)findViewById(R.id.blueButton);
btnGreen = (Button)findViewById(R.id.greenButton);
btnYellow = (Button)findViewById(R.id.yellowButton);
randomInt = new Random();
Toast toast = Toast.makeText(getApplicationContext(), "The Game Will Now Show You /n" +
"A Sequence Of Colors.", Toast.LENGTH_LONG);
toast.show();
startSequence();
}
An example of a button's onClick() function:
Code
public void onBtnRedClicked(View v){
playerSequence.add(1);
}
And my sequencing function:
Code
public void startSequence(){
++level;
sequence.clear();
while(sequence.size() != level){
int i = randomInt.nextInt(3) + 1;
Toast toast = Toast.makeText(getApplicationContext(), i, Toast.LENGTH_LONG);
toast.show();
sequence.add(i);
}
}
I don't have any design plan towards this, I'm just going in with my pants down basically. I think most of the above code makes sense, if there's any questions please ask.
My concern is the following; I'm not sure how to leave a window of time for the player to press the right sequence of buttons after the startSequence() function has run. I think once that's out of the way, a quick comparison of both vectors side by side to see if the integers match. If they all do, you run startSequence() again, if they don't well, gameOver, reset all variables, etc. Lmk what you guys think.
/e I messed up the text in the Toast at the beginning -.- Just noticed
This post was edited by SCVonSteroids on Feb 22 2014 12:54pm