import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Random;
public class top_down_rpg_panel extends JPanel
{
int hold_var = 0;
//
int level_one_location_array[] = {
1,1,1,1,1,1,1,1,1,1,
1,0,4,3,0,0,0,0,0,1,
1,0,3,3,0,0,0,0,0,1,
1,0,3,3,0,0,0,0,0,1,
1,0,3,3,0,0,0,0,0,1,
1,0,3,3,0,0,0,0,0,1,
1,0,3,3,0,0,0,5,0,1,
1,0,3,3,0,0,0,0,0,1,
1,0,3,3,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1
};
int level_two_location_array[] = {
1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,7,0,1,
1,0,0,0,0,0,0,7,0,1,
1,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1
};
int end_level_location_array[] = {
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0
};
int location_array[] ={
1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1
};
public int monsters_killed = 0;
boolean changelevel = false;
public int which_level = 1;
public int end_level = 3;
//
static Random rand = new Random();
//height and length of panel
public final int height = 300;
public final int length = 300;
//player stats
public int player_which_square = 11;
public int player_exp = 0;
public int player_level = 0;
int player_level_array[] = {250,1000,2400,4600};
public int player_size_x = 30;
public int player_size_y = 30;
public int player_x = 30;
public int player_y = 30;
public int player_attack = 6;
public int player_life = 9;
public int player_max_life = 9;
public int player_defence = 6;
public int player_attack_boost = 1;
public int player_defence_boost = 1;
//rock stats
public int rock_size_x = 30;
public int rock_size_y = 30;
//big crab one stats
public int big_crab_one_block_one_which_square = 67;
public int big_crab_one_block_two_which_square = 77;
public int big_crab_one_which_direction = 0;
public int big_crab_one_speed = 1;
public int big_crab_one_is_go = 60;
public int big_crab_one_size_x = 30;
public int big_crab_one_size_y = 30;
public int big_crab_one_block_one_x = 210;
public int big_crab_one_block_two_x = 210;
public int big_crab_one_block_one_y = 180;
public int big_crab_one_block_two_y = 210;
public int big_crab_one_attack = 9;
public int big_crab_one_life = 6;
public int big_crab_one_defence = 5;
public int big_crab_one_defence_boost = 1;
public int big_crab_one_attack_boost = 1;
public int big_crab_one_counter = 0;
public int big_crab_one_end_counter = 1;
public boolean big_crab_one_isAlive = true;
//water monster one stats
public int water_monster_one_which_square = 12;
public int water_monster_one_which_direction = 0;
public int water_monster_one_speed = 1;
public int water_monser_one_is_go = 50;
public int water_monster_one_size_x = 30;
public int water_monster_one_size_y = 30;
public int water_monster_one_x = 60;
public int water_monster_one_y = 30;
public int water_monster_one_attack = 6;
public int water_monster_one_life = 5;
public int water_monster_one_defence = 4;
public int water_monster_one_defence_boost = 1;
public int water_monster_one_attack_boost = 1;
public int water_monster_one_counter = 0;
public int water_monster_one_end_counter = 1;
public boolean water_monster_one_isAlive = true;
//land monster stats
public int land_monster_one_which_square = 67;
public int land_monster_one_which_direction = 0;
public int land_monster_one_speed = 1;
public int land_monser_one_is_go = 60;
public int land_monster_one_size_x = 30;
public int land_monster_one_size_y = 30;
public int land_monster_one_x = 210;
public int land_monster_one_y = 180;
public int land_monster_one_attack = 4;
public int land_monster_one_life = 6;
public int land_monster_one_defence = 6;
public int land_monster_one_defence_boost = 1;
public int land_monster_one_attack_boost = 1;
public int land_monster_one_counter = 0;
public int land_monster_one_end_counter = 1;
public boolean land_monster_one_isAlive = true;
//
Timer timer;
//-----------------------------------------------------------------
// Constructor: Sets up this panel and loads the images.
//-----------------------------------------------------------------
public top_down_rpg_panel()
{
addKeyListener (new DirectionListener());
timer = new Timer(20, new ReboundListener());
setBackground (Color.white);
setPreferredSize (new Dimension(length, height));
setFocusable(true);
timer.start();
}
//-----------------------------------------------------------------
// Draws the image in the current location.
//-----------------------------------------------------------------
public void paintComponent (Graphics page)
{
super.paintComponent (page);
//sets up level one
if(!changelevel && monsters_killed == 0)
{
for(int change_array_value_level_one = 0; change_array_value_level_one < 100; change_array_value_level_one++)
{
location_array[change_array_value_level_one] = (level_one_location_array[change_array_value_level_one]);
}
changelevel = true;
}
else
{
}
//changes level and location array to level two
if(monsters_killed == 2 && changelevel)
{
for(int change_array_value_level_two = 0; change_array_value_level_two < 100; change_array_value_level_two++)
{
location_array[change_array_value_level_two] = level_two_location_array[change_array_value_level_two];
}
which_level++;
changelevel = false;
}
else
{
}
//changes level and location array to the end level (under construction)
if(monsters_killed == 3 && !changelevel)
{
which_level++;
changelevel = true;
for(int change_array_value_end_level = 0; change_array_value_end_level < 100; change_array_value_end_level++)
{
location_array[change_array_value_end_level] = end_level_location_array[change_array_value_end_level];
}
}
else
{
}
//levels up player
if(player_exp < player_level_array[player_level])
{
}
else if(player_exp >= player_level_array[player_level])
{
if(player_level == 0)
{
player_attack += 1;
player_defence += 1;
player_max_life += 1;
player_life += 1;
player_level += 1;
}
else if(player_level == 1)
{
player_attack += 1;
player_defence += 1;
player_max_life += 2;
player_life += 2;
player_level += 1;
}
else if(player_level == 2)
{
player_attack += 1;
player_defence += 1;
player_max_life += 2;
player_life += 2;
player_level += 1;
}
}
//draws level one
if(which_level == 1)
{
page.setColor(Color.yellow);
page.fillRect(0, 0, height, length);
page.setColor(Color.red);
page.fillRect(0, 0, 30, 300);
page.fillRect(0, 0, 300, 30);
page.fillRect(270, 0, 30, 300);
page.fillRect(0, 270, 300, 30);
page.setColor(Color.cyan);
page.fillRect(60, 30, 60, 240);
}
//draws level two
else if(which_level == 2)
{
page.setColor(Color.yellow);
page.fillRect(0, 0, height, length);
page.setColor(Color.red);
page.fillRect(0, 0, 30, 300);
page.fillRect(0, 0, 300, 30);
page.fillRect(270, 0, 30, 300);
page.fillRect(0, 270, 300, 30);
}
//draws the game over (you won) screen
else if(which_level == end_level)
{
page.setColor(Color.white);
page.fillRect(0, 0, 400, 400);
page.setColor(Color.black);
page.drawString("Game over. You Won!", 10, 10);
}
else
{
}
//draws land monster one
if(land_monster_one_isAlive && which_level == 1)
{
page.setColor(Color.DARK_GRAY);
page.fillRect(land_monster_one_x, land_monster_one_y,land_monster_one_size_x,land_monster_one_size_y);
page.setColor(Color.black);
page.drawString("life: "+land_monster_one_life , land_monster_one_x, land_monster_one_y);
}
//draws water monster one
if(water_monster_one_isAlive && which_level == 1)
{
page.setColor(Color.blue);
page.fillRect(water_monster_one_x, water_monster_one_y,water_monster_one_size_x,water_monster_one_size_y);
page.setColor(Color.black);
page.drawString("life: "+water_monster_one_life , water_monster_one_x, water_monster_one_y);
}
else
{
}
//draws big crab monster one
if(big_crab_one_isAlive && which_level == 2)
{
page.setColor(Color.MAGENTA);
page.fillRect(big_crab_one_block_one_x,big_crab_one_block_one_y, big_crab_one_size_x, big_crab_one_size_y);
page.fillRect(big_crab_one_block_two_x,big_crab_one_block_two_y, big_crab_one_size_x, big_crab_one_size_y);
page.setColor(Color.black);
page.drawString("life: "+big_crab_one_life , big_crab_one_block_one_x, big_crab_one_block_one_y);
}
//draws player and player stats
if(player_life > 0 && which_level != end_level)
{
page.setColor(Color.green);
page.fillOval(player_x, player_y, player_size_x, player_size_y);
page.setColor(Color.black);
page.drawString("attack boost: "+player_attack_boost, 10, 10);
page.drawString("defence boost: "+player_defence_boost, 10, 20);
page.drawString("life: "+player_life+"/"+player_max_life, player_x, player_y);
page.drawString("attack: "+player_attack, player_x, player_y+10);
page.drawString("defence: "+player_defence, player_x, player_y+20);
page.drawString("experience: "+player_exp+"/"+(player_level_array[player_level]), 10, 290);
page.drawString("player level: "+(player_level+1), 10, 300);
page.drawString("game level: "+which_level, 180, 300);
}
//draws the game over (you lost) screen
else if(player_life <= 0 && which_level != end_level)
{
page.setColor(Color.white);
page.fillRect(0, 0, 300, 300);
page.setColor(Color.black);
page.drawString("You Lose", 10, 10);
}
page.drawString("Monster killed: "+monsters_killed, 150, 10);
}
private class ReboundListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
//moves land monster randomly
if((land_monster_one_counter/land_monser_one_is_go) == land_monster_one_end_counter && which_level == 1)
{
land_monster_one_which_direction = rand.nextInt(4);
switch(land_monster_one_which_direction)
{
case 0: //moves up
{
switch(location_array[land_monster_one_which_square - 10])
{
case 0:
{
location_array[land_monster_one_which_square] = 0;
land_monster_one_which_square -= 10;
location_array[land_monster_one_which_square] = 5;
land_monster_one_y -= 30;
break;
}
default:
{
break;
}
}
break;
}
case 1: //moves down
{
switch(location_array[land_monster_one_which_square + 10])
{
case 0:
{
location_array[land_monster_one_which_square] = 0;
land_monster_one_which_square += 10;
location_array[land_monster_one_which_square] = 5;
land_monster_one_y += 30;
break;
}
default:
{
break;
}
}
break;
}
case 2: //moves left
{
switch(location_array[land_monster_one_which_square - 1])
{
case 0:
{
location_array[land_monster_one_which_square] = 0;
land_monster_one_which_square -= 1;
location_array[land_monster_one_which_square] = 5;
land_monster_one_x -= 30;
break;
}
default:
{
break;
}
}
break;
}
case 3: //moves right
{
switch(location_array[land_monster_one_which_square + 1])
{
case 0:
{
location_array[land_monster_one_which_square] = 0;
land_monster_one_which_square += 1;
location_array[land_monster_one_which_square] = 5;
land_monster_one_x += 30;
break;
}
default:
{
break;
}
}
break;
}
}
land_monster_one_end_counter += 1;
}
else
{
land_monster_one_counter += land_monster_one_speed;
}
//moves water monster one randomly
if((water_monster_one_counter/water_monser_one_is_go) == water_monster_one_end_counter && which_level == 1)
{
water_monster_one_which_direction = rand.nextInt(4);
switch(water_monster_one_which_direction)
{
case 0: //moves up
{
switch(location_array[water_monster_one_which_square - 10])
{
case 3:
{
location_array[water_monster_one_which_square] = 3;
water_monster_one_which_square -= 10;
location_array[water_monster_one_which_square] = 4;
water_monster_one_y -= 30;
break;
}
default:
{
break;
}
}
break;
}
case 1: //moves down
{
switch(location_array[water_monster_one_which_square + 10])
{
case 3:
{
location_array[water_monster_one_which_square] = 3;
water_monster_one_which_square += 10;
location_array[water_monster_one_which_square] = 4;
water_monster_one_y += 30;
break;
}
default:
{
break;
}
}
break;
}
case 2: //moves left
{
switch(location_array[water_monster_one_which_square - 1])
{
case 3:
{
location_array[water_monster_one_which_square] = 3;
water_monster_one_which_square -= 1;
location_array[water_monster_one_which_square] = 4;
water_monster_one_x -= 30;
break;
}
default:
{
break;
}
}
break;
}
case 3: //moves right
{
switch(location_array[water_monster_one_which_square + 1])
{
case 3:
{
location_array[water_monster_one_which_square] = 3;
water_monster_one_which_square += 1;
location_array[water_monster_one_which_square] = 4;
water_monster_one_x += 30;
break;
}
default:
{
break;
}
}
break;
}
}
water_monster_one_end_counter += 1;
}
else
{
water_monster_one_counter += water_monster_one_speed;
}
//moves big crab one randomly
if((big_crab_one_counter/big_crab_one_is_go) == big_crab_one_end_counter && which_level == 2)
{
big_crab_one_which_direction = rand.nextInt(4);
switch(big_crab_one_which_direction)
{
case 0:
{
switch(location_array[big_crab_one_block_one_which_square - 10])
{
case 0: //moves up
{
location_array[big_crab_one_block_one_which_square] = 7;
location_array[big_crab_one_block_two_which_square] = 0;
big_crab_one_block_one_which_square -= 10;
big_crab_one_block_two_which_square -= 10;
location_array[big_crab_one_block_one_which_square] = 7;
location_array[big_crab_one_block_two_which_square] = 7;
big_crab_one_block_one_y += 30;
big_crab_one_block_two_y += 30;
break;
}
default:
{
break;
}
}
}
case 1: //moves down
{
switch(location_array[big_crab_one_block_two_which_square + 10])
{
case 0:
{
location_array[big_crab_one_block_one_which_square] = 0;
location_array[big_crab_one_block_two_which_square] = 7;
big_crab_one_block_one_which_square += 10;
big_crab_one_block_two_which_square += 10;
location_array[big_crab_one_block_one_which_square] = 7;
location_array[big_crab_one_block_two_which_square] = 7;
big_crab_one_block_one_y -= 30;
big_crab_one_block_two_y -= 30;
break;
}
default:
{
break;
}
}
}
case 2: //moves left
{
switch(location_array[big_crab_one_block_one_which_square - 1])
{
case 0:
{
switch(location_array[big_crab_one_block_two_which_square - 1])
{
case 0:
{
location_array[big_crab_one_block_one_which_square] = 0;
location_array[big_crab_one_block_two_which_square] = 0;
big_crab_one_block_one_which_square -= 1;
big_crab_one_block_two_which_square -= 1;
location_array[big_crab_one_block_one_which_square] = 7;
location_array[big_crab_one_block_two_which_square] = 7;
big_crab_one_block_one_x -= 30;
big_crab_one_block_two_x -= 30;
}
default:
{
break;
}
}
}
}
}
case 3: //moves right
{
switch(location_array[big_crab_one_block_one_which_square + 1])
{
case 0:
{
switch(location_array[big_crab_one_block_two_which_square+1])
{
case 0:
{
location_array[big_crab_one_block_one_which_square] = 0;
location_array[big_crab_one_block_two_which_square] = 0;
big_crab_one_block_one_which_square += 1;
big_crab_one_block_two_which_square += 1;
location_array[big_crab_one_block_one_which_square] = 7;
location_array[big_crab_one_block_two_which_square] = 7;
big_crab_one_block_one_x += 30;
big_crab_one_block_two_x += 30;
break;
}
}
break;
}
default:
{
break;
}
}
}
default:
{
break;
}
}
big_crab_one_end_counter += 1;
}
else
{
big_crab_one_counter += 1;
}
repaint();
}
}
//*****************************************************************
// Represents the listener for keyboard activity.
//*****************************************************************
private class DirectionListener implements KeyListener
{
//--------------------------------------------------------------
// Responds to the user pressing arrow keys by adjusting the
// image and image location accordingly. also responds to the user attacking monsters.
//--------------------------------------------------------------
public void keyPressed (KeyEvent event)
{
switch (event.getKeyCode())
{
//moves player and interacts with objects
case KeyEvent.VK_UP:
switch (location_array[player_which_square - 10])
{
case 0:
{
player_which_square -= 10;
player_y -= 30;
player_attack_boost = 1;
player_defence_boost = 1;
break;
}
case 1:
{
}
break;
case 3:
{
player_which_square -= 10;
player_y -= 30;
player_attack_boost = 0;
player_defence_boost = 0;
}
break;
case 4:
{
if(water_monster_one_isAlive)
{
hold_var = (rand.nextInt(player_attack)+player_attack_boost) - (rand.nextInt(water_monster_one_defence)+water_monster_one_defence_boost);
if(hold_var >= 0)
{
water_monster_one_life -= hold_var;
}
else
{
}
if (water_monster_one_life > 0)
{
hold_var = (rand.nextInt(water_monster_one_attack)+water_monster_one_attack_boost) - (rand.nextInt(player_defence)+player_defence_boost);
if(hold_var >= 0 )
{
player_life -= hold_var;
}
else
{
}
}
else
{
water_monster_one_isAlive = false;
player_exp += 700;
location_array[water_monster_one_which_square] = 3;
monsters_killed++;
}
}
else
{
}
break;
}
case 5:
{
if(land_monster_one_isAlive)
{
hold_var = (rand.nextInt(player_attack)+player_attack_boost) - (rand.nextInt(land_monster_one_defence)+land_monster_one_defence_boost);
if(hold_var >= 0)
{
land_monster_one_life -= hold_var;
}
else
{
}
if (land_monster_one_life > 0)
{
hold_var = (rand.nextInt(land_monster_one_attack)+water_monster_one_attack_boost) - (rand.nextInt(player_defence)+player_defence_boost);
if(hold_var >= 0 )
{
player_life -= hold_var;
}
else
{
}
}
else
{
land_monster_one_isAlive = false;
player_exp += 500;
location_array[land_monster_one_which_square] = 0;
monsters_killed++;
}
}
else
{
}
break;
}
case 7:
{
hold_var = (rand.nextInt(player_attack)+player_attack_boost) - (rand.nextInt(big_crab_one_defence)+big_crab_one_defence_boost);
if(hold_var >= 0)
{
big_crab_one_life -= hold_var;
}
else
{
}
if (big_crab_one_life > 0)
{
hold_var = (rand.nextInt(big_crab_one_attack)+big_crab_one_attack_boost) - (rand.nextInt(player_defence)+player_defence_boost);
if(hold_var >= 0 )
{
player_life -= hold_var;
}
else
{
}
}
else
{
big_crab_one_isAlive = false;
player_exp += 1500;
location_array[big_crab_one_block_one_which_square] = 0;
location_array[big_crab_one_block_two_which_square] = 0;
monsters_killed++;
}
break;
}
default:
{
}
break;
}
break;
case KeyEvent.VK_DOWN:
switch (location_array[player_which_square + 10])
{
case 0:
{
player_which_square += 10;
player_y += 30;
player_attack_boost = 1;
player_defence_boost = 1;
break;
}
case 1:
{
}
break;
case 3:
{
player_which_square += 10;
player_y += 30;
player_attack_boost = 0;
player_defence_boost = 0;
break;
}
case 4:
{
if(water_monster_one_isAlive)
{
hold_var = (rand.nextInt(player_attack)+player_attack_boost) - (rand.nextInt(water_monster_one_defence)+water_monster_one_defence_boost);
if(hold_var >= 0)
{
water_monster_one_life -= hold_var;
}
else
{
}
if (water_monster_one_life > 0)
{
hold_var = (rand.nextInt(water_monster_one_attack)+water_monster_one_attack_boost) - (rand.nextInt(player_defence)+player_defence_boost);
if(hold_var >= 0 )
{
player_life -= hold_var;
}
else
{
}
}
else
{
water_monster_one_isAlive = false;
player_exp += 700;
location_array[water_monster_one_which_square] = 3;
monsters_killed++;
}
}
else
{
}
break;
}
case 5:
{
if(land_monster_one_isAlive)
{
hold_var = (rand.nextInt(player_attack)+player_attack_boost) - (rand.nextInt(land_monster_one_defence)+land_monster_one_defence_boost);
if(hold_var >= 0)
{
land_monster_one_life -= hold_var;
}
else
{
}
if (land_monster_one_life > 0)
{
hold_var = (rand.nextInt(land_monster_one_attack)+water_monster_one_attack_boost) - (rand.nextInt(player_defence)+player_defence_boost);
if(hold_var >= 0 )
{
player_life -= hold_var;
}
else
{
}
}
else
{
land_monster_one_isAlive = false;
player_exp += 500;
location_array[land_monster_one_which_square] = 0;
monsters_killed++;
}
}
else
{
}
break;
}
case 7:
{
hold_var = (rand.nextInt(player_attack)+player_attack_boost) - (rand.nextInt(big_crab_one_defence)+big_crab_one_defence_boost);
if(hold_var >= 0)
{
big_crab_one_life -= hold_var;
}
else
{
}
if (big_crab_one_life > 0)
{
hold_var = (rand.nextInt(big_crab_one_attack)+big_crab_one_attack_boost) - (rand.nextInt(player_defence)+player_defence_boost);
if(hold_var >= 0 )
{
player_life -= hold_var;
}
else
{
}
}
else
{
big_crab_one_isAlive = false;
player_exp += 1500;
location_array[big_crab_one_block_one_which_square] = 0;
location_array[big_crab_one_block_two_which_square] = 0;
monsters_killed++;
}
break;
}
default:
{
}
break;
}
break;
case KeyEvent.VK_LEFT:
switch (location_array[player_which_square - 1])
{
case 0:
{
player_which_square -= 1;
player_x -= 30;
player_attack_boost = 1;
player_defence_boost = 1;
break;
}
case 1:
{
}
break;
case 3:
{
player_which_square -= 1;
player_x -= 30;
player_attack_boost = 0;
player_defence_boost = 0;
}
break;
case 4:
{
if(water_monster_one_isAlive)
{
hold_var = (rand.nextInt(player_attack)+player_attack_boost) - (rand.nextInt(water_monster_one_defence)+water_monster_one_defence_boost);
if(hold_var >= 0)
{
water_monster_one_life -= hold_var;
}
else
{
}
if (water_monster_one_life > 0)
{
hold_var = (rand.nextInt(water_monster_one_attack)+water_monster_one_attack_boost) - (rand.nextInt(player_defence)+player_defence_boost);
if(hold_var >= 0 )
{
player_life -= hold_var;
}
else
{
}
}
else
{
water_monster_one_isAlive = false;
player_exp += 700;
location_array[water_monster_one_which_square] = 3;
monsters_killed++;
}
}
else
{
}
}
break;
case 5:
{
if(land_monster_one_isAlive)
{
hold_var = (rand.nextInt(player_attack)+player_attack_boost) - (rand.nextInt(land_monster_one_defence)+land_monster_one_defence_boost);
if(hold_var >= 0)
{
land_monster_one_life -= hold_var;
}
else
{
}
if (land_monster_one_life > 0)
{
hold_var = (rand.nextInt(land_monster_one_attack)+water_monster_one_attack_boost) - (rand.nextInt(player_defence)+player_defence_boost);
if(hold_var >= 0 )
{
player_life -= hold_var;
}
else
{
}
}
else
{
land_monster_one_isAlive = false;
player_exp += 500;
location_array[land_monster_one_which_square] = 0;
monsters_killed++;
}
}
else
{
}
break;
}
case 7:
{
hold_var = (rand.nextInt(player_attack)+player_attack_boost) - (rand.nextInt(big_crab_one_defence)+big_crab_one_defence_boost);
if(hold_var >= 0)
{
big_crab_one_life -= hold_var;
}
else
{
}
if (big_crab_one_life > 0)
{
hold_var = (rand.nextInt(big_crab_one_attack)+big_crab_one_attack_boost) - (rand.nextInt(player_defence)+player_defence_boost);
if(hold_var >= 0 )
{
player_life -= hold_var;
}
else
{
}
}
else
{
big_crab_one_isAlive = false;
player_exp += 1500;
location_array[big_crab_one_block_one_which_square] = 0;
location_array[big_crab_one_block_two_which_square] = 0;
monsters_killed++;
}
break;
}
default:
{
}
break;
}
break;
case KeyEvent.VK_RIGHT:
switch (location_array[player_which_square + 1])
{
case 0:
{
player_which_square += 1;
player_x += 30;
player_attack_boost = 1;
player_defence_boost = 1;
break;
}
case 1:
{
}
break;
case 3:
{
player_which_square += 1;
player_x += 30;
player_attack_boost = 0;
player_defence_boost = 0;
}
break;
case 4:
{
if(water_monster_one_isAlive)
{
hold_var = (rand.nextInt(player_attack)+player_attack_boost) - (rand.nextInt(water_monster_one_defence)+water_monster_one_defence_boost);
if(hold_var >= 0)
{
water_monster_one_life -= hold_var;
}
else
{
}
if (water_monster_one_life > 0)
{
hold_var = (rand.nextInt(water_monster_one_attack)+water_monster_one_attack_boost) - (rand.nextInt(player_defence)+player_defence_boost);
if(hold_var >= 0 )
{
player_life -= hold_var;
}
else
{
}
}
else
{
water_monster_one_isAlive = false;
player_exp += 700;
location_array[water_monster_one_which_square] = 3;
monsters_killed++;
}
}
else
{
}
}
break;
case 5:
{
if(land_monster_one_isAlive)
{
hold_var = (rand.nextInt(player_attack)+player_attack_boost) - (rand.nextInt(land_monster_one_defence)+land_monster_one_defence_boost);
if(hold_var >= 0)
{
land_monster_one_life -= hold_var;
}
else
{
}
if (land_monster_one_life > 0)
{
hold_var = (rand.nextInt(land_monster_one_attack)+water_monster_one_attack_boost) - (rand.nextInt(player_defence)+player_defence_boost);
if(hold_var >= 0 )
{
player_life -= hold_var;
}
else
{
}
}
else
{
land_monster_one_isAlive = false;
player_exp += 500;
location_array[land_monster_one_which_square] = 0;
monsters_killed++;
}
}
else
{
}
break;
}
case 7:
{
hold_var = (rand.nextInt(player_attack)+player_attack_boost) - (rand.nextInt(big_crab_one_defence)+big_crab_one_defence_boost);
if(hold_var >= 0)
{
big_crab_one_life -= hold_var;
}
else
{
}
if (big_crab_one_life > 0)
{
hold_var = (rand.nextInt(big_crab_one_attack)+big_crab_one_attack_boost) - (rand.nextInt(player_defence)+player_defence_boost);
if(hold_var >= 0 )
{
player_life -= hold_var;
}
else
{
}
}
else
{
big_crab_one_isAlive = false;
player_exp += 1500;
location_array[big_crab_one_block_one_which_square] = 0;
location_array[big_crab_one_block_two_which_square] = 0;
monsters_killed++;
}
break;
}
default:
{
}
break;
}
break;
}
repaint();
}
//--------------------------------------------------------------
// Provide empty definitions for unused event methods.
//--------------------------------------------------------------
public void keyTyped (KeyEvent event) {}
public void keyReleased (KeyEvent event) {}
}
}
the previous code was the "shell" of a game I was programming earlier. I decided to abandon it because of the fact that I had no real plan with it.
it contains:
collision detector
good, old fashioned, bump into things to attack them, game play.
easily modifiable map (if you want to change the location array to make it bigger, make sure to edit the character motion and collision detection code.)
if anyone wants it, they can use it, if they promise to credit me.
if you do take it, it would probably be a good idea to make each monster its own class, and edit accordingly, to reduce clutter.