Esempio n. 1
0
 private static void generateScenery(
     String mapId, int x, int y, int nx, int ny, DatastoreService store) {
   if (x != nx && y != ny && x != y) { // Clear the diagonal line for escape
     Entity obstacle = new Entity(Transport.SCENERY);
     obstacle.setProperty("x", x);
     obstacle.setProperty("y", y);
     obstacle.setProperty("map", mapId);
     store.put(obstacle);
   }
 }
Esempio n. 2
0
  private static Entity ensurePlayerExists(String username, DatastoreService store) {
    Query q =
        new Query(Transport.PLAYER)
            .setFilter(new Query.FilterPredicate("identity", Query.FilterOperator.EQUAL, username));
    Entity player = store.prepare(q).asSingleEntity();
    if (player == null) {
      Long x = 10l;
      Long y = 10l;
      player = new Entity(Transport.PLAYER);
      player.setProperty("identity", username);
      player.setProperty("speed", 4);
      PointSet points = new PointSet(20, 20);
      points.add(new Transport.Point(x, y));
      player.setProperty("path", new Gson().toJson(new Transport.Points(points)));
      store.put(player);

      QueueFactory.getDefaultQueue().add(withUrl("/tick").param("identity", username));
    }
    return player;
  }
Esempio n. 3
0
 private static Entity ensureMapExists(Entity player, DatastoreService store) {
   Query mq = new Query(Transport.MAP);
   Entity map = store.prepare(mq).asSingleEntity();
   Random rand = new Random();
   if (map == null) {
     map = new Entity(Transport.MAP);
     String mapId = "sandbox";
     int width = 20;
     int height = 20;
     map.setProperty("width", width);
     map.setProperty("height", height);
     map.setProperty("identity", mapId);
     store.put(map);
     for (int j = 0; j < 8; j++) {
       int sx = width / 2;
       int sy = height / 2;
       for (int i = 0; i < 100; i++) {
         switch (rand.nextInt(4)) {
           case 0:
             sx++;
             break;
           case 1:
             sy++;
             break;
           case 2:
             sx--;
             break;
           case 3:
             sy--;
             break;
         }
         generateScenery(mapId, sx, sy, 10, 10, store);
       }
     }
     player.setProperty("map", mapId);
     store.put(player);
   }
   return map;
 }
Esempio n. 4
0
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    int index;

    DatastoreService ds;
    MemcacheService ms;

    Cookie[] cookies;
    boolean insideFlag;

    String delpw;
    String paramOffset;
    String paramSize;
    int offset;
    int size;

    Key postObjGroupKey;
    Query q;
    List<Entity> postObjList;
    PostObj postObj;

    Gson gson;
    List<String> filelinkList;

    resp.setCharacterEncoding("UTF-8");
    resp.setContentType("text/plain");

    ds = DatastoreServiceFactory.getDatastoreService();
    ms = MemcacheServiceFactory.getMemcacheService();

    insideFlag = false;
    try {
      cookies = req.getCookies();
      if (cookies.length > 0) {
        if (ms.contains(cookies[0].getValue()) == true) {
          insideFlag = true;
        }
      }
    } catch (Exception e) {
      insideFlag = false;
    }

    delpw = req.getParameter("delpw");
    if (delpw != null) {
      if (delpw.equals("") == true) {
        delpw = null;
      }
    }

    paramOffset = req.getParameter("offset");
    if (paramOffset != null) {
      offset = Integer.valueOf(paramOffset);
    } else {
      offset = 0;
    }

    paramSize = req.getParameter("size");
    if (paramSize != null) {
      size = Integer.valueOf(paramSize);
    } else {
      size = 4096;
    }

    postObjGroupKey = KeyFactory.createKey("PostObjGroup", 1L);
    q = new Query("PostObj", postObjGroupKey);
    if (delpw != null) {
      q.addFilter("delpw", FilterOperator.EQUAL, delpw);
      q.addSort("delpw");
    }
    q.addSort("posttime", SortDirection.DESCENDING);
    postObjList = ds.prepare(q).asList(FetchOptions.Builder.withOffset(offset).limit(size));

    postObj = new PostObj();
    filelinkList = new ArrayList<String>();
    for (index = 0; index < postObjList.size(); index++) {
      postObj.getDB(postObjList.get(index));
      if ((postObj.flag.equals("showgallery") == false && insideFlag == true)
          || (postObj.flag.equals("showgallery") == true && insideFlag == false)
          || delpw != null) {
        filelinkList.add(postObj.filelink);
      }
    }

    gson = new Gson();
    resp.getWriter().print(gson.toJson(filelinkList));
  }