0

我有一个问题游戏,我在其中问用户一些问题,并根据用户正确回答的速度以及用户所处的级别,我希望用户为我拥有的进度视图获得不同数量的 xp/进度。

所以我有一个名为“levelInt”的全局变量,它保存用户所在级别的值(最大级别为 20)。我还有一个打印“levelInt”变量的标签和一个进度视图,显示您进入更高级别的进度/显示您当前级别的进度。我还有一个计时器,它从 2 分钟开始倒计时,根据你回答这个问题的速度,你会在进度视图中获得更多的经验值/更多的进度。我是这样设置的:

  • 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 秒内快速正确回答时,进度视图只会增加大约 0.10。我应该做 progressView.progress = progressView.progress + (amount) 吗?

4

2 回答 2

2

第一个或第二个语句将始终 validates 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
}
于 2012-07-21T20:55:22.590 回答
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)

于 2012-07-22T09:05:11.010 回答