Project 5 PROJECT 5 Title: The Board Game Stratego - Classic Modules: 08 & 09 & 10 - 2D Arrays and Class Types, 11-Polymorphism Point Value: 100 Date: due 4/8 at 11pm Topics Covered: Object-oriented...

1 answer below »
Computer Science Java


Project 5 PROJECT 5 Title: The Board Game Stratego - Classic Modules: 08 & 09 & 10 - 2D Arrays and Class Types, 11-Polymorphism Point Value: 100 Date: due 4/8 at 11pm Topics Covered: Object-oriented programming, writing advanced classes, inheritance, 2D arrays, polymorphism, and file I/O. Overview: The purpose of this project is to implement a text-based version of a classic board game called Stratego - classic variation. Overall Grading Breakdown: (remember that code that doesn’t compile gets a 0 grade) ● [10] Completeness and quality of code ● [5] Style, submission, and no run-time errors ● [75] Functionality ● [5] Good use of subroutines ● [5] Correct / good use of classes, inheritance and polymorphism Game Description: Stratego is a fun classic board game with simple rules (not meaning that mastering it is easy; there are “Stratego” competitions around the world, including a world championship!) . First thing is to educate yourself on how to play the game unless you already know it. Read about the rules of the game and how to play here: https://www.fgbradleys.com/rules/Stratego.pdf You may also find tutorial videos on youtube, for example: https://www.youtube.com/watch?v=3R7d0A9ymwQ You may play Stratego online: http://www.jayoogee.com/masteroftheflag/game.html Project Description: You must download and use the starter code. You will code the logic and rules of the game. While modern variations of the game have come to existence, we implement the classic version of the game with 2 players. One player has red pieces and the other player takes the blue pieces. Players take turns to make one move at a turn (similar to chess) where the player with red pieces always starts the game (again similar to chess where white always starts). Each player has 40 pieces. There are two main categories of stratego pieces: immovable and movable. There are two kinds of immovable pieces: bomb and flag. Movable pieces are ranked from 10 (highest) to 1 (lowest) and each has an army rank. The table in the next page shows all the pieces, how many from each piece each player has, and the symbols (char values) we use in this project to represent them. Note, if you add up the counts of all the pieces for each player, it totals to 40. https://www.fgbradleys.com/rules/Stratego.pdf https://www.youtube.com/watch?v=3R7d0A9ymwQ http://www.jayoogee.com/masteroftheflag/game.html https://drive.google.com/file/d/1idhXPBPcHMpqeZOYolwsyWvaipaBcEa6/view?usp=sharing Piece Type Piece Rank Symbol (char) used How many per player? Flag NA ‘f’ for blue ‘F’ for red 1 Bomb NA ‘b’ for blue ‘B’ for red 6 Marshal 10 ‘m’ for blue ‘M’ for red 1 General 9 ‘g’ for blue ‘G’ for red 1 Colonel 8 ‘c’ for blue ‘C’ for red 2 Major 7 ‘j’ for blue ‘J’ for red 3 Captain 6 ‘p’ for blue ‘P’ for red 4 Lieutenant 5 ‘l’ for blue ‘L’ for red 4 Sergeant 4 ‘s’ for blue ‘S’ for red 4 Miner 3 ‘i’ for blue ‘I’ for red 5 Scout 2 ‘o’ for blue ‘O’ for red 8 Spy 1 ‘y’ for blue ‘Y’ for red 1 USER INTERFACE and File I/O (Main.java and FileIO.java): We implement a text-based version of the game where both players share the same keyboard, similar to Project 4, to put in their inputs and move their pieces around the board. Main.java is already provided to you which implements the interface of the game. You should NOT change anything in this file. In the game of Stratego, the true identity of each player’s pieces should only be visible to himself/herself and most definitely not to his/her opponent. As such, whenever it’s red’s turn to move, the face of blue pieces are masked out (all shown as *). Similarly, when it’s blue’s turn to move, true faces of red pieces become hidden on the screen/console. The symbol ‘-’ denotes an empty cell on the board, ‘X’ denotes a “lake” region, while all other symbols (character values) should be interpreted as specified in the above table. The initial setup of the board should be loaded from a proper board file. The main() method initially fills the board with the content of a file named in.txt, thus there must be a proper board file named in.txt in the current folder in order for Main.java to work. FileIO.java handles all the file I/O operations and is already provided to you. You should not make any changes to this file. Once a board file is successfully loaded and the board is filled with pieces, the game can be started. If it is a fresh game, red will move first. But if it’s a “saved game”, it might be blue’s turn to make a move (the very last line of a board file that has a single number in it specifies whose turn it is: r for red, b for blue). Don’t change FileIO.java either. The items in the main menu are as follows: ● Q or q: will quit the game ● D or d: At any time during the game, choosing this item shows the content of the board with all pieces’ true identities revealed. ● L or l: will consequently ask for a filename and will load the content of the file into the board. Note, this can be either the starting position for a new game or an already-started saved game. ● S or s: will consequently ask for a filename and will save the game into a file with the specified name. ● M or m: will give a player (either red or blue depending on whose turn it is) a chance to make a move on the board. Four valid numbers should be provided. The first two numbers indicate the row index and column index of the starting position respectively and the next two numbers show the row and column indices of the destination. The entered move, of course, must be a valid one based on the rules of the game, otherwise no move should be made. Sample input board files are provided to you here, here, and here. An example run is provided here. Assuming you will finish a correct implementation of all the missing parts, as detailed in the remainder of this document, you should be able to replicate the provided example run. GAME BOARD (Board.java): The standard Stratego game board is a 10 x 10 grid with a total of 100 cells. Each cell on the board may be occupied by only one piece at a time, it might be empty, or it might be a lake cell. There are two lakes on a standard Stratego board where the first one occupies 4 spots at the following positions: (4, 2), (4, 3), (5, 2), (5, 3), and the second lake is located at: (4, 6), (4, 7), (5, 6), (5, 7). Note we use a 0-based indexing system, so, for https://drive.google.com/file/d/1fYCnD2dU55tzBcnhJOxOfXBr11GYERwA/view?usp=sharing https://drive.google.com/file/d/1po3KQLPaWr61mEedRYkg4LQsUXo4IcrX/view?usp=sharing https://drive.google.com/file/d/16W87yxjbCW-_BVzYzpoX0QO4rbBE0HAG/view?usp=sharing https://drive.google.com/file/d/19slssGk7agyLvWF2RAd-p4rTdevCyKp3/view?usp=sharing instance, (4, 2) means 5th row and 3rd column of the board. Lakes cannot be crossed, nor can be landed in (i.e. no piece can move into a lake). It is always assumed that the blue pieces are positioned on the top part of the board (rows 1 through 4) and red pieces have the bottom part (rows 7 through 10), when a new game starts. The game board is implemented in Board.java and is partially implemented. There are four public methods you need to complete here: ● public int getCountMovables(boolean red): This method should count and return the number of movable pieces of a given color on the current board. If the input to this method is true, the method should return the count of red movable pieces. Otherwise, it should return the number of blue movable pieces. ● public Cell[] getMovables(boolean red): This method should find movable pieces of a given color on the current board and return them as an array of cells. If the input to this method is true, the method should return the red movable pieces. Otherwise, it should return the blue movable pieces. Hint: make use of getCountMovables() to decide what the size of your array should be! ● public boolean hasFlag(boolean red): This method decides if a player’s flag still exists on the board (e.g. has been captured or not). Hint: this method could come handy when you do “Stratego” class to decide if the game is over or not. ● public boolean isTrapped(Cell cell): This method decides if the given cell that contains a movable piece is “trapped” or not. A trapped piece is a movable piece that cannot move because it is surrounded by lake(s), other pieces of the same color, and/or boundaries of the board. Hint: this is useful when deciding the game is over or not Important Note: You may not make any changes to other methods already implemented in this class. However, you can add extra private helper methods to this class. Also, you may NOT change the signature of any of the public methods described above. MOVE (Move.java): It represents a piece move on the board. Each move has a source (starting position) and a destination. Objects of type Move are already used in some of the files provided to you, and you as well may use it. You should not change anything in this file. CELL (Cell.java): The Stratego board consists of 100 cells. Each cell on the board may be occupied by only one piece at a time, it might be empty, or a lake cell. Also, each has row and column coordinates (indices) showing which cell it is on the board. For instance, a cell with coordinates (0, 0) refers to the top left cell on the board. You should not change anything here. PIECE (Piece.java): This class represents a Stratego Piece. Don’t be frightened with it being declared as an abstract class: it is declared so because “Piece” is an abstract concept in the context of this game; only movable pieces and immovable pieces exist. In Java, when a class is declared as abstract, no objects can be directly constructed from it; it is only possible to create objects from an abstract class’s children, in this case MPiece and ImPiece classes. Each piece, though, regardless of being movable or not, has a symbol (character) and a color (either blue or red). These two properties are common to both movable and immovable pieces, so we have put these two fields in the Piece class so ImPiece and MPiece classes inherit those fields from their parent (Piece class). MOVABLE PIECE (MPiece.java): This should represent a movable piece. This class should be implemented by you from scratch. MPiece should be inherited (i.e., extends) Piece. Each movable piece object should have a rank (1 through 10) as specified by the game on the top of its character and color
Answered 1 days AfterApr 04, 2021

Answer To: Project 5 PROJECT 5 Title: The Board Game Stratego - Classic Modules: 08 & 09 & 10 - 2D Arrays and...

Sonu answered on Apr 06 2021
125 Votes
Proj5_Starter/.classpath

    
    
    
Proj5_Starter/.project

     Proj5_Starter
    
    
    
    
        
             org.eclipse.jdt.core.javabuilder
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
Proj5_Starter/bin/Board.class
public final synchronized class Board {
private static final Board INSTANCE;
private static final int SIZE = 10;
private Cell[][] grid;
private Move[] l2MovesR;
private Move[] l2MovesB;
private boolean turn;
static void ();
private void Board();
public static Board getInstance();
public int size();
public void display(boolean, boolean);
public Cell[][] getGrid();
public void setGrid(Cell[][]);
public Move[] getL2Moves(boolean);
public void setLMove(Move, boolean);
public boolean isOutOfBound(Move);
public boolean isLake(int, int);
public int getCountMovables(boolean);
public Cell[] getMovables(boolean);
public boolean hasFlag(boolean);
public boolean isTrapped(Cell);
public boolean getTurn();
public void setTurn(boolean);
}
Proj5_Starter/bin/Cell.class
public synchronized class Cell {
private Piece piece;
private int row;
private int column;
private boolean lake;
public void Cell(Piece);
public void Cell(Piece, int, int);
public void Cell(int, int, boolean);
public void Cell();
public Piece getPiece();
public void setPiece(Piece);
public int getRow();
public void setRow(int);
public int getColumn();
public void setColumn(int);
public boolean isLake();
public boolean isEmpty();
public void setLake(boolean);
public String toString();
public int hashCode();
public boolean equals(Object);
}
Proj5_Starter/bin/FileIO.class
public synchronized class FileIO {
public void FileIO();
public static int fillBoard(String, Board) throws java.io.FileNotFoundException;
public static void saveBoard(String, Board, char) throws java.io.IOException;
}
Proj5_Starter/bin/ImPiece.class
public synchronized class ImPiece extends Piece {
boolean flag;
public void ImPiece(char, boolean);
public void ImPiece(char, boolean, boolean);
public boolean isFlag();
public String toString();
}
Proj5_Starter/bin/in.txt
p o o l o p i m o p
l s b y g o j j c o
s b s j c l b l p s
o i b o i b f b i i
- - X X - - X X - -
- - X X - - X X - -
M P L I O P O O O P
S O C C F O S B B L
J O J Y P L B S L O
J I I I S B G B B I
r
Proj5_Starter/bin/Main.class
public synchronized class Main {
public void Main();
private static void printMenu();
private static void printBoard(Board, boolean);
private static boolean tryMove(Board, Move, boolean);
public static void main(String[]) throws java.io.IOException, InterruptedException;
}
Proj5_Starter/bin/Move.class
public synchronized class Move {
private int sr;
private int sc;
private int dr;
private int dc;
public void Move(int, int, int, int);
public void setSource(int, int);
public void setDest(int, int);
public void setMove(Move);
public int getSr();
public void setSr(int);
public int getSc();
public void setSc(int);
public int getDr();
public void setDr(int);
public int getDc();
public void setDc(int);
public int hashCode();
public boolean equals(Object);
public boolean isOpposite(Object);
public boolean isHorizontal();
public boolean isVertical();
public boolean isHorizontalRight();
public boolean isVerticalDown();
public String toString();
}
Proj5_Starter/bin/MPiece.class
public synchronized class MPiece extends Piece {
public void MPiece(char, boolean);
private boolean isMovePossible(Board, Move);
public boolean makeMove(Board, Move);
public boolean isLegalMove(Move);
public int getRank();
}
Proj5_Starter/bin/Piece.class
public abstract synchronized class Piece {
protected char character;
protected boolean red;
public void Piece(char, boolean);
public void Piece(char);
public char getCharacter();
public void setCharacter(char);
public boolean isRed();
public void setColor(boolean);
public String toString();
public int hashCode();
public boolean equals(Object);
}
Proj5_Starter/bin/Stratego.class
public synchronized class Stratego {
public void Stratego();
public static boolean crossesAnotherPiece(Board, Move);
public static boolean twoSquareRule(Board, Move);
public static int isGameOver(Board);
public static boolean crossesLake(Board, Move);
public static int getWinner(Piece,...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here