gpt4 book ai didi

java - : Hand over points to GameOverActivity

转载 作者:行者123 更新时间:2023-12-02 11:42:15 25 4
gpt4 key购买 nike

我有一个 GameActivity 和一个 GameOverActivity。我将游戏积分保存在 GameActivity 中,但会在 GameOverActivity 中显示这些积分。我必须做什么?我的游戏 Activity :

 public void finishGameActivity(){
Intent intent = new Intent(this, GameOverActivity.class);
intent.putExtra("points", points);
Intent i = getIntent();
setResult(Activity.RESULT_OK, i);
finish();
}

public void setPoints(){
points++;
TextView points_show = (TextView) findViewById(R.id.points);
points_show.setText("Points: " + points);
}


public class GameOverActivity extends AppCompatActivity {
private int points;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_over);
changeFont();
TextView points = (TextView) findViewById(R.id.point_stats);
}

private void changeFont(){
TextView gameover = (TextView) findViewById(R.id.gameover);
Typeface custom_font = Typeface.createFromAsset(getAssets(),
"fonts/font.ttf");
gameover.setTypeface(custom_font);
}
}

最佳答案

您可以使用sharedPreferences全局保存您当前的分数。否则,如果您只想通过 Intent 传递分数,请在目标 Intent 中使用 .GetExtras()

关于java - : Hand over points to GameOverActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48469237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com