游戏金币单位换算管理类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//金币单位
public enum GoldUnit
{
N = 0,
K,
M,
B,
T,
AA,
BB,
CC,
DD,
EE,
FF,
GG,
HH,
II,
JJ,
KK,
LL,
MM,
NN,
OO,
PP,
QQ,
RR,
SS,
TT,
UU,
VV,
WW,
XX,
YY,
ZZ,
}
/// <summary>
/// 金币数量
/// </summary>
public class GoldNum
{
//构造函数
private string goldCountText;
public string GoldCountText
{
get
{
if (goldUnit == 0)
{
goldCountText = ((int)goldValue).ToString();
}
else
{
float tempValue = (float)decimal.Round((decimal)goldValue, 2);
goldCountText = tempValue + ((GoldUnit)goldUnit).ToString();
}
return goldCountText;
}
set { goldCountText = value; }
}
internal int goldUnit;
internal float goldValue;
public GoldNum(string value)
{
value = value.Trim(); //删除字符串首部和尾部的空格
bool isSingleDigit = true;
for (int i = 30; i >= 0; i--)
{
if (value.EndsWith(((GoldUnit)i).ToString()))
{
value = value.Trim(((GoldUnit)i).ToString().ToCharArray());
isSingleDigit = false;
goldUnit = i;
goldValue = float.Parse(value);
break;
}
}
if (isSingleDigit)
{
goldUnit = 0;
goldValue = float.Parse(value);
}
while (goldValue > 500 && goldUnit < 30)
{
goldUnit++;
goldValue /= 1000;
}
while (goldValue > 0 && goldValue < 1 && goldUnit > 0)
{
goldUnit--;
goldValue *= 1000;
}
}
//运算符重写
/*operator是C#、C++和pascal的关键字,它和运算符一起使用,表示一个运算符函数,理解时应将operator和运算符整体上视为一个函数名。
重载运算符的函数一般格式如下
函数类型 operator 运算符名称 (形参表列)
{对运算符的重载处理}
例如,想将“+”用于Complex(复数)的加法运算,函数的原型可以是这样的:
Complex operator + (Complex & c1,Complex &c2);
operator+函数表示对运算符+重载。
其中,operator是关键字,专门用于定义重载运算符的函数的,运算符名称就是C++提供给用户的预定运算符。
注意:函数名是由operator和运算符组成。
*/
public static GoldNum operator +(GoldNum A, GoldNum B)
{
int limit = 4;
int tempUnit = 0;
float tempValue = 0;
if (A.goldUnit == B.goldUnit)
{
tempUnit = A.goldUnit;
tempValue = A.goldValue + B.goldValue;
}
else if (A.goldUnit > B.goldUnit)
{
if (A.goldUnit - B.goldUnit <= limit)
{
tempUnit = A.goldUnit;
tempValue = A.goldValue + B.goldValue / Mathf.Pow(1000, A.goldUnit - B.goldUnit);
}
else if (A.goldUnit - B.goldUnit > limit)
{
tempUnit = A.goldUnit;
tempValue = A.goldValue;
}
}
else if (A.goldUnit < B.goldUnit)
{
if (B.goldUnit - A.goldUnit <= limit)
{
tempUnit = B.goldUnit;
tempValue = A.goldValue / Mathf.Pow(1000, B.goldUnit - A.goldUnit) + B.goldValue;
}
else if (B.goldUnit - A.goldUnit > limit)
{
tempUnit = B.goldUnit;
tempValue = B.goldValue;
}
}
GoldNum result = new GoldNum(tempValue + ((GoldUnit)tempUnit).ToString());
return result;
}
public static GoldNum operator -(GoldNum A, GoldNum B)
{
int limit = 4;
int tempUnit = 0;
float tempValue = 0;
if (A.goldUnit == B.goldUnit)
{
tempUnit = A.goldUnit;
tempValue = A.goldValue - B.goldValue;
}
else if (A.goldUnit > B.goldUnit)
{
if (A.goldUnit - B.goldUnit <= limit)
{
tempUnit = A.goldUnit;
tempValue = A.goldValue - B.goldValue / Mathf.Pow(1000, A.goldUnit - B.goldUnit);
}
else if (A.goldUnit - B.goldUnit > limit)
{
tempUnit = A.goldUnit;
tempValue = A.goldValue;
}
}
else if (A.goldUnit < B.goldUnit)
{
if (B.goldUnit - A.goldUnit <= limit)
{
tempUnit = B.goldUnit;
tempValue = A.goldValue / Mathf.Pow(1000, B.goldUnit - A.goldUnit) - B.goldValue;
}
else if (B.goldUnit - A.goldUnit > limit)
{
tempUnit = B.goldUnit;
tempValue = -B.goldValue;
}
}
GoldNum result = new GoldNum(tempValue + ((GoldUnit)tempUnit).ToString());
return result;
}
public static bool operator >(GoldNum A, GoldNum B)
{
GoldNum result = B - A;
return result.GoldCountText.StartsWith("-");
}
public static bool operator <(GoldNum A, GoldNum B)
{
GoldNum result = A - B;
return result.GoldCountText.StartsWith("-");
}
public static bool operator >=(GoldNum A, GoldNum B)
{
GoldNum result = A - B;
return !result.GoldCountText.StartsWith("-") || result.GoldCountText == "0";
}
public static bool operator <=(GoldNum A, GoldNum B)
{
GoldNum result = A - B;
return result.GoldCountText.StartsWith("-") || result.GoldCountText == "0";
}
public static GoldNum operator *(GoldNum A, float B)
{
int tempUnit = A.goldUnit;
float tempValue = A.goldValue * B;
GoldNum result = new GoldNum(tempValue + ((GoldUnit)tempUnit).ToString());
return result;
}
public static GoldNum operator /(GoldNum A, float B)
{
int tempUnit = A.goldUnit;
float tempValue = A.goldValue / B;
GoldNum result = new GoldNum(tempValue + ((GoldUnit)tempUnit).ToString());
return result;
}
public static GoldNum operator *(GoldNum A, GoldNum B)
{
int tempUnit = A.goldUnit + B.goldUnit;
float tempValue = A.goldValue * B.goldValue;
GoldNum result = new GoldNum(tempValue + ((GoldUnit)tempUnit).ToString());
return result;
}
}
游戏金币单位换算管理类相关推荐
- 游戏自定义金币单位换算管理类
https://blog.csdn.net/QuVi_God/article/details/83382628 根据这篇游戏金币管理类文章,所改写的Java版本的游戏金币管理类. ---------- ...
- 计算机专业可以考事业单位a类吗,事业单位综合管理类a类考什么
事业单位综合管理类a类考<职业能力倾向测验>(包括常识判断.言语理解与表达.数量关系.判断推理和资料分析等部分):<综合应用能力(A类)>(主要测查应试人员的管理角色意识.分析 ...
- 数字、时间等单位换算工具类收集
将字节数转换成KB或者MB public static String bytes2kb(long bytes) {BigDecimal filesize = new BigDecimal(bytes) ...
- 游戏金币数据库:QPTreasureDB
数据库内容: 金币数据库:存放用户金币.游戏局数的相关信息及银行存款.道具和礼物等.例如游戏金币.胜局.和局.逃局,登录时间等信息. 数据库表结构: 表AndroidUserinfo(机器人) 由以下 ...
- js距离单位换算_JS数据容量单位转换(kb,mb,gb,tb)
JS代码如下: var size = '8164674'; function bytesToSize(bytes) { if (bytes === 0) return '0 B'; var k = 1 ...
- 2019年全国硕士研究生入学统一考试管理类专业学位联考逻辑试题
2019年一月联考逻辑真题 三.逻辑推理:第 26-55 小题,每小题 2 分,共 60 分.下列每题给出的 A.B.C.D. E 五个选项中,只有一项是符合试题要求的.请在答题卡上将所选项的字母涂黑 ...
- 个人永久性免费-Excel催化剂功能第35波-Excel版最全单位换算,从此不用到处百度找答案...
全球化的今天,相信我们经常可以有机会接触到外国的产品,同时我们也有许多产品出口到外国,国与国之间的度量单位不一,经常需要做一些转换运算,一般网页提供这样的转换,但没有什么比在Excel上计算来得更为方 ...
- 万航单位换算器 V1.0 绿色版
软件名称: 万航单位换算器 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win 32位/64位 软件大小: 347KB 图片预览: 软件简介: 万航单位换算器是一个可以随意转换单位的绿色软 ...
- 管理类业务系统菜单部分美化经验分享,把所有好的东西拿过来拼凑并不容易能形成整体的效果...
这个项目是最近忙乎接近一年的大型管理类软件系统的菜单折腾.折磨.优化过程的经验分享,以前开发软件系统都是用微软的网站风格,一般中小型的管理类软件,用那个效果也不错,用了好几年客户也能接受,虽然不是很漂 ...
最新文章
- ASP.NET Web API 使用Swagger生成在线帮助测试文档
- AI预测RNA结构登上Science封面,论文一作已成立药物公司开始招人
- Netty 框架学习(二):Netty粘包和拆包
- vue引入外部文件_vue文件中引入外部js
- angular-ui-router路由备忘
- 接口文档生成工具apipost
- .htaccess跳转https
- Ubuntu系统多屏幕时 触摸屏如何分屏定位
- servlet详细理解
- QQ音乐无损下载工具 Music Download Man v3.1绿色版
- Java 在PDF中添加水印——文本/图片水印
- 如何安装.ipa文件
- 使用cmd指令生成Doc文档
- 中石化卖咖啡报:产品体验报告 | 网易云音乐,体验一个“社交+音乐+直播”的动听世界
- 一文读懂IT行业都有哪些职位
- 远光天擎 | 研发运维一体化智能云平台
- Pytorch之KLDivLoss
- HTML图片不能上下铺满屏幕_这应该是最最最简单的,职场PPT图片排版方法了!...
- [Python笔记_2]循环、字符串、列表、函数、异常处理
- java架构师视频,附源代码