Skip to content

Commit

Permalink
hzuapps#5 hzuapps#882 第五次实验+报告修改
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed May 20, 2018
1 parent 3c20ff2 commit 245005a
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class soft1614080902204BActivity extends AppCompatActivity {

Expand All @@ -23,22 +29,91 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View v) {
Intent intent=new Intent(soft1614080902204BActivity.this,soft1614080902204CActivity.class);
startActivity(intent);
intent.putExtra("quan","2");
startActivityForResult(intent,1);
}
});
jiandao.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(soft1614080902204BActivity.this,soft1614080902204CActivity.class);
startActivity(intent);
intent.putExtra("quan","0");
startActivityForResult(intent,1);
}
});
shitou.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(soft1614080902204BActivity.this,soft1614080902204CActivity.class);
startActivity(intent);
intent.putExtra("quan","1");
startActivityForResult(intent,1);
}
});

}
@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==1&&resultCode==2){
String s=data.getStringExtra("jieguo");

if(!s.isEmpty()) {
write(s);
}
refreshHistoricalRecord(s);
}
initHistoricalRecord();
}
private void refreshHistoricalRecord(String msg) //刷新一下记录

{
if(msg==null) return;
TextView textView = (TextView) findViewById(R.id.textview_history);
String s = textView.getText().toString();
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate=df.format(c.getTime());
textView.setText(s+"\n"+formattedDate+":"+msg);
}

private void initHistoricalRecord() //初始化记录
{
TextView textView = (TextView) findViewById(R.id.textview_history);
String s = read();
if(s!=null)
refreshHistoricalRecord(s);
}
public String read() { //读入存储数据
try {
FileInputStream inStream = this.openFileInput("message.txt");
byte[] buffer = new byte[1024];
int hasRead = 0;
StringBuilder sb = new StringBuilder();
while ((hasRead = inStream.read(buffer)) != -1) {
sb.append(new String(buffer, 0, hasRead));
}
inStream.close();
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public void write(String msg){ //写出存储数据
// 步骤1:获取输入值
if(msg == null) return;
try {
// 步骤2:创建一个FileOutputStream对象,MODE_APPEND追加模式
msg += read(); //前面的也读进来
FileOutputStream fos = openFileOutput("storage.txt", MODE_APPEND);
// 步骤3:将获取过来的值放入文件
fos.write(msg.getBytes());
// 步骤4:关闭数据流
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

Original file line number Diff line number Diff line change
@@ -1,19 +1,75 @@
package com.example.gwl20.soft1614080902204;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class soft1614080902204CActivity extends AppCompatActivity {

private Button fanhui;
private TextView jieguo,xx;
String ret;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_soft1614080902204_c);

fanhui=(Button) findViewById(R.id.button_fanhui);
jieguo=(TextView)findViewById(R.id.textview_03_01);
xx=(TextView)findViewById(R.id.textview_03_02);
final Intent intent=getIntent();
String st=intent.getStringExtra("quan");
int s=Integer.parseInt(st);
String sp=null;
if(s==2){
sp="布 ";
}
else if(s==1){
sp="石头";
}
else if(s==0){
sp="剪刀";
}
int x=(int)(Math.random()*3);
String sx=null;
if(x==2){
sx="布 ";
}
else if(x==1){
sx="石头";
}
else if(x==0){
sx="剪刀";
}
if ((s == 0 && x == 1) ||
(s == 1 && x == 2) ||
(s == 2 && x == 0)){
jieguo.setText("^-^ 你输了 真瓜怂");
ret="输了";
}
else if (s == x) {
jieguo.setText("有缘TnT平手,再来");
ret="平手";
}
else {
jieguo.setText("(^v^) oh 你赢了 ");
ret="赢了";
}
xx.setText("你出"+sp+",电脑出"+sx);
ret=xx.getText().toString()+" 因此 "+ret;
fanhui.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent data=new Intent();
data.putExtra("jieguo",ret);
setResult(2,data);
finish();
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,63 @@
android:orientation="vertical"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
tools:layout_editor_absoluteY="0dp"
android:background="#F5fffa">
<ImageView
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_height="250dp"
android:background="@drawable/timg"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_height="wrap_content"
android:text="请选择要出的拳"
android:textColor="#636363"
android:textStyle="bold"
android:textSize="28sp"
android:background="#DB7093"/>
android:background="#F5fffa"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#FFFADC">
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@+id/button_bu"
android:layout_width="125dp"
android:layout_height="50dp"
android:text=""/>
android:text=""
android:textSize="23sp"
android:textStyle="bold"/>

<Button
android:id="@+id/button_jiandao"
android:layout_width="125dp"
android:layout_height="50dp"
android:text="剪刀"/>
android:text="剪刀"
android:textSize="23sp"
android:textStyle="bold"/>

<Button
android:id="@+id/button_shitou"
android:layout_width="125dp"
android:layout_height="50dp"
android:text="石头"/>
android:text="石头"
android:textSize="23sp"
android:textStyle="bold"/>

</LinearLayout>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:text="历史记录:"/>
<TextView
android:id="@+id/textview_history"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="15sp"
android:textColor="#636363"/>
</LinearLayout>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,35 @@
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp"
android:background="#FFFADC">
android:background="#F5ffff">
<TextView
android:layout_marginTop="30dp"
android:id="@+id/textview_03_01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="你赢了!"
android:textStyle="bold"
android:textSize="100sp"/>
android:textSize="35sp"
android:textColor="#EE0000"/>
<TextView
android:layout_marginTop="20dp"
android:id="@+id/textview_03_02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"/>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:layout_marginLeft="250dp"
android:id="@+id/button_fanhui"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="返回"/>

</LinearLayout>
</LinearLayout>

</android.support.design.widget.CoordinatorLayout>
File renamed without changes.
Binary file added soft1614080902204/sy5/tupian5.1.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 soft1614080902204/sy5/tupian5.2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 245005a

Please sign in to comment.