Я довольно новичок в этом. Я делаю калькулятор, который будет служить руководством для игры, чтобы узнать, сколько времени потребуется, чтобы завершить sh каждый уровень строительства, постепенно увеличивая время для каждого повышающегося уровня и составляя общую сумму времени. им потребовалось построить все здания.
//cannon1
public void upcanon1(View view) {
TextView textlvlcannon1 = findViewById(R.id.lvlCannon1);
TextView textgoldcannon1 = findViewById(R.id.goldCannon1);
TextView texttimecannon1 = findViewById(R.id.timeCannon1);
//Increase Counter to move to next Image and increase data
lvlcannon1++;
switch (lvlcannon1) {
case 1:
break;
case 2:
cannonImage1.setImageResource(R.drawable.cannon2);
maxlvlcannon1 = maxlvlcannon1 + 1;
goldcannon1 = goldcannon1 + 1000;
mincannon1 = mincannon1 + 15;
if (seccannon1 >= 60) {
seccannon1 = seccannon1 - 60;
mincannon1 = mincannon1 + 1;
}
if (mincannon1 >= 60) {
mincannon1 = mincannon1 - 60;
hourcannon1 = hourcannon1 + 1;
}
if (hourcannon1 >= 24) {
hourcannon1 = hourcannon1 - 24;
daycannon1 = daycannon1 + 1;
}
textlvlcannon1.setText("lvl: " + maxlvlcannon1 + "/18");
textgoldcannon1.setText(Integer.toString(goldcannon1));
texttimecannon1.setText(mincannon1 + "m " + seccannon1 + "s");
break;
case 3:
if (th < 2) {
lvlcannon1 = 2;
break;
}
cannonImage1.setImageResource(R.drawable.cannon3);
maxlvlcannon1 = maxlvlcannon1 + 1;
goldcannon1 = goldcannon1 + 4000;
mincannon1 = mincannon1 + 45;
if (seccannon1 >= 60) {
seccannon1 = seccannon1 - 60;
mincannon1 = mincannon1 + 1;
}
if (mincannon1 >= 60) {
mincannon1 = mincannon1 - 60;
hourcannon1 = hourcannon1 + 1;
}
if (hourcannon1 >= 24) {
hourcannon1 = hourcannon1 - 24;
daycannon1 = daycannon1 + 1;
}
textlvlcannon1.setText("lvl: " + maxlvlcannon1 + "/18");
textgoldcannon1.setText(Integer.toString(goldcannon1));
texttimecannon1.setText(hourcannon1 + "h " + mincannon1 + "m " + seccannon1 + "s");
break;
case 4:
lvlcannon1 = 3;
break;
}
TextView tv10 = findViewById(R.id.textView19);
totalgold = anteriorgold + goldcannon1;
tv10.setText(Integer.toString(totalgold));
TextView tv11 = findViewById(R.id.textView26);
totalsec = anteriorsec + seccannon1;
totalmin = anteriormin + mincannon1;
totalhour = anteriorhour + hourcannon1;
totalday = anteriorday + daycannon1;
if (totalsec >= 60) {
totalsec = totalsec - 60;
totalmin = totalmin + 1;
}
if (totalmin >= 60) {
totalmin = totalmin - 60;
totalhour = totalhour + 1;
}
if (totalhour >= 24) {
totalhour = totalhour - 24;
totalday = totalday + 1;
}
if (totalsec < 0) {
totalsec = totalsec + 60;
totalmin = totalmin - 1;
}
if (totalmin < 0) {
totalmin = totalmin + 60;
totalhour = totalhour - 1;
}
if (totalhour < 0) {
totalhour = totalhour + 24;
totalday = totalday - 1;
}
tv11.setText(totalday + "d " + totalhour + "h " + totalmin + "m " + totalsec + "s");
}
public void downcanon1(View view) {
TextView textlvlcannon1 = findViewById(R.id.lvlCannon1);
TextView textgoldcannon1 = findViewById(R.id.goldCannon1);
TextView texttimecannon1 = findViewById(R.id.timeCannon1);
//Increase Counter to move to next Image and increase data
lvlcannon1--;
switch (lvlcannon1) {
case 0:
lvlcannon1 = 1;
break;
case 1:
cannonImage1.setImageResource(R.drawable.cannon1);
maxlvlcannon1 = maxlvlcannon1 - 1;
goldcannon1 = goldcannon1 - 1000;
mincannon1 = mincannon1 - 15;
if (seccannon1 < 0) {
seccannon1 = seccannon1 + 60;
mincannon1 = mincannon1 - 1;
}
if (mincannon1 < 0) {
mincannon1 = mincannon1 + 60;
hourcannon1 = hourcannon1 - 1;
}
if (hourcannon1 < 0) {
hourcannon1 = hourcannon1 + 24;
daycannon1 = daycannon1 - 1;
}
textlvlcannon1.setText("lvl: " + maxlvlcannon1 + "/18");
textgoldcannon1.setText(Integer.toString(goldcannon1));
texttimecannon1.setText(mincannon1 + "m " + seccannon1 + "s");
break;
case 2:
cannonImage1.setImageResource(R.drawable.cannon2);
maxlvlcannon1 = maxlvlcannon1 - 1;
goldcannon1 = goldcannon1 - 4000;
mincannon1 = mincannon1 - 45;
if (seccannon1 < 0) {
seccannon1 = seccannon1 + 60;
mincannon1 = mincannon1 - 1;
}
if (mincannon1 < 0) {
mincannon1 = mincannon1 + 60;
hourcannon1 = hourcannon1 - 1;
}
if (hourcannon1 < 0) {
hourcannon1 = hourcannon1 + 24;
daycannon1 = daycannon1 - 1;
}
textlvlcannon1.setText("lvl: " + maxlvlcannon1 + "/18");
textgoldcannon1.setText(Integer.toString(goldcannon1));
texttimecannon1.setText(hourcannon1 + "h " + mincannon1 + "m " + seccannon1 + "s");
break;
}
TextView tv10 = findViewById(R.id.textView19);
totalgold = anteriorgold + goldcannon1;
tv10.setText(Integer.toString(totalgold));
TextView tv11 = findViewById(R.id.textView26);
totalsec = anteriorsec + seccannon1;
totalmin = anteriormin + mincannon1;
totalhour = anteriorhour + hourcannon1;
totalday = anteriorday + daycannon1;
if (totalsec < 0) {
totalsec = totalsec + 60;
totalmin = totalmin - 1;
}
if (totalmin < 0) {
totalmin = totalmin + 60;
totalhour = totalhour - 1;
}
if (totalhour < 0) {
totalhour = totalhour + 24;
totalday = totalday - 1;
}
if (seccannon1 >= 60) {
seccannon1 = seccannon1 - 60;
mincannon1 = mincannon1 + 1;
}
if (mincannon1 >= 60) {
mincannon1 = mincannon1 - 60;
hourcannon1 = hourcannon1 + 1;
}
if (totalhour >= 24) {
totalhour = totalhour - 24;
totalday = totalday + 1;
}
tv11.setText(totalday + "d " + totalhour + "h " + totalmin + "m " + totalsec + "s");
}
Я использовал эту строку кода, но я знаю, что есть метод для создания переменных времени. Я видел некоторые рекомендации, но я все еще не понимаю, как реализовать это в моем приложении.