Created
November 30, 2017 18:01
-
-
Save toriannnn/18cc514214c7043472fda7d8f43f82cd to your computer and use it in GitHub Desktop.
make a game of war
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
//******************************************************************* | |
//Assignment: Program 3 | |
//Account: TAM154 | |
// | |
//Author: Tori Murray | |
// | |
//Completion Time: 4 hours | |
// | |
//Honor Code: I pledge that this program represents my own program code. | |
//I received help from Alex Nogy | |
//******************************************************************* | |
package peace; | |
//import java.util.Scanner; | |
import card.Card; | |
import java.util.*; | |
import yesnoextractor.YesNoExtractor; | |
public class Peace { | |
public static void main(String args[]) { | |
//Creates Vectors for all possible decks/hands | |
Vector deck = new Vector(52); | |
Vector cpu = new Vector(26); | |
Vector p = new Vector (26); | |
int pw=0; | |
int cw=0; | |
//creates deck with all 52 cards | |
int z=1; | |
while(deck.size()<52) { | |
deck.addElement(z); | |
z=z+1; | |
if (deck.size()==53) { | |
break; | |
} | |
} | |
//shuffles deck | |
Collections.shuffle(deck); | |
//Dealing Cards | |
while(deck.size()>0) { | |
cpu.addElement(deck.get(0)); | |
deck.remove(0); | |
p.addElement(deck.get(0)); | |
deck.remove(0); | |
if (deck.isEmpty()) { | |
break; | |
} | |
} | |
System.out.println("Let's play some peace."); | |
//Playing Game | |
int x=1; | |
while(x<27) { | |
Card a=new Card((int) cpu.get(0)); | |
Card b=new Card((int) p.get(0)); | |
int compare=a.compare(b); | |
System.out.println("\nTrick number: "+x); | |
System.out.println("Player played: "+b); | |
System.out.println("Dealer played: "+a); | |
if(compare>0) { | |
//Say the dealer's card wins | |
System.out.println("Dealer's card wins"); | |
cw=cw+2; | |
} | |
else { | |
//Say the player's card wins | |
System.out.println("Player's card wins"); | |
pw=pw+2; | |
} | |
p.remove(0); | |
cpu.remove(0); | |
x=x+1; | |
if (x==27) { | |
break; | |
} | |
} | |
//End the game and see who won | |
System.out.println("\nGame is over, let's tally who won."); | |
System.out.println("Player pile has "+pw+" cards"); | |
System.out.println("Dealer pile has "+cw+" cards"); | |
if (cw>pw) { | |
//say The dealer wins | |
System.out.println("Dealer wins!"); | |
} | |
else { | |
// Say the player (you) wins | |
System.out.println("You win!"); | |
} | |
YesNoExtractor play = new YesNoExtractor(); | |
//Ask for another round | |
if (play.askUser("Play another round?")) { | |
System.out.println("\nThanks for the last GAME -- Better luck this time"); | |
} | |
else { System.out.println("\nCOWARD!!!"); | |
} | |
} // end of main | |
} // end of Peace.java |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment