Commit 4266eadf authored by edward.pearce's avatar edward.pearce

initial commit

parents
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_12" default="true" project-jdk-name="12" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/battleships.iml" filepath="$PROJECT_DIR$/battleships.iml" />
</modules>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
import java.util.Random;
public class AIPlayer {
int[] pickTile(boolean lastTileHit, int lastTileX, int lastTileY){
int[] returnCoords = new int[2];
if(lastTileHit){
returnCoords[0]=lastTileX+1;
returnCoords[1]=lastTileY;
}
return returnCoords;
}
}
public class Board {
private final int board_size = 10;
private int[][] numBoard = new int[board_size][board_size];
//0 - empty
//1 - ship
//2 - shot empty
//3 - hit ship
Board(){
for(int i = 0; i < board_size; i++){
for(int j = 0; j < board_size; i++){
numBoard[i][j] = 0;
}
}
}
boolean checkIfEmpty(int x, int y){
if(numBoard[x][y]==0){
return true;
}
else{
return false;
}
}
void placeShip(int startX, int startY, int endX, int endY){
//already validated
for(int x = startX; x < endX; x++){
for(int y = startY; y < endY; y++) {
numBoard[x][y] = 1;
}
}
}
boolean checkIfHit(int x, int y){
if(numBoard[x][y] == 1){
numBoard[x][y] = 3;
return true;
}
else{
numBoard[x][y] = 2;
return false;
}
}
void displayBoard(){
}
void win(Player winner){
//display win message
}
}
public class Game {
Player[] players;
int turn = 0;
Board board = new Board();
Game(){
players = new Player[]{
new Player("1"),
new Player("2")};
}
void play(){
board.displayBoard();
//place ships
while((players[0].lives>0)&&(players[1].lives>0)){ //the beginning of the game
//players[turn].haveTurn();
//javafx click target
//takes target here
if(turn==1){ //this is the computers turn
}
int xTarg = 0;
int yTarg = 0;
if(board.checkIfHit(xTarg,yTarg)){
players[turn].lives--;
}
if(turn == 0){ // keeps track of which players turn it is
turn = 1;
}
else{
turn = 0;
}
}
if(players[0].lives>players[1].lives){ //this dictates the winner, whichever player has more lives when one has run out wins
board.win(players[0]);
}
else{
board.win(players[1]);
}
}
}
public class Main {
public static void main(String[] args) {
Game game = new Game();
game.play();
}
}
public class Player {
String id;
int score;
int lives;
Player(String id){
this.id = id;
score = 0;
lives = 25; //sum of all ship lives
}
void addToScore(){
score++;
}
}
public class Ship {
String name;
int size;
int lives;
boolean isAlive;
//1 carrier
//2 battleships
//2 destroyers
//3 patrol boats
Ship(String shipName){
if(shipName.equals("Carrier")){
name=shipName;
size=5;
lives=size;
isAlive=true;
}
else if (shipName.equals("Battleship")){
name=shipName;
size=4;
lives=size;
isAlive=true;
}
else if (shipName.equals("Destroyer")){
name=shipName;
size=3;
lives=size;
isAlive=true;
}
else if (shipName.equals("Patrol")){
name=shipName;
size=2;
lives=size;
isAlive=true;
}
}
void isHit(){
lives--;
if(lives==0){
isAlive=false;
}
}
}
public class Window {
Window(){
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment