Created
December 17, 2018 10:17
-
-
Save jmbruel/42bfdff35e4c0ff437d40dd16469e646 to your computer and use it in GitHub Desktop.
CPOA Design pattern course IUT Blagnac
This file contains 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 cpoa2018; | |
// Initial code from https://www.usna.edu/Users/cs/wcbrown/courses/S15IC211/lec/l03/lec.html | |
import java.util.*; | |
public class Game | |
{ | |
public static boolean winner(int c1, int c2) | |
{ | |
int f1 = Card.cardToFace(c1), s1 = Card.cardToSuit(c1); | |
int f2 = Card.cardToFace(c2), s2 = Card.cardToSuit(c2); | |
return f1 > f2 || f1 == f2 && s1 > s2; | |
} | |
public static void main(String[] args) | |
{ | |
// Initialize the game | |
Random rand = new Random(System.currentTimeMillis()); | |
int[] D = Card.makeDeck(); | |
int top = 0; | |
Card.shuffle(D,rand); | |
Player pu = new Player(); | |
pu.money = 5.0; | |
Player pai = new Player(); | |
pai.money = 5.0; | |
// Play 5 rounds w/o betting (ante only) | |
for(int i = 0; i < 5; i++) | |
{ | |
// Collect ante deal | |
double pot = .10; | |
pu.money -= 0.05; | |
pai.money -= 0.05; | |
pu.card = D[top++]; | |
pai.card = D[top++]; | |
System.out.println("You have $" + pu.money | |
+ ", your opponent has $" + pai.money | |
+ ", and you see card " + Card.cardToString(pai.card)); | |
// Report outcome and give winner the pot | |
System.out.println("You had a " + Card.cardToString(pu.card)); | |
if (winner(pu.card,pai.card)) | |
{ | |
pu.money += pot; | |
System.out.println("You won!"); | |
} | |
else | |
{ | |
pai.money += pot; | |
System.out.println("You lost!"); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment