java coding 8 l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Java Coding 8 PowerPoint Presentation
Download Presentation
Java Coding 8

Loading in 2 Seconds...

play fullscreen
1 / 15

Java Coding 8 - PowerPoint PPT Presentation


  • 285 Views
  • Uploaded on

Java Coding 8 Object-Oriented Design Examples David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. email: david@bilkent.edu.tr IMPORTANT… Students…

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Java Coding 8' - Faraday


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
java coding 8

Java Coding 8

Object-Oriented Design Examples

David Davenport

Computer Eng. Dept.,

Bilkent UniversityAnkara - Turkey.

email: david@bilkent.edu.tr

important
IMPORTANT…
  • Students…

This presentation is designed to be used in class as part of a guided discovery sequence. It is not self-explanatory! Please use it only for revision purposes after having taken the class. Simply flicking through the slides will teach you nothing. You must be actively thinking, doing and questioning to learn!

  • Instructors…

You are free to use this presentation in your classes and to make any modifications to it that you wish. All I ask is an email saying where and when it is/was used. I would also appreciate any suggestions you may have for improving it.

thank you,David.

card games

Card Games

As an example of

Object Oriented Design

the problem
The Problem…
  • Design & implement a program to play a simple game of cards between four players. To begin, a full pack of cards are shuffled and dealt face-down to the players. The game then proceeds in rounds. For each round, players play the top card from their hand and add it face-up to a pile on the table in front of them. The player who plays the highest value card is the winner of the round and their score is incremented by one. When all of the cards have been played the player with the highest score is declared the winner of the game.
the problem5
The Problem…
  • Design & implement a program to play a simple game of cards between four players. To begin, a full pack of cards are shuffled and dealt face-down to the players. The game then proceeds in rounds. For each round, players play the top card from their hand and add it face-up to a pile on the table in front of them. The player who plays the highest value card is the winner of the round and their score is incremented by one. When all of the cards have been played the player with the highest score is declared the winner of the game.
picture it

score

Table

player

player

player

score

score

score

player

Pack of cards

Picture it…
  • Simple Game
    • Pack of cards
    • 4 Players
    • Table
      • 4 Scores
      • 4 Cards
classes
Classes
  • Player
    • Name
    • Hand of cards
  • Cards
    • Collection of cards
  • Card
    • Face value
    • Suit
  • Simple Game
    • Pack of cards
    • 4 Players
    • 4 Scores
    • 4 Cards on table
the problem8
The Problem…
  • Design & implement a program to play a simple game of cards between four players. To begin, a full pack of cards are shuffled and dealt face-down to the players. The game then proceeds in rounds. For each round, playersplay the top card from their hand and add it face-up to a pile on the table in front of them. The player who plays the highest value card is the winner of the round and their score is incremented by one. When all of the cards have been played the player with the highest score is declared the winner of the game.
simple game class
Simple Game class
  • properties
    • Pack of cards
    • 4 Players
    • 4 Scores
    • 4 Piles of cards on table
  • constructor ( 4 players)creates the game with the given players
  • methods
    • playGame()plays a complete game sets scores
    • getScore( player number)returns players score

Represents a single card game played by 4 players

player class
Player class
  • properties
    • Name
    • Hand of cards
  • constructor ( name)creates player with name & empty hand
  • methods
    • getName()returns players name
    • add( Card)add the card to players hand
    • playCard()removes and returns the top card from the players hand

Represents a single player for a card game

cards class
Cards class
  • properties
    • Collection of cards
  • constructor ()creates a collection of cards with no cards in it!
  • methods
    • getTopCard()removes & returns top card from collection
    • addTopCard( Card)adds the card to the collection
    • shuffle()randomises order of cards in collection

Represents a set of zero or more playing cards

card class
Card class
  • properties
    • FaceValue
    • Suit
  • constructor ( card number)creates card with given position number in ordered pack!constructor ( faceValue, Suit)creates card with given face value & suit
  • methods
    • getFaceValue()returns faceValue
    • getSuit()returns suit

Represents a single playing card

playing the game
Playing the Game
  • Algorithm for playGame method
  • Create the pack of cards
  • Shuffle the pack
  • Deal all the pack between the players
  • Create empty piles of cards on table
  • Set all players scores to zero
  • For each round (until players have no cards left)
    • Each player plays card by adding it to their pile on table
    • Find biggest value card on top of piles on table
    • Increment scores of players who played cardswith biggest value
slide14
ToDo…
  • Decide on implementation details
    • For cards collection, for card, …
  • Design other algorithms
    • Shuffle, deal, …
  • Build & test
  • Extend
    • Add GUI (Graphical User Interface)
    • Make interactive
    • Make clever games & playable over Internet!