Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package controller;
- public class CoordInf {
- /* stad janee dorp janee
- * x y
- * weg x y x2 y2
- * tile janee
- * fishe janee & waarde ding
- * kleur tile als tile op coord zit
- *
- */
- static databaseConnection dbcon = new databaseConnection("jdbc:mysql://databases.aii.avans.nl/sficken_db", "sficken", "Ab12345");
- public static String getBuilding(int x, int y){
- return dbcon.select("SELECT * FROM spelerstuk JOIN stuk on stuk.idstuk = spelerstuk.idstuk WHERE x_naar IS null AND y_naar IS null AND x_van = "+x+" AND y_van = "+y , "stuksoort").get(0);
- }
- public static void buildVillage(int x, int y, String username, int gameid){
- for(int i=1; i<6; i++){
- if(dbcon.select("SELECT * FROM spelerstuk WHERE username = '" + username + "' AND idstuk = 'd0" + i + "'", "x_van").get(0).equals(null)){
- dbcon.insert("INSERT INTO spelerstuk VALUES (" + gameid + ", '"+ username + "', 'd0" + i + "', " + x + ", " + y);
- }
- }
- }
- public static void buildCity(int x, int y, String username, int gameid){
- for(int i=1; i<6; i++){
- if(dbcon.select("SELECT * FROM spelerstuk WHERE username = '" + username + "' AND idstuk = 'c0" + i + "'", "x_van").get(0).equals(null)){
- dbcon.insert("INSERT INTO spelerstuk VALUES (" + gameid + ", '"+ username + "', 'c0" + i + "', " + x + ", " + y);
- }
- }
- }
- public static void buildRoad(int x_from, int y_from, int x_to, int y_to, String username, int gameid){
- for(int i=1; i<6; i++){
- if(i<10){
- if(dbcon.select("SELECT * FROM spelerstuk WHERE username = '" + username + "' AND idstuk = 'r0" + i + "'", "x_van").get(0).equals(null)){
- dbcon.insert("INSERT INTO spelerstuk VALUES (" + gameid + ", '"+ username + "', 'r0" + i + "', " + x_from + ", " + y_from + ", " + x_to + ", " + y_to);
- }
- }
- if (i>=10){
- if(dbcon.select("SELECT * FROM spelerstuk WHERE username = '" + username + "' AND idstuk = 'r" + i + "'", "x_van").get(0).equals(null)){
- dbcon.insert("INSERT INTO spelerstuk VALUES (" + gameid + ", '"+ username + "', 'r" + i + "', " + x_from + ", " + y_from + ", " + x_to + ", " + y_to);
- }
- }
- }
- }
- public static int[] getStreets(int x, int y){
- String query = "SELECT * FROM spelerstuk JOIN stuk on stuk.idstuk = spelerstuk.idstuk WHERE x_naar = "+x+" AND y_naar = "+y+" OR x_van = "+x+" AND y_van = "+y;
- int[] streetCoords = new int[4];
- if(dbcon.select(query, "stuksoort").get(0).equals("straat")){
- streetCoords[0]=Integer.parseInt(dbcon.select(query, "x_van").get(0));
- streetCoords[1]=Integer.parseInt(dbcon.select(query, "y_van").get(0));
- streetCoords[2]=Integer.parseInt(dbcon.select(query, "x_naar").get(0));
- streetCoords[3]=Integer.parseInt(dbcon.select(query, "y_naar").get(0));
- return streetCoords;
- }
- else{
- return null;
- }
- }
- public static int getTokenID(int x, int y){
- if(Integer.parseInt(dbcon.select("SELECT tegel.idgetalfiche FROM tegel JOIN getalfiche on tegel.idgetalfiche = getalfiche.idgetalfiche WHERE x="+x+" AND y="+y, "idgetalfiche").get(0))>0){
- return Integer.parseInt(dbcon.select("SELECT tegel.idgetalfiche FROM tegel JOIN getalfiche on tegel.idgetalfiche = getalfiche.idgetalfiche WHERE x="+x+" AND y="+y, "idgetalfiche").get(0));
- }
- //returns tokenID and returns 0 if there is none
- else{
- return 0;
- }
- }
- public static int getTokenValue(int x, int y){
- return Integer.parseInt(dbcon.select("SELECT getalfiche.waarde FROM tegel JOIN getalfiche on tegel.idgetalfiche = getalfiche.idgetalfiche WHERE x="+ x +" AND y="+y, "waarde").get(0));
- }
- public static String getResource(int x, int y){
- return dbcon.select("SELECT idgrondstofsoort FROM tegel WHERE x="+x+" AND y="+y, "idgrondstofsoort").get(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement