Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class NimAdvisorAdvanced{
- public static int times;
- public static void main (String[]args){
- Scanner nim = new Scanner(System.in);
- int matches = 1;
- System.out.println("Welcome to the advanced version of Nim Advisor.");
- sleep(1600);
- System.out.println("Let me take some information about the specific game you are playing.");
- sleep(2000);
- System.out.println("First, tell me what is the maximum number of matches\na player can take every turn.");
- int possTake;
- while(true){
- possTake = Integer.parseInt(nim.nextLine());
- sleep(300);
- if(possTake<=1){
- System.out.println("Invalid input.");
- }
- else{
- break;
- }
- }
- System.out.println("Now, tell me, the one who takes the last match...");
- sleep(1000);
- System.out.println("Wins / Loses");
- String winCond;
- // =========================================================================================================================
- // Who takes the last match wins.
- // =========================================================================================================================
- while (true){
- winCond = nim.nextLine();
- sleep(300);
- if (winCond.toLowerCase().equals("wins")){
- while(true){
- System.out.println("Tell me how many matches are left when your turn comes.");
- matches = nim.nextInt();
- sleep(300);
- if(matches<0){
- System.out.println("Invalid input, again,");
- sleep(1000);
- }
- else if(matches==0){
- System.out.println("In that case you lost. Goodbye.");
- return;
- }
- else if (matches==1){
- System.out.println("You can only take 1 match, therefore you won. Goodbye.");
- return;
- }
- else{
- int take = matches%(possTake+1);
- switch (take){
- case 0: System.out.println("you are currently in a losing situation, unless your opponent fails,\nyou will lose. Take between 1-"+possTake+" matches.");
- sleep(3200);
- break;
- case 1: System.out.println("Take " + take + " match");
- sleep(1000);
- break;
- default: System.out.println("Take " + take + " matches");
- sleep(1000);
- break;
- }
- }
- }
- }
- // =========================================================================================================================
- // Who takes the last match loses.
- // =========================================================================================================================
- else if (winCond.toLowerCase().equals("loses")){
- while(true){
- System.out.println("Tell me how many matches are left when your turn comes.");
- matches = nim.nextInt();
- sleep(300);
- if(matches<0){
- System.out.println("Invalid input, again,");
- sleep(1000);
- }
- else if(matches==0){
- System.out.println("In that case you won. Goodbye.");
- return;
- }
- else if (matches==1){
- System.out.println("You can only take 1 match, therefore you lost. Goodbye.");
- return;
- }
- else{
- int p = matches/(possTake+1);
- if (matches%(possTake+1)==0){
- p = p-1;
- }
- int should = (possTake+1)*p + 1;
- int take = matches-should;
- switch (take){
- case 0: System.out.println("you are currently in a losing situation, unless your opponent fails,\nyou will lose. Take between 1-"+possTake+" matches.");
- sleep(3200);
- break;
- case 1: System.out.println("Take " + take + " match");
- sleep(1000);
- break;
- default: System.out.println("Take " + take + " matches");
- sleep(1000);
- break;
- }
- }
- }
- }
- else{
- System.out.println("Invalid input.");
- }
- }
- }
- public static void sleep (int times){
- try {
- Thread.sleep(times);
- }
- catch(InterruptedException e){
- System.out.println("got interrupted!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement