-
Notifications
You must be signed in to change notification settings - Fork 1
Win lose condition based on eviction: Code Guideline Sprint3
The Design Guideline:Sprint3: Win/lose Condition
- Display the Win/Lose prompt window after select the traitor.
- Dispaly a result dialog and traitor message
- Handles the game logic of choosing a traitor.
In sprint3, in order to better implement the game logic and display a series of related popup windows, we created a new class NpcEvictionMenuDisplayNew.java. The above contents are all implemented in this class.
In createResultDialog, The wrong box will display to to inform the player that they picked the wrong NPC and how many chances they have left. if player run out of their chance and lose, it will jump to ending screen, no need to create dialog.
If the player selects the correct traitor and clicks on the Select button corresponding to the correct traitor, the stage will display a dialog. After click the ok button, the stage will display another dialog to show the traitor message, and the meassage handled by the function helper.createTraitorMessageForSaveAtlantis, which related to the class NpcEvictionMenuDisplayHelper.java. And all scales of dialog are calculated according to the prototype from team7.
private void createResultDialog(String button_name, NpcResultDialogType type) {
logger.debug("create Result dialog from name: " + button_name + " type:" + type);
if (type == NpcResultDialogType.LOSE) {
EndingMenuDisplay.setLose();
entity.getEvents().trigger("ending");
return;}
if (type == NpcResultDialogType.WIN) {handleWin();return;}
// set the style of dialog include font color of title; background; size; position
float dialog_size_x,dialog_size_y;
String backgroundPath, buttonPathDefault, buttonPathHover;
if (type == NpcResultDialogType.RIGHT_BOX) {
backgroundPath = IMAGES_PATH + "rightBox.png";
buttonPathDefault = IMAGES_PATH + "rightBtn.png";
buttonPathHover = IMAGES_PATH + "rightBtn_H.png";
} else if (type == NpcResultDialogType.WRONG_BOX1) {...} else {....}
TextureRegionDrawable styleImage = new TextureRegionDrawable(
resourceService.getAsset(backgroundPath, Texture.class));
Window.WindowStyle windowStyle = new Window.WindowStyle(new BitmapFont(), Color.BLACK, styleImage);
Window dialog = new Window("", windowStyle);
dialog.setModal(true); // The dialog is always at the front
Button okButton = createButton(buttonPathDefault, buttonPathHover);
if (type == NpcResultDialogType.RIGHT_BOX) {
dialog_size_x = (float) (bgWidth * (683.67 / 1600));
dialog_size_y = (float) (bgHeight * (416.24 / 900));
dialog.setSize(dialog_size_x, dialog_size_y);
dialog.setPosition((float) (bgWidth * (433.33 / 1600)), (float) (bgHeight * (1 - 663.33 / 900)));
okButton.setSize((float) (dialog_size_x * (116.67/683.67)), (float) (dialog_size_y * (53.33/416.24)));
okButton.setPosition((float) (dialog.getWidth() * ((764.04-433.33)/683.67)),
(float) (dialog.getHeight() * ((663.33 - 635.65) / 416.24)));
Label message_interjection =new Label(helper.createTraitorMessageInterjection(type),skin);
message_interjection.setFontScale(dialog_size_y/400);
message_interjection.setAlignment(Align.center);
Label message = new Label(helper.createTraitorMessageForSaveAtlantis(button_name,type), skin);
message.setFontScale(dialog_size_y/400);
message.setWrap(true);
message.setAlignment(Align.left);
Table table = new Table();
table.add(message_interjection).width(dialog_size_x * 3 / 5);
table.row();
table.add(message).width(dialog_size_x * 3 / 5);
table.padLeft(dialog_size_x/6).padTop(dialog_size_y/6);
dialog.add(table);
} else {...}
okButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.info("yes_button from " + button_name + " clicked");
//when you select ok button
dialog.remove();
if (type == NpcResultDialogType.RIGHT_BOX)
handleWin();
}
});
dialog.addActor(okButton);
stage.addActor(dialog);
}
private void exitMenu() {
stage.remove();
}
public void setFindKey(Boolean findKey) {
this.findKey = findKey;
}
In the handlewin, when player select the correct traitor, after click OK button on right_box, an win Information page will display and the key will be spawn on the game area.
private void handleWin() {
logger.debug("Function handleWin is called");
// set the style of dialog include font color of title; background; size; position
TextureRegionDrawable styleImage = new TextureRegionDrawable(
resourceService.getAsset(IMAGES_PATH + "saveMessage.png", Texture.class));
Window.WindowStyle windowStyle = new Window.WindowStyle(new BitmapFont(), Color.BLACK, styleImage);
Window dialog = new Window("", windowStyle);
dialog.setModal(true); // The dialog is always at the front
dialog.setFillParent(true);
dialog.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
logger.debug("win game page clicked");
dialog.remove();
exitMenu();
// here we need call findKey function from team 5.
if (!findKey){
gameArea.spawnKey(game);
findKey = true;
}
return true;
}
});
showWinContext(dialog);
stage.addActor(dialog);
}
In addition, the showWinContext will create a table to include the lable of win context about the message of the traitor. The content of the message handle by the if (findKey)(if player chose the right traitor and find the key), the message will display in the scales of Team7 prototype.
private void showWinContext(Window dialog){
// create frame for both title and context
Table title = new Table();
title.setSize(stage.getWidth()*(1106-636)/1600,
stage.getHeight()*(220-160)/900);
title.setPosition(...);
Table context = new Table();
context.setSize(...); context.setPosition(...);
// set title/context srting
String titleContent;
String contextContent;
titleContent = "Message from Ares";
if (findKey) {
contextContent = """
You have found the traitor and got the information to save Atlantis.
Go and find the mysterious key!""";
} else {
contextContent = """
\s
I love my country and people very much, but I have to do it for the throne. However, I regretted it after Atlantis sank, but maybe you can save it:
\s\s
Find the mysterious key, it can help you save Atlantis and help you out of here!""";
}
// create skin of label same as default skin in main menu
Skin skin = new Skin(Gdx.files.internal("flat-earth/skin/flat-earth-ui.json"));
// create and set the label with content
Label titleLabel = new Label(titleContent, skin, "title",Color.NAVY);
titleLabel.setAlignment(Align.center);
titleLabel.setFontScale(stage.getWidth()/1920,stage.getHeight()/980);
Label contextLabel = new Label(contextContent, skin, "font_large",Color.DARK_GRAY);
contextLabel.setSize(context.getWidth(),context.getHeight());
contextLabel.setAlignment(Align.top);
contextLabel.setFontScale(stage.getWidth()/1920,stage.getHeight()/980);
contextLabel.setWrap(true);
// add to goal position
title.add(titleLabel).center();
context.addActor(contextLabel);
dialog.addActor(title);
dialog.addActor(context);
}
In handleLogic, Players have three chances to select the traitor, each wrong choice will reduce the player's HP and countdown at the same time. These series of functions are used for display the different result of the each selection.
- NpcResultDialogType.RIGHT_BOX: if player correctly select the traitor
- NpcResultDialogType.WRONG_BOX1: if player fails for the first time
- NpcResultDialogType.WRONG_BOX2: if player fails for the second time
- NpcResultDialogType.LOSE: if player select 3 times and all fail
- NpcResultDialogType.WIN: if player have correctly select in the past
Otherwise, functions entity.getComponent(CombatStatsComponent.class).getHealth() and entity.getComponent(countdownDisplay.class).getRemainingTime() are used to determin the change of the player's HP and remaining chances.
protected NpcResultDialogType handleLogic (String name) {
if (findKey) { // player have selected correct in the past
return NpcResultDialogType.WIN;
}
if (Objects.equals(name, "Ares")){ // select npc correctly
errorNum = 0;
return NpcResultDialogType.RIGHT_BOX;
} else {
if (errorNum == 0){
//decrease blood 10%
int health = entity.getComponent(CombatStatsComponent.class).getHealth();
entity.getComponent(CombatStatsComponent.class).setHealth((int) (health*0.9));
//at the same time decrease remaing time 10%
float remainingTime =entity.getComponent(countdownDisplay.class).getRemainingTime();
entity.getComponent(countdownDisplay.class).setTimeRemaining((float) remainingTime*0.9f);
errorNum++;
return NpcResultDialogType.WRONG_BOX1;
} else if (errorNum == 1) {
//decrease blood 20%
int health = entity.getComponent(CombatStatsComponent.class).getHealth();
entity.getComponent(CombatStatsComponent.class).setHealth((int) (health*0.8));
//at the same time decrease remaing time 20%
float remainingTime =entity.getComponent(countdownDisplay.class).getRemainingTime();
entity.getComponent(countdownDisplay.class).setTimeRemaining((float) remainingTime*0.8f);
errorNum++;
return NpcResultDialogType.WRONG_BOX2;
} else if (errorNum == 2){
// game over
errorNum = 0;
return NpcResultDialogType.LOSE;
}
}
return null; // if return null, it means some error in code, please check
}
}
- Uniform Pixel Grid Resolution
- Storyline
- Instruction
- NPC info
- NPC Communication Script
- Inventory-System-and-Consumables
- Storyline User Test
- Traitor Clues
- Game Characters
- Player Profile User Test
- Player Eviction Menu Sprint1: User survey (Team 7)
- Player Eviction Menu Sprint2: User survey (Team 7)
- Sprint3 - Win/lose Condition: User survey (Team 7)
- Sprint4 - Polishing-tasks: User survey (Team 7)
- Transition Animation/Special Effects/Sound Effects: Feature Overviews
- Transition Animation and Effects: Design Process & Guideline
- Sprint 4 User Testing
- Transition Animation & Effect: Code Guideline-Sprint4
- Sound effect when players complete npc tasks and hover over npc cards
- Fixing the clue bug
- Music Test
- Player Eviction Menu: Design Process & Guideline
- Player Eviction Menu (Feature Overviews)
- Player Eviction Menu: Code Guideline - Sprint1
- Sprint 1 User Testing
- Detailed Eviction Card: Design Process & Guideline
- Detailed Eviction Card: Feature Overviews
- Sprint 2 User Testing
- Player Eviction Menu: Code Guideline - Sprint2
- Sprint 2 Inventory System and Consumables Items User Testing
- Sprint 2 Inventory System and Consumables Items Functionality
- NPC interaction testing plan sprint3
- NPC interaction testing results sprint3
- NPC Dialogue Scripts
- Code Guideline
- Win/lose Condition: Design Process & Guideline
- Win/lose Condition: Feature Overviews
- Sprint 3 User Testing
- Win/lose condition: Code Guideline - Sprint3
- Enemy List
- User Testing 1: Enemy Image Filter
- User Testing 2: Enemy Animation and AI
- User Testing 3: Basic Attack