Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request for Issue30 #46

Merged
merged 5 commits into from
Nov 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*.class
Score.txt
build/
javadoc/
*~

# Package Files #
*.jar
Expand Down
5 changes: 2 additions & 3 deletions Score.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
1735
635
785
580
580
375
315
0
4 changes: 3 additions & 1 deletion src/edu/ucsb/cs56/projects/games/roguelike/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void main(String[] args)
public GUI()
{
final JFrame guiFrame = new JFrame("Roguelike"); // frame window title will be Roguelike

Sound.menuMusic.loop();

JButton playButton = new JButton("Play"); //new button with text "Play"
setButtonCharacteristics(playButton);
Expand Down Expand Up @@ -119,6 +119,8 @@ public void openHighScoresWindow()

public void openGameWindow()
{
Sound.menuMusic.stop();
Sound.gameMusic.loop();
String[] args = {};
RogueController.main(args);
}
Expand Down
32 changes: 18 additions & 14 deletions src/edu/ucsb/cs56/projects/games/roguelike/LogicEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,15 @@ public void move(int x,int y,int xOrig,int yOrig){
* attacks if the 2 coordinates hold different GamePieces
*/
public void attack(int x,int y,int xOrig,int yOrig){
if(floor[x][y] instanceof Monster && floor[xOrig][yOrig] instanceof Player){
thePlayer.attacking(listOfMonsters[x][y]);
}
// if ((x > 1 && x < floorWidth - 1) && (y > 1 && y < floorHeight - 1)) {
if(floor[x][y] instanceof Monster && floor[xOrig][yOrig] instanceof Player) {
thePlayer.attacking(listOfMonsters[x][y]);
}

if(floor[x][y]instanceof Player && floor[xOrig][yOrig] instanceof Monster){
listOfMonsters[xOrig][yOrig].attacking(thePlayer);}
listOfMonsters[xOrig][yOrig].attacking(thePlayer);
}
// }
}
/**
* x and y are the position thats being tested
Expand All @@ -204,23 +207,17 @@ public boolean movable(int x,int y,int xOrig, int yOrig){
return false;
}
/* not movable, out of boundary*/
if (x < 1 || x >= floorWidth-1){
if (!inBounds(x, y))
return false;
}

if (y < 1 || y >= floorHeight-1){
return false;
}



//player isn't movable, start attack for player
if(floor[x][y] instanceof Monster){
if(floor[xOrig][yOrig] instanceof Player){
/*if(floor[xOrig][yOrig] instanceof Player){
return false;
}else{
return false;
}
}*/
return false;
}

//monster isn't movable, start attack for monster
Expand All @@ -231,6 +228,13 @@ public boolean movable(int x,int y,int xOrig, int yOrig){

return true;
}

public boolean inBounds(int x, int y) {
if ((x < 1 || x >= floorWidth - 1) || (y < 1 || y >= floorHeight - 1))
return false;
else
return true;
}

/**
* check if the monster at position x,y has 0 or less hp
Expand Down
20 changes: 11 additions & 9 deletions src/edu/ucsb/cs56/projects/games/roguelike/RogueController.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ public void moveHero(){
if ( logicHandler.movable(x,y,origX, origY)) {
logicHandler.move(x,y,origX,origY);
}
else{
logicHandler.attack(x, y, origX, origY);
if(logicHandler.monsterIsDead(x,y)){
if(logicHandler.getObject(x,y) instanceof Item){
canvas.drawItem(x,y, logicHandler.getItem(x,y));
}else {
canvas.clear(x,y);
else { // Only case in which character is in bounds but can't move, is when there is a monster
if (logicHandler.inBounds(x, y)) {
logicHandler.attack(x, y, origX, origY);
if(logicHandler.monsterIsDead(x,y)){
if(logicHandler.getObject(x,y) instanceof Item){
canvas.drawItem(x,y, logicHandler.getItem(x,y));
}else {
canvas.clear(x,y);
}
}
}
x = origX;
Expand Down Expand Up @@ -399,12 +401,12 @@ public static void main(String[] args){
RogueController mainControl = new RogueController();
mainControl.setVisible(true);
mainControl.setLocationRelativeTo(null); // center the window

//Initially fills the map with monsters
mainControl.logicHandler.createMonster();


//Screen that shows after game is opened
mainControl.canvas.write("MOVE WITH W A S D. Survive the waves. Eat monsters to earn points.",9,12,RoguePanel.white,RoguePanel.black);
mainControl.canvas.write("MOVE WITH W A S D. Survive the waves. Eat monsters to earn points.",9,12,RoguePanel.white,RoguePanel.black);



Expand Down
51 changes: 51 additions & 0 deletions src/edu/ucsb/cs56/projects/games/roguelike/Sound.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package edu.ucsb.cs56.projects.games.roguelike;

import javax.sound.sampled.*;
import java.io.File;
import java.net.URL;

public class Sound {

private Clip clip;

public static Sound gameMusic = new Sound("./src/edu/ucsb/cs56/projects/games/roguelike/music/gameMusic.wav");
public static Sound menuMusic = new Sound("./src/edu/ucsb/cs56/projects/games/roguelike/music/menuMusic.wav");

public Sound (String fileName) {
try {
File file = new File(fileName);
AudioInputStream ais = AudioSystem.getAudioInputStream(file);
clip = AudioSystem.getClip();
clip.open(ais);
} catch (Exception e) {
e.printStackTrace();
}
}

public void stop() {
if(clip == null) return;
clip.stop();
}

public void loop() {
try {
if (clip != null) {
new Thread() {
public void run() {
synchronized (clip) {
clip.stop();
clip.setFramePosition(0);
clip.loop(Clip.LOOP_CONTINUOUSLY);
}
}
}.start();
}
} catch (Exception e) {
e.printStackTrace();
}
}

public boolean isActive() {
return clip.isActive();
}
}
Binary file not shown.
Binary file not shown.