Last active
February 6, 2018 22:31
-
-
Save finia2NA/fc87f2c99e1eafd6b350e5de298d6f6d to your computer and use it in GitHub Desktop.
MVC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Controller { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
Model board = new Model(); | |
String input = ""; | |
while (!input.equals("HALT")) { | |
System.out.print("input command, parameters"); | |
input = sc.nextLine(); | |
String[] command = input.split(" "); | |
switch (command[0]) { | |
case "move": | |
int xAlt = Integer.parseInt(command[1]); | |
int yAlt = Integer.parseInt(command[2]); | |
int xNeu = Integer.parseInt(command[3]); | |
int yNeu = Integer.parseInt(command[4]); | |
board.move(xAlt, yAlt, xNeu, yNeu); | |
break; | |
case "add": | |
String type = command[1]; | |
int xPos = Integer.parseInt(command[2]); | |
int yPos = Integer.parseInt(command[3]); | |
board.addCharacter(type, xPos, yPos); | |
break; | |
case "render": | |
//hier den view(board) einfügen | |
break; | |
default: | |
throw new IllegalArgumentException("IAE on main: unknown command."); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import javafx.scene.paint.Color; | |
public class Model { | |
ArrayList<Character> Characters = new ArrayList<Character>(); | |
public Model() { | |
} | |
public boolean move(int xAlt, int yAlt, int xNeu, int yNeu) { | |
for (Character i : Characters) { | |
if (i.getXPos() == xAlt && i.getYPos() == yAlt) { | |
// TODO: inactive markierung ohne alles aufzuhalten -> parallel dazu; | |
if (i instanceof Fren) { | |
((Fren) i).markActive(); | |
} | |
i.setPos(xNeu, yNeu); | |
return true; | |
} | |
} | |
return false; | |
} | |
public void addCharacter(String type, int xPos, int yPos) { | |
if (type.equals("Fren")) { | |
Characters.add(new Fren(xPos, yPos)); | |
} else if (type.equals("Enemy")) { | |
Characters.add(new Enemy(xPos, yPos)); | |
} else { | |
throw new IllegalArgumentException("IAE on addCharacters: type must be Fren or Enemy, was " + type); | |
} | |
} | |
public ArrayList<Character> getCharacters() { | |
return Characters; | |
} | |
} | |
class Enemy extends Character { | |
public Enemy() { | |
color = Color.RED; | |
} | |
public Enemy(int xPos, int yPos) { | |
color = Color.RED; | |
} | |
} | |
class Fren extends Character { | |
public Fren() { | |
color = Color.GREEN; | |
} | |
public Fren(int xPos, int yPos) { | |
color = Color.GREEN; | |
} | |
public void markActive() { | |
color = Color.WHITE; | |
} | |
public void markInactive() { | |
color = Color.GREEN; | |
} | |
} | |
class Character { | |
int xPos = 0; | |
int yPos = 0; | |
Color color = Color.GREY; | |
int maxHP = 100; | |
int hp = maxHP; | |
int movesPerTurn = 3; | |
public Character() { | |
} | |
public Character(int xPos, int yPos) { | |
this.xPos = xPos; | |
this.yPos = yPos; | |
} | |
public void setHP(int hp) { | |
this.hp = hp; | |
} | |
public void setPos(int xPos, int yPos) { | |
this.xPos = xPos; | |
this.yPos = yPos; | |
} | |
public int getHP() { | |
return hp; | |
} | |
public int getXPos() { | |
return xPos; | |
} | |
public int getYPos() { | |
return yPos; | |
} | |
public Color getColor() { | |
return color; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment