I want to create a basic chess clock but I got stuck.
package SatrancSaati;
import java.util.Scanner;
public class SatrancSaatiRunner {
static int beyazZamani = 60;
static int siyahZamani = 60;
static boolean BeyazinSirasi = false;
static boolean SiyahinSirasi = false;//rakip baslar
static boolean zamanVarMi = true;
public static void main(String[] args) throws InterruptedException {
for (int i = 0; i < 999; i++) {
Scanner scanner = new Scanner(System.in);
System.out.println("Beyaz hamle yaptiktan sonra 1 e basmali");
System.out.println("Siyah hamle yaptiktan sonra 2 e basmali");
int kiminSirasi = scanner.nextInt();
if (kiminSirasi == 1) {
saatCalistirSiyah(BeyazinSirasi, siyahZamani, zamanVarMi, beyazZamani, siyahZamani);
} else if (kiminSirasi == 2) {
saatCalistirBeyaz(BeyazinSirasi, siyahZamani, zamanVarMi, beyazZamani, siyahZamani);
}
}
}
private static void saatCalistirBeyaz(boolean beyazinSirasi, int siyahZamani, boolean zamanVarMi, int beyazZamani, int siyahZamani1) throws InterruptedException {
System.out.println("***Hamle Beyazda***");
while (true) {
siyahZamani++;
beyazZamani--;
System.out.print("Beyaz: " + beyazZamani + " ");
System.out.print("Siyah: " + siyahZamani);
System.out.print("\u000C");
Thread.sleep(1000);
if (beyazZamani <= 0 || siyahZamani <= 0) {
break;
}
}
}
private static void saatCalistirSiyah(boolean beyazinSirasi, int siyahZamani, boolean zamanVarMi,
int beyazZamani, int siyahZamani1) throws InterruptedException {
System.out.println("***Hamle Siyahta***");
while (true) {
beyazZamani++;
siyahZamani--;
System.out.print("Beyaz: " + beyazZamani + " ");
System.out.print("Siyah: " + siyahZamani);
System.out.print("\u000C");
Thread.sleep(1000);
if (beyazZamani <= 0 || siyahZamani <= 0) {
break;
}
}
}
}
This is my basic code, I want that code to work like this:
when I click 1 on IntelliJ then black's time starts dropping and white time increases by the same amount. while this code running when I click 2 I want to stop the other method and start the opposite method that increases white's time and decreases black's time by the same amount. This is very difficult because when I start one method it works until finished. That's my problem.