0

ユーザーにいくつかの質問をする質問ゲームがあり、ユーザーが正しく答える速さとユーザーのレベルに応じて、進行状況ビューでさまざまな量の 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 + (金額) を行う必要がありますか?

4

2 に答える 2

2

最初または2番目のステートメントは常に検証されるtrueため
、最後の3つの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 に答える