Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * APPLY GRAVITY METHOD *
- private boolean applyGravity(int exceptRow, int exceptCol) {
- boolean fellOnPlayer = false;
- for (int r = rows - 2; r > -1; r--) { //a massive object can thus not be moved off the board!
- for (int c = 0; c < cols; c++) {
- if (world[r][c].hasMass()) {
- if ((world[r + 1][c].isVulnerable()) && !(r + 1 == exceptRow) && !(c == exceptCol)) {
- if (world[r + 1][c] instanceof Alien) {
- alienDead = true;
- System.out.println("Alien is dead!");
- } else if (world[r+1][c].isPlayer()) {
- fellOnPlayer = true;
- System.out.println("Player is dead!");
- }
- else {
- WorldObject falling = world[r][c];
- world[r+1][c] = world[r][c];
- world[r-1][c] = new Space();
- }
- }
- }
- }
- }
- return fellOnPlayer;
- }
- * MAIN METHOD *
- class Main
- {
- /**
- * Main entry point.
- */
- public static void main(final String[] args) throws BadFileFormatException
- {
- Tests.testLoadFile("example.txt");
- Tests.testLoadFile("example2.txt");
- Tests.testLoadFile("example3.txt");
- final World world = new World(10, 10, 7);
- // Play the game
- int outcome = 0;
- while (outcome == 0)
- {
- System.out.println(world);
- final char ch = world.getMove();
- if (!world.validMove(ch))
- System.out.println("Error. Please enter u,d,l,r.");
- else
- outcome = world.applyMove(ch);
- }
- // Show the result
- System.out.println(world + "\n");
- if (outcome == 1)
- System.out.println("Yay! You won!");
- else
- System.out.println("Whoops, you lost........ :-/");
- }
- }
- * OUTPUT *
- Emeralds remaining: 16
- e##.p#d###
- e##e#####d
- .###re####
- ####.##..#
- .###d#####
- e#####r###
- rd#####ee#
- ##########
- ##e##a####
- #r######.#
- Error : invalid character . The error is at row 11 and at col 8
- Emeralds remaining: 20
- ###.p#d###
- #e#######d
- .###re####
- ####.##..#
- .###d####e
- e###e#r###
- rd#####ee#
- ##########
- ##e##a##nullnull
- nullnullnullnullnullnullnullnullnullnull
- Error : remaining emeralds cannot be more than total worth of emeralds . The error is at row 2 and at col 0
- Emeralds remaining: 25
- ###.p#e###
- #e#######e
- .###re####
- ####.##..#
- .###d####e
- e###e#r###
- rd#####ee#
- ##########
- ##e##a####
- #r###e##.#
- Emeralds remaining: 16
- #r##e#####
- ##ee######
- r##d######
- #a########
- #######p##
- #e##e###e#
- ######d###
- #de#e#####
- #####r####
- #r########
- Where to? d
- Emeralds remaining: 16
- #r##e#####
- ##ee######
- r##d######
- #.########
- #a#####.##
- #e##e##pe#
- ######d###
- #de#e#####
- #####r####
- #r########
- Where to? d
- Emeralds remaining: 16
- #r##e#####
- ##ee######
- r##d######
- #.########
- #.a####.##
- #e##e##.e#
- ######dp##
- #de#e#####
- #####r####
- #r########
- Where to? d
- Emeralds remaining: 16
- #r##e#####
- ##ee######
- r##d######
- #.########
- #a.####.##
- #e##e##.e#
- ######d.##
- #de#e##p##
- #####r####
- #r########
- Where to? d
- Emeralds remaining: 16
- #r##e#####
- ##ee######
- r##d######
- #.########
- #..####.##
- #a##e##.e#
- ######d.##
- #de#e##.##
- #####r#p##
- #r########
- Where to? d
- Emeralds remaining: 16
- #r##e#####
- ##ee######
- r##d######
- #.########
- #..####.##
- a.##e##.e#
- ######d.##
- #de#e##.##
- #####r#.##
- #r#####p##
- Where to? l
- Emeralds remaining: 16
- #r##e#####
- ##ee######
- r##d######
- #.########
- #..####.##
- ..##e##.e#
- a#####d.##
- #de#e##.##
- #####r#.##
- #r####p.##
- Where to? l
- Emeralds remaining: 16
- #r##e#####
- ##ee######
- r##d######
- #.########
- #..####.##
- a.##e##.e#
- .#####d.##
- #de#e##.##
- #####r#.##
- #r###p..##
- Where to? l
- Emeralds remaining: 16
- #r##e#####
- ##ee######
- r##d######
- #.########
- a..####.##
- ..##e##.e#
- .#####d.##
- #de#e##.##
- #####r#.##
- #r##p...##
- Where to? l
- Emeralds remaining: 16
- #r##e#####
- ##ee######
- r##d######
- #.########
- .a.####.##
- ..##e##.e#
- .#####d.##
- #de#e##.##
- #####r#.##
- #r#p....##
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement