我有一个问题游戏,其中我向用户询问一些问题,具体取决于用户正确回答的速度以及用户所处的级别,我希望用户获得具有进度视图的不同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 +(金额)吗?
最佳答案
第一条或第二条语句将始终验证true
,
因此,最后三个if
语句将永远不会被验证。
数字不能同时验证false
和<= 100
。
验证> 100
至false
的数字始终为> 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
}