Black Jack MVC By Jeremy DiPaolo. Introduction Goal: To create a Black Jack game that takes advantage of the MVC framework. Uses many of the components.

Slides:



Advertisements
Similar presentations
Modelling & Datatypes John Hughes. Software Software = Programs + Data.
Advertisements

1 Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure Definitions 10.3Initializing Structures 10.4Accessing.
Black Jack in Objective-C
Case Study: Focus on Structures Math 130 Lecture 21 B Smith: 10/04: Required 35 minutes to complete. 15 minutes was spent returning test 2 and completing.
CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure.
1 Greg Wilson BA 4234 CSC407: Software Architecture Fall 2006 Refactoring.
New features in JDK 1.5 Can these new and complex features simplify Java development?
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 7.9Arrays of Pointers Arrays can contain pointers For.
© Glenn Rowe AC Lab 2 A simple card game (twenty- one)
Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
Computer Science 209 Images and GUIs. Working with Java Colors The class java.awt.Color includes constants, such as Color.red, for some commonly used.
Dealer Comm Hand Player makes Ante bet and optional Bonus bet. Five cards are dealt to each player from the shuffler. Five cards are dealt from the shuffler.
BLACKJACK SHARKS: Aabida Mayet, Omar Bacerra, Eser Kaptan March 15, 2010.
An application of the Probability Theory
12 Pontoon1May Pontoon program CE : Fundamental Programming Techniques.
Design Example. Requirements Make a program that simulates the game of blackjack For now, we ignore money/betting…. just simulate game play But… this.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 7 - Pointers Outline 7.1Introduction 7.2Pointer.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 10 - C Structures, Unions, Bit Manipulations,
Lesson 6 - Pointers Outline Introduction Pointer Variable Declarations and Initialization Pointer Operators Calling Functions by Reference Using the const.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 7 - Pointers Outline 7.1Introduction 7.2Pointer Variable Declarations and Initialization 7.3Pointer.
Intro to Probability & Games
Chapter 5 Black Jack. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 5-2 Chapter Objectives Provide a case study example from problem statement.
UNR, MATH/STAT 352, Spring Radar target detection How reliable is the signal on the screen? (Is it a target of a false alarm?)
VOCABULARY  Deck or pack  Suit  Hearts  Clubs  Diamonds  Spades  Dealer  Shuffle  Pick up  Rank  Draw  Set  Joker  Jack 
CSS446 Spring 2014 Nan Wang.  To learn how to choose appropriate classes for a given problem  To understand the concept of cohesion  To minimize dependencies.
© Amir Kirsh Object Oriented Programming with Java Written by Amir Kirsh.
Inner and Anonymous Classes Though you are captive in the OO paradigm, you can use inner classes and anonymous classes to get around this constraint and.
CPT: Ptr+Str/ Computer Programming Techniques Semester 1, 1998 Objective of these slides: –to discuss how pointers are used with structs.
Two Way Tables Venn Diagrams Probability. Learning Targets 1. I can use a Venn diagram to model a chance process involving two events. 2. I can use the.
Poker. Basic card terminology Suits: Hearts, diamonds, clubs, spades Deuce, face cards.
Exceptions: Checked versus Unchecked Exceptions.
A Singleton Puzzle: What is Printed? 1 public class Elvis { public static final Elvis INSTANCE = new Elvis(); private final int beltSize; private static.
15.3 Counting Methods: Combinations ©2002 by R. Villar All Rights Reserved.
Proportions Round One 2) x + 3 = 15 Answers 2.) x + 3 = 15 X=12 21.
Chapter 7 Arrays. A 12-element array Declaring and Creating Arrays Arrays are objects that occupy memory Created dynamically with keyword new int c[]
What is the Purpose of This Class
英語研習營 Speakers: English Service Club, National Chiayi University 指導教授 :Dr. Chao-chih Liao Week 5 (March 28) A: Be sure to write alphabet on the right place.
Introduction to Computer Science 2 Slide 1 Enumerated types We already know some data types int, float, char good for problems that involve int,
16. STRUCTURES, UNIONS, AND ENUMERATIONS. Declaring Structures A structure is a collection of one or more components (members), which may be of different.
CompSci Event Handling. CompSci Event Handling The Plan  Sequential (Single Thread) Model  Event Model  Making the GUI interactive  Examples.
CMSC 132: Object-Oriented Programming II Java Constructs Department of Computer Science University of Maryland, College Park.
C Lecture Notes 1 Structures & Unions. C Lecture Notes Introduction Structures –Collections of related variables (aggregates) under one name Can.
Chapter 10 Structures, Unions, Bit Manipulations, and Enumerations Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering.
Objects and Classes Continued Engineering 1D04, Teaching Session 10.
Draw 3 cards without replacement from a standard 52 card deck. What is the probability that: 1.They are all red ? 2.At least one is black ? 3.They are.
1 EPSII 59:006 Spring HW’s and Solutions on WebCT.
CLICK THE NUMBERS IN SEQUENCE
Week 8 : User-Defined Objects (Simple Blackjack Game)
1 Lecture 8 Pointers and Strings: Part 2 Section 5.4, ,
Comparing ArrayLists and Arrays. ArrayLists ArrayLists are one type of flexible-size collection classes supported by Java –ArrayLists increase and decrease.
L19 a 1 Example Using Arrays Using Top-Down Design and Functions to Simplify Code and Create Modules.
 2000 Prentice Hall, Inc. All rights reserved Introduction Structures –Collections of related variables (aggregates) under one name Can contain.
StructureStructure. Outline Introduction Structure Definitions Initializing Structures Accessing Members of Structures Using Structures with Functions.
Chapter 8: Arrays Gator Engineering One-dimensional array Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Move the first element to the.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
Introduction to Enumerations CMSC 202. Enumerated Values Enumerated values are used to represent a set of named values. Historically in Java (and other.
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
Java Programming: From the Ground Up
11/7/16 Entry 173 – Objective I will review and continue developing my understanding of uniform probability models, including the complement of an event.
Chapter 5 Black Jack.
Chapter 7 - Pointers Outline 7.1 Introduction
Introduction to Programming
Task 2 Implementation help
CLICK THE NUMBERS IN SEQUENCE
Homework Due Friday.
CLICK THE NUMBERS IN SEQUENCE
and Functions to Simplify Code
HOW TO PLAY POKER.
Presentation transcript:

Black Jack MVC By Jeremy DiPaolo

Introduction Goal: To create a Black Jack game that takes advantage of the MVC framework. Uses many of the components we have discussed in class, and follows very close with idea of event-driven programming. Components used: Jpanel, Jlabel, JTextArea, Jbutton, Jspinner.

Introduction MVC Framwork: This program has 4 different classes: BlackJackView (the view) BlackJackModel (the model) Hand (the controllers) Card (the controllers)

Program Design: Card Class This is the simplest of all classes. This class is very portable and can be used for any card game that uses a standard deck of 52 playing cards. Uses enumerations to store the rank and suit. Each Card Object has two atrributes, rank and suit. Each card object also an images attached, based on the suit and rank. Card Images are stored in a two-dimensional String Array, with the ranks and suits as the indices,respectively. There is also a setDeck(), shuffleDeck(), and getCard() method.

Coding Examples: Card Class public class Card { public enum Rank { DEUCE, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE } public enum Suit { DIAMONDS, HEARTS, SPADES, CLUBS } static String[][] cardImages = new String[13][4]; static List deck = new ArrayList (); Rank rank; Suit suit; public Rank rank() { return rank; } public Suit suit() { return suit; } private Card(Rank rank, Suit suit) { this.rank = rank; this.suit = suit; }

Coding Examples: Card Class static public void setCardImages() { for (Suit s : Suit.values()) { for (Rank r : Rank.values()) { cardImages[r.ordinal()][s.ordinal()] = "C:\\Users\\Jeremy\\Desktop\\Fall 2010\\Window System Programming\\ProjectCards\\" + r + "_" + s + ".png"; } public static void setDeck() { for (Suit s : Suit.values()) { for (Rank r : Rank.values()) { deck.add(new Card(r, s)); } public static void shuffleDeck(){ Collections.shuffle(deck); } public static Card getCard(){ return deck.get(1); }

Program Design: Hand Class Another important class is the Hand Class. This class handles every situation that would arise in the game involving “Hands”., including the following methods: getCardValue(Card card) setHandValue( Card hand) & getHandValue() isBusted() compareHands (int dealerHandValue, int playerHandValue) clearCards() and clearHandValue() aceHandler()

Coding Examples: Hand Class public class Hand { static int handValue; static boolean aceFlag; public int getHandValue() { return handValue; } public void setHandValue(List hand) { for (int i = 0; i < hand.size(); i++) { handValue = handValue + getCardValue(hand.get(i)); } public boolean isBusted() { if (handValue > 21) { return true; } else { return false; } public static int aceHandler() { if (handValue + 11 > 21) { return 1; } else { return 11; } public boolean compareHands(int dealerHandValue, int playerHandValue) { if (playerHandValue > dealerHandValue) { return true; } else { return false; }

public static void clearCards() { Card.setDeck(); Card.shuffleDeck(); BlackJackModel.dealerHandValue = 0; BlackJackModel.playerHandValue = 0; for (int i = 0; i < BlackJackModel.dealerHand.size(); i++) { BlackJackModel.dealerHand.remove(i); } for (int i = 0; i < BlackJackModel.playerHand.size(); i++) { BlackJackModel.playerHand.remove(i); } public static void clearHandValue() { handValue = 0; } public static int getCardValue(Card card) { if (card.rank() == Card.Rank.ACE) { //if (aceFlag == true) { return aceHandler(); } else if (card.rank() == Card.Rank.DEUCE) { return 2; } else if (card.rank() == Card.Rank.THREE) { return 3; } else if (card.rank() == Card.Rank.FOUR) { return 4; } else if (card.rank() == Card.Rank.FIVE) { return 5; } else if (card.rank() == Card.Rank.SIX) { return 6; } else if (card.rank() == Card.Rank.SEVEN) { return 7; } else if (card.rank() == Card.Rank.EIGHT) { return 8; } else if (card.rank() == Card.Rank.NINE) { return 9; } else { return 10; }

Program Design: The View Uses several components the user can interact with: Jpanel - Represents the area where the dealer’s cards and player’s cards are displayed. JLabel - Represents one Card. JTextArea - Displays the current balance of the player Jspinner - Represents the amount the player wishes to bet each round. Jbutton – Represents each option the player has during the course of a game: Deal, Hit, and Stand.

Coding Examples: The View ActionListener dealActionListener = new ActionListener() { public void actionPerformed(ActionEvent dealActionEvent) { BlackJackModel.setBetSize(Integer.parseInt(betSpinner.getValue().toString())); BlackJackModel.deal(); balanceTextArea.setText(Integer.toString(BlackJackModel.balance)); dealButton.setEnabled(false); hitButton.setEnabled(true); standButton.setEnabled(true); betSpinner.setEnabled(false); Hand.clearHandValue(); for (int i = 0; i <= 1; i++) { Card pHand = BlackJackModel.playerHand.get(i); Card dHand = BlackJackModel.dealerHand.get(i); Deal ActionListener:

Coding Examples: The View (cont’d) JLabel pcard = new JLabel(new ImageIcon(Card.cardImages[pHand.rank().ordinal()][pHand.suit().ordinal()])); playerPane.add(pcard, FlowLayout.LEFT); playerPane.revalidate(); JLabel dcard = new JLabel(new ImageIcon(Card.cardImages[dHand.rank().ordinal()][dHand.suit().ordinal()])); dealerPane.add(dcard, FlowLayout.LEFT); dealerPane.revalidate(); } System.out.println(BlackJackModel.playerHandValue); } };

Program Design: The Model The model holds all the methods that dictate the rules of the game and the actions taken by the user during the game. It contains such methods as deal(), hit(), stand(), setBetSize(int betSize),updateBalance(int Value). All of these methods are attached to the view in some way, but the view simply displays the results of each of these methods.

Coding Examples: The Model public static void deal() { //Get the betSize from the spinner value //Deduct that amount from the player's balance balance = balance - betSize; playerCurrent = true; Card.setDeck(); Card.shuffleDeck(); Card playerCard1 = Card.getCard(); playerHand.add(playerCard1); Card.deck.remove(playerCard1); Card dealerCard1 = Card.getCard(); dealerHand.add(dealerCard1); Card.deck.remove(dealerCard1); Card playerCard2 = Card.getCard(); playerHand.add(playerCard2); Card.deck.remove(playerCard2); Card dealerCard2 = Card.getCard(); dealerHand.add(dealerCard2); Card.deck.remove(dealerCard2); hand.setHandValue(playerHand); //hand.setHandValue(dealerHand); playerHandValue = hand.getHandValue(); } Deal() Method:

Coding Examples: The Model (cont’d) public static void hit() { if (playerCurrent == true) { Card newCard = Card.getCard(); playerHand.add(newCard); Card.deck.remove(newCard); Hand.handValue = 0; hand.setHandValue(playerHand); playerHandValue = hand.getHandValue(); if (hand.isBusted() == true) { isBusted = true; } } else { Card newCard = Card.getCard(); dealerHand.add(newCard); Card.deck.remove(newCard); Hand.handValue = 0; hand.setHandValue(dealerHand); dealerHandValue = hand.getHandValue(); if (hand.isBusted() == true) { isBusted = true; } Hit() Method:

Conclusion Overall, I enjoyed this project as it allowed me to use a lot of the components that we learned in class. It made me appreciate the MVC framework and event driven paradigm, and how much more flexible it is to use such programming theories.

Conclussion Things to add to the program: Surrender option Double Down option I would also like to develop a similar project for other card games using the MVC framework already in place.