Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Spy implements Character{
- int row;
- int col;
- int currentLives = 3; //stores the number of remaining lives, by default starts at 3.
- static int ammoLeft = 1; //stores the number of remaining shots, default 1. Not a boolean, because a player may pick up the ammo powerup before firing.
- boolean alive=true; //an entity is either alive (true, on the field) or dead (false, removed from play)
- public int icon = '4'; //each object that can occupy a mapsquare will get an int for debugging purposes
- public Spy(int r, int c){//and if the game ever calls for modifying the start params, we can do that by deleting the above fields' values, and replacing them with arguments in the contructor.
- this.row = r;
- this.col = c;
- }
- //The player should only be able to do one view and one move/shoot action thing per turn
- public void movePlayer(Mapsquare[][] board, int direction, Character Spy){ //the player uses the UI to control the movement of their Spy
- move(board, direction, Spy);//This method may be unnecessary. If it isn't, it'll take the direction number 'n' from the UI and call Spy.move(n)
- }
- private void playerView(int direction, Ninja Ninja, Powerup Powerup, Mapsquare board[][]){ //the player has the option to view the squares ahead of them
- switch(direction){
- case 1://north call check on row-1, row-2 mapsquares, assuming that row=y-axis, col=x-axis
- if (CheckSquare.checkSquare( (row-1), col, Ninja, board) == true){
- System.out.println((row-1)+", "+(col)+" contains a Ninja!");
- }
- if (CheckSquare.checkSquare( (row-2), col, Ninja, board)== true){
- System.out.println((row-2)+", "+(col)+" contains a Ninja!");
- }
- break;
- case 2: //east call check on col-1, col-2 msquares
- if (CheckSquare.checkSquare( (row), (col-1), Ninja, board) == true){
- System.out.println((row)+", "+(col-1)+" contains a Ninja!");
- }
- if (CheckSquare.checkSquare( (row), (col-2), Ninja, board)== true){
- System.out.println((row)+", "+(col-2)+" contains a Ninja!");
- }
- break;
- case 3: //south call check on row+1, row+1 msquares
- if (CheckSquare.checkSquare( (row+1), col, Ninja, board) == true){
- System.out.println((row-1)+", "+(col)+" contains a Ninja!");
- }
- if (CheckSquare.checkSquare( (row+2), col, Ninja, board)== true){
- System.out.println((row-2)+", "+(col)+" contains a Ninja!");
- }
- break;
- case 4: //west call check on col+1, col+2 msquares
- if (CheckSquare.checkSquare( (row), (col+1), Ninja, board) == true){
- System.out.println((row)+", "+(col-1)+" contains a Ninja!");
- }
- if (CheckSquare.checkSquare( (row), (col+2), Ninja, board)== true){
- System.out.println((row)+", "+(col-2)+" contains a Ninja!");
- }
- break;
- }
- }
- private void shootGun(Mapsquare[][] board, int direction){ //the player can, ammunition permitting, attack a straight line, killing the first ninja that they hit
- switch(direction){
- //check squares in a line until you find either a ninja or a board edge.
- case 1: //north call check on row-- mapsquares,
- for(int n = (row-1); n >= 0; n--)
- if(board[n][col].c!=new emptychar(n, col)){
- board[n][col].c.kill();
- break;
- }
- break;
- case 2: //east call check on col-- msquares
- for(int n = (col-1); n >= 0; n--)
- if(board[row][n].c != new emptychar(row, n)){
- board[row][n].c.kill();
- break;
- }
- break;
- case 3: //south call check on row++ msquares
- for(int n = (row+1); n <= 8; n++)
- if(board[n][col].c!=new emptychar(n, col)){
- board[col][n].c.kill();
- break;
- }
- break;
- case 4: //west call check on col++ msquares
- for(int n = (col+1); n <= 8; n++)
- if(board[row][n].c != new emptychar(row, n)){
- board[row][n].c.kill();
- break;
- }
- break;
- }
- Spy.ammoLeft--;
- }
- private void respawn(){ //if the player is killed but has lives remaining, they will be replaced on the game field
- if(this.alive==false && this.currentLives >0){
- //respawn code - reset the world to starting status, minus any pickups acquired.
- }
- else{
- System.out.println("Game Over");
- //Driver.breakLoop(); //the assumes that we have a method in Driver, which only contains the break command, for just such an occasion.
- }
- }
- private void pickup(Powerup power){
- power.kill();
- power.powerupFunction();
- }
- public void kill() {
- this.alive=false;
- this.currentLives--;
- }
- public void move(Mapsquare[][] board, int direction, Character Spy) {
- switch(direction){
- case 1:
- //System.out.println("move north");
- board[row][col].c=new emptychar(row, col);
- board[row-1][col].c=Spy;
- row=row-1;
- break;
- case 2:
- //System.out.println("move south");
- board[row][col].c=new emptychar(row, col);
- board[row+1][col].c=Spy;
- row=row+1;
- break;
- case 3:
- //System.out.println("move west");
- board[row][col].c=new emptychar(row, col);
- board[row][col-1].c=Spy;
- col=col-1;
- break;
- case 4:
- //System.out.println("move east");
- board[row][col].c=new emptychar(row, col);
- board[row][col+1].c=Spy;
- col=col+1;
- break;
- }
- }
- public void setLocation(int[][] board, int r, int c) {
- this.row = r;
- this.col = c;
- }
- public String returnLocation() {
- return ("r: " + row + ", col: " + col);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement