Advertisement
Guest User

Rolufe

a guest
Jan 28th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.89 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4. import java.lang.Math;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.             Scanner input = new Scanner(System.in);
  11.             System.out.println("[1]Play. ");
  12.             int restart=0;
  13.             for (int i=0; i<restart; i++){
  14.                
  15.             System.out.println("Type playername.");
  16.             String playerName = input.next();
  17.  
  18.             System.out.println("Throw a minimum of 5 bananas at the ape, before it chose to eat you instead.");
  19.  
  20.             //Apans variabler.
  21.             int apeStartingRange = 100;
  22.             int apeMovement= 10;
  23.             int apeSize = 6;
  24.             DecimalFormat df = new DecimalFormat("#.##");
  25.  
  26.             for ( i=0; i<10; i++){
  27.  
  28.                 double negativeOrNot = 1;
  29.                 if (Math.random()>0.5){
  30.                     negativeOrNot=-1;
  31.                 }
  32.                 double wind = Math.random() * (-3) * negativeOrNot;
  33.                 System.out.println("Wind:"+df.format(wind)+".");
  34.                 System.out.println("Ape is now:"+apeStartingRange+"m away.");
  35.                 System.out.println("Input throwingpower.");
  36.  
  37.                 //Kastarens kraft och lutningen på kastet.
  38.                 double power = input.nextDouble();
  39.                 System.out.println("Input throwingangel.");
  40.                 double grades = input.nextDouble();
  41.                 //Naturens djävulskap.
  42.  
  43.                 double gravity =9.81;
  44.  
  45.  
  46.  
  47.  
  48.                 //Hur långt kastet blir efter alla olika variabler har haft sitt roliga=)
  49.  
  50.                 double throwingRange=(2*power*power*Math.cos(grades)*Math.sin(grades)/gravity)-(wind*power*Math.sin(grades)/gravity);
  51.                 System.out.println("Throw length:"+df.format(throwingRange)+"m");
  52.  
  53.  
  54.                 int hitOrNoHit=0 ;
  55.                 if (throwingRange>=apeStartingRange-apeSize/2 && throwingRange<=apeStartingRange+apeSize/2){
  56.                     hitOrNoHit=1;
  57.                 }
  58.                 else {hitOrNoHit=2;
  59.  
  60.                 }
  61.                 //Antalet träffar som behöves.
  62.                 int hitsNeeded =5;
  63.  
  64.                 //Avgör om man vinner eller förlorar.
  65.  
  66.                 int winOrLose = 0;
  67.                 if (hitsNeeded == 0){
  68.                     winOrLose = 1;
  69.                 }
  70.                 else {winOrLose=2;
  71.  
  72.                 }
  73.  
  74.                 //Träff eller miss.
  75.                 switch(hitOrNoHit){
  76.                 case(1):
  77.                     System.out.println("Great! you hit the ape.");
  78.                 System.out.println("The ape eats the banana and moves closer, hoping for more.");
  79.                 hitsNeeded = hitsNeeded-1;
  80.  
  81.                 break;
  82.                 case(2):
  83.                     System.out.println("Oh, no! You missed the ape.");
  84.                 System.out.println("The ape moves closer in hopes of some delicous "+playerName+"!");
  85.                 break;
  86.                 }
  87.  
  88.                 System.out.println("You need:"+hitsNeeded+" more hits.");
  89.                 apeStartingRange= apeStartingRange-apeMovement;
  90.  
  91.  
  92.                 switch(winOrLose){
  93.                 case(1):
  94.                     System.out.println("You made it!\n The Ape gives you a hug.");
  95.                 break;
  96.                 case(2):
  97.                     System.out.println("The apes starts ripping you appart and eats "+playerName+"!");
  98.                 break;
  99.                 }
  100.                 System.out.println("[1]Try again");
  101.                 restart=input.nextInt();
  102.                 int gameOver = input.nextInt();
  103.                 switch(gameOver){
  104.  
  105.                 case(1):
  106.                     break;
  107.  
  108.  
  109.                 case(2):
  110.                     break;
  111.  
  112.                 }
  113.             }
  114.  
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement