Advertisement
Guest User

Untitled

a guest
May 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. package controller;
  2.  
  3. public class CoordInf {
  4. /* stad janee dorp janee
  5. * x y
  6. * weg x y x2 y2
  7. * tile janee
  8. * fishe janee & waarde ding
  9. * kleur tile als tile op coord zit
  10. *
  11. */
  12. static databaseConnection dbcon = new databaseConnection("jdbc:mysql://databases.aii.avans.nl/sficken_db", "sficken", "Ab12345");
  13.  
  14. public static String getBuilding(int x, int y){
  15. 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);
  16. }
  17.  
  18. public static void buildVillage(int x, int y, String username, int gameid){
  19. for(int i=1; i<6; i++){
  20. if(dbcon.select("SELECT * FROM spelerstuk WHERE username = '" + username + "' AND idstuk = 'd0" + i + "'", "x_van").get(0).equals(null)){
  21. dbcon.insert("INSERT INTO spelerstuk VALUES (" + gameid + ", '"+ username + "', 'd0" + i + "', " + x + ", " + y);
  22. }
  23. }
  24. }
  25.  
  26. public static void buildCity(int x, int y, String username, int gameid){
  27. for(int i=1; i<6; i++){
  28. if(dbcon.select("SELECT * FROM spelerstuk WHERE username = '" + username + "' AND idstuk = 'c0" + i + "'", "x_van").get(0).equals(null)){
  29. dbcon.insert("INSERT INTO spelerstuk VALUES (" + gameid + ", '"+ username + "', 'c0" + i + "', " + x + ", " + y);
  30. }
  31. }
  32. }
  33.  
  34. public static void buildRoad(int x_from, int y_from, int x_to, int y_to, String username, int gameid){
  35. for(int i=1; i<6; i++){
  36. if(i<10){
  37. if(dbcon.select("SELECT * FROM spelerstuk WHERE username = '" + username + "' AND idstuk = 'r0" + i + "'", "x_van").get(0).equals(null)){
  38. dbcon.insert("INSERT INTO spelerstuk VALUES (" + gameid + ", '"+ username + "', 'r0" + i + "', " + x_from + ", " + y_from + ", " + x_to + ", " + y_to);
  39. }
  40. }
  41. if (i>=10){
  42. if(dbcon.select("SELECT * FROM spelerstuk WHERE username = '" + username + "' AND idstuk = 'r" + i + "'", "x_van").get(0).equals(null)){
  43. dbcon.insert("INSERT INTO spelerstuk VALUES (" + gameid + ", '"+ username + "', 'r" + i + "', " + x_from + ", " + y_from + ", " + x_to + ", " + y_to);
  44. }
  45. }
  46. }
  47. }
  48.  
  49. public static int[] getStreets(int x, int y){
  50. 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;
  51. int[] streetCoords = new int[4];
  52. if(dbcon.select(query, "stuksoort").get(0).equals("straat")){
  53. streetCoords[0]=Integer.parseInt(dbcon.select(query, "x_van").get(0));
  54. streetCoords[1]=Integer.parseInt(dbcon.select(query, "y_van").get(0));
  55. streetCoords[2]=Integer.parseInt(dbcon.select(query, "x_naar").get(0));
  56. streetCoords[3]=Integer.parseInt(dbcon.select(query, "y_naar").get(0));
  57. return streetCoords;
  58. }
  59. else{
  60. return null;
  61. }
  62. }
  63.  
  64. public static int getTokenID(int x, int y){
  65. 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){
  66. 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));
  67. }
  68. //returns tokenID and returns 0 if there is none
  69. else{
  70. return 0;
  71. }
  72. }
  73.  
  74. public static int getTokenValue(int x, int y){
  75. 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));
  76. }
  77.  
  78. public static String getResource(int x, int y){
  79. return dbcon.select("SELECT idgrondstofsoort FROM tegel WHERE x="+x+" AND y="+y, "idgrondstofsoort").get(0);
  80. }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement