Inventar java could be uses for jme


SUBMITTED BY: Guest

DATE: Nov. 19, 2013, 5:21 p.m.

FORMAT: Java

SIZE: 1.6 kB

HITS: 1177

  1. package mygame;
  2. public class Inventar {
  3. public String[] places;
  4. public int big;
  5. public String[] src;
  6. public Inventar()
  7. {
  8. }
  9. public void setPlaces(int i)
  10. {
  11. places = new String[i+1];
  12. src= new String[i+1];
  13. big=i;
  14. }
  15. public int newItem(String name)
  16. {
  17. for(int s=0 ; s<=big;s++)
  18. {
  19. if (places[s]==null)
  20. {
  21. places[s]=name;
  22. return (s);
  23. }
  24. }
  25. return (-1);
  26. }
  27. public void addSrc(int id,String path)
  28. {
  29. src[id]=path;
  30. }
  31. public void removeItem(int id)
  32. {
  33. places[id]=null;
  34. src[id]=null;
  35. }
  36. public String getItemId(int id)
  37. {
  38. return (places[id]);
  39. }
  40. public String getItemSrc(int id)
  41. {
  42. return (src[id]);
  43. }
  44. public int searchItemId(String name)
  45. {
  46. for(int s=0 ; s<=big;s++)
  47. {
  48. if (places[s].equals(name))
  49. {
  50. return (s);
  51. }
  52. }
  53. return -1;
  54. }
  55. public int searchItemSrc(String path)
  56. {
  57. for(int s=0 ; s<=big;s++)
  58. {
  59. if (src[s].equals(path))
  60. {
  61. return (s);
  62. }
  63. }
  64. return -1;
  65. }
  66. public String printItems()
  67. {
  68. String ret=places[0];
  69. for(int s=0 ; s<=big;s++)
  70. {
  71. ret = ret + ","+places[s];
  72. }
  73. return ret;
  74. }
  75. public void ItemMove(int id,int id2)
  76. {
  77. String name=places[id];
  78. String name2=places[id2];
  79. String path=src[id];
  80. String path2=src[id2];
  81. if (name2==null)
  82. {
  83. places[id2]=name;
  84. src[id2]=path;
  85. removeItem(id);
  86. }
  87. else
  88. {
  89. places[id2]=name;
  90. src[id2]=path;
  91. removeItem(id);
  92. newItem(name2);
  93. addSrc(id2,path2);
  94. }
  95. }
  96. }

comments powered by Disqus