Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Chaowen Zeng-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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chaowen Zeng
Chaowen Zeng-project-1
Commits
01ff107d
Commit
01ff107d
authored
Apr 23, 2021
by
Chaowen Zeng
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
ff6017e0
No related branches found
No related tags found
1 merge request
!1
Upload New File
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Shadow_Treasure.txt
+116
-0
116 additions, 0 deletions
Shadow_Treasure.txt
with
116 additions
and
0 deletions
Shadow_Treasure.txt
0 → 100644
+
116
−
0
View file @
01ff107d
import bagel.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.DecimalFormat;
/**
* An example Bagel game.
*/
public class ShadowTreasure extends AbstractGame {
// for rounding double number; use this to print the location of the player
private static DecimalFormat df = new DecimalFormat("0.00");
public static void printInfo(double x, double y, int e) {
System.out.println(df.format(x) + "," + df.format(y) + "," + e);
}
public ShadowTreasure() throws IOException {
this.loadEnvironment("res/IO/environment.csv");
// Add code to initialize other attributes as needed
private final Image PlayerImage = new Image("res/images/player.png");
private final Image BackgroundImage = new Image("res/images/background.png");
private final Image ZoombieImage = new Image("res/images/Zombie.png");
private final Image SandwichImage = new Image("res/images/Sandwich.png");
private final Font font = new Font("DejaVuSans-Bold.ttf", 20);
private static final double STEP_SIZE = 10;
private static final double Meet_DISTANCE = 50;
private static final Point Zoombie_POINT = new Point(300, 200);
private static final Point Sandwich_POINT = new Point(500, 400);
private static final double SCORE_DISTANCE = 20;
private double playerX = 650;
private double playerY = 100;
private double player_Energy = 2;
}
/**
* Load from input file
*/
private void loadEnvironment(String filename){
// Code here to read from the file and set up the environment
try (BufferedReader br =
new BufferedReader(new FileReader("res/environment.csv.\n"))) {
while ((text = br.readLine()) != null) {
<block of code to execute >
}
}
}
/**
* Performs a state update.
*/
@Override
public void update(Input input) {
// Logic to update the game, as per specification must go here
if (input.isDown(Keys.LEFT)) {
playerX -= STEP_SIZE;
}
if (input.isDown(Keys.RIGHT)) {
playerX += STEP_SIZE;
}
if (input.isDown(Keys.UP)) {
playerY -= STEP_SIZE;
}
if (input.isDown(Keys.DOWN)) {
playerY += STEP_SIZE;
}
if (new Point(playerX, playerY).distanceTo(Zoombie_POINT) <= Meet_DISTANCE) {
player_Energy -= 3;
font.drawString(playerX, playerY, player_Energy);
break;
}
if (new Point(playerX, playerY).distanceTo(Sandwich_POINT) <= Meet_DISTANCE) {
player_Energy += 5;
font.drawString(playerX, playerY, player_Energy);
break;
}
if (play_Energy >= 3){
int X = Math.pow(Zoombie_POINT.x - playerX, 2);
int Y = Math.pow(Zoombie_POINT.y - playerY, 2);
X += STEP_SIZE;
Y += STEP_SIZE;
}
if (play_Energy < 3){
int X = Math.pow(Sandwich_POINT.x - playerX, 2);
int Y = Math.pow(Sandwich_POINT.y - playerY, 2);
X += STEP_SIZE;
Y += STEP_SIZE;
}
ZoombieImage.draw(Zoombie_POINT.x, Zoombie_POINT.y);
PlayerImage.draw(playerX, playerY);
SandwichImage.draw(Sandwich_POINT.x, Sandwich_POINT.y);
/**
* The entry point for the program.
*/
public static void main(String[] args) throws IOException {
ShadowTreasure game = new ShadowTreasure();
game.run();
}
}
\ No newline at end of file
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