Skip to content

This is a demo game running on console. This game is designed to understand the uses of Strategy and Simple Factory Design Patterns.

Notifications You must be signed in to change notification settings

KeremTAN/WellsHellGame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wells Hell Game

Strategy and Simple Factory Design Patterns

Random values are assigned to the places where data must be entered in the control class. In this way, you can run and observe the game directly, or you can play the game on the console by changing the necessary places in the control class.

Statement of Work:

Our project is to design a 2 player fighting game. The logic of our game is quite simple. Although our game looks like a fighting game, it is actually a strategy game. Our players have to choose the most effective attack for them by trying to predict their opponent's moves correctly to win the game. The game will be played on the console. When our game starts, the players will first choose their characters. Players should only be able to create characters determined by us. The main characteristics of our characters are their attack power and self-defense coefficient. Characters can harm their opponents with their attack power and protect themselves with their self-defense coefficient. After our players have selected their characters, the game will continue until 1 of 2 players has 0 health. During the game, our players will be asked to choose an attack to attack their opponent every time it comes to their turn, and according to this selected attack, our player will hit his opponent. In each attack selection, the hitting property of the player's fighter character must be changed instantly and the hitting process must take place.

Design Patterns:

Strategy pattern and simple factory pattern were used in our project. The reason for this is as it will be remembered, our players were hitting each other in turn. In the game, the same hitting can be done in different ways. A different percentage of the user's attack power is used according to each strike action. For the hitting process, the attack process that the user wants to do is selected first. The choice made by our player is sent as a parameter to the createAttack method of an object of our FactoryAttack class. When the Attacks object created according to the sent value is sent back to us, we send the returned Attacks object as a parameter to the setAttacks method of our player's fight object.

public int chooseAttack(Fighters attackPlayer) { 
  …
  attackPlayer.setAttack(new FactoryAttack().createAttack(chosenAttack)); 
  … 
}

Thanks to the FactoryAttacks object, although we do not see the background, the createAttack method produces the Attacks object we want. So we're using the simple factory pattern here. With the value sent, we reset the Attacks area of our player's Fighters object. In this way, while our user only hits his opponent through the fight method, the hit method of the Attacks object in the fight method applies an attack strategy as desired by our player. So here we are using the strategy pattern. The FactoryFighters class works the same as the FactoryAttack class. The only difference is that instead of producing different objects for us, our Fighter object is produced according to the rules we have determined.

UML:

UML

Releases

No releases published

Packages

No packages published

Languages