Advertisement
Guest User

Camel

a guest
Jul 29th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class Camel {
  5. public static void main(String[] args) {
  6.  
  7. Scanner userInput = new Scanner(System.in);
  8. Random rand = new Random();
  9.  
  10. System.out.println("Welcome to the Camel Game!");
  11. System.out.println("You have stolen a camel and must escape over the Gobi desert into Mongolia while a tribe hunts you down!");
  12. System.out.println("You must stay ahead of the tribe while keeping your self hydrated and keep your camel dying from exhaustion. ");
  13.  
  14. /* Program Calculations */
  15. int userDistance = 20;
  16. int tribeDistance = 0;
  17. double thirst = 0;
  18. int camelTiredness = 0;
  19. int water = 3;
  20.  
  21. while (true) {
  22.  
  23. int oasis = 1 + rand.nextInt(20);
  24.  
  25. /* User inputs */
  26. System.out.println("\r\n");
  27. System.out.println("A) Move at a fast pace.");
  28. System.out.println("B) Move at a moderate pace.");
  29. System.out.println("C) Drink a litre of water.");
  30. System.out.println("D) Rest for the day");
  31. System.out.println("E) Status.");
  32. System.out.println("F) Quit");
  33.  
  34. System.out.println("Enter command: ");
  35. String userCommand = userInput.next();
  36. int rngtribeFas = 10 + rand.nextInt(20);
  37. if (userCommand.toUpperCase().equals("A")) {
  38. System.out.println("You move at a fast pace.");
  39. int rnguserFas = 15 + rand.nextInt(25);
  40. userDistance += rnguserFas;
  41. tribeDistance += rngtribeFas;
  42. thirst += 1;
  43. camelTiredness += 2;
  44. System.out.format("You travel %d kilometres.", rnguserFas);
  45. } else if (userCommand.toUpperCase().equals("B")) {
  46. System.out.println("You move at a moderate pace");
  47. int rngMod = 7 + rand.nextInt(15);
  48. userDistance += rngMod;
  49. tribeDistance += rngtribeFas;
  50. thirst += 0.5;
  51. camelTiredness += 1;
  52. System.out.format("You travel %d kilometres.", rngMod);
  53. } else if (userCommand.toUpperCase().equals("C")) {
  54. if (water > 0) {
  55. System.out.println("You drink a litre of water.");
  56. water -= 1;
  57. thirst = 0;
  58. }
  59. else{
  60. System.out.println("You have no water left!");
  61. }
  62. } else if (userCommand.toUpperCase().equals("D")) {
  63. System.out.println("You and the camel rest");
  64. tribeDistance += rngtribeFas;
  65. camelTiredness = 0;
  66. } else if (userCommand.toUpperCase().equals("E")) {
  67. System.out.format("You have traveled %d miles, the tribe is %d behind you, and you have %d litres of water remaining.", userDistance, userDistance - tribeDistance, water);
  68. } else if (userCommand.toUpperCase().equals("F")) {
  69. break;
  70. } else {
  71. System.out.println("Unknown input");
  72. }
  73.  
  74.  
  75. if (userDistance == 500) {
  76. System.out.println("You escaped into mongolia and survived!");
  77. System.out.println("GAME OVER");
  78. break;
  79. } else if (tribeDistance >= userDistance) {
  80. System.out.println("You've been captured by the tribe!");
  81. System.out.println("GAME OVER");
  82. break;
  83. }
  84.  
  85. else if (tribeDistance == userDistance - 20) {
  86. System.out.println("The tribe is getting close!");
  87. }
  88.  
  89. if (thirst >= 3 && thirst <= 6) {
  90. System.out.println("You are thirsty.");
  91. } else if (thirst >= 8) {
  92. System.out.println("Have you died from thirst!");
  93. System.out.println("GAME OVER!");
  94. break;
  95. }
  96. if (camelTiredness >= 4 && camelTiredness <= 7) {
  97. System.out.println("Your camel is tired.");
  98. } else if (camelTiredness >= 8) {
  99. System.out.println("Your camel has died from exhaustion! The tribe has caught you!");
  100. System.out.println("GAME OVER!");
  101. break;
  102. }
  103.  
  104. if (oasis == 20) {
  105. System.out.println("You found an oasis! You've drunk your fill, refilled your canteen and rested the camel!");
  106. water = 3;
  107. thirst = 0;
  108. camelTiredness = 0;
  109. }
  110.  
  111. }
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement