public static void moveRight(Character character) {
if (Square.squares[player.xPosition + 1][player.yPosition][player.floorPosition].getAccessibility() == true) {
character.xPosition++;
Game.gui.md_moveSprite(character.id, character.xPosition, character.yPosition);
character.food--;
}
}
public static void moveLeft(Character character) {
if (Square.squares[player.xPosition - 1][player.yPosition][player.floorPosition].getAccessibility() == true) {
character.xPosition--;
Game.gui.md_moveSprite(character.id, character.xPosition, character.yPosition);
character.food--;
}
}
public static void moveUp(Character character) {
if (Square.squares[player.xPosition][player.yPosition - 1][player.floorPosition].getAccessibility() == true) {
character.yPosition--;
Game.gui.md_moveSprite(character.id, character.xPosition, character.yPosition);
character.food--;
}
}
public static void moveDown(Character character) {
if (Square.squares[player.xPosition][player.yPosition + 1][player.floorPosition].getAccessibility() == true) {
character.yPosition++;
Game.gui.md_moveSprite(character.id, character.xPosition, character.yPosition);
character.food--;
}
}
public static void dontMove(Character character) {
Game.gui.md_moveSprite(character.id, character.xPosition, character.yPosition);
}
public static void generatePlayer() {
Game.gui.md_addSprite(player.id, "black-king.png", true);
Game.gui.md_setSpriteVisible(player.id, true);
Game.gui.md_moveSprite(player.id, player.xPosition, player.yPosition);
boolean gameContinues = true;
while (gameContinues) {
switch (Game.gui.md_getLastAction()) {
case "right":
Character.moveRight(player);
break;
case "left":
Character.moveLeft(player);
break;
case "up":
Character.moveUp(player);
break;
case "down":
Character.moveDown(player);
break;
default:
Character.dontMove(player);
}
getGold(player);
getFood(player);
Game.gui.md_setTextFood(player.food);
Game.gui.md_setTextFloor(player.floorPosition);
Game.gui.md_setTextGold(player.gold);
Game.gui.md_setTextHealthCurrent(player.currentLife);
Game.gui.md_setTextHealthMax(player.maxLife);
Game.gui.md_setTextPerception(player.perception);
Game.gui.md_setTextStrength(player.strength);
if(player.food==0){
gameContinues=false;
Game.gui.md_showMessageDialog("GAME OVER"+"\n"+"Gold obtained: " + player.gold);
}
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.