Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Junita Sinambela
IF3230-Tugas-Besar-Sister-2015
Commits
de5f6247
Commit
de5f6247
authored
Apr 26, 2015
by
Junita Sinambela
Browse files
edit map done
parent
ae889530
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/server/src/server/helper/Cache.java
deleted
100644 → 0
View file @
ae889530
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
server.helper
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
*
* @author user
*/
public
class
Cache
{
public
static
List
<
Offer
>
listOffer
=
new
ArrayList
<>();
public
static
void
addOffer
(
Offer
off
){
listOffer
.
add
(
off
);
}
public
static
IPAddress
getIP
(
String
offer_token
){
IPAddress
ip
=
null
;
for
(
Offer
off
:
listOffer
){
if
(
off
.
getToken
().
equals
(
offer_token
)){
ip
=
off
.
getIP
();
break
;
}
}
return
ip
;
}
public
static
void
removeToken
(
String
offer_token
){
for
(
Offer
off
:
listOffer
){
if
(
off
.
getToken
().
equals
(
offer_token
)){
listOffer
.
remove
(
off
);
break
;
}
}
}
}
src/server/src/server/helper/Map.java
View file @
de5f6247
...
...
@@ -27,7 +27,6 @@ public class Map {
public
Map
(
String
token
){
map
=
Store
.
getMap
();
this
.
token
=
token
;
}
public
String
[][]
getMap
(){
...
...
@@ -37,6 +36,33 @@ public class Map {
return
token
;
}
public
void
generateMap
()
{
map
[
0
][
0
]
=
Honey
;
map
[
0
][
1
]
=
Mineral
;
map
[
0
][
2
]
=
Herbs
;
map
[
0
][
3
]
=
Herbs
;
map
[
0
][
4
]
=
Mineral
;
map
[
1
][
0
]
=
Clay
;
map
[
1
][
1
]
=
Clay
;
map
[
1
][
2
]
=
Herbs
;
map
[
1
][
3
]
=
Mineral
;
map
[
1
][
4
]
=
Potion
;
map
[
3
][
0
]
=
Mineral
;
map
[
3
][
1
]
=
Herbs
;
map
[
3
][
2
]
=
Clay
;
map
[
3
][
3
]
=
Herbs
;
map
[
3
][
4
]
=
Incense
;
map
[
4
][
0
]
=
Mana
;
map
[
4
][
1
]
=
Gems
;
map
[
4
][
2
]
=
Potion
;
map
[
4
][
3
]
=
LifeElix
;
map
[
4
][
4
]
=
Mineral
;
}
public
int
getItemIndex
(
int
xPos
,
int
yPos
)
{
int
HONEY
=
0
;
int
HERBS
=
1
;
...
...
@@ -72,4 +98,9 @@ public class Map {
return
-
1
;
}
}
public
void
setEmpty
(
int
x
,
int
y
)
{
map
[
x
][
y
]
=
"-1"
;
}
}
src/server/src/server/helper/Message.java
View file @
de5f6247
...
...
@@ -531,7 +531,6 @@ public class Message {
int
x
;
int
y
;
Store
.
generateMap
();
int
item
;
String
response
;
try
{
...
...
@@ -539,7 +538,7 @@ public class Message {
x
=
jsonPosition
.
getInt
(
"x"
);
y
=
jsonPosition
.
getInt
(
"y"
);
item
=
Map
.
getItemIndex
(
x
,
y
);
item
=
Store
.
getMap
(
token
)
.
getItemIndex
(
x
,
y
);
if
(
Database
.
addItemToInventory
(
token
,
item
))
{
jsonObj
.
put
(
"status"
,
"ok"
);
...
...
@@ -630,8 +629,8 @@ public class Message {
jsonObj
=
new
JSONObject
();
jsonObj
.
put
(
"method"
,
"findoffer"
);
jsonObj
.
put
(
"item"
,
itemId
);
//
listResponse = ServerHandler.broadcast(jsonObj.toString());
listResponse
.
add
(
"{\"status\":\"ok\",\"offers\":[[3,2,4,3,false,\"553c35e53c892b1b9ddb1b86\"],[4,5,6,2,true,\"553c36143c892b1bbf7723d6\"],[4,1,5,3,false,\"553c372f3c892b1c27a0e924\"]]}"
);
listResponse
=
ServerHandler
.
broadcast
(
jsonObj
.
toString
());
//
listResponse.add("{\"status\":\"ok\",\"offers\":[[3,2,4,3,false,\"553c35e53c892b1b9ddb1b86\"],[4,5,6,2,true,\"553c36143c892b1bbf7723d6\"],[4,1,5,3,false,\"553c372f3c892b1c27a0e924\"]]}");
for
(
String
temp
:
listResponse
)
{
JSONObject
tempJSON
=
new
JSONObject
(
temp
);
if
(
tempJSON
.
getString
(
"status"
).
equals
(
"ok"
)){
...
...
src/server/src/server/helper/Offer.java
deleted
100644 → 0
View file @
ae889530
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
server.helper
;
/**
*
* @author user
*/
public
class
Offer
{
private
final
int
idItem
;
private
final
IPAddress
ip
;
private
final
String
offer_token
;
public
Offer
(
IPAddress
ip
,
String
offerToken
,
int
id
){
idItem
=
id
;
this
.
ip
=
ip
;
offer_token
=
offerToken
;
}
public
String
getToken
(){
return
offer_token
;
}
public
IPAddress
getIP
(){
return
ip
;
}
}
src/server/src/server/helper/Store.java
View file @
de5f6247
...
...
@@ -18,44 +18,6 @@ public class Store {
private
static
final
String
[][]
map
=
new
String
[
5
][
5
];
private
static
List
<
Map
>
listMap
=
new
ArrayList
<>();
private
static
final
String
Honey
=
"R11"
;
private
static
final
String
Herbs
=
"R12"
;
private
static
final
String
Clay
=
"R13"
;
private
static
final
String
Mineral
=
"R14"
;
private
static
final
String
Potion
=
"R21"
;
private
static
final
String
Incense
=
"R22"
;
private
static
final
String
Gems
=
"R23"
;
private
static
final
String
LifeElix
=
"R31"
;
private
static
final
String
Mana
=
"R32"
;
private
static
final
String
Stone
=
"R41"
;
public
static
void
generateMap
()
{
map
[
0
][
0
]
=
Honey
;
map
[
0
][
1
]
=
Mineral
;
map
[
0
][
2
]
=
Herbs
;
map
[
0
][
3
]
=
Herbs
;
map
[
0
][
4
]
=
Mineral
;
map
[
1
][
0
]
=
Clay
;
map
[
1
][
1
]
=
Clay
;
map
[
1
][
2
]
=
Herbs
;
map
[
1
][
3
]
=
Mineral
;
map
[
1
][
4
]
=
Potion
;
map
[
3
][
0
]
=
Mineral
;
map
[
3
][
1
]
=
Herbs
;
map
[
3
][
2
]
=
Clay
;
map
[
3
][
3
]
=
Herbs
;
map
[
3
][
4
]
=
Incense
;
map
[
4
][
0
]
=
Mana
;
map
[
4
][
1
]
=
Gems
;
map
[
4
][
2
]
=
Potion
;
map
[
4
][
3
]
=
LifeElix
;
map
[
4
][
4
]
=
Mineral
;
}
public
static
void
Store
(){
listServer
=
null
;
}
...
...
@@ -88,10 +50,19 @@ public class Store {
public
static
List
<
IPAddress
>
getServers
(){
return
listServer
;
}
/**
* Add map for user who login
* @param token
*/
public
static
void
addMap
(
String
token
){
Map
mp
=
new
Map
(
token
);
listMap
.
add
(
mp
);
}
/**
* Get map by token
* @param token
* @return
*/
public
static
Map
getMap
(
String
token
){
Map
mp
=
null
;
for
(
Map
temp
:
listMap
){
...
...
@@ -102,4 +73,10 @@ public class Store {
}
return
mp
;
}
public
static
void
generateMap
(
String
token
){
Map
mp
=
new
Map
(
token
);
mp
.
generateMap
();
listMap
.
add
(
mp
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment