programmed everything besides the winningEvalouation

TODO: Update UML at later state
This commit is contained in:
2020-09-10 12:53:36 +02:00
parent 945b942484
commit 11c0d12b27
20 changed files with 371 additions and 3 deletions

2
.idea/modules.xml generated
View File

@@ -2,7 +2,7 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/Game/Game.iml" filepath="$PROJECT_DIR$/Game/Game.iml" /> <module fileurl="file://$PROJECT_DIR$/Testing/Testing.iml" filepath="$PROJECT_DIR$/Testing/Testing.iml" />
</modules> </modules>
</component> </component>
</project> </project>

View File

@@ -2,8 +2,8 @@
<module type="JAVA_MODULE" version="4"> <module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$/../Testing">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/../Testing/src" isTestSource="false" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />

View File

@@ -0,0 +1,26 @@
package Cards;
public class Card {
private CardType cardType;
private CardValue cardValue;
public Card(int cardType, int cardValue){
this.cardType = CardType.values()[cardType];
this.cardValue = CardValue.values()[cardValue];
}
public CardValue getCardValue() {
return cardValue;
}
public CardType getCardType() {
return cardType;
}
public String getName(){
int index = this.getCardValue().getIndex();
return (0<index && index<14) ? this.getCardType().name() + "e " + this.getCardValue().name()
: this.getCardType().name() + "er " + this.getCardValue().name();
}
}

View File

@@ -0,0 +1,37 @@
package Cards;
import java.util.Collections;
import java.util.LinkedList;
public class CardDeck {
private LinkedList<Card> cards;
public CardDeck(){
cards = new LinkedList<>();
generateCards();
}
private void generateCards(){
int index = 0;
for (int i = 0; i < 4; i++){
for (int j = 0; j < 15; j++){
cards.add(new Card(i, j));
}
}
}
public void printDeck(){
for (Card c: cards) {
System.out.print(c.getName() + "; ");
}
}
public void shuffle(){
Collections.shuffle(cards);
}
public LinkedList<Card> getCards() {
return cards;
}
}

View File

@@ -0,0 +1,20 @@
package Cards;
public enum CardType {
rot(0),
gelb(1),
blau(2),
grün(3);
int index;
private CardType(int i){
this.index = i;
}
public int getIndex() {
return index;
}
}

View File

@@ -0,0 +1,29 @@
package Cards;
public enum CardValue {
Narr(0),
Eins(1),
Zwei(2),
Drei(3),
Vier(4),
Fünf(5),
Sechs(6),
Sieben(7),
Acht(8),
Neun(9),
Zehn(10),
Elf(11),
Zwölf(12),
Dreizehn(13),
Zauberer(14);
int index;
private CardValue(int i){
this.index = i;
}
public int getIndex() {
return index;
}
}

133
Testing/src/Game.java Normal file
View File

@@ -0,0 +1,133 @@
import Cards.Card;
import Cards.CardDeck;
import Cards.CardType;
import Participant.AI;
import Participant.Player;
import sun.awt.image.ImageWatched;
import java.util.LinkedList;
import java.util.Scanner;
public class Game {
private LinkedList<Player> players;
private LinkedList<Card> pickedCards;
private CardDeck deck;
private int leadingType;
private int round;
public Game(){
players = new LinkedList<>();
pickedCards = new LinkedList<>();
deck = new CardDeck();
leadingType = -1;
round = 1;
generatePlayers();
}
public static void main(String[] args) {
Game game = new Game();
game.control();
}
private void generatePlayers(){
System.out.println("WELCOME TO THE GAME OF WIZARD!");
System.out.println("What is you name?");
String name = new Scanner(System.in).nextLine();
System.out.println("Against how many players do you want to play? (2-5)");
int playerAmount = new Scanner(System.in).nextInt();
players.add(new Player(name, false));
for (int i = 0; i < playerAmount; i++){
players.add(new AI("Opponent " +(i+1), true));
}
System.out.println("----- ROUND 1 -----");
}
private void control(){
while(round <= 60/players.size()){
dealCards();
printLeadingType();
players.get(0).displayHand();
makePredictions();
System.out.println();
while (players.get(0).getHand().size() != 0) {
pickCards();
printPickedCards();
System.out.println();
}
newRound();
}
}
private void dealCards(){
deck.shuffle();
LinkedList<Card> availableCards = (LinkedList<Card>) deck.getCards().clone();
for (Player p: players) {
for (int i = 0; i < round; i++){
p.addToHand(availableCards.get(0));
availableCards.remove(0);
}
}
try{
leadingType = availableCards.get(0).getCardType().getIndex();
} catch (Exception e){
System.out.println("Letzte Runde: Keine Trumpffarbe mehr");
leadingType = -1;
}
}
private void newRound(){
round++;
System.out.println();
System.out.println("----- ROUND " + round + " -----");
for (Player p: players) {
p.clearHand();
}
}
private void makePredictions(){
for (Player p: players) {
p.predict();
System.out.print(p.getPrediction()+ "; ");
}
}
private void pickCards(){
for (int i = 0; i < players.size(); i++) {
players.get(i).pickCard();
pickedCards.add(players.get(i).getCurrentCard());
}
}
private void printLeadingType(){
System.out.println("Trumpffarbe: " + CardType.values()[leadingType]);
}
private void printPickedCards(){
System.out.print("Gewählte Karten: ");
for (Card c: pickedCards) {
System.out.print(c.getName() +"; ");
}
pickedCards.clear();
}
private void winningProcess(){
int highestCardIndex = -1;
for (int i = 0; i < pickedCards.size(); i++) {
}
}
}

View File

@@ -0,0 +1,23 @@
package Participant;
import java.util.Random;
public class AI extends Player{
public AI(String name, boolean isAI) {
super(name, isAI);
}
@Override
public void predict() {
int index = new Random().nextInt(this.getHand().size());
this.setPrediction(index);
}
@Override
public void pickCard() {
int index = new Random().nextInt(this.getHand().size());
this.setCurrentCard(this.getHand().get(index));
this.getHand().remove(index);
}
}

View File

@@ -0,0 +1,99 @@
package Participant;
import Cards.Card;
import java.util.LinkedList;
import java.util.Scanner;
public class Player {
private String name;
private LinkedList<Card> hand;
private int timesWon;
private Card currentCard;
private int prediction;
private int points;
private boolean isAI;
public Player(String name, boolean isAI){
this.name = name;
this.isAI = isAI;
hand = new LinkedList<>();
timesWon = 0;
currentCard = null;
prediction = -1;
points = 0;
}
public void predict(){
System.out.println("Wie viele Stiche gewinnst du?");
prediction = new Scanner(System.in).nextInt();
}
public void addPoints(int points){
this.points += points;
}
public void addToHand(Card card){
hand.add(card);
}
public void clearHand(){
hand.clear();
}
public void displayHand(){
System.out.print("Hand: ");
for (int i = 0; i < hand.size(); i++) {
System.out.print("(" + (i+1) + ")" + hand.get(i).getName() + "; ");
}
System.out.println();
}
public void pickCard(){
displayHand();
System.out.println("Welche Karte willst du spielen? (Index der Karte)");
int card = new Scanner(System.in).nextInt();
currentCard = hand.get(card-1);
hand.remove(card-1);
}
public void setTimesWon(int timesWon) {
this.timesWon = timesWon;
}
public void setCurrentCard(Card currentCard) {
this.currentCard = currentCard;
}
public void setPrediction(int prediction) {
this.prediction = prediction;
}
public int getPrediction() {
return prediction;
}
public Card getCurrentCard() {
return currentCard;
}
public int getTimesWon() {
return timesWon;
}
public LinkedList<Card> getHand() {
return hand;
}
public int getPoints() {
return points;
}
public String getName() {
return name;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 120 KiB

1
WizardSkill.vpd.vpd Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.