diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..e7e9d11
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,2 @@
+# Default ignored files
+/workspace.xml
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..a55e7a1
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..639900d
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..90ed89c
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OOP_Project-Lake_Nozama.iml b/OOP_Project-Lake_Nozama.iml
new file mode 100644
index 0000000..e7b98ac
--- /dev/null
+++ b/OOP_Project-Lake_Nozama.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/out/production/OOP_Project-Lake_Nozama/game/Fish.class b/out/production/OOP_Project-Lake_Nozama/game/Fish.class
new file mode 100644
index 0000000..0571850
Binary files /dev/null and b/out/production/OOP_Project-Lake_Nozama/game/Fish.class differ
diff --git a/out/production/OOP_Project-Lake_Nozama/game/Game.class b/out/production/OOP_Project-Lake_Nozama/game/Game.class
new file mode 100644
index 0000000..e26cc62
Binary files /dev/null and b/out/production/OOP_Project-Lake_Nozama/game/Game.class differ
diff --git a/out/production/OOP_Project-Lake_Nozama/game/GameController.class b/out/production/OOP_Project-Lake_Nozama/game/GameController.class
new file mode 100644
index 0000000..65cf947
Binary files /dev/null and b/out/production/OOP_Project-Lake_Nozama/game/GameController.class differ
diff --git a/out/production/OOP_Project-Lake_Nozama/game/GridLocation.class b/out/production/OOP_Project-Lake_Nozama/game/GridLocation.class
new file mode 100644
index 0000000..9ed0626
Binary files /dev/null and b/out/production/OOP_Project-Lake_Nozama/game/GridLocation.class differ
diff --git a/out/production/OOP_Project-Lake_Nozama/game/InhabitantCharacter.class b/out/production/OOP_Project-Lake_Nozama/game/InhabitantCharacter.class
new file mode 100644
index 0000000..ca2b255
Binary files /dev/null and b/out/production/OOP_Project-Lake_Nozama/game/InhabitantCharacter.class differ
diff --git a/out/production/OOP_Project-Lake_Nozama/game/InnocentFish.class b/out/production/OOP_Project-Lake_Nozama/game/InnocentFish.class
new file mode 100644
index 0000000..d5f7533
Binary files /dev/null and b/out/production/OOP_Project-Lake_Nozama/game/InnocentFish.class differ
diff --git a/out/production/OOP_Project-Lake_Nozama/game/KillerFish.class b/out/production/OOP_Project-Lake_Nozama/game/KillerFish.class
new file mode 100644
index 0000000..cb0381b
Binary files /dev/null and b/out/production/OOP_Project-Lake_Nozama/game/KillerFish.class differ
diff --git a/out/production/OOP_Project-Lake_Nozama/game/Lotus.class b/out/production/OOP_Project-Lake_Nozama/game/Lotus.class
new file mode 100644
index 0000000..e187d6d
Binary files /dev/null and b/out/production/OOP_Project-Lake_Nozama/game/Lotus.class differ
diff --git a/out/production/OOP_Project-Lake_Nozama/game/NormalWarrior.class b/out/production/OOP_Project-Lake_Nozama/game/NormalWarrior.class
new file mode 100644
index 0000000..a9e5e9b
Binary files /dev/null and b/out/production/OOP_Project-Lake_Nozama/game/NormalWarrior.class differ
diff --git a/out/production/OOP_Project-Lake_Nozama/game/RubberFish.class b/out/production/OOP_Project-Lake_Nozama/game/RubberFish.class
new file mode 100644
index 0000000..81907d9
Binary files /dev/null and b/out/production/OOP_Project-Lake_Nozama/game/RubberFish.class differ
diff --git a/out/production/OOP_Project-Lake_Nozama/game/SuperWarrior.class b/out/production/OOP_Project-Lake_Nozama/game/SuperWarrior.class
new file mode 100644
index 0000000..f69ea2e
Binary files /dev/null and b/out/production/OOP_Project-Lake_Nozama/game/SuperWarrior.class differ
diff --git a/out/production/OOP_Project-Lake_Nozama/game/Treasure.class b/out/production/OOP_Project-Lake_Nozama/game/Treasure.class
new file mode 100644
index 0000000..2bef9c1
Binary files /dev/null and b/out/production/OOP_Project-Lake_Nozama/game/Treasure.class differ
diff --git a/out/production/OOP_Project-Lake_Nozama/game/Warrior.class b/out/production/OOP_Project-Lake_Nozama/game/Warrior.class
new file mode 100644
index 0000000..332b401
Binary files /dev/null and b/out/production/OOP_Project-Lake_Nozama/game/Warrior.class differ
diff --git a/src/game/Fish.java b/src/game/Fish.java
new file mode 100644
index 0000000..ade0e92
--- /dev/null
+++ b/src/game/Fish.java
@@ -0,0 +1,11 @@
+package game;
+
+public abstract class Fish extends InhabitantCharacter implements Runnable{
+ public Fish(String name,int x,int y){
+ this.setCharacterName(name);
+ this.setXCoordinate(x);
+ this.setYCoordinate(y);
+ }
+ public void swim(){}
+ public abstract void eat();
+}
\ No newline at end of file
diff --git a/src/game/Game.java b/src/game/Game.java
new file mode 100644
index 0000000..08b86eb
--- /dev/null
+++ b/src/game/Game.java
@@ -0,0 +1,61 @@
+package game;
+import java.util.*;
+
+public class Game {
+ static GameController gamecontroller;
+ static Treasure tChest;
+ public static void main(String[] args) {
+ ArrayList Inhabitants=new ArrayList<>(); //store newly created warrior and fish objects
+ Warrior[] listOfWarriors=new Warrior[4]; //store newly created warrior objects
+ gamecontroller=new GameController(); //make a new playground(lake)
+ System.out.println("-------Let's start the game--------");
+ int[][] warriorCoordinates=gamecontroller.placeWarriors(); //get random initial coordinates for warriors
+ String[] warriorNames={"SuperWarrior1","NormalWarrior1","SuperWarrior2","NormalWarrior2"};
+ for(int i=0;i<4;i++){ //create two normalWarriors & two superWarriors
+ Warrior newWarrior;
+ if(i%2==0){
+ newWarrior=new SuperWarrior(warriorNames[i],warriorCoordinates[i][0],warriorCoordinates[i][1]);
+ }else{
+ newWarrior=new NormalWarrior(warriorNames[i],warriorCoordinates[i][0],warriorCoordinates[i][1]);
+ }
+ gamecontroller.addCharacters(newWarrior,newWarrior.getXCoordinate(),newWarrior.getYCoordinate()); //insert the newly created warrior into the grid
+ listOfWarriors[i]=newWarrior;
+ Inhabitants.add(newWarrior);
+ }
+ int[][][] fishAndlotusCoordinates=gamecontroller.placeFishAndLotus();
+ int[][] fishCoordinates=fishAndlotusCoordinates[0]; //get random initial coordinates for fish
+ String[] fishNames={"KillerFish1","KillerFish2","RubberFish1","RubberFish2","InnocentFish1","InnocentFish2"};
+ for(int i=0;i<6;i++){ //create fish objects
+ Fish newfish;
+ if(i<2){
+ newfish=new KillerFish(fishNames[i],fishCoordinates[i][0],fishCoordinates[i][1]);
+ }else if(i<4){
+ newfish=new RubberFish(fishNames[i],fishCoordinates[i][0],fishCoordinates[i][1]);
+ }else{
+ newfish=new InnocentFish(fishNames[i],fishCoordinates[i][0],fishCoordinates[i][1]);
+ }
+ gamecontroller.addCharacters(newfish,newfish.getXCoordinate(),newfish.getYCoordinate()); //insert the newly created fish into the grid
+ Inhabitants.add(newfish);
+ }
+ for(int i=0;i possibleCoordinates=new ArrayList<>();
+ for(int i=1;i<11;i++){
+ int[] a={0,i};int[] b={i,0};
+ possibleCoordinates.add(a);possibleCoordinates.add(b);
+ }
+ for(int j=0;j<4;j++){
+ int temp=ran.nextInt(possibleCoordinates.size());
+ int[] coordinates=possibleCoordinates.get(temp);
+ possibleCoordinates.remove(temp);
+ initialCoordinates[j][0]=coordinates[0];
+ initialCoordinates[j][1]=coordinates[1];
+ }
+ return initialCoordinates;
+ }
+ public int[][][] placeFishAndLotus(){ //randomly create the initial coordinates of the fish and lotus
+ int[][] initialCoordinates1=new int[6][2];
+ int[][] initialCoordinates2=new int[5][2];
+ ArrayList possibleCoordinates=new ArrayList<>();
+ for(int i=1;i<11;i++){
+ for(int j=1;j<11;j++){
+ if(i==5 && j==5){continue;}
+ int[] temp={i,j};
+ possibleCoordinates.add(temp);
+ }
+ }
+ for(int j=0;j<6;j++){
+ int temp=ran.nextInt(possibleCoordinates.size());
+ int[] coordinates=possibleCoordinates.get(temp);
+ possibleCoordinates.remove(temp);
+ initialCoordinates1[j][0]=coordinates[0];
+ initialCoordinates1[j][1]=coordinates[1];
+ }
+ for(int j=0;j<5;j++){
+ int temp=ran.nextInt(possibleCoordinates.size());
+ int[] coordinates=possibleCoordinates.get(temp);
+ possibleCoordinates.remove(temp);
+ initialCoordinates2[j][0]=coordinates[0];
+ initialCoordinates2[j][1]=coordinates[1];
+ }
+ int[][][] temp={initialCoordinates1,initialCoordinates2};
+ return temp;
+ }
+ public void checkTheNewLocation(Warrior w){
+ System.out.println(w.getCharacterName()+" moves to "+"("+w.getXCoordinate()+","+w.getYCoordinate()+")"); //print the new position on console
+
+ GridLocation newGridLocation=getTheLocation(w.getXCoordinate(),w.getYCoordinate()); //get the new grid location of the warrior
+ if(newGridLocation.checkForTreasure()){ //check whether he is win or not
+ Game.tChest.anounceTheWinner(w);
+ double finishingTime=System.currentTimeMillis()-w.getStartTime();
+ printWinner(w.getCharacterName(),finishingTime);
+ // System.out.println("Congratz, "+w.getCharacterName()+" won the game !!!!!!!!!!!! -"+" (Finishing Time - "+finishingtime+" ms)");
+ }
+ newGridLocation.checkForFish(); //check for any kind of fish
+ if(newGridLocation.checkForLotus()){
+ if(!w.checkImmortle()){
+ w.setImmortal(true); //if there is a lotus then make player immortle
+ System.out.println(w.getCharacterName()+" become immortal !!!!!!!!!!!");
+ }
+ }
+ }
+ public void printWinner(String name,Double time){ //store the winner&time in a file
+ System.out.println("Congratz, "+name+" won the game !!! - ");
+ System.out.println(" (Finishing Time - "+time+" ms)");
+ System.out.println(" ---Game Over---");
+ }
+}
\ No newline at end of file
diff --git a/src/game/GridLocation.java b/src/game/GridLocation.java
new file mode 100644
index 0000000..ebcea91
--- /dev/null
+++ b/src/game/GridLocation.java
@@ -0,0 +1,60 @@
+package game;
+
+public class GridLocation {
+ private Object[] charactersOccupiedTheLocation; //store the inhabitants that occupied this
+ public GridLocation(){ //of the grid at the moment
+ charactersOccupiedTheLocation=new Object[4];
+ }
+ public Warrior checkWarrior(){ //check whether there is a warrior in this location
+ Object obj=charactersOccupiedTheLocation[0];
+ if(obj!=null){
+ return (Warrior)obj;
+ }
+ return null;
+ }
+ public void checkForFish(){ //check whether there is ant kind of fish in this location
+ Object obj=charactersOccupiedTheLocation[1];
+ if(obj!=null){
+ Thread t=new Thread((Fish)obj);
+ t.start(); //start the thread of the fish
+ try {
+ t.join(); //join warrior's thread to the end of the fish thread
+ } catch (InterruptedException ex) {}
+ }
+ }
+ public boolean checkForLotus(){ //check whether there is a lotus in this location
+ Object obj=charactersOccupiedTheLocation[2];
+ if(obj!=null){return true;}
+ return false;
+ }
+ public boolean checkForTreasure(){ //check whether there is the treasure in this location
+ Object obj=charactersOccupiedTheLocation[3];
+ if(obj!=null){return true;}
+ return false;
+ }
+ public void initiallyFillTheLocation(Object obj){ //add objects to grid location at the start of game
+ if(obj instanceof Warrior){
+ charactersOccupiedTheLocation[0]=obj;
+ }else if(obj instanceof Fish){
+ charactersOccupiedTheLocation[1]=obj;
+ }else if(obj instanceof Lotus){
+ charactersOccupiedTheLocation[2]=obj;
+ }else{
+ charactersOccupiedTheLocation[3]=obj;
+ }
+ }
+ public synchronized void addTheWarrior(Warrior w){ //add the incoming warrior to the location
+ Warrior obj=(Warrior)charactersOccupiedTheLocation[0];
+ while(obj!=null && w.checkMobility() && obj.checkMobility() && obj.checkIsAlive()){
+ try {
+ wait(1000); //1000
+ } catch (InterruptedException ex) {}
+ obj=(Warrior)charactersOccupiedTheLocation[0];
+ }
+ charactersOccupiedTheLocation[0]=w;
+ }
+ public synchronized void removeTheWarrior(){ //remove outgoing warrior from the location
+ charactersOccupiedTheLocation[0]=null;
+ notifyAll();
+ }
+}
\ No newline at end of file
diff --git a/src/game/InhabitantCharacter.java b/src/game/InhabitantCharacter.java
new file mode 100644
index 0000000..008ce02
--- /dev/null
+++ b/src/game/InhabitantCharacter.java
@@ -0,0 +1,25 @@
+package game;
+
+public abstract class InhabitantCharacter{
+ private String characterName;
+ private int currentXCoordinate;
+ private int currentYCoordinate;
+ public void setCharacterName(String name){
+ characterName=name;
+ }
+ public String getCharacterName(){
+ return characterName;
+ }
+ public int getXCoordinate(){
+ return currentXCoordinate;
+ }
+ public int getYCoordinate(){
+ return currentYCoordinate;
+ }
+ public void setXCoordinate(int x){
+ currentXCoordinate=x;
+ }
+ public void setYCoordinate(int y){
+ currentYCoordinate=y;
+ }
+}
\ No newline at end of file
diff --git a/src/game/InnocentFish.java b/src/game/InnocentFish.java
new file mode 100644
index 0000000..f70e04d
--- /dev/null
+++ b/src/game/InnocentFish.java
@@ -0,0 +1,11 @@
+package game;
+
+public class InnocentFish extends Fish{
+ public InnocentFish(String name,int x,int y){
+ super(name,x,y);
+ }
+ @Override
+ public void run(){}
+ @Override
+ public void eat(){}
+}
\ No newline at end of file
diff --git a/src/game/KillerFish.java b/src/game/KillerFish.java
new file mode 100644
index 0000000..6136e6a
--- /dev/null
+++ b/src/game/KillerFish.java
@@ -0,0 +1,21 @@
+package game;
+
+public class KillerFish extends Fish{
+ public KillerFish(String name,int x,int y){
+ super(name,x,y);
+ }
+ @Override
+ public void run(){
+ GridLocation gl=Game.gamecontroller.getTheLocation(this.getXCoordinate(),this.getYCoordinate()); //get its location
+ Warrior w=gl.checkWarrior(); //get the wrrior there
+ kill(w); //execute kill method
+ }
+ public void kill(Warrior w){
+ if(!w.checkImmortle()){
+ w.setIsAlive(false); //kill the warrior
+ System.out.println("KillerFish "+this.getCharacterName()+" kills "+w.getCharacterName());
+ }
+ }
+ @Override
+ public void eat(){}
+}
\ No newline at end of file
diff --git a/src/game/Lotus.java b/src/game/Lotus.java
new file mode 100644
index 0000000..b345e4e
--- /dev/null
+++ b/src/game/Lotus.java
@@ -0,0 +1,22 @@
+package game;
+
+public class Lotus{
+ private int xCoordinate;
+ private int yCoordinate;
+ public Lotus(int x,int y){
+ xCoordinate=x;
+ yCoordinate=y;
+ }
+ public int getXCoordinate(){
+ return xCoordinate;
+ }
+ public int getYCoordinate(){
+ return yCoordinate;
+ }
+ public void setXCoordinate(int x){
+ xCoordinate=x;
+ }
+ public void setYCoordinate(int y){
+ yCoordinate=y;
+ }
+}
\ No newline at end of file
diff --git a/src/game/NormalWarrior.java b/src/game/NormalWarrior.java
new file mode 100644
index 0000000..42930ac
--- /dev/null
+++ b/src/game/NormalWarrior.java
@@ -0,0 +1,47 @@
+package game;
+import java.util.*;
+
+public class NormalWarrior extends Warrior{
+ public NormalWarrior(String name,int x,int y){
+ super(name,x,y);
+ }
+ @Override
+ public void sleep(){System.out.println("NormalWarrior "+this.getCharacterName()+" sleeps");}
+ @Override
+ public void eat(){System.out.println("NormalWarrior "+this.getCharacterName()+" eats");}
+ @Override
+ public void swim(){
+ int previousXcoordinate=getXCoordinate();
+ int previousYcoordinate=getYCoordinate();
+ Random ran=new Random();
+ boolean foundNewCoordinate=false;
+ int[] newCoordinates=new int[2];
+ while(!foundNewCoordinate){ //Loop will run until a new appropiate set of coordinates is found
+ int randomInt=ran.nextInt(2); //choose the ccoordinate that is going to be changed(either x or y)
+ int[] possibleMoves={-1,1};
+ int expectedNewX;
+ int expectedNewY;
+ if(randomInt==0){ //change only the x coordinate
+ int nextChange=possibleMoves[ran.nextInt(2)]; //choose whether warrior is going to his left or right
+ expectedNewX=getXCoordinate()+nextChange;
+ expectedNewY=getYCoordinate();
+ }else{ //change only the y coordinate
+ int nextChange=possibleMoves[ran.nextInt(2)]; //choose whether warrior is going up or down
+ expectedNewY=getYCoordinate()+nextChange;
+ expectedNewX=getXCoordinate();
+ }
+ if((expectedNewX>=0)&&(expectedNewX<11)&&(expectedNewY>=0)&&(expectedNewY<11)){
+ GridLocation expectedLocation=Game.gamecontroller.getTheLocation(expectedNewX,expectedNewY);
+ if(expectedLocation.checkWarrior()==null){ //check whether the new location is already occupied by an other warrior or not
+ this.setXCoordinate(expectedNewX); //set the new coordinates if new location is vacant
+ this.setYCoordinate(expectedNewY);
+ newCoordinates[0]=expectedNewX;
+ newCoordinates[1]=expectedNewY;
+ foundNewCoordinate=true;
+ }
+ }
+ }
+ Game.gamecontroller.tranferTheWarrior(this, previousXcoordinate, previousYcoordinate, newCoordinates[0], newCoordinates[1]); //transfer warrior from old location to new location
+ Game.gamecontroller.checkTheNewLocation(this); //check the new location
+ }
+}
\ No newline at end of file
diff --git a/src/game/RubberFish.java b/src/game/RubberFish.java
new file mode 100644
index 0000000..9f00e41
--- /dev/null
+++ b/src/game/RubberFish.java
@@ -0,0 +1,21 @@
+package game;
+
+public class RubberFish extends Fish{
+ public RubberFish(String name,int x,int y){
+ super(name,x,y);
+ }
+ @Override
+ public void run(){
+ GridLocation gl=Game.gamecontroller.getTheLocation(this.getXCoordinate(),this.getYCoordinate());
+ Warrior w=gl.checkWarrior(); //get the wrrior there
+ eatFins(w); //execute eatfins method
+ }
+ @Override
+ public void eat(){}
+ public void eatFins(Warrior w){
+ if(w.checkIsAlive()){
+ System.out.println("RubberFish "+this.getCharacterName()+" eats "+w.getCharacterName()+"'s fins");
+ w.setIsMobile(false); //eat fins
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/game/SuperWarrior.java b/src/game/SuperWarrior.java
new file mode 100644
index 0000000..fa5f425
--- /dev/null
+++ b/src/game/SuperWarrior.java
@@ -0,0 +1,70 @@
+package game;
+import java.util.Random;
+
+public class SuperWarrior extends Warrior {
+ public SuperWarrior(String name,int x,int y){
+ super(name,x,y);
+ }
+ @Override
+ public void sleep(){System.out.println("SuperWarrior "+this.getCharacterName()+" sleeps");}
+ @Override
+ public void eat(){System.out.println("SuperWarrior "+this.getCharacterName()+" eats");}
+ @Override
+ public void swim(){
+ int previousXcoordinate=getXCoordinate();
+ int previousYcoordinate=getYCoordinate();
+ Random ran=new Random();
+ int[] newCoordinates=new int[2];
+ int expectedNewX=-1;
+ int expectedNewY=-1;
+ if(!this.checkImmortle()){
+ int[] expectedNewCoordinates=lookForLotus(Game.gamecontroller); //first check whether there are lotus flowers in adjacent locations
+ if(expectedNewCoordinates!=null){ //if lotus are there then try to move to that location
+ expectedNewX=expectedNewCoordinates[0];
+ expectedNewY=expectedNewCoordinates[1];
+ }
+ }
+ //if there are no lotus in adjacent locations then swim like a normal warrior
+ do{
+ if((expectedNewX>=0)&&(expectedNewX<11)&&(expectedNewY>=0)&&(expectedNewY<11)){
+ GridLocation expectedLocation=Game.gamecontroller.getTheLocation(expectedNewX,expectedNewY);
+ if(expectedLocation.checkWarrior()==null){ //check whether the new location is already occupied by an other warrior or not
+ setXCoordinate(expectedNewX); //set the new coordinates if new location is vacant
+ setYCoordinate(expectedNewY);
+ newCoordinates[0]=expectedNewX;
+ newCoordinates[1]=expectedNewY;
+ break;
+ }
+ }
+ int randomInt=ran.nextInt(2); //choose the ccoordinate that is going to be changed(either x or y)
+ int[] possibleMoves={-1,1};
+ if(randomInt==0){ //change only the x coordinate
+ int nextChange=possibleMoves[ran.nextInt(2)]; //choose whether warrior is going to his left or right
+ expectedNewX=this.getXCoordinate()+nextChange;
+ expectedNewY=this.getYCoordinate();
+ }else{ //change only the y coordinate
+ int nextChange=possibleMoves[ran.nextInt(2)]; //choose whether warrior is going up or down
+ expectedNewY=this.getYCoordinate()+nextChange;
+ expectedNewX=this.getXCoordinate();
+ }
+ }while(true);
+
+ Game.gamecontroller.tranferTheWarrior(this, previousXcoordinate, previousYcoordinate, newCoordinates[0], newCoordinates[1]); //transfer warrior from old location to new location
+ Game.gamecontroller.checkTheNewLocation(this); //check the new location
+ }
+ public int[] lookForLotus(GameController gc){ //find are there any lotus flowers in adjacent locations
+ int currentX=this.getXCoordinate();
+ int currentY=this.getYCoordinate();
+ int[][] coordinateSet={{currentX-1,currentY},{currentX+1,currentY},{currentX,currentY-1},{currentX,currentY+1}};
+ for(int i=0;i<4;i++){
+ int[] coordinates=coordinateSet[i];
+ if((coordinates[0]>=0)&&(coordinates[0]<11)&&(coordinates[1]>=0)&&(coordinates[1]<11)){
+ if(gc.getTheLocation(coordinates[0],coordinates[1]).checkForLotus()){
+ this.setImmortal(true);
+ return coordinates; //if there exist lotus then return that coordinates
+ }
+ }
+ }
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/src/game/Treasure.java b/src/game/Treasure.java
new file mode 100644
index 0000000..5bdc009
--- /dev/null
+++ b/src/game/Treasure.java
@@ -0,0 +1,30 @@
+package game;
+import java.util.*;
+
+public class Treasure extends Observable{
+ private int xCoordinate;
+ private int yCoordinate;
+ public Treasure(int x,int y){
+ xCoordinate=x;
+ yCoordinate=y;
+ }
+ public int getXCoordinate(){
+ return xCoordinate;
+ }
+ public int getYCoordinate(){
+ return yCoordinate;
+ }
+ public void setXCoordinate(int x){
+ xCoordinate=x;
+ }
+ public void setYCoordinate(int y){
+ yCoordinate=y;
+ }
+ public void getNotified(Warrior w){
+ this.addObserver(w);
+ }
+ public void anounceTheWinner(Warrior w){ //notify other warriors that there is a winner
+ setChanged();
+ notifyObservers(w);
+ }
+}
\ No newline at end of file
diff --git a/src/game/Warrior.java b/src/game/Warrior.java
new file mode 100644
index 0000000..0ec6c6f
--- /dev/null
+++ b/src/game/Warrior.java
@@ -0,0 +1,67 @@
+package game;
+import java.util.*;
+
+public abstract class Warrior extends InhabitantCharacter implements Runnable,Observer{
+ private static int noOfWarriors;
+ private boolean isMobile;
+ private boolean isImmortal;
+ private boolean isAlive;
+ private boolean iswon;
+ private double startTime;
+ public Warrior(String name,int x,int y){
+ this.setCharacterName(name);
+ this.setXCoordinate(x);
+ this.setYCoordinate(y);
+ isMobile=true;
+ isImmortal=false;
+ isAlive=true;
+ iswon=false;
+ noOfWarriors++;
+ }
+ @Override
+ public void run(){
+ notifyTreasureChest(); //notify treasurechest that he start the game
+ startTime=System.currentTimeMillis();
+ while(isMobile && isAlive){ //swim if he is mobile and alive
+ swim();
+ }
+ }
+ @Override
+ public void update(Observable o, Object arg) {
+ setIsMobile(false); //mobility will get false when another warrior wins
+ }
+ public abstract void swim();
+ public abstract void sleep();
+ public abstract void eat();
+ public double getStartTime(){return startTime;}
+ public void setIsMobile(boolean value){
+ isMobile=value;
+ }
+ public void setIsAlive(boolean value){
+ isAlive=value;
+ }
+ public void setImmortal(boolean value){
+ isImmortal=value;
+ }
+ public boolean checkMobility(){
+ return isMobile;
+ }
+ public boolean checkIsAlive(){
+ return isAlive;
+ }
+ public boolean checkImmortle(){
+ return isImmortal;
+ }
+ public boolean checkIswon(){
+ return iswon;
+ }
+ public void looseFins(){
+ this.setIsMobile(false);
+ }
+ public static int getNoOfWarriors(){
+ return noOfWarriors;
+ }
+ public void notifyTreasureChest(){
+ Game.tChest.getNotified(this); //notify treasurechest that he start the game
+ }
+}
\ No newline at end of file