Exemplo n.º 1
0
 public void collect(String name) {
   switch (name) {
     case "stick":
       if (getCurrentTile().contains("tree")) {
         console.print("You break some sticks off of the tree.");
         p.inv.add(new Item("stick"), 2);
         getCurrentTile().removeEntity("tree");
         p.decFood(1);
         p.decWater(1);
       } else {
         console.print("There are no sticks in sight.");
       }
       break;
     case "rock":
       if (getCurrentTile().contains("rock")) {
         console.print("You collect a pile of rocks.");
         p.inv.add(new Item("rock"), 3);
         getCurrentTile().removeEntity("rock");
         p.decFood(2);
         p.decWater(1);
       } else {
         console.print("There are no rocks in sight.");
       }
       break;
     default:
   }
 }
Exemplo n.º 2
0
 // Player actions
 public void drink() {
   if (getCurrentTile().contains("pond")) {
     console.print("You kneel at the pond and drink water.");
     p.maxWater();
   } else if (getCurrentTile().contains("village")) {
     console.print("You drink some water at the village fountain.");
     p.maxWater();
   } else console.print("There is no water in sight.");
 }
Exemplo n.º 3
0
 public void toss(String name, int amount) {
   String sname = name.substring(0, name.length() - 1);
   if (!p.inv.contains(name)) {
     if (p.inv.contains(sname)) name = sname;
     else console.print("You don't have any " + name + "s.");
   }
   if (p.inv.remove(name, amount)) {
     if (amount > 1) name += "s";
     console.print("You toss " + amount + " " + name);
   } else console.print("You don't have that many " + name + "s.");
 }
Exemplo n.º 4
0
 /*
  * THIS METHOD IS FOR USE WITH THE INTERACTION CLASS.
  * USE ITEM FROM THE PLAYER'S INVENTORY ON ENVIRONMENT.
  */
 public void use(String itemName) {
   Item item = new Item(itemName);
   if (!p.inv.contains(item.name)) console.print("You don't have a " + itemName + ".");
   else {
     Interaction in = Interaction.getInteraction(item, getCurrentTile().entities);
     if (in == null) console.print("Nothing to use the " + item.name + " with.");
     else {
       Interaction.interact(in, getCurrentTile(), p.inv);
       console.print(in.msg);
       p.decFood(1);
       p.decWater(1);
     }
   }
 }
Exemplo n.º 5
0
  public void playGame() {
    Joystick joystick = game.getJoystick();

    do {
      printBoard();

      String line = console.read();
      boolean bomb = false;
      boolean move = false;
      for (Character ch : line.toCharArray()) {
        if (ch == 's' || ch == 'ы') {
          if (move) {
            game.tick();
            bomb = false;
          }
          joystick.down();
          move = true;
        } else if (ch == 'a' || ch == 'ф') {
          if (move) {
            game.tick();
            bomb = false;
          }
          joystick.left();
          move = true;
        } else if (ch == 'd' || ch == 'в') {
          if (move) {
            game.tick();
            bomb = false;
          }
          joystick.right();
          move = true;
        } else if (ch == 'w' || ch == 'ц') {
          if (move) {
            game.tick();
            bomb = false;
          }
          joystick.up();
          move = true;
        } else if (ch == ' ') {
          if (bomb) {
            game.tick();
            move = false;
          }
          joystick.act();
          bomb = true;
        }
      }
      game.tick();
    } while (!game.isGameOver());

    printBoard();
    console.print("Game over!");
  }
Exemplo n.º 6
0
 public void pray() {
   if (getCurrentTile().contains("altar")) {
     if (p.razeCount <= 0)
       console.print("You kneel at the altar and pray for a while. You feel a bit better.");
     else if (p.razeCount <= 2)
       console.print("You kneel at the altar and pray for a while. There is only silence.");
     else
       console.print(
           "The ones who erected this altar are weak and simple. Their dead god has nothing to offer you.");
   } else {
     int choice = rand.nextInt(3);
     switch (choice) {
       case 0:
         console.print("There's no church in the wild.");
         break;
       case 1:
         console.print("What's a god to a non-believer?");
         break;
       case 2:
         console.print("You cry out to a non-existent god.");
         break;
       default:
     }
   }
 }
Exemplo n.º 7
0
  public void offerNewGame() {
    GameOpt gameOpt;
    if (Game.hasInstance()) {
      // Copy the game options of the active instance.
      gameOpt = new GameOpt(Game.getInstance().getOpt());
      gameOpt.setRules(Rules.REPLAY);
    } else {
      // Start with the default game options.
      gameOpt = new GameOpt();
    }

    final int maxHands = ParmBox3.HANDS_DEALT_MAX;
    final HandOpt handOpts[] = new HandOpt[maxHands];
    for (int iHand = 0; iHand < maxHands; iHand++) {
      HandOpt handOpt;
      if (Game.hasInstance() && iHand < gameOpt.getHandsDealt()) {
        final ReadHand hand = Game.getInstance().getHand(iHand);
        handOpt = new HandOpt(hand.getOpt());
      } else {
        handOpt = new HandOpt("User");
      }
      handOpts[iHand] = handOpt;
    }

    final Wizard wizard = new Wizard(frame);

    final ParmBox1 parmBox1 = new ParmBox1(wizard);
    wizard.addCard(parmBox1);

    final WizardCard parmBox2 = new ParmBox2(wizard);
    wizard.addCard(parmBox2);

    final WizardCard parmBox3 = new ParmBox3(wizard);
    wizard.addCard(parmBox3);

    final WizardCard handBox = new HandBox(wizard);
    wizard.addCard(handBox);

    // pack and go
    final boolean completed = wizard.run(parmBox1, gameOpt, handOpts);

    if (!completed) {
      Console.print("New game aborted.\n");
      return;
    }

    final GameView view = GameView.getInstance();
    view.saveHand();
    final GameStyle oldStyle = Game.getStyle();
    new Game(gameOpt, handOpts);
    view.newGame(oldStyle);
  }
Exemplo n.º 8
0
  public static void main(String[] args) {
    Console c = new Console();
    int numb[];
    int answer = 0;
    int remain = 0;
    numb = new int[2];

    for (int x = 0; x <= 1; x++) {
      c.print("Enter number " + (x + 1) + ": ");
      numb[x] = c.readInt();
    }
    if (numb[0] <= numb[1]) {
      answer = numb[1] / numb[0];
      remain = numb[1] % numb[0];
      c.print(
          ""
              + numb[1]
              + " divided by "
              + numb[0]
              + " equals "
              + answer
              + " with a remainder of "
              + remain);
    } else if (numb[1] < numb[0]) {
      answer = numb[0] / numb[1];
      remain = numb[0] % numb[1];
      c.print(
          ""
              + numb[0]
              + " divided by "
              + numb[1]
              + " equals "
              + answer
              + " with a remainder of "
              + remain);
    }
  }
Exemplo n.º 9
0
 public static void main(String[] args) {
   Console c = new Console();
   Format f = new Format();
   double salaryold = 0, salarynew = 40000, raise = 40000;
   c.print(Format.justify('r', "Year", 6));
   c.print(Format.justify('r', "Old Salary", 15));
   c.print(Format.justify('r', "Raise", 11));
   c.print(Format.justify('r', "New Salary\n", 17));
   c.print(Format.justify('r', "----", 6));
   c.print(Format.justify('r', "--- ------", 15));
   c.print(Format.justify('r', "-----", 11));
   c.print(Format.justify('r', "--- ------\n", 17));
   for (int x = 0; x <= 9; x++) {
     c.print(Format.justify('r', x + 1, 6));
     c.print(Format.justify('r', salaryold, 15, 2));
     c.print(Format.justify('r', raise, 12, 2));
     c.println(Format.justify('r', salarynew, 14, 2));
     raise = (salarynew * .03);
     salaryold = salarynew;
     salarynew = raise + salaryold;
   }
 }
Exemplo n.º 10
0
  public void move(int dir) {
    int prevX = p.x;
    int prevY = p.y;
    boolean moved = false;
    switch (dir) {
      case 0:
        if (getCurrentTile().contains("village")) {
          console.print(
              "You leave the safety of the village and head north into the wild,"
                  + " where you'll have to find your own food and water.");
        } else {
          console.print("You gather your things and head north.");
        }
        if (p.y > 0) {
          p.up();
          moved = true;
        } else
          console.print(
              "You are met with a large mountain range, and snow begins to swirl down around you."
                  + " You can't go any further. You turn around and head back.");
        break;
      case 1:
        if (getCurrentTile().contains("village")) {
          console.print(
              "You leave the safety of the village and head west into the wild,"
                  + " where you'll have to find your own food and water.");
        } else {
          console.print("You gather your things and head west.");
        }
        if (p.x > 0) {
          p.left();
          moved = true;
        } else
          console.print(
              "You find a long coastline, and can't go any "
                  + "further. You turn around and head back.");
        break;
      case 2:
        if (getCurrentTile().contains("village")) {
          console.print(
              "You leave the safety of the village and head south into the wild,"
                  + " where you'll have to find your own food and water.");
        } else {
          console.print("You gather your things and head south.");
        }
        if (p.y < 14) {
          p.down();
          moved = true;
        } else
          console.print(
              "You hear loud howling, and your skin crawls. "
                  + "You can't go any further. You turn around and head back");
        break;
      case 3:
        if (getCurrentTile().contains("village")) {
          console.print(
              "You leave the safety of the village and head east into the wild,"
                  + " where you'll have to find your own food and water.");
        } else {
          console.print("You gather your things and head east.");
        }
        if (p.x < 14) {
          p.right();
          moved = true;
        } else
          console.print(
              "You find an interminable desert, devoid of life. "
                  + "You can't go any further. You turn around and head back");
    }
    tiles[prevX][prevY].setPlayer(false);
    if (tiles[p.x][p.y].setPlayer(true)) {
      for (Entity e : tiles[p.x][p.y].entities) {
        p.discovery(e.type);
      }
    }
    if (moved) sponGen();
    handleMilestones(getCurrentTile());

    // What you see when you get there
    if (p.health > 0) console.print(getCurrentTile().toString());
    else {
      console.print("You see nothing.");
      container.death();
    }
  }
Exemplo n.º 11
0
 public void rest() {
   if (getCurrentTile().contains("village")) {
     console.print("You find a bed, and lay down to rest.");
     p.maxHealth();
   } else console.print("There is no place to rest.");
 }
Exemplo n.º 12
0
 public void eat() {
   if (getCurrentTile().contains("village")) {
     console.print("You acquire some meat at the village, and gobble it down.");
     p.maxFood();
   } else console.print("There is no food in sight.");
 }
Exemplo n.º 13
0
 private void printBoard() {
   console.print(game.getBoardAsString());
 }