Last active
December 29, 2015 06:49
-
-
Save Bapho/7631978 to your computer and use it in GitHub Desktop.
This is a class to store values and execute methods of hand cards. - three-day project
This file contains hidden or 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
package com.baphoware.prjhelloween.executions; | |
public class HelloWeenCardHand | |
{ | |
// deklaration und initialisierung der Klassenvariablen | |
private boolean isHuman = false; | |
private int[][] handStats = new int[5][4]; | |
private int[] handCards = new int[5]; | |
private int indexHand = 0; | |
private static int DIFF_INDEX_TO_STAT = 25; | |
public HelloWeenCardHand() | |
{ | |
// standard constructor | |
} | |
// overloaded constructor | |
public HelloWeenCardHand( boolean isHuman, int[][] handStats, int indexHand, int[] handCards ) | |
{ | |
this.isHuman = isHuman; | |
this.handStats = handStats; | |
this.indexHand = indexHand; | |
this.handCards = handCards; | |
} | |
public boolean isHuman() | |
{ | |
return isHuman; | |
} | |
public void setHuman( boolean isHuman ) | |
{ | |
this.isHuman = isHuman; | |
} | |
// Formel zum setzen der gesamten maximalen Kartenstärke | |
public int getHandMaxStats( int indexCard ) | |
{ | |
return ( indexCard * 2 ) + DIFF_INDEX_TO_STAT; | |
} | |
public int getHandStats( int a, int b ) | |
{ | |
return handStats[a][b]; | |
} | |
// Zufallsgenerierung der Figuren von den 5 Handkarten | |
private void setHandObjects() | |
{ | |
for ( int i = 0; i < 5; i++ ) | |
{ | |
double temp = Math.random(); | |
// Index zufällig generieren (von 0-10) | |
this.handCards[i] = (int) (temp * 10); | |
// abrunden | |
if( temp < 0.1 ) | |
{ | |
this.handCards[i] = (int) Math.floor( temp * 10 ); | |
} | |
// aufrunden | |
if( temp > 0.9 && temp < 1.0) | |
{ | |
this.handCards[i] = (int) Math.ceil( temp * 10 ); | |
} | |
} | |
} | |
//Stärke der Handkarten zufällig generieren | |
public void setHandStats() | |
{ | |
// HandKarten-Figuren erzeugen | |
setHandObjects(); | |
// Schleife für die 5 Handkarten | |
for ( int c = 0; c < 5; c++ ) | |
{ | |
// temp. Variablen um die Werte zufällig zu verteilen | |
double w, n, e, s, q, x; | |
double wWest, nNorth, eEast, sSouth; | |
w = Math.random(); | |
n = Math.random(); | |
e = Math.random(); | |
s = Math.random(); | |
// mathematischer Dreisatz | |
q = w + n + e + s; | |
x = 1 / q; | |
wWest = w * x; | |
nNorth = n * x; | |
eEast = e * x; | |
sSouth = w * x; | |
// Fallbestimmung und Wertzuweisung für die jeweilige Himmelsrichtung | |
for ( int v = 0; v < 4; v++ ) | |
{ | |
// Variable zur jeweiligen Berechnung | |
double value = 4.5; | |
switch( v ) | |
{ | |
case 0: | |
value = wWest; | |
break; | |
case 1: | |
value = nNorth; | |
break; | |
case 2: | |
value = eEast; | |
break; | |
case 3: | |
value = sSouth; | |
break; | |
} | |
// Handkarte den Richtungswert und Zufallswert zuweisen | |
this.handStats[c][v] = (int) ( 1 + ( Math.random() * value * getHandMaxStats( c ) ) ); | |
// exception-handling | |
if( handStats[c][v] > 9 ) | |
{ | |
handStats[c][v] = 9; | |
} | |
System.out.println( "Handkarte: " + c + "\t Richtung: " + v + "\t Wert: " + handStats[c][v] + "\t Figurindex: " + handCards[c] ); | |
} | |
} | |
} | |
// Nummer der aktuellen Handkarten-Figur ausgeben | |
public synchronized int getHandCard() | |
{ | |
return handCards[indexHand]; | |
} | |
// index der aktuellen Handkarte erhöhen | |
public synchronized void setNextHandCard() | |
{ | |
if( indexHand < 4 ) | |
{ | |
indexHand++; | |
} else | |
{ | |
indexHand = 0; | |
} | |
} | |
public synchronized int getIndexHand() | |
{ | |
return indexHand; | |
} | |
public synchronized void setIndexHand( int indexHand ) | |
{ | |
this.indexHand = indexHand; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment