Finished implementation of Human, improving IO

This commit is contained in:
Malte Tammena 2017-10-20 22:58:07 +02:00 committed by Maurizio Bruetsch
parent eef311480f
commit b6214bd9e1
3 changed files with 71 additions and 4 deletions

View file

@ -17,6 +17,7 @@ src\game\GameHistory.java \
src\game\GameEntry.java \
src\game\PlayerObject.java \
src\player\Player.java \
src\player\Human.java \
src\player\malte\MalteAI.java \
src\player\malte\Pattern.java \
src\player\malte\PatternGenerator.java \
@ -30,13 +31,15 @@ BUILDFILES=$(OBJECTS) $(FXMLS_BUILD)
MAIN=game.Main
N=100
P1=
P2=
all: $(CLASSES) $(FXMLS_BUILD)
$(JAVAC) $(JAVAC_OPTIONS) -cp $(CLASSPATH) $(CLASSES) -d $(BUILDS)
run: $(CLASSES)
$(JAVA) -cp $(BUILDS) $(MAIN)
$(JAVA) -cp $(BUILDS) $(MAIN) $(P1) $(P2)
simulate: $(CLASSES)
$(JAVA) -cp $(BUILDS) $(MAIN) $(N)

View file

@ -1,17 +1,43 @@
package game;
import player.Player;
import player.Human;
import player.maurizio.MaurizioAI;
import player.malte.MalteAI;
public class Main {
public static void main(String[] args) {
if (args.length == 1) {
Player p1, p2;
if (args.length == 2) {
switch (args[0].toLowerCase()) {
case "maurizio":
p1 = new MaurizioAI("Maurizio");
break;
case "human":
p1 = new Human();
break;
case "malte":
default:
p1 = new MalteAI("Malte");
}
switch (args[1].toLowerCase()) {
case "malte":
p2 = new MalteAI("Malte");
break;
case "human":
p2 = new Human();
break;
case "maurizio":
default:
p2 = new MaurizioAI("Maurizio");
}
new Game(p1, p2).start(true, true); //1. param = output mode, 2. param = random beginner
} else if (args.length == 1) {
Game.simulate(Integer.parseInt(args[0]));
} else {
Player p1 = new MalteAI("Malte");
Player p2 = new MaurizioAI("Maurizio");
p1 = new MalteAI("Malte");
p2 = new MaurizioAI("Maurizio");
new Game(p1, p2).start(true, true); //1. param = output mode, 2. param = random beginner
}
}

38
src/player/Human.java Normal file
View file

@ -0,0 +1,38 @@
package player;
import java.util.Scanner;
public class Human implements Player {
private Scanner sc;
private int id;
private int enemyID;
private String name;
public Human() {
sc = new Scanner(System.in);
System.out.print("Bitte gib deinen Namen ein: ");
this.name = sc.nextLine();
}
@Override
public int move(int[][] board) {
System.out.print("Choose a move: ");
return sc.nextInt();
}
@Override
public void setPlayerID(int id) {
this.id = id;
}
@Override
public void setEnemyID(int enemyID) {
this.enemyID = enemyID;
}
@Override
public String getName() {
return this.name;
}
}