Merge branch '11-implementation-of-player-class' into 'master'

Resolve "Implementation of player class"

Closes #11

See merge request !23
This commit is contained in:
Malte Tammena 2017-10-20 23:10:34 +02:00
commit 64e6109ff9
3 changed files with 84 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/Item.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
}
}

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

@ -0,0 +1,51 @@
package player;
import java.util.Scanner;
import java.util.HashSet;
import java.util.Set;
import java.util.Arrays;
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) {
Set<Integer> options = new HashSet<>(Arrays.asList(0,1,2,3,4,5,6));
for (Integer i: new HashSet<Integer>(options)) {
if (board[i][0] != 0) {
options.remove(i);
}
}
int choice = -1;
while (!options.contains(new Integer(choice))) {
System.out.print("Choose a move from " + options + ": ");
choice = sc.nextInt();
}
return choice;
}
@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;
}
}