Android Open Source - MiReversi Player






From Project

Back to project page MiReversi.

License

The source code is released under:

MIT License

If you think the Android project MiReversi 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

/*
* Copyright (c) 2011 Makoto Ishida//  w  ww .ja  v  a  2  s.co m
* Please see the file MIT-LICENSE.txt for copying permission.
*/

package com.example.mireversi.model;

import android.content.Context;
import com.example.mireversi.Pref;
import com.example.mireversi.model.Cell.E_STATUS;

public abstract class Player {
  
  protected E_STATUS mTurn;
  protected String mName;
  protected Board mBoard;

  private int mProgress;
  private Cell mCurrentCell;
  
  
  public Player(E_STATUS turn, String name, Board board){
    setTurn(turn);
    setName(name);
    mBoard = board;
  }
  
  public abstract boolean isHuman();

  public void setTurn(E_STATUS mTurn) {
    this.mTurn = mTurn;
  }

  public E_STATUS getTurn() {
    return mTurn;
  }

  public void setName(String mName) {
    this.mName = mName;
  }

  public String getName() {
    return mName;
  }
  
  public abstract void startThinking(IPlayerCallback callback);
  public abstract void stopThinking();
  
  private static final Player getPlayer(String name, Board board, E_STATUS turn, String value){
    int int_value = Integer.valueOf(value);
    Player player;
    switch (int_value){
//    case 0: 
//      player = new ComputerPlayerLevel0(turn, name, board);
//      break;
    case 1: 
      player = new ComputerPlayerLevel1(turn, name, board);
      break;
    case 2:
      player = new ComputerPlayerLevel2(turn, name, board);
      break;
    case 3:
      player = new ComputerPlayerLevel3(turn, name, board);
      break;
    default:
      player = new HumanPlayer(turn, name,board);
    }
    return player;
  }
  
  public static final Player getPlayer1(Context con, Board board, E_STATUS turn){
    String name = Pref.getPlayer1Name(con);
    String value = Pref.getPlayer1(con);
    return getPlayer(name, board, turn, value);
  }

  public static final Player getPlayer2(Context con, Board board, E_STATUS turn){
    String name = Pref.getPlayer2Name(con);
    String value = Pref.getPlayer2(con);
    return getPlayer(name, board, turn, value);
  }

  public void setProgress(int mProgress) {
    this.mProgress = mProgress;
  }

  public int getProgress() {
    return mProgress;
  }

  public void setCurrentCell(Cell mCurrentCell) {
    this.mCurrentCell = mCurrentCell;
  }

  public Cell getCurrentCell() {
    return mCurrentCell;
  }

}




Java Source Code List

com.example.mireversi.GameActivity.java
com.example.mireversi.Pref.java
com.example.mireversi.ReversiView.java
com.example.mireversi.Utils.java
com.example.mireversi.exceptions.InvalidMoveException.java
com.example.mireversi.model.Board.java
com.example.mireversi.model.Cell.java
com.example.mireversi.model.ComputerPlayerLevel0.java
com.example.mireversi.model.ComputerPlayerLevel1.java
com.example.mireversi.model.ComputerPlayerLevel2.java
com.example.mireversi.model.ComputerPlayerLevel3.java
com.example.mireversi.model.ComputerPlayer.java
com.example.mireversi.model.HumanPlayer.java
com.example.mireversi.model.IPlayerCallback.java
com.example.mireversi.model.Player.java