Professional Documents
Culture Documents
Hadi #1 Ting #2
Abstract
This report summarizes the “2048” game-making programming using C# in Visual
Studio 2022. The objectives of this program are to make simple games, easy to
understand game, and fun to play for long terms. The objective of this game is to get
the highest score from making high-value of block. The methodology for this program
is the designing, implementation, and testing stages. The key findings for the 2048
game encompass its successful implementation, user-friendly interface, integration of
sound effects, and also identification of occasional errors in declaring the game over.
In conclusion, this program is a user friendly game because it simpleness to play.
1. Introduction
This report introduces the creation of a "2048" game through C# in Visual Studio
2022, aiming to provide a straightforward, comprehensible, and enjoyable gaming
experience while striving for the highest score through block combinations. The
significance lies in crafting an interface that is user-friendly and addressing occasional
errors in determining game over. The report's structure includes an introduction to the
project's purpose, the chosen object-oriented programming undertaking, and its
importance.
In the subsequent sections, the report explores the methodology used, with a focus on
the design, implementation, and testing stages. Key findings emphasize the successful
implementation of the game, its user-friendly interface, incorporation of sound
effects, and the identification of occasional game-over errors. The report concludes by
underscoring the program's user-friendly nature, attributed to its simplicity and ease
of play.
2. Project Overview
The primary goals of the project are to create a "2048" game using C# in Visual
Studio 2022, with the overarching objective of developing a simple, easy-to-
understand, and enjoyable gaming experience that promotes long-term engagement.
Specifically, the goal within the game is to achieve the highest score through the
combination of blocks to form high-value ones. The requirements for the project
include designing, implementing, and testing the game, placing significant emphasis
on ensuring a user-friendly interface and addressing occasional errors related to
declaring game over.
The problem domain revolves around users' desire for a simple, easy-to-understand,
and engaging game experience that can be played for extended periods. Typically,
users also want features such as scoring and best score tracking to add challenges to
the gameplay. The solution involves creating a 2048 game controlled simply by arrow
buttons, ensuring the game has no elements other than the game over condition, and
implementing a scoring system that records and saves the achieved scores as the best
score.
3. System Architecture
The architecture of the provided code is a simple event-driven design based on the
Windows Forms framework. Here's a concise breakdown:
Form1 Class: The main class representing the UI and game logic.
PictureBox and Label Controls: Used for rendering the game grid, tiles, and
scores.
Buttons: UI elements for user interaction (e.g., "Refresh" and "Again").
2. Game Logic Layer:
Tile Generation and Movement: Methods like GenerateNewPic, SlideLeft,
moveLeft, etc., handle the core game logic.
Scoring: Tracks and updates the game score.
Color Updates: ChangeColor method updates tile colors based on their values.
Game Over Check: IsGameOver method checks for game over conditions.
3. Sound Layer:
SoundPlayer Class: Manages sound effects during tile merging and game over.
4. Randomization Layer:
Random Class: Generates random positions for new tiles.
5. Key Event Handling:
Game Grid State: Maintains the state of the game grid, scores, and game over
status.
4. Implementation
1. Game Logic :
The main class representing the form of the application, handling UI and game logic.
Key Methods:
CreateMap(): Initializes the game grid, creating PictureBox controls for each cell.
GenerateNewPic(): Generates a new tile with the value "2" at a random empty
position.
ChangeColor(): Updates the colors of the tiles based on their values.
OnKeyboardPressed(): Handles keyboard input events to move tiles and trigger game
actions.
Slide(), SlideLeft(), swap(), mirrorupdown(), transpose(): Implement the core logic
for moving and merging tiles in different directions.
moveLeft(), moveRight(), moveUp(), moveDown(): Coordinate the tile movement in
respective directions.
IsGameOver(): Checks if the game is over by verifying if the grid is full and no more
valid moves are possible.
btnRefresh_Click(), Again_Click(): Event handlers for the "Refresh" and "Again"
buttons.
2. Tile Color and Value Mapping:
This event handler make the color of each value different. this method is to
help the user to recognize different value of block.
5. Key Features
The 2048 game implementation incorporates various key features that contribute to its
functionality and user experience. Object-oriented principles have been applied to
enhance code modularity, reusability, and maintainability.
5. Score Tracking:
Feature: The game keeps track of the player's score, updating it when tiles are
merged.
Object-Oriented Application: Score-related logic is encapsulated within methods and
properties, adhering to encapsulation principles.
7. Sound Effects:
Feature: The game includes sound effects during tile merging and upon reaching a
game over state.
Object-Oriented Application: SoundPlayer objects are encapsulated within the Form1
class, providing a modular approach for managing sound effects.
8. Restart Functionality:
Feature: Users can restart the game by clicking the "Again" button.
Object-Oriented Application: The restart functionality is encapsulated within the
Again_Click() method, promoting code modularity and reusability.
1. Unit testing
Block Movement Function:
Test Case: Ensure that the function responsible for moving blocks in
response to user input works correctly.
Result: Passed. The block movement function accurately adjusts block
positions based on user input.
Score Calculation:
Test Case: Verify that the scoring mechanism calculates the score
correctly for different block combinations.
Result: Passed. The scoring function consistently provides accurate
scores based on block combinations.
Random Block Generation.
Test Case: Test the randomness of the block generation function to
ensure a fair distribution across the grid.
Result: Passed. The random block generation function creates blocks in
different grid positions, maintaining fairness.
Game Over Condition:
Test Case: Check if the game over condition is appropriately triggered
when there are no possible moves left.
Result: Passed. The game over condition is accurately identified when
there are no valid moves left.
2. Integration testing
User Input and Block Movements:
Test Description: Verify that user input (arrow key presses) results in
appropriate block movements on the grid.
Results: Successful. User input consistently corresponds to the
expected movements of blocks, demonstrating a smooth interaction.
Scoring Mechanism Integration:
Test Description: Ensure that the scoring mechanism integrates
correctly with block combinations, providing accurate scores.
Results: Successful. The scoring system accurately calculates and
updates the score based on combined block values.
Sound Effects Integration:
Test Description: Confirm that sound effects are appropriately
triggered during key events, such as block combination or game over.
Results: Successful. Sound effects are integrated seamlessly,
enhancing the gaming experience without causing disruptions.
Game Over Declaration:
Test Description: Test the conditions for declaring a game over,
ensuring it accurately identifies when no further moves are possible.
Results: Partially Successful. Occasionally, the game over condition is
triggered prematurely, even when there are still possible moves. This
aspect requires further investigation.
Interface and Color Changes:
Test Description: Validate that interface elements and color changes
occur consistently with game events (e.g., block combination leading
to color change).
Results: Successful. Interface elements and color changes align with
the expected outcomes based on game events.
7. Challenges Faced
Technical hurdles
translate the javascript language:Find the same way to achieve a certain
function
button focus can’t be removed:Put buttons in panel.
Managing the complexity of game logic for tile movement, merging, and
game over conditions. Breaking down the logic into modular functions, using
abstraction to simplify complex operations, and ensuring each method has a
single responsibility.
Unexpected obstacles
9. Lessons Learned
Implementation Efficiency:
Identifying areas for improving implementation efficiency became a key takeaway.
This involved a closer examination of algorithms, code structure, and overall system
performance. The need for continuous optimization was underscored, prompting a
commitment to ongoing learning and exploration of best practices in coding and
software development.
Achievement System:
Implement an achievement system to recognize and reward players for specific
accomplishments during the game. Achievements could include reaching high scores,
completing games within certain time limits, or successfully merging tiles to create
rare combinations. This system encourages players to explore different aspects of the
game and adds an element of progression.
Interactive Tutorials:
Develop interactive tutorials or hints to guide new players through the game
mechanics and strategies. This ensures a smoother onboarding process and helps users
grasp the rules and objectives quickly, enhancing the accessibility of the game.
11. Conclusion
Our objective was to replicate the enjoyable experience of the 2048 game, providing
users with the satisfaction of merging numerical blocks. However, this project has
also served as a valuable learning experience. We understand the significance of
effective time management and recognize areas for improving implementation
efficiency. Looking ahead, the addition of background music is a potential feature to
enhance the gaming ambiance. Despite challenges, we hope that users will find joy in
playing our 2048 replica, and we encourage everyone to have fun with the game.
12. References
Game 2048 in 5 mins - JavaScript - 5minsofcode.com
2048 GAME IN C# WITH SOURCE CODE