Project: ASP .Net Core - Web MVC
Project Summary
This is an individual class project to create a web application for the game of BlackJack.
It is created in Visual Studio, using ASP.NET Core Web MVC and uses Object Oriented Programming.
Each player receives an initial balance of 500, and they can place a bet between 1 and 100 for each game. The hand values are calculated and displayed on the screen and multiple players can play on the website at the same time.
The design is fully responsive to work on various screen sizes, and the card movements are animated with CSS.
Code on GitHub DemoTechnologies Used
Backend
C#, ASP .NET Core, Azure Web App
Frontend
HTML, CSS, Bootstrap,
ASP.NET Razor pages
Screenshots
Details
Application Design
- This project uses Object Oriented Programming and follows the Model-View-Controller design pattern. The controller manages all the routes, while the logic is handled by the model and the views are only responsible for displaying the data.
- Some of the classes used in this design include: Game, Dealer, Player, Deck, Hand and Card. Each player has a hand of cards, each hand has a method to calculate its value. The Deck has methods for shuffling and drawing cards, the dealer has methods for dealing, hitting, and checking for BlackJack.
- The game class is where everything comes together. This class is responsible for starting a new game, introducing the dealer and player to each other, and deciding the outcome of the game.
- Finally, using meaningful variable names and comments have made the code readable and maintainable.
Request Validation & Simultaneous Games
- An instance variable is used to keep the current "GameStatus" at any point in time, and this will help with validating all user actions. For example, while the GameStatus is PLACE_BET, the user cannot visit the Game page to peek at the cards, and once the GameStatus become ONGOING, the user cannot change the placed bet. To avoid undesired user actions, the front end will hide any un-necessary controls from the user, and at the same time, the back end will ignore any such incoming requests, nonetheless.
- The game can be used by multiple players simultaneously. This is achieved by using session variables, creating multiple game objects, and assigning a game ID to each instance of the game. These "game sessions" will expire after 30 minutes of inactivity.
Responsive User Interface
- The front end was created using ASP.Net Razor pages, includes valid HTML and is fully responsive. SEO best practices are also respected.
- CSS animations are used to animate the cards, have them stack on top of each other and cast a shadow underneath them.
- The hand value is calculated and displayed for the player and dealer to avoid any mistakes, and if the game is in development mode, more information about the status of the game (including the value of the dealer's hidden card) would be displayed at the bottom of the page.