forked from hzuapps/android-labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
466 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901229/DBhelper.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,38 @@ | ||
package com.example.administrator.fingergame; | ||
|
||
import android.content.Context; | ||
import android.database.DatabaseErrorHandler; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
|
||
/** | ||
* Created by Administrator on 2016/6/18. | ||
*/ | ||
public class DBhelper extends SQLiteOpenHelper { | ||
public DBhelper(Context context) { | ||
super(context, null, null, 1); | ||
} | ||
|
||
public DBhelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler) { | ||
super(context, name, factory, version, errorHandler); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) { | ||
String sql = "create table IF NOT EXISTS guess(all_data text not null," + | ||
"win_data text not null,fail_data text not null,ping_data text not null)"; | ||
String sql1 = "insert into user values ('33','11','22','44')"; | ||
String sql2 = "insert into user values ('11','22','44','55')"; | ||
|
||
db.execSQL(sql); | ||
// db.execSQL(sql1); | ||
// db.execSQL(sql2); | ||
|
||
|
||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
|
||
} | ||
} |
140 changes: 140 additions & 0 deletions
140
app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901229/Game.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,140 @@ | ||
package com.example.administrator.fingergame; | ||
|
||
import android.app.Activity; | ||
import android.content.ContentValues; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import java.util.Random; | ||
|
||
/** | ||
* Created by Administrator on 2016/6/18. | ||
*/ | ||
public class Game extends Activity { | ||
public int dn=0; | ||
public Random r; | ||
Button bt1,bt2,bt3; | ||
ImageView imageView; | ||
TextView tv; | ||
public static int win; | ||
public static int fail; | ||
public static int ping; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.game); | ||
|
||
bt1=(Button)findViewById(R.id.bt1); | ||
bt2=(Button)findViewById(R.id.bt2); | ||
bt3=(Button)findViewById(R.id.bt3); | ||
imageView=(ImageView)findViewById(R.id.im1); | ||
tv=(TextView)findViewById(R.id.tv1); | ||
bt1.setOnClickListener(new ButtonListener()); | ||
bt2.setOnClickListener(new ButtonListener()); | ||
bt3.setOnClickListener(new ButtonListener()); | ||
|
||
|
||
|
||
|
||
} | ||
|
||
@Override | ||
public void onBackPressed() { | ||
super.onBackPressed(); | ||
int all=win+fail+ping; | ||
DBhelper dBhelper=new DBhelper(Game.this); | ||
SQLiteDatabase db=dBhelper.getWritableDatabase(); | ||
ContentValues cv=new ContentValues(); | ||
cv.put("all_data","1"); | ||
cv.put("win_data","2"); | ||
cv.put("fail_data", "3"); | ||
cv.put("ping_data", "4"); | ||
System.out.println(cv.toString()); | ||
long id = db.insert("guess", null, cv); | ||
System.out.println("longid:"+id); | ||
|
||
|
||
} | ||
|
||
private class ButtonListener implements View.OnClickListener { | ||
|
||
@Override | ||
public void onClick(View v) { | ||
|
||
switch (v.getId()){ | ||
case R.id.bt1://0 | ||
r= new Random(); | ||
dn=r.nextInt(3); //0为石头。1为剪刀,2为布 | ||
switch (dn){ | ||
case 0: | ||
imageView.setBackgroundResource(R.drawable.shitou); | ||
tv.setText("平局"); | ||
ping++; | ||
break; | ||
case 1: | ||
imageView.setBackgroundResource(R.drawable.jiandao); | ||
tv.setText("你赢了"); | ||
win++; | ||
break; | ||
case 2: | ||
imageView.setBackgroundResource(R.drawable.bu); | ||
tv.setText("你输了"); | ||
fail++; | ||
break; | ||
} | ||
|
||
|
||
|
||
break; | ||
case R.id.bt2://1 | ||
r= new Random(); | ||
dn=r.nextInt(3); //0为石头。1为剪刀,2为布 | ||
switch (dn) { | ||
case 0: | ||
imageView.setBackgroundResource(R.drawable.shitou); | ||
tv.setText("你输了"); | ||
fail++; | ||
break; | ||
case 1: | ||
imageView.setBackgroundResource(R.drawable.jiandao); | ||
tv.setText("平局"); | ||
ping++; | ||
break; | ||
case 2: | ||
imageView.setBackgroundResource(R.drawable.bu); | ||
tv.setText("你赢了"); | ||
win++; | ||
break; | ||
} | ||
break; | ||
case R.id.bt3://2 | ||
r= new Random(); | ||
dn=r.nextInt(3); //0为石头。1为剪刀,2为布 | ||
switch (dn) { | ||
case 0: | ||
imageView.setBackgroundResource(R.drawable.shitou); | ||
tv.setText("你赢了"); | ||
win++; | ||
break; | ||
case 1: | ||
imageView.setBackgroundResource(R.drawable.jiandao); | ||
tv.setText("你输了"); | ||
fail++; | ||
break; | ||
case 2: | ||
imageView.setBackgroundResource(R.drawable.bu); | ||
tv.setText("平局"); | ||
ping++; | ||
break; | ||
} | ||
break; | ||
} | ||
|
||
|
||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901229/GameData.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,46 @@ | ||
package com.example.administrator.fingergame; | ||
|
||
import android.app.Activity; | ||
import android.database.Cursor; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.os.Bundle; | ||
import android.widget.TextView; | ||
|
||
/** | ||
* Created by Administrator on 2016/6/18. | ||
*/ | ||
public class GameData extends Activity { | ||
String win; | ||
String fail; | ||
String ping; | ||
String all; | ||
String winlu; | ||
TextView tv; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.data_layout); | ||
|
||
|
||
DBhelper dbHelper = new DBhelper(GameData.this); | ||
SQLiteDatabase readdb = dbHelper.getReadableDatabase(); | ||
Cursor c = readdb.query("guess", null, null, null, null, null, null); | ||
while (c.moveToNext()) { | ||
all = c.getString(c.getColumnIndex("all_data")); | ||
win = c.getString(c.getColumnIndex("win_data")); | ||
fail = c.getString(c.getColumnIndex("fail_data")); | ||
ping = c.getString(c.getColumnIndex("ping_data")); | ||
|
||
// System.out.println("摇一摇:"+String.format("win=%s,fail=%s,ping=%s",win,fail,ping)); | ||
System.out.println("Game_data all:" + all + "win:" + win); | ||
} | ||
readdb.close(); | ||
|
||
} | ||
|
||
// tv.setText("胜率:"+ping+"负:"+fail); | ||
|
||
|
||
|
||
} | ||
|
43 changes: 43 additions & 0 deletions
43
app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901229/MainActivity.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,43 @@ | ||
package com.example.administrator.fingergame; | ||
|
||
import android.content.Intent; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity); | ||
Button bt1,bt2,bt3; | ||
bt1=(Button)findViewById(R.id.bt1); | ||
bt2=(Button)findViewById(R.id.bt2); | ||
bt3=(Button)findViewById(R.id.bt3); | ||
bt1.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Intent i=new Intent(); | ||
i.setClass(MainActivity.this,Game.class); | ||
startActivity(i); | ||
|
||
} | ||
}); | ||
bt2.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Intent i2=new Intent(); | ||
i2.setClass(MainActivity.this,GameData.class); | ||
startActivity(i2); | ||
} | ||
}); | ||
bt3.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
MainActivity.this.finish(); | ||
} | ||
}); | ||
} | ||
} |
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,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" | ||
android:layout_height="match_parent" tools:context=".MainActivity"> | ||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/bt1" | ||
android:background="@drawable/bluebtn" | ||
android:text="开始游戏" | ||
android:layout_alignParentTop="true" | ||
android:layout_alignLeft="@+id/bt3" | ||
android:layout_alignStart="@+id/bt3" | ||
android:layout_marginTop="134dp" /> | ||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/bt2" | ||
android:background="@drawable/greenbtn" | ||
android:text="游戏数据" | ||
android:layout_below="@+id/bt1" | ||
android:layout_alignLeft="@+id/bt3" | ||
android:layout_alignStart="@+id/bt3" /> | ||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/bt3" | ||
android:background="@drawable/yellowbtn" | ||
android:text="退出游戏" | ||
android:layout_below="@+id/bt2" | ||
android:layout_centerHorizontal="true" /> | ||
|
||
|
||
</RelativeLayout> |
Oops, something went wrong.