Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nagaik-project-1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Keigo Nagai
nagaik-project-1
Commits
2dd75516
Commit
2dd75516
authored
4 years ago
by
zlatax
Browse files
Options
Downloads
Patches
Plain Diff
everything runs without error
parent
1b55c470
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
project-1/src/ShadowTreasure.java
+18
-19
18 additions, 19 deletions
project-1/src/ShadowTreasure.java
with
18 additions
and
19 deletions
project-1/src/ShadowTreasure.java
+
18
−
19
View file @
2dd75516
...
@@ -3,6 +3,7 @@ import bagel.*;
...
@@ -3,6 +3,7 @@ import bagel.*;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.text.DecimalFormat
;
import
java.text.DecimalFormat
;
import
java.util.Scanner
;
import
java.util.Scanner
;
...
@@ -30,7 +31,7 @@ public class ShadowTreasure extends AbstractGame {
...
@@ -30,7 +31,7 @@ public class ShadowTreasure extends AbstractGame {
public
ShadowTreasure
()
throws
IOException
{
public
ShadowTreasure
()
throws
IOException
{
super
(
1024
,
768
,
"ShadowTreasure"
);
super
(
1024
,
768
,
"ShadowTreasure"
);
this
.
loadEnvironment
(
"test/test
1
/environment.csv"
);
// encoding includes 65279 char which fucks up the scanning part.
this
.
loadEnvironment
(
"test/test
2
/environment.csv"
);
// Add code to initialize other attributes as needed
// Add code to initialize other attributes as needed
bg
=
new
Image
(
"res/images/background.png"
);
bg
=
new
Image
(
"res/images/background.png"
);
}
}
...
@@ -41,7 +42,7 @@ public class ShadowTreasure extends AbstractGame {
...
@@ -41,7 +42,7 @@ public class ShadowTreasure extends AbstractGame {
private
void
loadEnvironment
(
String
filename
)
{
private
void
loadEnvironment
(
String
filename
)
{
// Code here to read from the file and set up the environment
// Code here to read from the file and set up the environment
try
{
try
{
Scanner
scanner
=
new
Scanner
(
new
File
(
filename
),
"utf-8"
);
Scanner
scanner
=
new
Scanner
(
new
File
(
filename
),
StandardCharsets
.
UTF_8
);
double
xcoor
,
ycoor
;
double
xcoor
,
ycoor
;
int
level
,
counter
=
0
;
int
level
,
counter
=
0
;
while
(
scanner
.
hasNextLine
())
{
while
(
scanner
.
hasNextLine
())
{
...
@@ -54,37 +55,29 @@ public class ShadowTreasure extends AbstractGame {
...
@@ -54,37 +55,29 @@ public class ShadowTreasure extends AbstractGame {
linescan
.
useDelimiter
(
","
);
linescan
.
useDelimiter
(
","
);
String
item
=
linescan
.
next
();
String
item
=
linescan
.
next
();
switch
(
item
.
toLowerCase
())
{
switch
(
item
.
toLowerCase
())
{
case
"player"
:
case
"player"
->
{
xcoor
=
Double
.
parseDouble
(
linescan
.
next
());
xcoor
=
Double
.
parseDouble
(
linescan
.
next
());
ycoor
=
Double
.
parseDouble
(
linescan
.
next
());
ycoor
=
Double
.
parseDouble
(
linescan
.
next
());
level
=
Integer
.
parseInt
(
linescan
.
next
());
level
=
Integer
.
parseInt
(
linescan
.
next
());
// System.out.println("Player: ("+xcoor+","+ycoor+"), "+level);
player
=
new
Player
(
"res/images/player.png"
,
new
APoint
(
xcoor
,
ycoor
),
level
);
player
=
new
Player
(
"res/images/player.png"
,
new
APoint
(
xcoor
,
ycoor
),
level
);
break
;
}
case
"zombie"
:
case
"zombie"
->
{
xcoor
=
Double
.
parseDouble
(
linescan
.
next
());
xcoor
=
Double
.
parseDouble
(
linescan
.
next
());
ycoor
=
Double
.
parseDouble
(
linescan
.
next
());
ycoor
=
Double
.
parseDouble
(
linescan
.
next
());
// System.out.println("Zombie: ("+xcoor+","+ycoor+")");
zombie
=
new
Zombie
(
"res/Images/Zombie.png"
,
new
APoint
(
xcoor
,
ycoor
));
zombie
=
new
Zombie
(
"res/Images/Zombie.png"
,
new
APoint
(
xcoor
,
ycoor
));
break
;
}
case
"sandwich"
:
case
"sandwich"
->
{
xcoor
=
Double
.
parseDouble
(
linescan
.
next
());
xcoor
=
Double
.
parseDouble
(
linescan
.
next
());
ycoor
=
Double
.
parseDouble
(
linescan
.
next
());
ycoor
=
Double
.
parseDouble
(
linescan
.
next
());
// System.out.println("Sandwich: ("+xcoor+","+ycoor+")");
sandwich
=
new
Sandwich
(
"res/Images/Sandwich.png"
,
new
APoint
(
xcoor
,
ycoor
));
sandwich
=
new
Sandwich
(
"res/Images/Sandwich.png"
,
new
APoint
(
xcoor
,
ycoor
));
break
;
}
default
:
default
->
throw
new
IllegalStateException
(
"Unexpected value: "
+
item
.
toLowerCase
());
throw
new
IllegalStateException
(
"Unexpected value: "
+
item
.
toLowerCase
());
}
}
linescan
.
close
();
linescan
.
close
();
}
}
scanner
.
close
();
scanner
.
close
();
System
.
out
.
println
(
"player: "
+
player
.
getPos
().
toString
());
System
.
out
.
println
(
"zombie: "
+
zombie
.
getPos
().
toString
());
System
.
out
.
println
(
"sandwich: "
+
sandwich
.
getPos
().
toString
());
}
catch
(
FileNotFoundException
e
)
{
}
catch
(
FileNotFoundException
e
)
{
System
.
out
.
println
(
"File was not found!\n"
+
e
);
System
.
out
.
println
(
"File was not found!\n"
+
e
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -104,9 +97,15 @@ public class ShadowTreasure extends AbstractGame {
...
@@ -104,9 +97,15 @@ public class ShadowTreasure extends AbstractGame {
APoint
playerPos
=
player
.
getPos
();
APoint
playerPos
=
player
.
getPos
();
APoint
zombiePos
=
zombie
.
getPos
();
APoint
zombiePos
=
zombie
.
getPos
();
printInfo
(
playerPos
.
getX
(),
playerPos
.
getY
(),
player
.
getEnergy
());
// Logic to update the game, as per specification must go here
// Logic to update the game, as per specification must go here
if
(
playerPos
.
distanceTo
(
zombiePos
)
<
50
)
{
if
(
playerPos
.
distanceTo
(
zombiePos
)
<
50
)
{
player
.
addEnergy
(-
3
);
player
.
addEnergy
(-
3
);
APoint
dir
=
playerPos
.
getDirection
(
zombiePos
);
playerPos
.
setX
(
playerPos
.
getX
()
+
dir
.
getX
()
*
player
.
getStepsize
());
playerPos
.
setY
(
playerPos
.
getY
()
+
dir
.
getY
()
*
player
.
getStepsize
());
printInfo
(
playerPos
.
getX
(),
playerPos
.
getY
(),
player
.
getEnergy
());
System
.
exit
(
0
);
System
.
exit
(
0
);
}
else
if
(
sandwich
!=
null
&&
playerPos
.
distanceTo
(
sandwich
.
getPos
())
<
50
)
{
}
else
if
(
sandwich
!=
null
&&
playerPos
.
distanceTo
(
sandwich
.
getPos
())
<
50
)
{
player
.
addEnergy
(
5
);
player
.
addEnergy
(
5
);
...
@@ -121,7 +120,7 @@ public class ShadowTreasure extends AbstractGame {
...
@@ -121,7 +120,7 @@ public class ShadowTreasure extends AbstractGame {
playerPos
.
setX
(
playerPos
.
getX
()
+
dir
.
getX
()
*
player
.
getStepsize
());
playerPos
.
setX
(
playerPos
.
getX
()
+
dir
.
getX
()
*
player
.
getStepsize
());
playerPos
.
setY
(
playerPos
.
getY
()
+
dir
.
getY
()
*
player
.
getStepsize
());
playerPos
.
setY
(
playerPos
.
getY
()
+
dir
.
getY
()
*
player
.
getStepsize
());
}
}
printInfo
(
playerPos
.
getX
(),
playerPos
.
getY
(),
player
.
getEnergy
());
count
=
0
;
count
=
0
;
}
}
count
++;
count
++;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment