예제 #1
0
  public void genTiles() {
    tiles = new Tile[15][15];
    int tileWidth = getWidth() / tiles.length;
    int tileHeight = getHeight() / tiles[0].length;

    int ponds = 0;
    for (int i = 0; i < 15; i++) {
      for (int j = 0; j < 15; j++) {
        tiles[i][j] = new Tile(tileWidth, tileHeight, (i == 7 && j == 7));
        c.gridx = i;
        c.gridy = j;
        if (tiles[i][j].contains("pond")) ponds++;
        add(tiles[i][j], c);
      }
    }
    // Color background = new Color(167, 175, 60);
    // Color dest = new Color(22, 192, 16);
    ponds -= 20;
    if (ponds < 0) ponds = 0;
    if (ponds > 10) ponds = 10;
    int r = (int) (167 - 14.5 * ponds);
    int g = (int) (175 + 1.7 * ponds);
    int b = (int) (60 - 4.4 * ponds);

    for (Tile[] tileRow : tiles) {
      for (Tile tile : tileRow) {
        tile.background = new Color(r, g, b);
      }
    }

    p.x = (int) Math.ceil(tiles.length / 2);
    p.y = (int) Math.ceil(tiles[p.x].length / 2);
    // tiles[p.x][p.y].setPlayer(true);
    balance();
  }
예제 #2
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:
   }
 }
예제 #3
0
 public void pillage() {
   getCurrentTile().removeEntity("village");
   p.maxFood += 3;
   p.maxWater += 3;
   p.maxHealth += 2;
   p.decFood(3);
   p.decWater(3);
   p.razeCount++;
 }
예제 #4
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.");
 }
예제 #5
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);
     }
   }
 }
예제 #6
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();
    }
  }
예제 #7
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.");
 }
예제 #8
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.");
 }