Package game_model

Source Code of game_model.position

package game_model;

import java.awt.Point;
import java.io.IOException;
import java.util.Observable;

import view.card_view;
import view.statics;
import data_model.card;
import data_model.gambler;
//Noch nicht �berarbeitet!!!!!!!!!!!
public class position extends Observable
{
//Globale Variablen--------------------------------------------------------------------------------------------------------------
  private card own;
  private gambler owner;

  private position north;
  private position south;
  private position east;
  private position west;
 
  String coord;
//--------------------------------------------------------------------------------------------------------------------------------
   
//Konstruktoren-------------------------------------------------------------------------------------------------------------------
  public position(String s){
    coord = s;
  }
//--------------------------------------------------------------------------------------------------------------------------------
   
//Getter&Setter-------------------------------------------------------------------------------------------------------------------
  public card getOwn()
  {
    return own;
  }
 
  public position getNorth()
  {
    return north;
  }
 
  public position getSouth()
  {
    return south;
  }
 
  public position getEast()
  {
    return east;
  }
 
  public position getWest()
  {
    return west;
  }
 
  public void setNorth(position p)
  {
    north = p;
  }
 
  public void setSouth(position p)
  {
    south = p;
  }
 
  public void setEast(position p)
  {
    east = p;
  }
 
  public void setWest(position p)
  {
    west = p;
  }
   
  public gambler getOwner() {
    return owner;
  }

  public void setOwner(gambler owner) {
    this.owner = owner;
  }
//--------------------------------------------------------------------------------------------------------------------------------

//Listener------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------

//Sonstige Methoden---------------------------------------------------------------------------------------------------------------
  public void setNeighbour(position north,position east, position south,position west){
    setNorth(north);
    setEast(east);
    setSouth(south);
    setWest(west);
  }
 
  public void setOwn(card c)
  {
    own = c;
  }
 
  public void attack(){
        //Attacke gen Norden
    //System.out.println("Attacke gestartet");
    gambler g = null;
   
    /*------------------System.out Befehle dienen zu Testzwecken
    if(this.north==null)System.out.println("Kein n�rdlicher Nachbar");
    else  if(this.north.getOwn()==null)System.out.println("Keine Karte n�rdlicher Nachbar");
   
    if(this.east==null)System.out.println("Kein �stlicher Nachbar");
    else if(this.east.getOwn()==null)System.out.println("Keine Karte �stlicher Nachbar");
   
    if(this.south==null)System.out.println("Kein s�dlicher Nachbar");
    else if(this.south.getOwn()==null)System.out.println("Keine Karte s�dlicher Nachbar");
   
    if(this.west==null)System.out.println("Kein westlicher Nachbar");
    else if(this.west.getOwn()==null)System.out.println("Keine Karte westlicher Nachbar");
    //---------------------------------------------------------*/
   
    if(this.north!=null && this.north.getOwn()!=null){
      //System.out.println("Norden angegriffen");
      if(!this.owner.equals(this.north.getOwner())){
        if(this.own.getNorth()>this.north.getOwn().getSouth()){
              //System.out.println("Norden besiegt");
              this.north.changeOwner();
            }
      }               
    }
    else{
      //System.out.println("Kein Angrif gen Norden m�glich");
    }
        //Attacke gen Osten
    if(this.east!=null && this.east.getOwn()!=null){
      //System.out.println("Osten angegriffen");
      if(!this.owner.equals(this.east.getOwner())){
            if(this.own.getEast()>this.east.getOwn().getWest()){
              //System.out.println("Osten besiegt");
              this.east.changeOwner();
            }
      }
    }
    else{
      //System.out.println("Kein Angrif gen Osten m�glich");
    }
        //Attacke gen S�den
    if(this.south!=null && this.south.getOwn()!=null){
      //System.out.println("S�den angegriffen");
      if(!this.owner.equals(this.south.getOwner())){
            if(this.own.getSouth()>this.south.getOwn().getNorth()){
              //System.out.println("S�den besiegt");
              this.south.changeOwner();
            }
      }
    }
    else{
      //System.out.println("Kein Angrif gen S�den m�glich");
    }
        //Attacke gen Westen
    if(this.west!=null && this.west.getOwn()!=null){
      //System.out.println("Westen angegriffen");
      if(!this.owner.equals(this.west.getOwner())){
            if(this.own.getWest()>this.west.getOwn().getEast()){
              //System.out.println("Westen besiegt");
              this.west.changeOwner();
            }
      }
    }
    else{
      //System.out.println("Kein Angrif gen Westen m�glich");
    }
  }
 
  public void changeOwner(){
    //System.out.print("Spieler von "+coord+" wird auf ");
    if(owner.equals(statics.getPlayer1())){
      owner = statics.getPlayer2();
      //System.out.println("Spieler 2 ge�ndert");
    }
    else {
      owner = statics.getPlayer1();
      //System.out.println("Spieler 1 ge�ndert");
    }
    this.setChanged();
    this.notifyObservers();
  }
 
  public String toString(){
    String res = "Eigene Position: "+coord+"...";
    if(this.north!=null)res+="N�rdlicher Nachbar: "+north.coord+"...";
    if(this.east!=null)res+="�stlicher Nachbar: "+east.coord+"...";
    if(this.south!=null)res+="S�dlicher Nachbar: "+south.coord+"...";
    if(this.west!=null)res+="Westlicher Nachbar: "+west.coord+"...";
    if(owner!=null){
      if(owner.equals(statics.getPlayer1()))res+="Owner: Spieler1(rot)...";
      else res+="Owner: Spieler2(blau)...";
    }
    return res;
  }
//--------------------------------------------------------------------------------------------------------------------------------
}
TOP

Related Classes of game_model.position

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.