Skip to content
Snippets Groups Projects
Commit 01ff107d authored by Chaowen Zeng's avatar Chaowen Zeng
Browse files

Upload New File

parent ff6017e0
No related branches found
No related tags found
1 merge request!1Upload New File
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment