gpt4 book ai didi

ios - Objective-c 为 iPhone 游戏制作关卡

转载 作者:行者123 更新时间:2023-11-28 22:52:31 24 4
gpt4 key购买 nike

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

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

  • 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 秒时,进度 View 只会增加大约 .10。我应该做 progressView.progress = progressView.progress + (amount) 吗?

最佳答案

第一个或第二个语句将始终验证 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
}

关于ios - Objective-c 为 iPhone 游戏制作关卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11593736/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com