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
40ba5d20
Commit
40ba5d20
authored
Apr 26, 2015
by
Junita Sinambela
Browse files
adding map controller and offer
parent
1cf7eae5
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/server/nbproject/project.properties
View file @
40ba5d20
...
...
@@ -63,7 +63,7 @@ javadoc.splitindex=true
javadoc.use
=
true
javadoc.version
=
false
javadoc.windowtitle
=
main.class
=
server.
helper.Message
main.class
=
server.
Server
manifest.file
=
manifest.mf
meta.inf.dir
=
${src.dir}/META-INF
mkdist.disabled
=
false
...
...
src/server/src/server/ServerHandler.java
View file @
40ba5d20
...
...
@@ -34,9 +34,7 @@ public class ServerHandler{
InputStream
in
=
s
.
getInputStream
();
DataOutputStream
out
=
new
DataOutputStream
(
s
.
getOutputStream
());
out
.
write
(
request
.
getBytes
());
byte
[]
byt
=
new
byte
[
4096
];
int
count
=
in
.
read
(
byt
);
request
=
new
String
(
byt
);
if
(
response
!=
null
)
{
// request = request.substring(0,count);
...
...
src/server/src/server/helper/Cache.java
0 → 100644
View file @
40ba5d20
/*
* 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 @
40ba5d20
...
...
@@ -13,6 +13,19 @@ package server.helper;
public
class
Map
{
private
String
[][]
map
;
private
String
token
;
private
final
String
Honey
=
"R11"
;
private
final
String
Herbs
=
"R12"
;
private
final
String
Clay
=
"R13"
;
private
final
String
Mineral
=
"R14"
;
private
final
String
Potion
=
"R21"
;
private
final
String
Incense
=
"R22"
;
private
final
String
Gems
=
"R23"
;
private
final
String
LifeElix
=
"R31"
;
private
final
String
Mana
=
"R32"
;
private
final
String
Stone
=
"R41"
;
public
Map
(
String
token
){
map
=
Store
.
getMap
();
this
.
token
=
token
;
...
...
@@ -23,4 +36,40 @@ public class Map {
public
String
getToken
(){
return
token
;
}
public
int
getItemIndex
(
int
xPos
,
int
yPos
)
{
int
HONEY
=
0
;
int
HERBS
=
1
;
int
CLAY
=
2
;
int
MINERAL
=
3
;
int
POTION
=
4
;
int
INCENSE
=
5
;
int
GEMS
=
6
;
int
LIFEELIXIR
=
7
;
int
MANACRYSTAL
=
8
;
int
PHILSTONE
=
9
;
if
(
map
[
xPos
][
yPos
].
equals
(
Honey
))
{
return
HONEY
;
}
else
if
(
map
[
xPos
][
yPos
].
equals
(
Herbs
))
{
return
HERBS
;
}
else
if
(
map
[
xPos
][
yPos
].
equals
(
Clay
))
{
return
CLAY
;
}
else
if
(
map
[
xPos
][
yPos
].
equals
(
Mineral
))
{
return
MINERAL
;
}
else
if
(
map
[
xPos
][
yPos
].
equals
(
Potion
))
{
return
POTION
;
}
else
if
(
map
[
xPos
][
yPos
].
equals
(
Incense
))
{
return
INCENSE
;
}
else
if
(
map
[
xPos
][
yPos
].
equals
(
Gems
))
{
return
GEMS
;
}
else
if
(
map
[
xPos
][
yPos
].
equals
(
LifeElix
))
{
return
LIFEELIXIR
;
}
else
if
(
map
[
xPos
][
yPos
].
equals
(
Mana
))
{
return
MANACRYSTAL
;
}
else
if
(
map
[
xPos
][
yPos
].
equals
(
Stone
))
{
return
PHILSTONE
;
}
else
{
return
-
1
;
}
}
}
src/server/src/server/helper/Message.java
View file @
40ba5d20
...
...
@@ -539,7 +539,7 @@ public class Message {
x
=
jsonPosition
.
getInt
(
"x"
);
y
=
jsonPosition
.
getInt
(
"y"
);
item
=
Store
.
getItemIndex
(
x
,
y
);
item
=
Map
.
getItemIndex
(
x
,
y
);
if
(
Database
.
addItemToInventory
(
token
,
item
))
{
jsonObj
.
put
(
"status"
,
"ok"
);
...
...
src/server/src/server/helper/Offer.java
0 → 100644
View file @
40ba5d20
/*
* 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 @
40ba5d20
...
...
@@ -6,6 +6,7 @@
package
server.helper
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
...
...
@@ -15,6 +16,7 @@ import java.util.List;
public
class
Store
{
private
static
List
<
IPAddress
>
listServer
;
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"
;
...
...
@@ -71,42 +73,6 @@ public class Store {
public
static
String
[][]
getMap
(){
return
map
;
}
public
static
int
getItemIndex
(
int
xPos
,
int
yPos
)
{
int
HONEY
=
0
;
int
HERBS
=
1
;
int
CLAY
=
2
;
int
MINERAL
=
3
;
int
POTION
=
4
;
int
INCENSE
=
5
;
int
GEMS
=
6
;
int
LIFEELIXIR
=
7
;
int
MANACRYSTAL
=
8
;
int
PHILSTONE
=
9
;
if
(
map
[
xPos
][
yPos
].
equals
(
Honey
))
return
HONEY
;
else
if
(
map
[
xPos
][
yPos
].
equals
(
Herbs
))
return
HERBS
;
else
if
(
map
[
xPos
][
yPos
].
equals
(
Clay
))
return
CLAY
;
else
if
(
map
[
xPos
][
yPos
].
equals
(
Mineral
))
return
MINERAL
;
else
if
(
map
[
xPos
][
yPos
].
equals
(
Potion
))
return
POTION
;
else
if
(
map
[
xPos
][
yPos
].
equals
(
Incense
))
return
INCENSE
;
else
if
(
map
[
xPos
][
yPos
].
equals
(
Gems
))
return
GEMS
;
else
if
(
map
[
xPos
][
yPos
].
equals
(
LifeElix
))
return
LIFEELIXIR
;
else
if
(
map
[
xPos
][
yPos
].
equals
(
Mana
))
return
MANACRYSTAL
;
else
if
(
map
[
xPos
][
yPos
].
equals
(
Stone
))
return
PHILSTONE
;
else
return
-
1
;
}
/**
* Get an IPAddress from list of server in this class with index
* @param index
...
...
@@ -122,4 +88,18 @@ public class Store {
public
static
List
<
IPAddress
>
getServers
(){
return
listServer
;
}
public
static
void
addMap
(
String
token
){
Map
mp
=
new
Map
(
token
);
listMap
.
add
(
mp
);
}
public
static
Map
getMap
(
String
token
){
Map
mp
=
null
;
for
(
Map
temp
:
listMap
){
if
(
temp
.
getToken
().
equals
(
token
)){
mp
=
temp
;
break
;
}
}
return
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