我有一个问题游戏,其中我向用户询问一些问题,并且取决于用户正确回答的速度以及用户所处的级别,我希望用户获得不同的进度视图的xp /进度量有
所以我有一个名为'levelInt'的全局变量,它保存用户所处级别的值(最大级别为20)。我还有一个打印'levelInt'变量的标签和一个进度视图,显示您进入更高级别/显示当前级别进度的进度。我还有一个计时器,从2分钟开始倒计时,根据您回答这个问题的速度,您可以获得更多xp /更多进度视图的进度。我这样设置:
totalSeconds是计时器
levelInt是保存用户所在级别值的全局变量
progressView是显示剩余xp直到下一级
和代码:
if ( levelInt == 0 && totalSeconds > 100){
progressView.progress = .60;
}else if ( levelInt == 0 && totalSeconds <= 100 ){
progressView.progress = .40;
}else if ( levelInt == 0 && totalSeconds > 80 ){
progressView.progress = .20;
}else if ( levelInt == 0 && totalSeconds <= 80 ) {
progressView.progress = .10;
}else {
progressView.progress = .05;
}
if ( levelInt == 1 && totalSeconds > 100){
progressView.progress = .55;
}else if ( levelInt == 1 && totalSeconds <= 100 ){
progressView.progress = .35;
}else if ( levelInt == 1 && totalSeconds > 80 ){
progressView.progress = .15;
}else if ( levelInt == 1 && totalSeconds <= 80 ) {
progressView.progress = .05;
}else {
progressView.progress = .02;
}
if ( levelInt == 2 && totalSeconds > 100){
progressView.progress = .50;
}else if ( levelInt == 2 && totalSeconds <= 100 ){
progressView.progress = .30;
}else if ( levelInt == 2 && totalSeconds > 80 ){
progressView.progress = .10;
}else if ( levelInt == 2 && totalSeconds <= 80 ) {
progressView.progress = .05;
}else {
progressView.progress = .02;
}
if ( levelInt == 3 && totalSeconds > 100){
progressView.progress = .45;
}else if ( levelInt == 3 && totalSeconds <= 100 ){
progressView.progress = .25;
}else if ( levelInt == 3 && totalSeconds > 80 ){
progressView.progress = .05;
}else if ( levelInt == 3 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 4 && totalSeconds > 100){
progressView.progress = .40;
}else if ( levelInt == 4 && totalSeconds <= 100 ){
progressView.progress = .20;
}else if ( levelInt == 4 && totalSeconds > 80 ){
progressView.progress = .05;
}else if ( levelInt == 4 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 5 && totalSeconds > 100){
progressView.progress = .35;
}else if ( levelInt == 5 && totalSeconds <= 100 ){
progressView.progress = .15;
}else if ( levelInt == 5 && totalSeconds > 80 ){
progressView.progress = .05;
}else if ( levelInt == 5 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 6 && totalSeconds > 100){
progressView.progress = .30;
}else if ( levelInt == 6 && totalSeconds <= 100 ){
progressView.progress = .10;
}else if ( levelInt == 6 && totalSeconds > 80 ){
progressView.progress = .05;
}else if ( levelInt == 6 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 7 && totalSeconds > 100){
progressView.progress = .28;
}else if ( levelInt == 7 && totalSeconds <= 100 ){
progressView.progress = .08;
}else if ( levelInt == 7 && totalSeconds > 80 ){
progressView.progress = .04;
}else if ( levelInt == 7 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 8 && totalSeconds > 100){
progressView.progress = .26;
}else if ( levelInt == 8 && totalSeconds <= 100 ){
progressView.progress = .07;
}else if ( levelInt == 8 && totalSeconds > 80 ){
progressView.progress = .05;
}else if ( levelInt == 8 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 9 && totalSeconds > 100){
progressView.progress = .24;
}else if ( levelInt == 9 && totalSeconds <= 100 ){
progressView.progress = .05;
}else if ( levelInt == 9 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 9 && totalSeconds <= 80 ) {
progressView.progress = .02;
}else {
progressView.progress = .02;
}
if ( levelInt == 10 && totalSeconds > 100){
progressView.progress = .22;
}else if ( levelInt == 10 && totalSeconds <= 100 ){
progressView.progress = .04;
}else if ( levelInt == 10 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 10 && totalSeconds <= 80 ) {
progressView.progress = .02;
}else {
progressView.progress = .02;
}
if ( levelInt == 11 && totalSeconds > 100){
progressView.progress = .20;
}else if ( levelInt == 11 && totalSeconds <= 100 ){
progressView.progress = .04;
}else if ( levelInt == 11 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 11 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 12 && totalSeconds > 100){
progressView.progress = .18;
}else if ( levelInt == 12 && totalSeconds <= 100 ){
progressView.progress = .04;
}else if ( levelInt == 12 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 12 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 13 && totalSeconds > 100){
progressView.progress = .16;
}else if ( levelInt == 13 && totalSeconds <= 100 ){
progressView.progress = .04;
}else if ( levelInt == 13 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 13 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 14 && totalSeconds > 100){
progressView.progress = .14;
}else if ( levelInt == 14 && totalSeconds <= 100 ){
progressView.progress = .04;
}else if ( levelInt == 14 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 14 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 15 && totalSeconds > 100){
progressView.progress = .12;
}else if ( levelInt == 15 && totalSeconds <= 100 ){
progressView.progress = .03;
}else if ( levelInt == 15 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 15 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 16 && totalSeconds > 100){
progressView.progress = .10;
}else if ( levelInt == 16 && totalSeconds <= 100 ){
progressView.progress = .03;
}else if ( levelInt == 16 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 16 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 17 && totalSeconds > 100){
progressView.progress = .08;
}else if ( levelInt == 17 && totalSeconds <= 100 ){
progressView.progress = .02;
}else if ( levelInt == 17 && totalSeconds > 80 ){
progressView.progress = .02;
}else if ( levelInt == 17 && totalSeconds <= 80 ) {
progressView.progress = .02;
}else {
progressView.progress = .02;
}
if ( levelInt == 18 && totalSeconds > 100){
progressView.progress = .06;
}else if ( levelInt == 18 && totalSeconds <= 100 ){
progressView.progress = .02;
}else if ( levelInt == 18 && totalSeconds > 80 ){
progressView.progress = .02;
}else if ( levelInt == 18 && totalSeconds <= 80 ) {
progressView.progress = .02;
}else {
progressView.progress = .02;
}
if ( levelInt == 19 && totalSeconds > 100){
progressView.progress = .04;
}else if ( levelInt == 19 && totalSeconds <= 100 ){
progressView.progress = .02;
}else if ( levelInt == 19 && totalSeconds > 80 ){
progressView.progress = .02;
}else if ( levelInt == 19 && totalSeconds <= 80 ) {
progressView.progress = .02;
}else {
progressView.progress = .02;
}
if ( levelInt ==20 && totalSeconds > 100){
progressView.progress = .04;
}else if ( levelInt == 20 && totalSeconds <= 100 ){
progressView.progress = .02;
}else if ( levelInt == 20 && totalSeconds > 80 ){
progressView.progress = .02;
}else if ( levelInt == 20 && totalSeconds <= 80 ) {
progressView.progress = .02;
}else {
progressView.progress = .02;
}
问题是每当我快速正确地回答20秒时,进度视图只会增加约.10。我应该做progressView.progress = progressView.progress +(金额)吗?
答案 0 :(得分:2)
第一个或第二个语句将始终验证true
,
因此,最后三个if
语句永远不会被验证
数字无法向false
和<= 100
验证> 100
验证false
到> 100
的数字始终为<= 100
。
if ( i > 100 )
{
// All numbers above 100
}
else if ( i <= 100 )
{
// All numbers lower than or equal to 100
}
else if ( i > 80 )
{
// Never reached
}
else if ( i <= 80 )
{
// Never reached
}
else
{
// Never reached
}
答案 1 :(得分:0)
2种更好的工作方式:
1:创建一个函数(线性?)来计算你的进度。
float progress (int level , int seconds);
2:使用数组(从文件中读取以便更好地使用)
//float values [levels][cases];
//float values [21][3];
static init
float values[0] = {.10,.20,.60};
float values[1] = ....
int acase ;
if (totalSeconds <= 80){
acase=0;
}else{
// your are > 80 here
if (totalSeconds <= 100){
acase=1;
}else{
// your are > 100 here
acase=2;
}
}
progressView.progress = values[levelInt,acase];
它完成了(我认为更短)
您当然可以添加案例(此处为3)