简体   繁体   English

如何在二十一点android游戏开发中显示金额

[英]how displaying money amount in blackjack android game development

I'm new to android development and I was just wondering how I should store the money value the player current has? 我是android开发的新手,我只是想知道如何存储玩家当前所拥有的金钱价值? Should i store it as a string in string.xml or should i make it an int in a method? 我应该将其存储为string.xml中的字符串还是应该将其设置为int方法? Also how should i make the deck of cards. 另外,我应该如何制作一副扑克牌。 Should i use an array? 我应该使用数组吗? I was told you shouldnt store it as a string and i dont know how you can display it when you launch the app if its not stored as a string. 有人告诉我,您不应该将其存储为字符串,并且如果不将其存储为字符串,那么在启动应用程序时我不知道如何显示它。 Any help would be greatly appreciated! 任何帮助将不胜感激!

  <TextView
        android:background ="@android:color/white"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/cash"
        android:padding="5dip"
        /> 
 Im currently storing it in a textview

Not sure on the deck of cards, but store the money as a float. 不确定是否在纸牌上,但是将钱作为浮子存储。 It is not an int. 它不是int。 displaying it is simple as since java can make a float a string by simply adding the float to an empty string 显示它很简单,因为java可以通过简单地将浮点数添加到空字符串来使浮点数成为字符串

str = "" + flt; str =“” + flt; complicated? 复杂? How? 怎么样?

protected boolean store_cash(){
   SharedPreferences settings = getSharedPreferences("GENERAL", 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putFloat("cash", mCash);
        return editor.commit();
}
protected void load_cash(){
 SharedPreferences settings = getSharedPreferences("GENERAL", 0);
 mCash = settings.getFloat("cash", (float) 0.0);
}

with that it's just a matter of setting the title of the textview 只需设置textview的标题即可

protected void display_cash(){
    TextView cash = (TextView ) findViewById(R.id.cash);
    cash.setText( "$" + mCash);  //formatting may be required..  google is your friend
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM