summaryrefslogtreecommitdiffstats
path: root/Java/BlackJack/Hand.java
blob: a9fb174d8be1d6f85bdf7fdbc6160ba3c3abde7c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
public class Hand {

  // data member
  private int[] cardsInHandFace= new int[22]; //the maximum possible hands size is 22, if you draw 22 aces you'll bust. Values as expected
  private int[] cardsInHandSuit= new int[22]; //usual values
  private int numCardsInHand;
  
  // Constructors
  //accepts suit and face
  public Hand (int firstFace, int firstSuit, int secondFace, int secondSuit) {
	  cardsInHandFace[1] = firstFace;
	  cardsInHandSuit[1] = firstSuit;
	  cardsInHandFace[2] = secondFace;
	  cardsInHandSuit[2] = secondSuit;
	  //for some reason it wanted this, so I gave it. This code is total spaghetti and garbage. These assignments don't feel like they were ment to work with one another.
  }

// set & return
// set

//return 
public int calculateHandValue(){

int value = 0;

for(int i=0; i < cardsInHandFace.length;i++){
value = value + cardsInHandFace[i];
}
return value;
}

public void showAllCards(){ //there is absolutely no reason this should return something. These constraints are bad and don't teach OOP well. None of this need be OOP at all as it just overcomplicates this to a maximal degree. A much better teaching for OOP would be making some small farming game in where you had animals to take care of. OOP would be useful there as you could easily generate personalities, needs, types, colors, etc for each animal as to make good use of OOP and its capabilities. Blackjack doesn't need nor have variation like that and thus does not need OOP. Due to the fact that each class has a private value to it, there is great redundancy in the amonut of values stored, therefore causing the application to use more RAM than it needs to. This is also difficult to keep track of because some of these methods (such as card name and value finding) are redundant and cannot easily work with one another due to the strange constraints in what methods we must use. 

	for(int i=1; i < cardsInHandFace.length + 1;i++){
	System.out.print("Card Number " + i + "'s face is " + this.cardsInHandFace[i] + " and its suit is " + this.cardsInHandSuit[i]);
	}

}


public void showOneCard(int input) { //fix to return something
System.out.print("Card Number " + input + "'s face is " + this.cardsInHandFace[input] + " and its suit is " + this.cardsInHandSuit[input]);  
}

public void hit(Card c) { //fix to return something
	for(int i=0; i < cardsInHandFace.length;i++){
        if(cardsInHandFace[i] == 0) {
	cardsInHandFace[i] = c.getFaceNumericValue();
        cardsInHandSuit[i] = c.getSuitNumericValue();
	}}}
}