Android Open Source - tic-tac-toe Name Dialog






From Project

Back to project page tic-tac-toe.

License

The source code is released under:

Copyright (c) 2009 Florida State University. All rights reserved. Developed by: FSU Android Group Florida State University http://www.cs.fsu.edu Permission is hereby gra...

If you think the Android project tic-tac-toe listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fsu.android.tictactoe;
//from www  .j a  v a 2 s  .c om
import fsu.android.tictactoe.Game.Outcome;
import android.app.*;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class NameDialog extends Dialog {

  String name;
  Game parent;
  
  String get_name( ) {
    return name;
  }
  
  public NameDialog(Context context, final Outcome out, final int player_number, final String prev_name, int np) {
    super(context);
    this.setContentView(R.layout.name_dialog);    
    final NameDialog me = this;
    parent = (Game) context;
    
    /* can't get around it */
    setCancelable(false);

    /* get our controls */
    final EditText entry = (EditText) findViewById(R.id.EditText01);
    final Button button = (Button) findViewById(R.id.Button01);
    final TextView heading = (TextView) findViewById(R.id.TextView01);
    
    /* clear the text */
    entry.setText("");
    
    /* set up name we're looking for */
    String h = new String( );
    
    if(player_number == 1) {
      if(out == Outcome.P1_WON) h = "Player 1 (Winner)";
      else if(out == Outcome.CAT) h = "Player 1";
      else h = "Player 1 (Loser)";
    } else {
      if(out == Outcome.P1_WON) h = "Player 2 (Loser)";
      else if(out == Outcome.CAT) h = "Player 2";
      else h = "Player 2 (Winner)";
    }
    
    
    if(np == 1) h = "Player";
      
    heading.setText(h + " Please Enter Your Name:");
    
    button.setOnClickListener(new Button.OnClickListener( ) {
            public void onClick(View v) {
              name = entry.getText( ).toString( );
     
              /* do the callback */
              if(player_number == 1) {
                parent.finishGame(out, player_number + 1, name, "");
              } else {
                parent.finishGame(out, player_number + 1, prev_name, name);
              }
              me.dismiss( );
            }
        });
    
  }
}




Java Source Code List

fsu.android.tictactoe.Game.java
fsu.android.tictactoe.NameDialog.java
fsu.android.tictactoe.StatsDatabase.java
fsu.android.tictactoe.StatsView.java
fsu.android.tictactoe.TicTacToe.java