├── Hangman ├── README.md └── Hangman.java ├── README.md ├── Notepad ├── README.md └── Notepad.java ├── AdventureGame ├── Bear.java ├── Wizard.java ├── Warrior.java ├── Vampire.java ├── Zombie.java ├── Archer.java ├── Cave.java ├── River.java ├── Forest.java ├── Mine.java ├── Main.java ├── README.md ├── Snake.java ├── NormalLoc.java ├── Location.java ├── Item.java ├── Armor.java ├── Weapon.java ├── Game.java ├── Champion.java ├── SafeHouse.java ├── Obstacle.java ├── Inventory.java ├── ToolStore.java ├── Inhibitory.java ├── BattleLoc.java └── Player.java ├── JumbledWord ├── input.txt ├── README.md └── JumbledWord.java ├── GuessingNumberGame ├── README.md └── GuessingNumber.java └── LICENSE /Hangman/README.md: -------------------------------------------------------------------------------- 1 | Classic Hangman game without using arrays. 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mini-projects 2 | This repository is for my freestyle mini projects. 3 | -------------------------------------------------------------------------------- /Notepad/README.md: -------------------------------------------------------------------------------- 1 | Example of visual programming in Java. 2 | You can create, save and open a text file with this notepad program. 3 | -------------------------------------------------------------------------------- /AdventureGame/Bear.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Bear extends Obstacle { 4 | 5 | public Bear() { 6 | super("Bear", 7, 20, 12); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /JumbledWord/input.txt: -------------------------------------------------------------------------------- 1 | HSTAAME:HAMASET,HASTA,MATAH,HAMSE,HASAT,TASMA,MASAT,TEMAS,TAMAH,SAHTE,HASET,TAM,ET,SAHTE,SEMA,SAAT,SET,TASA,HATA,HAM,HAT,HAS,TAS,MAT,ET,AT,ESAME,TEMA -------------------------------------------------------------------------------- /AdventureGame/Wizard.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Wizard extends Champion { 4 | 5 | public Wizard() { 6 | super("Wizard", 24, 8, 0, 5); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /AdventureGame/Warrior.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Warrior extends Champion { 4 | 5 | public Warrior() { 6 | super("Warrior", 21, 5, 0, 15); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /GuessingNumberGame/README.md: -------------------------------------------------------------------------------- 1 | Play against to your PC. Try to guess the randomly generated number! 2 | The PC can generate better guesses through your guesses and its own guesses. 3 | -------------------------------------------------------------------------------- /AdventureGame/Vampire.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Vampire extends Obstacle { 4 | 5 | public Vampire() { 6 | super("Vampire", 4, 14, 7); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /AdventureGame/Zombie.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Zombie extends Obstacle { 4 | 5 | public Zombie() { 6 | super("Zombie", 3, 10, 4); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /AdventureGame/Archer.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Archer extends Champion { 4 | 5 | public Archer() { 6 | super("Archer", 18, 7, 0, 20); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /AdventureGame/Cave.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Cave extends BattleLoc { 4 | 5 | public Cave(Player player) { 6 | super(player, "Cave", new Zombie(), 3, "Food"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /AdventureGame/River.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class River extends BattleLoc { 4 | 5 | public River(Player player) { 6 | super(player, "River", new Bear(), 2, "Water"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /AdventureGame/Forest.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Forest extends BattleLoc { 4 | 5 | public Forest(Player player) { 6 | super(player, "Forest", new Vampire(), 3, "Firewood"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /AdventureGame/Mine.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Mine extends BattleLoc { 4 | 5 | public Mine(Player player) { 6 | super(player, "Mine", new Snake(), 5, "Snake Skin"); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /AdventureGame/Main.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | Game game = new Game(); 8 | game.start(); 9 | 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /AdventureGame/README.md: -------------------------------------------------------------------------------- 1 | A game for practicing OOP in java. 2 | To win the game you have to claim all the speacial items in dangerzones. 3 | You can buy armors and weapons in tool store. 4 | Some enemies are really powerful be careful about it. 5 | -------------------------------------------------------------------------------- /AdventureGame/Snake.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Snake extends Obstacle { 4 | 5 | private static int damage = (int) (Math.random()*10 + 5); 6 | 7 | public Snake() { 8 | super("Snake", damage, 15, 0); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /JumbledWord/README.md: -------------------------------------------------------------------------------- 1 | With a given jumbled letters you should try to guess the meaningfull words. (words is Turkish btw) 2 | Do not forget the paste the input files' path to determined line. 3 | The longer words makes more points. Letter points: A -> 1 ... Z -> 26 4 | Highest score wins. 5 | -------------------------------------------------------------------------------- /AdventureGame/NormalLoc.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public abstract class NormalLoc extends Location{ 4 | 5 | public NormalLoc(Player player, String name) { 6 | super(player, name); 7 | } 8 | 9 | @Override 10 | public boolean onLocation() { 11 | 12 | return true; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /AdventureGame/Location.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public abstract class Location { 4 | 5 | private String name; 6 | 7 | public Location(Player player, String name) { 8 | Game.player = player; 9 | this.name = name; 10 | } 11 | public abstract boolean onLocation(); 12 | /** 13 | * @return the name 14 | */ 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | /** 20 | * @param name the name to set 21 | */ 22 | public void setName(String name) { 23 | this.name = name; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /AdventureGame/Item.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public abstract class Item { 4 | 5 | public String name; 6 | public int price; 7 | 8 | /** 9 | * @return the price 10 | */ 11 | public int getPrice() { 12 | return price; 13 | } 14 | /** 15 | * @return the name 16 | */ 17 | public String getName() { 18 | return name; 19 | } 20 | /** 21 | * @param name the name to set 22 | */ 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | /** 27 | * @param price the price to set 28 | */ 29 | public void setPrice(int price) { 30 | this.price = price; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /AdventureGame/Armor.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Armor extends Item { 6 | 7 | private int defence; 8 | 9 | public Armor(String name, int damage, int price) { 10 | this.name = name; 11 | this.defence = damage; 12 | this.price = price; 13 | } 14 | public Armor() { 15 | 16 | } 17 | public static ArrayList armorList() { 18 | ArrayList armors = new ArrayList(); 19 | armors.add(new Armor("Gladiator Armor", 1, 15)); 20 | armors.add(new Armor("Necro Armor", 3, 25)); 21 | armors.add(new Armor("Molten Armor", 5, 40)); 22 | return armors; 23 | } 24 | 25 | /** 26 | * @return the defence 27 | */ 28 | public int getDefence() { 29 | return defence; 30 | } 31 | /** 32 | * @param defence the defence to set 33 | */ 34 | public void setDefence(int defence) { 35 | this.defence = defence; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /AdventureGame/Weapon.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Weapon extends Item { 6 | 7 | private int damage; 8 | 9 | public Weapon(String name, int damage, int price) { 10 | this.name = name; 11 | this.damage = damage; 12 | this.price = price; 13 | } 14 | public Weapon() { 15 | 16 | } 17 | public static ArrayList weaponList() { 18 | ArrayList weapons = new ArrayList(); 19 | weapons.add( new Weapon("Blood Butcherer", 2, 15)); 20 | weapons.add(new Weapon("Molten Fury", 3, 35)); 21 | weapons.add(new Weapon("Star Cannon", 7, 45)); 22 | return weapons; 23 | } 24 | 25 | /** 26 | * @return the damage 27 | */ 28 | public int getDamage() { 29 | return damage; 30 | } 31 | /** 32 | * @param damage the damage to set 33 | */ 34 | public void setDamage(int damage) { 35 | this.damage = damage; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /AdventureGame/Game.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Game { 4 | 5 | public static Player player = new Player(); 6 | 7 | public void start() { 8 | 9 | System.out.print("Welcome to the adventure!\nBefore you start please enter your nickname: "); 10 | String playerName = Inhibitory.sc.nextLine(); 11 | playerName = Inhibitory.takeValidName(playerName); 12 | player = new Player(playerName); 13 | System.out.printf("Welcome %s!\n\nSelect your champion to survive in this horrible island!\n", player.getName()); 14 | player.selectChamp(); 15 | while(true) 16 | { 17 | player.playerInfo(); 18 | player.selectLoc(); 19 | if(player.getLocation() == null) 20 | { 21 | System.out.println("Game terminated."); 22 | break; 23 | } 24 | else if(!player.getLocation().onLocation()) 25 | { 26 | System.out.println("\nYou died!\nGame Over!"); 27 | break; 28 | } 29 | else if(Game.player.inventory.hasFood() && Game.player.inventory.hasWood() && Game.player.inventory.hasWater()) 30 | { 31 | System.out.println("\nYou won the game\nDo you want to finish it?\nIf you want to contiune to play enter a key\nPress 0 to finish it"); 32 | String finish = Inhibitory.sc.next(); 33 | if(finish.equals("0")) 34 | { 35 | System.out.println("Stay strong..."); 36 | break; 37 | } 38 | } 39 | } 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /AdventureGame/Champion.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public abstract class Champion { 4 | 5 | private String name; 6 | private int health; 7 | private int damage; 8 | private int money; 9 | private int defence; 10 | 11 | public Champion(String name, int health, int damage, int defence, int money) { 12 | this.name = name; 13 | this.health = health; 14 | this.damage = damage; 15 | this.money = money; 16 | this.defence = defence; 17 | } 18 | /** 19 | * @return the name 20 | */ 21 | public String getName() { 22 | return name; 23 | } 24 | /** 25 | * @return the health 26 | */ 27 | public int getHealth() { 28 | return health; 29 | } 30 | /** 31 | * @return the damage 32 | */ 33 | public int getDamage() { 34 | return damage; 35 | } 36 | /** 37 | * @return the money 38 | */ 39 | public int getMoney() { 40 | return money; 41 | } 42 | /** 43 | * @return the defence 44 | */ 45 | public int getDefence() { 46 | return defence; 47 | } 48 | /** 49 | * @param defence the defence to set 50 | */ 51 | public void setDefence(int defence) { 52 | this.defence = defence; 53 | } 54 | /** 55 | * @param name the name to set 56 | */ 57 | public void setName(String name) { 58 | this.name = name; 59 | } 60 | /** 61 | * @param health the health to set 62 | */ 63 | public void setHealth(int health) { 64 | this.health = health; 65 | } 66 | /** 67 | * @param damage the damage to set 68 | */ 69 | public void setDamage(int damage) { 70 | this.damage = damage; 71 | } 72 | /** 73 | * @param money the money to set 74 | */ 75 | public void setMoney(int money) { 76 | this.money = money; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /AdventureGame/SafeHouse.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class SafeHouse extends NormalLoc{ 4 | 5 | public SafeHouse(Player player) { 6 | super(player, "Tavern"); 7 | } 8 | 9 | @Override 10 | public boolean onLocation() { 11 | Game.player.setHealth(Game.player.getChamp().getHealth()); 12 | System.out.println("Welcome to the tavern!\n-- Your health is regenereted --"); 13 | boolean showMenu = true; 14 | int drinkCounter = 0; 15 | while(showMenu) 16 | { 17 | if(Game.player.getHealth() > 0) 18 | { 19 | System.out.println("Do you want to drink something?\n1 - Yes\n0 - Exit"); 20 | Inhibitory.takeInt(Inhibitory.sc); 21 | int decision = Inhibitory.sc.nextInt(); 22 | decision = Inhibitory.takeValidDecision(decision); 23 | switch(decision) 24 | { 25 | case 0: 26 | System.out.println("See you..."); 27 | showMenu = false; 28 | break; 29 | case 1: 30 | if(Game.player.getMoney()!=0) 31 | { 32 | System.out.println("Here your beer!"); 33 | ++drinkCounter; 34 | if(drinkCounter>2) 35 | { 36 | System.out.println("-1$\n-1 HP"); 37 | Game.player.setHealth(Game.player.getHealth() - 1); 38 | Game.player.setMoney(Game.player.getMoney() - 1); 39 | switch(drinkCounter) 40 | { 41 | case 5: 42 | System.out.println("don't vomit here."); 43 | break; 44 | case 10: 45 | System.out.println("Easy man what is the matter with you?"); 46 | break; 47 | case 20: 48 | System.out.println("You don't look well"); 49 | break; 50 | } 51 | } 52 | } 53 | else 54 | { 55 | System.out.println("You don't have enough money!"); 56 | } 57 | break; 58 | } 59 | } 60 | else 61 | { 62 | return false; 63 | } 64 | } 65 | return true; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Hangman/Hangman.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Hangman { 4 | 5 | public static void main(String[] args) { 6 | Scanner in = new Scanner(System.in); 7 | boolean letter = true; 8 | int remaining = 5; 9 | System.out.print("Enter the mystery word: "); 10 | String word; 11 | do { 12 | word = in.nextLine(); 13 | word = word.toUpperCase(); 14 | for (int i = 0; i < word.length(); i++) { 15 | if (!Character.isLetter(word.charAt(i)) || word.charAt(i) == ' ' || word.charAt(i) == ' ') { 16 | letter = false; 17 | System.out.println("Please use only letters!"); 18 | break; 19 | } else { 20 | letter = true; 21 | } 22 | } 23 | } while (!letter); 24 | { 25 | for (int i = 0; i < 5; i++) { 26 | System.out.println(); // girilen kelimenin gözükmemesi için 5 satır boşluk 27 | } 28 | System.out.print("The word is: "); 29 | for (int i = 0; i < word.length(); i++) { 30 | System.out.print("_ "); 31 | } 32 | String displayWord = ""; 33 | for (int i = 0; i < word.length(); i++) { 34 | displayWord += "_"; 35 | } 36 | while (remaining > 0) { 37 | System.out.print("\nPlease guess a character: "); 38 | char guess = in.next().charAt(0); 39 | guess = Character.toUpperCase(guess); 40 | int position = word.indexOf(guess); 41 | if (position == -1) { 42 | --remaining; 43 | } else { 44 | for (; position >= 0; position = word.indexOf(guess, position + 1)) { 45 | displayWord = displayWord.substring(0, position) + guess + displayWord.substring(position + 1); 46 | } 47 | if (displayWord.equals(word)) { 48 | System.out.println(word + "\nYou won the game!"); 49 | break; 50 | } 51 | } 52 | System.out.println(displayWord + "\nNumber of guess left: " + remaining); 53 | } 54 | if (!displayWord.equals(word)) { 55 | System.out.println("\nYou lost the game! \nThe word was: " + word); 56 | } 57 | in.close(); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /AdventureGame/Obstacle.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Obstacle { 4 | 5 | private String name; 6 | private int damage; 7 | private int health; 8 | private int award; 9 | private int defaultHealth; 10 | 11 | public Obstacle(String name, int damage, int health, int award) { 12 | 13 | this.name = name; 14 | this.damage = damage; 15 | this.defaultHealth = health; 16 | this.health = health; 17 | this.award = award; 18 | } 19 | 20 | /** 21 | * @return the damage 22 | */ 23 | public int getDamage() { 24 | return damage; 25 | } 26 | 27 | /** 28 | * @return the health 29 | */ 30 | public int getHealth() { 31 | return health; 32 | } 33 | 34 | /** 35 | * @return the name 36 | */ 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | /** 42 | * @return the award 43 | */ 44 | public int getAward() { 45 | return award; 46 | } 47 | 48 | /** 49 | * @return the defaultHealth 50 | */ 51 | public int getDefaultHealth() { 52 | return defaultHealth; 53 | } 54 | 55 | /** 56 | * @param defaultHealth the defaultHealth to set 57 | */ 58 | public void setDefaultHealth(int defaultHealth) { 59 | this.defaultHealth = defaultHealth; 60 | } 61 | 62 | /** 63 | * @param award the award to set 64 | */ 65 | public void setAward(int award) { 66 | this.award = award; 67 | } 68 | 69 | /** 70 | * @param name the name to set 71 | */ 72 | public void setName(String name) { 73 | this.name = name; 74 | } 75 | 76 | /** 77 | * @param damage the damage to set 78 | */ 79 | public void setDamage(int damage) { 80 | this.damage = damage; 81 | } 82 | 83 | /** 84 | * @param health the health to set 85 | */ 86 | public void setHealth(int health) { 87 | 88 | if(health < 0) 89 | { 90 | this.health = 0; 91 | } 92 | else 93 | { 94 | this.health = health; 95 | } 96 | 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /AdventureGame/Inventory.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Inventory { 4 | 5 | private String weaponName = "Punch"; 6 | private String armorName = "Body"; 7 | private int weaponDamage = 0; 8 | private int armorDefence = 0; 9 | private boolean food; 10 | private boolean wood; 11 | private boolean water; 12 | private boolean snakeSkin; 13 | /** 14 | * @return the weaponName 15 | */ 16 | public String getWeaponName() { 17 | return weaponName; 18 | } 19 | /** 20 | * @return the armorName 21 | */ 22 | public String getArmorName() { 23 | return armorName; 24 | } 25 | /** 26 | * @return the weaponDamage 27 | */ 28 | public int getWeaponDamage() { 29 | return weaponDamage; 30 | } 31 | /** 32 | * @return the armorDefence 33 | */ 34 | public int getArmorDefence() { 35 | return armorDefence; 36 | } 37 | /** 38 | * @return the snakeSkin 39 | */ 40 | public boolean hasSnakeSkin() { 41 | return snakeSkin; 42 | } 43 | /** 44 | * @return the food 45 | */ 46 | public boolean hasFood() { 47 | return food; 48 | } 49 | /** 50 | * @return the wood 51 | */ 52 | public boolean hasWood() { 53 | return wood; 54 | } 55 | /** 56 | * @return the water 57 | */ 58 | public boolean hasWater() { 59 | return water; 60 | } 61 | /** 62 | * @param food the food to set 63 | */ 64 | public void setFood(boolean food) { 65 | this.food = food; 66 | } 67 | /** 68 | * @param wood the wood to set 69 | */ 70 | public void setWood(boolean wood) { 71 | this.wood = wood; 72 | } 73 | /** 74 | * @param water the water to set 75 | */ 76 | public void setWater(boolean water) { 77 | this.water = water; 78 | } 79 | /** 80 | * @param snakeSkin the snakeSkin to set 81 | */ 82 | public void setSnakeSkin(boolean snakeSkin) { 83 | this.snakeSkin = snakeSkin; 84 | } 85 | /** 86 | * @param weaponName the weaponName to set 87 | */ 88 | public void setWeaponName(String weaponName) { 89 | this.weaponName = weaponName; 90 | } 91 | /** 92 | * @param armorName the armorName to set 93 | */ 94 | public void setArmorName(String armorName) { 95 | this.armorName = armorName; 96 | } 97 | /** 98 | * @param weaponDamage the weaponDamage to set 99 | */ 100 | public void setWeaponDamage(int weaponDamage) { 101 | this.weaponDamage = weaponDamage; 102 | } 103 | /** 104 | * @param armorDefence the armorDefence to set 105 | */ 106 | public void setArmorDefence(int armorDefence) { 107 | this.armorDefence = armorDefence; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /GuessingNumberGame/GuessingNumber.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class GuessNumber { 4 | 5 | public static Scanner sc = new Scanner(System.in); 6 | 7 | final static int ANSWER = generateNumber(); 8 | final static int GENERATE_MAX = 100; 9 | final static int GENERATE_MİN = 0; 10 | 11 | public static int min = GENERATE_MİN; // initial maximum and minimum guess for PC 12 | public static int max = GENERATE_MAX; 13 | 14 | 15 | public static void main(String[] args) { 16 | System.out.printf("Guess the number between %d & %d\n", GENERATE_MİN, GENERATE_MAX); 17 | int userGuess = 0; 18 | int pcGuess = 0; 19 | while(userGuess != ANSWER && pcGuess != ANSWER) 20 | { 21 | // System.out.println("min: " + min + " max: " + max); 22 | System.out.println("Your turn"); 23 | userGuess = userGuess(); 24 | if(userGuess != ANSWER) 25 | { 26 | System.out.println("PC's turn"); 27 | pcGuess = pcGuess(); 28 | } 29 | 30 | } 31 | 32 | } 33 | 34 | public static int generateNumber() { 35 | int randomNumber = (int) (Math.random() * GENERATE_MAX + GENERATE_MİN); 36 | return randomNumber; 37 | } 38 | 39 | public static int userGuess() { 40 | 41 | int guess; 42 | 43 | // to validate the input 44 | while(true) 45 | { 46 | try 47 | { 48 | guess = sc.nextInt(); 49 | if(guess <= GENERATE_MAX && guess >= GENERATE_MİN) 50 | { 51 | break; 52 | } 53 | System.out.println("Invalid number. Please enter a number between " + GENERATE_MİN + "&" + GENERATE_MAX); 54 | } 55 | catch(Exception e) 56 | { 57 | System.out.println("Invalid syntax. Please enter a number between " + GENERATE_MİN + "&" + GENERATE_MAX); 58 | sc.nextLine(); 59 | } 60 | } 61 | 62 | if(guess == ANSWER) 63 | { 64 | System.out.println(guess + " that's right you won the game!"); 65 | } 66 | else if(guess < ANSWER) 67 | { 68 | if(min < guess) 69 | { 70 | min = guess; 71 | } 72 | System.out.println(guess + " is too SMALL"); 73 | } 74 | else // guess > ANSWER 75 | { 76 | if(max > guess) 77 | { 78 | max = guess; 79 | } 80 | System.out.println(guess + " is too BIG"); 81 | 82 | } 83 | return guess; 84 | } 85 | 86 | public static int pcGuess() { 87 | int guess = (int) (Math.random() * (max - min - 1) + min + 1); // generates a random number between min and max 88 | 89 | if(guess == ANSWER) 90 | { 91 | System.out.println("Answer was " + ANSWER + " PC won the game!"); 92 | } 93 | else if(guess < ANSWER) 94 | { 95 | if(min < guess) 96 | { 97 | min = guess; 98 | } 99 | System.out.println(guess + " is too SMALL"); 100 | } 101 | else // guess > ANSWER 102 | { 103 | if(max > guess) 104 | { 105 | max = guess; 106 | } 107 | System.out.println(guess + " is too BIG"); 108 | } 109 | return guess; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /JumbledWord/JumbledWord.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Assignment4 { 5 | 6 | public static void main(String[] args) { 7 | 8 | System.out.print("Shuffled letters: "); 9 | File file = new File("input.txt"); // YOUR PATH GOES HERE 10 | String data = ""; 11 | try { 12 | Scanner sc = new Scanner(file); 13 | while (sc.hasNextLine()) { 14 | data = sc.nextLine(); 15 | } 16 | sc.close(); 17 | } catch (FileNotFoundException e) { 18 | e.printStackTrace(); 19 | } 20 | char[] shuffledLetters = new char[numOfLetters(data)]; // to making array for the shuffled letters 21 | for (int i = 0; i < shuffledLetters.length; i++) { 22 | shuffledLetters[i] = data.charAt(i); 23 | System.out.print(shuffledLetters[i] + " "); 24 | } 25 | char[] alphabet = { 'A', 'B', 'C', 'Ç', 'D', 'E', 'F', 'G', 'Ğ', 'H', 'I', 'İ', 'J', 'K', 'L', 'M', 'N', 'O', 26 | 'Ö', 'P', 'R', 'S', 'Ş', 'T', 'U', 'Ü', 'V', 'Y', 'Z' };// alphabet to calculating the points of letters 27 | String[] possibleHelper = data.split(":"); // first step to making array of the possible words 28 | String[] possibleWords = possibleHelper[1].split(","); // second step to making array of the possible words 29 | System.out.println("\nPlease try to enter a 3 word with using this letters"); 30 | Scanner in = new Scanner(System.in); 31 | int score = 0; 32 | int counter = 0; 33 | String empty = ""; // to removing the entered words from array 34 | for (int i = 0; i < 3; i++) { 35 | counter++; 36 | System.out.printf("%d. word: ", counter); 37 | String userWord = in.nextLine(); 38 | userWord = userWord.toUpperCase(); 39 | int letterPoints = 0; 40 | boolean notFound = true; // to determining if a word doesn't exist in array 41 | for (int j = 0; j < possibleWords.length; j++) { 42 | if (userWord.equals(possibleWords[j])) { 43 | for (int x = 0; x < userWord.length(); x++) { 44 | for (int y = 0; y < alphabet.length; y++) { 45 | if (userWord.charAt(x) == alphabet[y]) { 46 | letterPoints += (y + 1); // +1: at the first index of array is 0 47 | } 48 | } 49 | } 50 | int point = userWord.length() * (letterPoints); 51 | System.out.printf("You earned %d points for this word!\n", point); 52 | notFound = false; 53 | score += point; 54 | possibleWords[j] = empty; // to removing the entered words from array 55 | break; // doesn't need to looking for every word 56 | } 57 | } 58 | if (notFound) { 59 | System.out.println("You earned 0 points for this word!"); 60 | } 61 | } 62 | in.close(); 63 | System.out.printf("\nThe game is over! your total score is: %d", score); 64 | 65 | } 66 | 67 | public static int numOfLetters(String s) { // to make array for shuffled letters 68 | int counter = 0; 69 | for (int i = 0; i < s.length(); i++) { 70 | if (s.charAt(i) == ' ' || s.charAt(i) == ' ') { 71 | ; 72 | } else if (s.charAt(i) == ':') { 73 | break; 74 | } else if (s != "") { 75 | counter++; 76 | } 77 | } 78 | return counter; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /AdventureGame/ToolStore.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class ToolStore extends NormalLoc { 4 | 5 | public ToolStore(Player player) { 6 | super(player, "ToolStore"); 7 | } 8 | 9 | @Override 10 | public boolean onLocation() { 11 | System.out.println("------------- Welcome to the ToolStore! -------------"); 12 | boolean showMenu = true; 13 | while(showMenu) 14 | { 15 | System.out.println("\nWhat do you want?"); 16 | System.out.println("1 - Weapons\n2 - Armors\n0 - Exit"); 17 | Inhibitory.takeInt(Inhibitory.sc); 18 | int choice = Inhibitory.sc.nextInt(); 19 | choice = Inhibitory.takeValidChoice(choice); 20 | Item item = null; 21 | switch(choice) 22 | { 23 | case 0: 24 | System.out.println("Take care."); 25 | showMenu = false; 26 | break; 27 | case 1: 28 | item = new Weapon(); 29 | break; 30 | case 2: 31 | item = new Armor(); 32 | break; 33 | } 34 | if(showMenu) 35 | { 36 | printItems(item); 37 | selectItem(item); 38 | } 39 | } 40 | return true; 41 | } 42 | public void printItems(Item item) { 43 | 44 | System.out.println("Your money: "+ Game.player.getMoney()+"$"); 45 | int ID = 0; 46 | if(item instanceof Weapon) 47 | { 48 | for(Weapon wp: Weapon.weaponList()) 49 | { 50 | ++ID; 51 | System.out.printf("%d - %s:\tDamage: %d\tPrice: %d$\n", ID, wp.getName(), wp.getDamage(), wp.getPrice()); 52 | } 53 | } 54 | else if(item instanceof Armor) 55 | { 56 | for(Armor ar: Armor.armorList()) 57 | { 58 | ++ID; 59 | System.out.printf("%d - %s:\tDefence: %d\tPrice: %d$\n", ID, ar.getName(), ar.getDefence(), ar.getPrice()); 60 | } 61 | } 62 | System.out.println("0 - Exit"); 63 | System.out.print("Enter the item ID you want to buy it: "); 64 | } 65 | public void selectItem(Item item) { 66 | 67 | int ID = -1; 68 | while(ID != 0) 69 | { 70 | if(item instanceof Weapon) 71 | { 72 | Inhibitory.takeInt(Inhibitory.sc); 73 | ID = Inhibitory.sc.nextInt(); 74 | ID = Inhibitory.chooseValidWeapon(ID); 75 | } 76 | else if(item instanceof Armor) 77 | { 78 | Inhibitory.takeInt(Inhibitory.sc); 79 | ID = Inhibitory.sc.nextInt(); 80 | ID = Inhibitory.chooseValidArmor(ID); 81 | } 82 | if(ID != 0) 83 | { 84 | buy(item, ID); 85 | printItems(item); 86 | } 87 | } 88 | } 89 | public void buy(Item item, int ID) { 90 | 91 | --ID; //index starts with 0 92 | if(item instanceof Weapon) 93 | { 94 | if(Game.player.getMoney() < Weapon.weaponList().get(ID).getPrice()) 95 | { 96 | System.out.println("You don't have enough money!"); 97 | } 98 | else 99 | { 100 | Game.player.inventory.setWeaponName(Weapon.weaponList().get(ID).getName()); 101 | Game.player.inventory.setWeaponDamage(Weapon.weaponList().get(ID).getDamage()); 102 | Game.player.setMoney(Game.player.getMoney() - Weapon.weaponList().get(ID).getPrice()); 103 | System.out.println("You bought: " + Weapon.weaponList().get(ID).getName()); 104 | } 105 | 106 | } 107 | else if(item instanceof Armor) 108 | { 109 | if(Game.player.getMoney() < Armor.armorList().get(ID).getPrice()) 110 | { 111 | System.out.println("You don't have enough money!"); 112 | } 113 | else 114 | { 115 | Game.player.inventory.setArmorName(Armor.armorList().get(ID).getName()); 116 | Game.player.inventory.setArmorDefence(Armor.armorList().get(ID).getDefence()); 117 | Game.player.setMoney(Game.player.getMoney() - Armor.armorList().get(ID).getPrice()); 118 | System.out.println("You bougth: " + Armor.armorList().get(ID).getName()); 119 | } 120 | } 121 | 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /Notepad/Notepad.java: -------------------------------------------------------------------------------- 1 | package pack; 2 | 3 | import java.awt.EventQueue; 4 | import javax.swing.JFileChooser; 5 | import javax.swing.JFrame; 6 | import javax.swing.JScrollPane; 7 | import javax.swing.JTextArea; 8 | import javax.swing.JMenuBar; 9 | import javax.swing.JMenu; 10 | import javax.swing.JMenuItem; 11 | import javax.swing.JOptionPane; 12 | import java.awt.event.ActionListener; 13 | import java.io.BufferedWriter; 14 | import java.io.FileNotFoundException; 15 | import java.io.FileReader; 16 | import java.io.FileWriter; 17 | import java.io.IOException; 18 | import java.util.Scanner; 19 | import java.awt.event.ActionEvent; 20 | 21 | public class NotePad { 22 | 23 | private JFrame frmNotepad; 24 | 25 | /** 26 | * Launch the application. 27 | */ 28 | public static void main(String[] args) { 29 | EventQueue.invokeLater(new Runnable() { 30 | public void run() { 31 | try { 32 | NotePad window = new NotePad(); 33 | window.frmNotepad.setVisible(true); 34 | } catch (Exception e) { 35 | e.printStackTrace(); 36 | } 37 | } 38 | }); 39 | } 40 | /** 41 | * Create the application. 42 | */ 43 | public NotePad() { 44 | initialize(); 45 | } 46 | /** 47 | * Initialize the contents of the frame. 48 | */ 49 | private void initialize() { 50 | frmNotepad = new JFrame(); 51 | frmNotepad.setTitle("Notepad"); 52 | frmNotepad.setBounds(100, 100, 450, 300); 53 | frmNotepad.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 54 | frmNotepad.getContentPane().setLayout(null); 55 | JScrollPane scrollPane = new JScrollPane(); 56 | scrollPane.setBounds(0, 0, 434, 261); 57 | frmNotepad.getContentPane().add(scrollPane); 58 | JTextArea txtNote = new JTextArea(); 59 | scrollPane.setViewportView(txtNote); 60 | JMenuBar menuBar = new JMenuBar(); 61 | scrollPane.setColumnHeaderView(menuBar); 62 | JMenu FileMenu = new JMenu("File"); 63 | menuBar.add(FileMenu); 64 | JMenuItem newitem = new JMenuItem("New File"); 65 | newitem.addActionListener(new ActionListener() { 66 | public void actionPerformed(ActionEvent e) { 67 | txtNote.setText(""); 68 | } 69 | }); 70 | FileMenu.add(newitem); 71 | JMenuItem openitem = new JMenuItem("Open File"); 72 | openitem.addActionListener(new ActionListener() { 73 | public void actionPerformed(ActionEvent e) { 74 | JFileChooser open = new JFileChooser(); 75 | int choice = open.showOpenDialog(openitem); 76 | if(choice == JFileChooser.APPROVE_OPTION) 77 | { 78 | try { 79 | Scanner sc = new Scanner(new FileReader(open.getSelectedFile().getPath())); 80 | 81 | JOptionPane.showMessageDialog(null, "File opened"); 82 | 83 | while (sc.hasNext()) { 84 | txtNote.append(sc.nextLine() +"\n"); 85 | } 86 | } 87 | catch (FileNotFoundException e1) { 88 | JOptionPane.showMessageDialog(null, e1); 89 | } 90 | } 91 | } 92 | }); 93 | FileMenu.add(openitem); 94 | JMenuItem saveitem = new JMenuItem("Save"); 95 | saveitem.addActionListener(new ActionListener() { 96 | public void actionPerformed(ActionEvent e) { 97 | JFileChooser save = new JFileChooser(); 98 | int choice = save.showOpenDialog(saveitem); 99 | if(choice == JFileChooser.APPROVE_OPTION) 100 | { 101 | try { 102 | BufferedWriter bw = new BufferedWriter(new FileWriter(save.getSelectedFile().getPath())); 103 | bw.write(txtNote.getText()); 104 | bw.close(); 105 | JOptionPane.showMessageDialog(null, "File saved"); 106 | } catch (IOException e1) { 107 | JOptionPane.showMessageDialog(null, e1); 108 | } 109 | } 110 | } 111 | }); 112 | FileMenu.add(saveitem); 113 | JMenu FormatMenu = new JMenu("Format"); 114 | menuBar.add(FormatMenu); 115 | JMenuItem textsytlitem = new JMenuItem("Text Style"); 116 | FormatMenu.add(textsytlitem); 117 | JMenuItem pasteitem = new JMenuItem("Paste"); 118 | FormatMenu.add(pasteitem); 119 | JMenuItem copyitem = new JMenuItem("Copy"); 120 | FormatMenu.add(copyitem); 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /AdventureGame/Inhibitory.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | import java.util.Scanner; 4 | 5 | public abstract class Inhibitory { 6 | 7 | public static Scanner sc = new Scanner(System.in); 8 | public static int numberOfChamp; 9 | public static int numberOfLoc; 10 | private static final String noPermittedChar="[ \"*-/<>|!,?.\\'@ .%]+"; 11 | private static final int maxNameLength=15, minNameLength=3; 12 | 13 | public static String takeValidName(String name) { 14 | 15 | while(!isValidName(name)) 16 | { 17 | if(name.length() < minNameLength || name.length() > maxNameLength) 18 | { 19 | System.out.printf("Your nickname must be %d-%d characters!\nPlease enter your nickname: ", minNameLength, maxNameLength); 20 | name = sc.nextLine(); 21 | } 22 | else 23 | { 24 | System.out.printf("Your nickname can not include these characters: %s\nPlease enter your nickname: ", noPermittedChar); 25 | name = sc.nextLine(); 26 | } 27 | } 28 | return name; 29 | } 30 | private static boolean isValidName(String name) { //checks the name valid or not 31 | 32 | if(minNameLength <= name.length() && name.length() <= maxNameLength && name.equals(optimalName(name))) 33 | return true; 34 | else 35 | return false; 36 | } 37 | private static String optimalName(String name) { 38 | 39 | String words[]=name.trim().split(noPermittedChar); 40 | String checker=""; 41 | for (String s:words) 42 | { 43 | checker+=s; 44 | } 45 | return checker; 46 | } 47 | public static void takeInt(Scanner sc) { 48 | 49 | while(!sc.hasNextInt()) 50 | { 51 | System.out.print("\nPlease use just integers!\nEnter again: "); 52 | sc.next(); 53 | } 54 | } 55 | public static String takeValidDecision(String decision) { 56 | decision = decision.toUpperCase(); 57 | while(!decision.equals("A") && !decision.equals("R")) 58 | { 59 | System.out.println("Enter a valid letter! ( - )"); 60 | decision = sc.nextLine().toUpperCase(); 61 | } 62 | return decision; 63 | } 64 | public static int takeValidDecision(int decision) { 65 | while(decision < 0 || decision > 1) 66 | { 67 | System.out.println("Enter a valid number! (0-1)\nDo you want to drink something?\n1 - Yes\n0 - Exit"); 68 | takeInt(sc); 69 | decision = sc.nextInt(); 70 | } 71 | return decision; 72 | } 73 | public static int takeValidID(int champID) { 74 | 75 | while(champID < 1 || champID > numberOfChamp) 76 | { 77 | System.out.printf("\nPlease enter a valid number! (1-%d)\nEnter the champion ID you want to choose it: ", numberOfChamp); 78 | takeInt(sc); 79 | champID = sc.nextInt(); 80 | } 81 | return champID; 82 | } 83 | public static int takeValidNO(int locNO) { 84 | while(locNO < 0 || locNO > numberOfLoc) 85 | { 86 | System.out.printf("\nPlease enter a valid number! (1-%d)\nEnter the location NO you want to go there: ", numberOfLoc); 87 | takeInt(sc); 88 | locNO = sc.nextInt(); 89 | } 90 | 91 | return locNO; 92 | } 93 | public static int takeValidChoice(int choice) { 94 | while(choice < 0 || choice > 3) 95 | { 96 | System.out.println("\nPlease enter a valid number! (0-3)\nWhat do you want?"); 97 | takeInt(sc); 98 | choice = sc.nextInt(); 99 | } 100 | return choice; 101 | } 102 | public static int chooseValidWeapon(int weaponID) { 103 | while(weaponID < 0 || weaponID > Weapon.weaponList().size()) 104 | { 105 | System.out.printf("\nPlease enter a valid ID! (0-%d)\nEnter the weapon ID you want to buy it: ", Weapon.weaponList().size()); 106 | takeInt(sc); 107 | weaponID = sc.nextInt(); 108 | } 109 | return weaponID; 110 | } 111 | public static int chooseValidArmor(int armorID) { 112 | while(armorID < 0 || armorID > Armor.armorList().size()) 113 | { 114 | System.out.printf("\nPlease enter a valid ID! (0-%d)\nEnter the armor ID you want to buy it: ", Armor.armorList().size()); 115 | takeInt(sc); 116 | armorID = sc.nextInt(); 117 | } 118 | return armorID; 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /AdventureGame/BattleLoc.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public abstract class BattleLoc extends Location { 4 | 5 | public int obsNumber; 6 | private Obstacle obstacle; 7 | private int maxObstacle; 8 | private String speacialItemName; 9 | public BattleLoc(Player player, String name, Obstacle obstacle, int maxObstacle, String speaicalItemName) { 10 | super(player, name); 11 | this.setObstacle(obstacle); 12 | this.setMaxObstacle(maxObstacle); 13 | this.setSpeacialItemName(speaicalItemName); 14 | } 15 | @Override 16 | public boolean onLocation() { 17 | 18 | obsNumber = this.randomObstacleNumber(); 19 | System.out.println("You are in " + this.getName()+ "\n" + obsNumber + " "+ this.getObstacle().getName() + "s are nearby"); 20 | Inhibitory.sc.nextLine(); //needs for initial empty entering 21 | combatDecision(makeDecision()); 22 | if(Game.player.getHealth() > 0) 23 | { 24 | return true; 25 | } 26 | else 27 | { 28 | return false; 29 | } 30 | } 31 | public String makeDecision() { 32 | System.out.print("\nttack or un: "); 33 | String decision = Inhibitory.sc.nextLine(); 34 | decision = Inhibitory.takeValidDecision(decision); 35 | return decision; 36 | } 37 | public void combatDecision(String decision) { 38 | if(decision.equals("A")) 39 | { 40 | combat(); 41 | } 42 | else if(decision.equals("R")) 43 | { 44 | System.out.println("You return to your village"); 45 | } 46 | } 47 | public void combat() { 48 | 49 | for(int i = 1; i <= obsNumber; ++i) 50 | { 51 | this.getObstacle().setHealth(this.getObstacle().getDefaultHealth()); 52 | Game.player.playerInfo(); 53 | obstacleInfo(i); 54 | while(Game.player.getHealth() > 0 && this.getObstacle().getHealth() > 0) 55 | { 56 | String decision = makeDecision(); 57 | int firstHit = this.firstHit(); 58 | if(decision.equals("A")) 59 | { 60 | if(firstHit == 0) 61 | { 62 | playerHitInfo(); 63 | if(this.getObstacle().getHealth() > 0) 64 | { 65 | obstacleHitInfo(); 66 | } 67 | } 68 | else if(firstHit == 1) 69 | { 70 | obstacleHitInfo(); 71 | if(Game.player.getHealth() > 0) 72 | { 73 | playerHitInfo(); 74 | } 75 | } 76 | } 77 | else if(decision.equals("R")) 78 | { 79 | System.out.println("You ran away from the war!"); 80 | return; 81 | } 82 | } 83 | if(Game.player.getHealth() == 0) 84 | { 85 | break; 86 | } 87 | if(i == obsNumber) 88 | { 89 | System.out.printf("You defeat all the %ss!", this.getObstacle().getName()); 90 | System.out.printf("\nYou earn %s", this.getSpeacialItemName()); 91 | if(this instanceof Cave) 92 | { 93 | Game.player.inventory.setFood(true); 94 | } 95 | else if(this instanceof Forest) 96 | { 97 | Game.player.inventory.setWood(true); 98 | } 99 | else if(this instanceof River) 100 | { 101 | Game.player.inventory.setWater(true); 102 | } 103 | else if(this instanceof Mine) 104 | { 105 | Game.player.inventory.setSnakeSkin(true); 106 | } 107 | } 108 | else 109 | { 110 | System.out.printf("%d. %s is dead!", i, this.getObstacle().getName()); 111 | } 112 | Game.player.setMoney(Game.player.getMoney() + this.getObstacle().getAward()); 113 | System.out.printf("\nYou receive %d$.", this.getObstacle().getAward()); 114 | } 115 | } 116 | public void playerHitInfo() { 117 | System.out.println("You hit " + Game.player.getDamage() + " damage to the " + this.getObstacle().getName()); 118 | this.getObstacle().setHealth(this.getObstacle().getHealth() - Game.player.getDamage()); 119 | System.out.println(this.getObstacle().getName() + "'s remaining health: " + this.getObstacle().getHealth()); 120 | } 121 | public void obstacleHitInfo() { 122 | System.out.println(this.getObstacle().getName() + " hitted you " + this.getObstacle().getDamage() + " damage."); 123 | if(this.getObstacle().getDamage() > Game.player.getDefence()) 124 | { 125 | Game.player.setHealth(Game.player.getHealth() - (this.getObstacle().getDamage() - Game.player.getDefence())); 126 | System.out.println("Your remaining health: " + Game.player.getHealth()); 127 | } 128 | else 129 | { 130 | System.out.println("Your armor is too strong you took no damage!"); 131 | } 132 | } 133 | public int firstHit() { 134 | int probability = (int) (Math.random()*2);// generates random number 1 or 0 135 | return probability; 136 | } 137 | public void obstacleInfo(int i) { 138 | System.out.println("\n----- " + i + ". Obstacle Info -----"); 139 | System.out.printf("Name: %s,\tHealth: %d,\tDamage: %d,\tMoney award: %d ", this.getObstacle().getName(), this.getObstacle().getHealth(), 140 | this.getObstacle().getDamage(), this.getObstacle().getAward()); 141 | } 142 | public int randomObstacleNumber() { 143 | int randomNum = (int) (Math.random()*this.getMaxObstacle()+1); 144 | return randomNum; 145 | } 146 | /** 147 | * @return the obstacle 148 | */ 149 | public Obstacle getObstacle() { 150 | return obstacle; 151 | } 152 | /** 153 | * @return the maxObstacle 154 | */ 155 | public int getMaxObstacle() { 156 | return maxObstacle; 157 | } 158 | /** 159 | * @return the speacialItemName 160 | */ 161 | public String getSpeacialItemName() { 162 | return speacialItemName; 163 | } 164 | /** 165 | * @param maxObstacle the maxObstacle to set 166 | */ 167 | public void setMaxObstacle(int maxObstacle) { 168 | this.maxObstacle = maxObstacle; 169 | } 170 | /** 171 | * @param obstacle the obstacle to set 172 | */ 173 | public void setObstacle(Obstacle obstacle) { 174 | this.obstacle = obstacle; 175 | } 176 | /** 177 | * @param speacialItemName the speacialItemName to set 178 | */ 179 | public void setSpeacialItemName(String speacialItemName) { 180 | this.speacialItemName = speacialItemName; 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /AdventureGame/Player.java: -------------------------------------------------------------------------------- 1 | package game; 2 | 3 | public class Player { 4 | 5 | public Inventory inventory = new Inventory(); 6 | private Champion champ; 7 | private Location location; 8 | private String name; 9 | private String champName; 10 | private int health; 11 | private int damage; 12 | private int defence; 13 | private int money; 14 | 15 | public Player(String name) { 16 | this.setName(name); 17 | } 18 | public Player() { 19 | 20 | } 21 | public void selectChamp() { 22 | 23 | Champion[] champions = {new Warrior(), new Archer(), new Wizard()}; 24 | Inhibitory.numberOfChamp = champions.length; 25 | int ID = 0; 26 | for(Champion c: champions) 27 | { 28 | ++ID; 29 | System.out.println("\n----------------------------------------------------------------------------------"); 30 | System.out.printf("%d -\tName: %s \tHealth: %d\tDamage: %d\tDefence: %d\tMoney: %d", ID, c.getName(), c.getHealth(), c.getDamage(), c.getDefence(), c.getMoney()); 31 | } 32 | System.out.println("\n----------------------------------------------------------------------------------"); 33 | System.out.print("\nEnter the champion ID you want to choose it: "); 34 | Inhibitory.takeInt(Inhibitory.sc); 35 | int selectedChamp = Inhibitory.sc.nextInt(); 36 | selectedChamp = Inhibitory.takeValidID(selectedChamp); 37 | initPlayer(champions[selectedChamp-1]); 38 | Game.player.setChamp(champions[selectedChamp-1]); 39 | printChampInfo(); 40 | 41 | } 42 | public void printChampInfo() { 43 | System.out.println("Chosen Champion: " + getChampName() 44 | + ", Health: " + getHealth() 45 | + ", Damage: " + getDamage() 46 | + ", Defence: " + getDefence() 47 | + ", Money: " + getMoney()); 48 | } 49 | public void selectLoc() { 50 | Location[] locations = {new SafeHouse(this), new ToolStore(this), new Cave(this), new Forest(this), new River(this), new Mine(this)}; 51 | Inhibitory.numberOfLoc = locations.length; 52 | int NO = 0; 53 | for(Location loc: locations) 54 | { 55 | ++NO; 56 | System.out.printf("\n%d - Place: %s", NO, loc.getName()); 57 | } 58 | System.out.println("\n0 - Exit game"); 59 | System.out.println("\nEnter the place NO you want to go there: "); 60 | Inhibitory.takeInt(Inhibitory.sc); 61 | int selectedLoc = Inhibitory.sc.nextInt(); 62 | selectedLoc = Inhibitory.takeValidNO(selectedLoc); 63 | switch(selectedLoc) 64 | { 65 | case 0: 66 | this.location = null; 67 | break; 68 | default: 69 | if(locations[selectedLoc-1] instanceof Cave && Game.player.inventory.hasFood() || locations[selectedLoc-1] instanceof Forest && Game.player.inventory.hasWood() || locations[selectedLoc-1] instanceof River && Game.player.inventory.hasWater() || locations[selectedLoc-1] instanceof Mine && Game.player.inventory.hasSnakeSkin()) 70 | { 71 | System.out.println("This area seems clear.\nChoose another"); 72 | selectLoc(); 73 | } 74 | else 75 | { 76 | this.setLocation((locations[selectedLoc-1])); 77 | } 78 | } 79 | 80 | } 81 | public void playerInfo() { 82 | System.out.println("\n\n----- Player Info -----"); 83 | System.out.printf("Weapon: %s,\tHealth: %d,\tDamage: %d" 84 | + "\nMoney: %d,\tArmor: %s,\tDefence: %d\n", inventory.getWeaponName(), this.getHealth(), this.getDamage(), 85 | this.getMoney(), inventory.getArmorName(), this.getDefence()); 86 | } 87 | public void initPlayer(Champion champ) { 88 | this.setHealth(champ.getHealth()); 89 | this.setDamage(champ.getDamage()); 90 | this.setMoney(champ.getMoney()); 91 | this.setChampName(champ.getName()); 92 | this.setDefence(champ.getDefence()); 93 | } 94 | /** 95 | * @return the champName 96 | */ 97 | public String getChampName() { 98 | return champName; 99 | } 100 | /** 101 | * @return the name 102 | */ 103 | public String getName() { 104 | return name; 105 | } 106 | /** 107 | * @return the health 108 | */ 109 | public int getHealth() { 110 | return health; 111 | } 112 | /** 113 | * @return the damage 114 | */ 115 | public int getDamage() { 116 | return damage + inventory.getWeaponDamage(); 117 | } 118 | /** 119 | * @return the defence 120 | */ 121 | public int getDefence() { 122 | return defence + inventory.getArmorDefence(); 123 | } 124 | /** 125 | * @return the money 126 | */ 127 | public int getMoney() { 128 | return money; 129 | } 130 | /** 131 | * @return the location 132 | */ 133 | public Location getLocation() { 134 | return location; 135 | } 136 | /** 137 | * @return the champ 138 | */ 139 | public Champion getChamp() { 140 | return champ; 141 | } 142 | /** 143 | * @param inventory the inventory to set 144 | */ 145 | public void setInventory(Inventory inventory) { 146 | this.inventory = inventory; 147 | } 148 | /** 149 | * @param champ the champ to set 150 | */ 151 | public void setChamp(Champion champ) { 152 | this.champ = champ; 153 | } 154 | /** 155 | * @param location the location to set 156 | */ 157 | public void setLocation(Location location) { 158 | this.location = location; 159 | } 160 | /** 161 | * @param champ the champName to set 162 | */ 163 | public void setChampName(String champName) { 164 | this.champName = champName; 165 | } 166 | /** 167 | * @param name the name to set 168 | */ 169 | public void setName(String name) { 170 | this.name = name; 171 | } 172 | /** 173 | * @param health the health to set 174 | */ 175 | public void setHealth(int health) { 176 | if(health < 0) 177 | { 178 | this.health = 0; 179 | } 180 | else 181 | { 182 | this.health = health; 183 | } 184 | } 185 | /** 186 | * @param damage the damage to set 187 | */ 188 | public void setDamage(int damage) { 189 | this.damage = damage; 190 | } 191 | /** 192 | * @param money the money to set 193 | */ 194 | public void setMoney(int money) { 195 | if(0<=money) 196 | { 197 | this.money = money; 198 | } 199 | } 200 | /** 201 | * @param defence the defence to set 202 | */ 203 | public void setDefence(int defence) { 204 | this.defence = defence; 205 | } 206 | 207 | } 208 | --------------------------------------------------------------------------------