Skip to content

Commit

Permalink
Merge pull request #743 from yjf2213939/master
Browse files Browse the repository at this point in the history
#91 #92 #93 #94 #95 #395已完成全部实验
  • Loading branch information
zengsn committed May 12, 2016
2 parents efd71b3 + f913481 commit 9531d3d
Show file tree
Hide file tree
Showing 31 changed files with 740 additions and 0 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package edu.hzuapps.androidworks.homeworks.net1314080903138;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.SystemClock;
import android.os.Bundle;
import android.view.View;
import android.widget.Chronometer;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class Net1314080903138Game extends Activity {

public Net1314080903138Game() {
Game = this;
}

private ImageButton buttonNewGame;
private Net1314080903138ChessBoard Net1314080903138ChessBoard;
private TextView tvBlackCount;
private TextView tvWhiteCount;
private ImageView ivCurrentTurn;
private Chronometer chTime;
private ImageButton buttonRetract;
private ImageButton buttonHint;

public LinearLayout getLlDialog(int i) {
LinearLayout llDialog = null;
switch (i){
case 0:
llDialog = (LinearLayout) getLayoutInflater().inflate(R.layout.net1314080903138draw,null);
break;
case 1:
llDialog = (LinearLayout) getLayoutInflater().inflate(R.layout.net1314080903138black_win,null);
break;
case 2:
llDialog = (LinearLayout) getLayoutInflater().inflate(R.layout.net1314080903138white_win,null);
break;
case 3:
llDialog = (LinearLayout) getLayoutInflater().inflate(R.layout.net1314080903138retract,null);
break;
case 4:
llDialog = (LinearLayout) getLayoutInflater().inflate(R.layout.net1314080903138new_game_layout,null);
break;
case 5:
llDialog = (LinearLayout) getLayoutInflater().inflate(R.layout.net1314080903138pass,null);
break;
default:
break;
}
return llDialog;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.net1314080903138activity_game);

Net1314080903138ChessBoard = (Net1314080903138ChessBoard) findViewById(R.id.ChessBoard);
buttonNewGame = (ImageButton) findViewById(R.id.new_game);
tvBlackCount = (TextView) findViewById(R.id.black_count);
tvWhiteCount = (TextView) findViewById(R.id.white_count);
ivCurrentTurn = (ImageView) findViewById(R.id.current_turn);
chTime = (Chronometer) findViewById(R.id.cosumed_time);
buttonRetract = (ImageButton) findViewById(R.id.retract);
buttonHint = (ImageButton) findViewById(R.id.ButtonHint);

toast = Toast.makeText(this, "Only one move can be retracted!", Toast.LENGTH_SHORT);
toast2 = Toast.makeText(this,"Please put the first move!",Toast.LENGTH_SHORT);

chTime.setFormat("Timing: %s");
chTime.setBase(SystemClock.elapsedRealtime());
chTime.start();

buttonHint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Net1314080903138ChessBoard.hint_switch();
}
});

buttonNewGame.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setNotfirstStep(false);
LinearLayout ll = getLlDialog(4);

AlertDialog.Builder builder = new AlertDialog.Builder(Net1314080903138Game.this);
builder.setMessage("Are you sure to start a new game?");
builder.setView(ll);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Net1314080903138ChessBoard.startNewGame();
}
});

builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
});

buttonRetract.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!notfirstStep){
toast2.show();
return;
}
retractCount++;

if(retractCount>=2){
toast.show();
}
else {
LinearLayout ll = getLlDialog(3);

AlertDialog.Builder builder = new AlertDialog.Builder(Net1314080903138Game.this);
builder.setMessage("Are you sure to retract?");
builder.setView(ll);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Net1314080903138ChessBoard.retract();
dialog.dismiss();
}
});

builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
retractCount--;
dialog.dismiss();
}
});
builder.create().show();
}

}
});
}

public void clearRecord(){
tvBlackCount.setText("2");
tvWhiteCount.setText("2");
ivCurrentTurn.setImageResource(R.drawable.net13140803138black_chess);
chTime.setBase(SystemClock.elapsedRealtime());
chTime.start();
}

public void setIvCurrentTurn(int n){
ivCurrentTurn.setImageResource(chessColor[n]);
}

public void setTvBlackCount(int n){
tvBlackCount.setText(n+"");
}

public void setTvWhiteCount(int n){
tvWhiteCount.setText(n+"");
}

private static int[] chessColor = new int[] {0,R.drawable.net13140803138black_chess,R.drawable.net13140803138white_chess};
private static Net1314080903138Game Game;

public void setRetractCount(int retractCount) {
this.retractCount = retractCount;
}

private int retractCount=0;

public void setNotfirstStep(boolean b){ notfirstStep = b;}
private Toast toast,toast2;
private boolean notfirstStep=false;

public static Net1314080903138Game getGame() {
return Game;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package edu.hzuapps.androidworks.homeworks.net1314080903138;

/**
* Created by Administrator on 2016/4/26.
*/
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;

public class Net1314080903138Sound extends Service {
private MediaPlayer mp;


@Override
public void onCreate() {
super.onCreate();
mp = MediaPlayer.create(this, R.raw.net1314080903138dididi);
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.start();
mp.setLooping(true);
}
});

}

@Override
public void onDestroy() {
super.onDestroy();
mp.release();
stopSelf();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//boolean playing = intent.getBooleanExtra("playing", false);
//if (playing) {
if(!mp.isPlaying()){
mp.start();
}
return START_STICKY;
// //} else {
// mp.pause();
// }
//return super.onStartCommand(intent, flags, startId);
}



@Override
public IBinder onBind(Intent intent) {
return null;
}

}
Binary file added app/src/main/res/drawable/net13140803138a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/net13140803138b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/net13140803138bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/net13140803138c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/net13140803138hint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/net13140803138icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/net13140803138left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/net13140803138name.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/net13140803138pass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/net13140803138q.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/net13140803138start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/net13140803138top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/net13140803138vs2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/net13140803138win.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/raw/net1314080903138dididi.mp3
Binary file not shown.
8 changes: 8 additions & 0 deletions app/src/main/res/values-w820dp/net1314080903138styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<resources>>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>
8 changes: 8 additions & 0 deletions app/src/main/res/values/net13140803138dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="width_of_chess1">40dp</dimen>
<dimen name="chess_margin1">5dp</dimen>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/net1314080903138colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#CCCC66</color>
<color name="colorPrimaryDark">#000000</color>
<color name="colorAccent">#FF4081</color>
</resources>
9 changes: 9 additions & 0 deletions app/src/main/res/values/net1314080903138strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<resources>
<string name="app_name">yjf黑白棋</string>
<string name="white">WHITE :</string>
<string name="X">X</string>
<string name="Retract">Retract</string>
<string name="hint">Hint Switch</string>
<string name="New_Game">New Game</string>
<string name="title_activity_game">Game</string>
</resources>
17 changes: 17 additions & 0 deletions app/src/main/res/values/net1314080903138styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

0 comments on commit 9531d3d

Please sign in to comment.