University of Engineering and Technology,
Taxila
SDA (THEORY#2)
Submitted to:
Ma’am Sidra Shafi
Submitted by:
Muhammad yousaf rana(21-SE-58)
AbdulAhad(21-SE-56)
Section:
OMEGA(Ω)
Title: Black shadow Game using strategy Pattern
Class Diagram:
Generated Pseudo Code Using Star UML:
<<Interface>>
package shadowBlade_Game;
public interface AttackStrategy {
public void attack();
}
Slash Attack Class:
package shadowBlade_Game;
public class SlashAttack implements AttackStrategy{
@Override
public void attack() {
[Link]("Performing Slash Attack... ...");
Stab Attack Class:
package shadowBlade_Game;
public class StabAttack implements AttackStrategy{
@Override
public void attack() {
[Link]("Performing StabAttack... ...");
Special Attack Class
package shadowBlade_Game;
public class SpecialAttack implements AttackStrategy{
@Override
public void attack() {
[Link]("Performing Special Attack... ...");
}
Attack Manager Class:
package shadowBlade_Game;
public class AttackManager implements AttackStrategy{
private String name;
private int health;
AttackStrategy attackStrategy;
public AttackManager( String name, int health) {
[Link] = name;
[Link] = health;
}
public void setStrategy(AttackStrategy attackStrategy) {
[Link] = attackStrategy;
}
@Override
public void attack() {
[Link]();
}
public void takedamage(int damage) {
[Link]-=damage;
[Link]("Name: "+[Link]+" take "+damage+" ... ..." );
if(health<=0) {
[Link]([Link]+" has been defeated... ...");
}
}
public void heal(int healing) {
if([Link]<100&&[Link]>=0) {
[Link]+=healing;
}
[Link]([Link]+" healed for "+ healing+"
health ...🌡...");
}
Main Class:
package shadowBlade_Game;
import [Link];
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int choice;
int count=0;
AttackManager attackManager = new AttackManager("Player", 100);
[Link](
"========== Wellome To Shadow Blade
Game ==========");
do {
[Link](
" 1. Slash Attack. \n"+
" 2. Stab Atack. \n"+
" 3. Special Attack. ");
[Link]("Enter Your Choice... ...");
choice = [Link]();
if(choice == 1) {
[Link](new SlashAttack());
[Link](20);
[Link](2);
count+=1;
}else if(choice == 2) {
[Link](new StabAttack());
[Link](30);
[Link](5);
count+=1;
}else if(choice == 3) {
[Link](new SpecialAttack());
[Link](40);
[Link](7);
count++;
}else {
[Link]("invalid Choice");
}
}while(count<=5);
[Link]();
Expected Output: