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
Merge requests
!1
Upload New File
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Open
Upload New File
scr
into
master
Overview
0
Commits
1
Pipelines
0
Changes
1
Open
Upload New File
Chaowen Zeng
requested to merge
scr
into
master
Apr 23, 2021
Overview
0
Commits
1
Pipelines
0
Changes
1
0
0
Merge request reports
Compare
master
master (HEAD)
and
latest version
latest version
01ff107d
1 commit,
Apr 23, 2021
1 file
+
116
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Shadow_Treasure.txt
0 → 100644
+
116
−
0
View file @ 4b3bc2c5
Edit in single-file editor
Open in Web IDE
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
Loading