Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.lang.Math;
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("[1]Play. ");
- int restart=0;
- for (int i=0; i<restart; i++){
- System.out.println("Type playername.");
- String playerName = input.next();
- System.out.println("Throw a minimum of 5 bananas at the ape, before it chose to eat you instead.");
- //Apans variabler.
- int apeStartingRange = 100;
- int apeMovement= 10;
- int apeSize = 6;
- DecimalFormat df = new DecimalFormat("#.##");
- for ( i=0; i<10; i++){
- double negativeOrNot = 1;
- if (Math.random()>0.5){
- negativeOrNot=-1;
- }
- double wind = Math.random() * (-3) * negativeOrNot;
- System.out.println("Wind:"+df.format(wind)+".");
- System.out.println("Ape is now:"+apeStartingRange+"m away.");
- System.out.println("Input throwingpower.");
- //Kastarens kraft och lutningen på kastet.
- double power = input.nextDouble();
- System.out.println("Input throwingangel.");
- double grades = input.nextDouble();
- //Naturens djävulskap.
- double gravity =9.81;
- //Hur långt kastet blir efter alla olika variabler har haft sitt roliga=)
- double throwingRange=(2*power*power*Math.cos(grades)*Math.sin(grades)/gravity)-(wind*power*Math.sin(grades)/gravity);
- System.out.println("Throw length:"+df.format(throwingRange)+"m");
- int hitOrNoHit=0 ;
- if (throwingRange>=apeStartingRange-apeSize/2 && throwingRange<=apeStartingRange+apeSize/2){
- hitOrNoHit=1;
- }
- else {hitOrNoHit=2;
- }
- //Antalet träffar som behöves.
- int hitsNeeded =5;
- //Avgör om man vinner eller förlorar.
- int winOrLose = 0;
- if (hitsNeeded == 0){
- winOrLose = 1;
- }
- else {winOrLose=2;
- }
- //Träff eller miss.
- switch(hitOrNoHit){
- case(1):
- System.out.println("Great! you hit the ape.");
- System.out.println("The ape eats the banana and moves closer, hoping for more.");
- hitsNeeded = hitsNeeded-1;
- break;
- case(2):
- System.out.println("Oh, no! You missed the ape.");
- System.out.println("The ape moves closer in hopes of some delicous "+playerName+"!");
- break;
- }
- System.out.println("You need:"+hitsNeeded+" more hits.");
- apeStartingRange= apeStartingRange-apeMovement;
- switch(winOrLose){
- case(1):
- System.out.println("You made it!\n The Ape gives you a hug.");
- break;
- case(2):
- System.out.println("The apes starts ripping you appart and eats "+playerName+"!");
- break;
- }
- System.out.println("[1]Try again");
- restart=input.nextInt();
- int gameOver = input.nextInt();
- switch(gameOver){
- case(1):
- break;
- case(2):
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement