Android Open Source - Werewolf-Android-Client Play






From Project

Back to project page Werewolf-Android-Client.

License

The source code is released under:

Copyright (c) 2013, Timothy Cohen All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...

If you think the Android project Werewolf-Android-Client 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 edu.wm.werewolf_client;
//from www  .  j a  va 2s  .  c o  m
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;

import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class Play extends Activity{
  
  
  
  private String TAG = "Play";
  private Boolean isAlive;
  private Boolean isNight;
  private Boolean isWerewolf;
  private int kills;
  private final Handler myHandler = new Handler();
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play);

    
    final GetAllAlive getAllAlive = new GetAllAlive();
    final IsNight isNightInstance = new IsNight();
    final isWerewolf isWerewolfInstance = new isWerewolf();
    
    Bundle b = this.getIntent().getExtras();
    final String username = b.getString("username");
    final String password = b.getString("password");
       
      
    
    new Thread(new Runnable() {
      @Override
      public void run() {
        isAlive = getAllAlive.isSpecificPlayerAlive(username, username, password);
        if (isAlive){
          Log.i(TAG, username+" is alive");
        }
        else{
          Log.i(TAG, username+" is not alive");
        }
        AccessUI();
      }
    }).start();
    
    new Thread(new Runnable() {
      @Override
      public void run() {
        isWerewolf = isWerewolfInstance.IsWerewolf(username, password);
        if (isWerewolf){
          Log.i(TAG, username+" is a werewolf");
        }
        else{
          Log.i(TAG, username+" is not a werewolf");
        }
        AccessUI();
      }
    }).start();
    
    
    
    new Thread(new Runnable() {
      @Override
      public void run() {
        isNight = isNightInstance.isNight(username, password);
        if (isNight){
          Log.i(TAG, "It is Night");
        }
        else{
          Log.i(TAG, "It is Day");
        }
        AccessUI();
      }
    }).start();
    
  }
  

  private void UpdateUI(){
    TextView isDeadText = (TextView) findViewById(R.id.isAliveText);
    isDeadText.setText("Is Alive: "+isAlive);
    
    TextView statsText = (TextView) findViewById(R.id.statsText);
    statsText.setText("Your Current Statistics");
    
    TextView nightText = (TextView) findViewById(R.id.isNightText);
    nightText.setText("Is It Night?   "+isNight);
    
    TextView werewolfText = (TextView) findViewById(R.id.typeText);
    werewolfText.setText("Is Werewolf?   "+isWerewolf);
    
    
    if (isWerewolf){
      TextView killsText = (TextView) findViewById(R.id.killsText);
      killsText.setText("Number of kills:   "+kills);
    }
    else{
      TextView killsText = (TextView) findViewById(R.id.killsText);
      killsText.setVisibility(View.GONE);
    }
    
  }
  
  final Runnable updateRunnable = new Runnable() {
        public void run() {
            //call the activity method that updates the UI
            UpdateUI();
        }
    };
    
    private void AccessUI()
    {
         //update the UI using the handler and the runnable
         myHandler.post(updateRunnable);

    }
    

  

}




Java Source Code List

edu.wm.werewolf_client.DayTab.java
edu.wm.werewolf_client.FindLocation.java
edu.wm.werewolf_client.GetAllAlive.java
edu.wm.werewolf_client.GetKills.java
edu.wm.werewolf_client.IsNight.java
edu.wm.werewolf_client.KillAttempt.java
edu.wm.werewolf_client.Locate.java
edu.wm.werewolf_client.MainActivity.java
edu.wm.werewolf_client.MainInterface.java
edu.wm.werewolf_client.NightTab.java
edu.wm.werewolf_client.ObatainLocation.java
edu.wm.werewolf_client.Play.java
edu.wm.werewolf_client.Player.java
edu.wm.werewolf_client.Register.java
edu.wm.werewolf_client.Stats.java
edu.wm.werewolf_client.UserTab.java
edu.wm.werewolf_client.UsernameAndPassword.java
edu.wm.werewolf_client.Validate.java
edu.wm.werewolf_client.Vote.java
edu.wm.werewolf_client.isWerewolf.java