-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #743 from yjf2213939/master
- Loading branch information
Showing
31 changed files
with
740 additions
and
0 deletions.
There are no files selected for viewing
446 changes: 446 additions & 0 deletions
446
.../java/edu/hzuapps/androidworks/homeworks/net1314080903138/Net1314080903138ChessBoard.java
Large diffs are not rendered by default.
Oops, something went wrong.
189 changes: 189 additions & 0 deletions
189
...c/main/java/edu/hzuapps/androidworks/homeworks/net1314080903138/Net1314080903138Game.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
.../main/java/edu/hzuapps/androidworks/homeworks/net1314080903138/Net1314080903138Sound.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
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.
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.
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.
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |