Skip to content

Alex-935/Sparta_Java_Core_Final_Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sparta Java Core Final Project

Requirements:

Expectations

  • A working application
  • A GitHub repository, along wiht a suitable branching strategy
  • Documentation of the task allocations and task completions amongst group members - e.g. a Trello Board
  • Unit testing

Tasks:

Deck of Cards:

  • Keep track of a deck of 52 cards (13 per suit)
  • Shuffle it into a random order
  • Retrieve a card from the top
  • Sort the deck in four ways:
    • By card value, the suit order: Ace -> 2 -> 3 -> .... -> Jack -> Queen -> King, Clubs -> Diamonds -> Hearts -> Spades.
    • Reverse order of the above: King -> Queen -> Jack -> .... -> 3 -> 2 -> 1, Spades -> Hearts -> Diamonds -> Clubs.
    • By suit order, then suit order: Clubs -> Diamonds -> Hearts -> Spades, Ace -> 2 -> 3 -> .... -> Jack -> Queen -> King.
    • Reverse order of the above: Spades -> Hearts -> Diamonds -> Clubs, King -> Queen -> Jack -> .... -> 3 -> 2 -> 1.

Card Game:

  • Player vs Computer
  • Handle the interaction of the player to both select and play the game.
  • Ensure that the player does not 'break' the game by invalid input.

Presenting Your Project:

  • Overview / Introduction to set the context for the presentation.
  • Outline any decisions you have made about scoping / prioritisation.
  • Show and explain elements of your code.
  • Presentation / Demonstration should last no more than 20 minutes.
  • Everyone in the group should contribute.


Our Solution:

App:

- Instantiates welcome menu.
image


WelcomeSelection:

- Allows the user to choose to play snap or blackjack.
- Allows the user to see the ruled for snap/blackjack without instantiating class.
- Allows the user to sort the deck in the ways mentioned in the requirements.
- Loops infinitely until the user opts to exit.
- All choices validated and only appropriate inputs are accepted.

Welcome menu:

image

Sorting menu:

image

Input validation:

image


Deck

- Used by both game classes.
- Instantiates ArrayList of 52 unique cards.
- Has a method to get the next card.
- Has a method to shuffle the deck.
- Overrides toString to print out the entrie deck in order (Uses StringBuilder for memory efficiency).
- Implements the required sorting functions.

Constructor and non-sorting functions:

image

Sorting functions:

image


Card:

- Instantiates card that has private attributes of suit and face.
- Has public getters and private setters.
- Functions to convert suits/face from integers to their appropriate strings.
- Overrides toString to return full card name.

Converts card attributes to make them more readily usable in the games:

image


Snap:

- Uses a stack to keep track of the middle pile and compare last card.
- Adds a delay between each card being placed to make it easier to follow.
- Allows user to type to place next card so you can go at your own pace.
- Player types in 's' to snap, while the computer uses a timer to delay it's 'snap'.
- Allows the user to choose different timer speeds to allow for different reaction times.
- Ability to replay game without returning to the menu.
- All user inputs validated.
- Static rules method to allow the rules to be seen without instantiating the game class.

Gameplay example:

image

SnapDelayTimer:

- Used to determine how long the user has to type 's' to snap before the computer says snap.

Selection method:

image


BlackJack

- Hides first computer card so you don't know exactly what the opponent has.
- Allows you to twist until you are bust but not beyond that.
- Automatically assigns Aces a value of 11 and reduces the value to 1 when hand total exceeds 21.
- Computer will stop twisting at a randomised hand total between 15 (inclusive) and 19 (exclusive).
- You always lose if you bust and ties are accounted for.
- Ability to replay game without returning to the menu.
- All user inputs validated.
- Static rules method to allow the rules to be seen without instantiating the game class.

Gameplay example:

image

Randomised computer stick point and Reducing ace value when bust:

image


Testing:

- Added testing where appropriate.
- Tested a range of expected and unexpected inputs.
- All unit tests passed.

Test code:

image

About

We have spent two weeks learning Java with Sparta Education. This is the final project to test and display our skills. We worked as a team to create a project that allows the user to choose playing between snap and blackjack. We must include unit tests, documentaion of task allocation, and give a 20 minute presentation on the project.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages