Android App Battleship Board

Nov 11, 2014

I want to make the board for the game, I want it to be a two-dimensional array of buttons.I know how to make a array but is there a class of buttons that I need to use? and how do I connect it to the xml?I am using eclipse.

View Replies


ADVERTISEMENT

Error In Battleship Game

Jun 8, 2014

I'm trying to make a simple battleship game, but when I make a ship with the addShip method (it is suppoused to initialize the board with the numbers 1,2,3 or 4 depending on the ship type, at the given coordinates) it dosen't initialize the field with any numbers, although the method returns true. The place the ship is suppoused to be made stays initialized with ".",

package battleship;

public class Sea {
private int width;
private int height;
private String[][] field;

[code].....

View Replies View Related

One Dimensional Battleship Game

Oct 24, 2014

I'm working on a project and I can't seem to get it working. It is a battleship game, in a one dimensional array. This is as much as I got. I can't get the 'river' to display when I run the program. How I might get it to work?

import java.util.*;
import java.util.Random;
public class Battleship
{
static Scanner input = new Scanner(System.in);
public static int promptForInt(String prompt)

[Code] ....

View Replies View Related

How To Improve Battleship Game Java

Dec 3, 2014

I have an battleship program that I would like to improve in performance. I know that using certain algorithms it can be improve however I am beginner in Java. I would like any recommendations and or hint in how to improve this game. The are 5 ships per game and the computers plays 10000. I just want to sink all ships in as many shots as possible.

Main class

package solution;
import battleship.BattleShip;
import java.awt.Point;
import java.util.List;

[Code] .....

View Replies View Related

Design And Implement GUI Front End For Computerized Version Of Battleship

Feb 21, 2014

Code for implementing a simple computerised version of Battleships has been supplied. Examine the code ensuring that you understand it. The game is played against the computer.

A number of ships (default is 6) are place randomly on a 4 x 4 grid. A ship occupies one square only. The player then guesses the position of a ship. If he/she guesses correctly the ship is HIT and sinks. If the guess is incorrect the player loses a life. The default number of lives is 7. If the location has been guessed already, no lives are lost.

When the game starts, a 4 x 4 grid should be displayed.

The user should be allowed to enter/select a cell location. If the selected cell contains a ship, the ship will be destroyed. If not the player loses a life. The cell should display an appropriate picture, icon or message informing the user of its current state.

The number of lives and number of ships remaining should be displayed.

When the game ends an appropriate message should be shown informing the player whether he/she has won or lost. The positions of the ships should also be shown.

The purpose of this assignment is that students demonstrate an understanding of the Java Swing library and that he/she can navigate and use the API effectively.

Your finished GUI should be both user-friendly and aesthetically pleasing.

Ideally, the user should have the option to play another game, to quit or give up mid-game. You may also wish to include other options such as different levels of difficulty, etc.

View Replies View Related

Board Of Colors And Players

Sep 14, 2014

My assignment is for a game where there is a board of colors and each player draws a color and moves to that position on the board. It will then output how many cards total in the game it took whichever player to win. If no winner it outputs the number of cards that none won by going through. I attached the file that corresponds with my code.

This is the desired output:

Player 1 won after 7 cards.
Player 2 won after 8 cards.
No player won after 8 cards.
Player 2 won after 4 cards.
No player won after 6 cards.
Player 2 won after 8 cards.
Player 1 won after 4 cards.
Player 2 won after 8 cards.
Player 1 won after 1 cards.
No player won after 200 cards.
Player 4 won after 100 cards.

import java.io.*;
import java.util.Scanner;
public class ProgrammingAssignment1 {
/**
* @param args the command line arguments
*/
public static int players;
public static int cards;
public static int boardlength;
public static String board;

[Code] .....

The output that I get is:

Player 1 won after 3 cards.
Player 2 won after 8 cards.
No player won after 8 cards.
Player 1 won after 3 cards.
No player won after 6 cards.
Player 2 won after 8 cards.
Player 1 won after 3 cards.
Player 2 won after 8 cards.
Player 1 won after 1 cards.
No player won after 200 cards.
Player 4 won after 100 cards.I guess I'm supposed to set the playerPos[] to -1, but I'm unsure how.

Attached File(s) : colors.in.txt (1.5K)

View Replies View Related

Randomly Filling Tic Tac Toe Board

Oct 19, 2014

So I an assignment in Java to write a code which will randomly populate squares in a Tic Tac Toe Board. I pretty much have it I think, but I cannot get the 'O' to appear on the board, some squares will be blank. We were told to use the Random utility to generate the squares. I am attaching the .gif's which are used. Here is my code:

import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class LandryTicTacToe extends JFrame
{
/**
*
*/
private static final long serialVersionUID = -8781512780135301721L;
private final int HEIGHT = 450;//Set value for Height
private final int WIDTH = 500;//Set value for Width
private static JButton [] button = new JButton[9];//Declare array of Buttons

[Code] .....

[attachment=37084:TicTac0.gif][attachment=37085:TicTacX.gif]

Instructions Given to me:

Display a frame that contains nine labels, arranged like a Tic Tac Toe board. A label may display an image icon for X, an image icon for O, or nothing. Display images randomly in each label. Use the Random class to generate 0, 1, or 2, which corresponds to displaying an X image, an O image, or nothing.

Attached image(s)

View Replies View Related

Tic Tac Toe Game - X And O Do Not Show In The Board

Apr 12, 2014

I have a tic tac toe game and when i run it it works and there are no errors. but the X's and O'x do not show in the board. I know the problem is in the "gameBoard" method and its cause i am telling the code to print the same board every time but i dont know how to do it the right way....

package chap7MDA;

import java.util.Scanner;
public class chapexe7we {
public static void main(String[] args) {
char[][] board = new char [3][3];//make a game board
gameBoard(board);// call the method game board to make the board

[Code] ....

View Replies View Related

Make A ToString That Returns A Board

Jan 26, 2015

I've been trying to make a class that has a toString method that displays the board at the same time displays the value of each index of a 2d character array inside of the code. My professor has made the client print the method. I assumed since he was printing it on the client we had to return a string that gives us this.The number 2 is part of the 2d character array while the rest of the index values are just space characters.

___________
| | | |
|___|___|___|
| | | |
|___|___|___|
| | | |
|___|___|___|
| | | |
|___|___|___|
| 2 | | |
|___|___|___|

I had trouble figuring out how to return this so I started testing it out in another file.

public static void main(String[] args) {
// TODO Auto-generated method stub
char[][] myHidingPlaces;
myHidingPlaces = new char[5][3];
myHidingPlaces[0][0] = 'p';
char play = '1';
for (int i = myHidingPlaces.length-1; i >= 0 ; i--) {

[code]...

View Replies View Related

Boggle Board Is Not Showing Up When Run The Program?

Jan 18, 2015

I'm making a Boggle game, but the issue here is that the boggle board is not showing up when i run the program.

Here is the code:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class Boggle {
public static void main(String[] args) {

[code]....

View Replies View Related

Creating Java Based Message Board?

Jan 4, 2015

I'm trying to create java based fairly simple forum.

The task is as following:-

• each user may post exactly one research topic;

• each each may see all research topics posted by other users;

• each each may read all messages contributed by all users on a particular research topic;

• each user may post a new message to contribute to the discussion on any of the topics posted.

Something like below:-

User topic: Intrusion Detection Systems
Posted by: John
[22/10/11 14:00] John wrote I am building a new IDS based
on neural networks. …………….Comments ………….?
[22/10/11 14:12] Kate wrote there could be too many false positives!

View Replies View Related

Bingo Board - Having Array To Fill A Grid

Dec 16, 2014

I am attempting to make a 5x5 bingo board. My array generates 75 numbers(15 per bingo letter) and displays them in a random order. What I am having trouble figuring out is how to fill the 5x5 grid with 25 numbers from my array. And yes, my code is probably much longer and much more redundant than it needs to be. Also, I think I'm using cells and grids terribly wrong (possibly the entire java language) but I'm not sure.

import java.util.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.event.*;
import java.util.ArrayList;
import java.awt.GridLayout;
import javax.swing.JButton;
public class bingoboard extends JFrame

[code]...

View Replies View Related

Arrays To Solve And Print A Kakuro Board

Feb 11, 2015

I am working on and am stuck on an assignment where we draw and then solve a Kakuro game.we have been given DrawingPanel.java and DrawGrid.java which should draw the board game grid then we need to pass a .txt document which has the game information

I tried getting my readGrid function to read the input file and store it in arrays but it is not working?

//main -get arguments -make grid -solve it
import java.io.File;
import java.util.Scanner;
import java.util.Arrays;
public class Kakuro {
static File gridFile; // The input file describing the grid

[code]...

View Replies View Related

Score Board - Constructor Null Pointer Exception

Sep 7, 2014

I'm getting constructor null pointer exception but i don't know what has gone wrong...

private int capacity; // maximum capacity of the board
private double minimum; // minimum distance of the flyer
private SortedLinkedList sortedList;
private int size = 0;
public ScoreBoard() {
capacity = 10;
minimum = 0.0;
sortedList = new SortedLinkedList();

[Code] ....

View Replies View Related

Keeping Track Of Player Position In Monopoly Board Game

Jun 28, 2014

I am trying to design a monopoly board game with a class and a main program. I can not make the method to keep track of the player's position after every roll. After every roll it prints "Previous position: 0".The player should also not go over 14th spot because the board is just 15 including 0. That is what I have (just the particular method and the part from the main program which call it).

public int getpospl1()
{
System.out.println( getplayer1name() + " Rolls "
+ "Dice 1: " + getrolld1() + "" + "Dice 2: " + getrolld2() + "" );
int spot1 = 14; //The end spot
int start = 0;
int previousPosition = start;

[Code] .....

View Replies View Related

Developing Tetris Based Characters - Can't Print The Piece Within Board

Dec 18, 2014

I post the code I'm developing for a tetris-based characters. The problem I have is that I can't print the piece within the board. I haven't any error.

Class Piezas

Java Code:

public class Piezas {

public Piezas() {}
//atributos
private int i;
private int j;
private char m[][];
private int formaPieza;

[Code] ....

View Replies View Related

Game Loop Freezing - Reset Button To Clear Board

Nov 9, 2014

I'm back with a question about the Black Jack assignment. I've created a working game that works for one round, as well as a reset button that's able to clear the board of the old hand. However the runGame() loop, which checks whether a player has played his hand seems to freeze the program the second time around

private void initNewGame(){
dealer.addCard();
for(int i = 0; i < numberofplayers; i++){
players[i].addCard(); //draws card, adds score and paints card to the board
players[i].setStatus(false); //makes the buttons usable in the players[] class

[Code] .....

I know it's probably not optimal having an while loop constantly running to check the status, but I can't seem to figure out why it freezes.

View Replies View Related

Comparing Characters Of A Word To Puzzle Board - Diagonal Search Algorithm

Feb 7, 2015

Coding (must follow pseudocode algorithm provided) for comparing characters of a word to a puzzle board char[][].

I've gotten the horizontal and vertical searches to work, but I'm having a difficult time figuring out how to search diagonally.

Here's the search algorithm format I have to use:

for each guess word
for each letter of the puzzle
for each letter of the guess word
check for diagonal match
if found, add word to list, break to next guess

I'm assuming there should be a +1 horizontal offset after I find the first letter, but every index I've bumped has caused me to screw up my array bounds. I'm missing something.

Here's the algorithm I'm using for diagonal search. This same algorithm worked for vertical search (minus the offset of course)

//diagonal search
for(String word : guessWords) {//for each guess word
 int letterCount = 0;
int index = 0;
for(int j=0; j<grid[index].length; j++) {//for each puzzle letter
 
[Code] ....

View Replies View Related

Build Backtracking Algorithm To Place N Queens On Chess Board Of Nxn With No Threat To Any Queen

Nov 17, 2014

Having some trouble coding this exercise in JAVA:

Build a backtracking algorithm to place n queens on a chess board of nxn, with no threat to any queen.

Using F=parameter, Print only the first result.

Using the same C=parameter, print every possible inlays.

This should work when running with a 4x4 board and an 8x8 board basically.

View Replies View Related

Android Manifest Could Not Be Found

Apr 14, 2014

I am trying to run a project and i am getting different errors, I know the code is working because i have seen it running, but now i cant even get the app to load up. sometime I get a AndroidManifest cannot be found error and sometimes i get a error like

[2014-04-14 17:28:31 - DatabasePrototype5] Failed to install DatabasePrototype5.apk on device 'emulator-5554!
[2014-04-14 17:28:31 - DatabasePrototype5] (null)
[2014-04-14 17:28:32 - DatabasePrototype5] Launch canceled!

my AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.databaseprototype5"
android:versionCode="1"
android:versionName="1.0" >

[Code] ....

View Replies View Related

Eclipse Android - How To Go From 2nd Activity To 3rd Using Buttons

Feb 8, 2015

I didn't see anything specific to Android. I am a very basic beginner when it comes to JAVA and Android programming.

The app is a very simple comic strip viewer that views 3 panels of a comic strip one at a time. My problem is going from a second activity to another. I can go from the main activity to the second fine but when I press the next button to go from the second activity to the third nothing happens. I have tried a few different things but end up with either nothing happening or the app crashes.

Here is my MainActivity Code:

package net.androidbootcamp.comicapp;
import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

[Code]...

Here is the code for the second panel:

package net.androidbootcamp.comicapp;
import android.app.Activity;
import android.os.Bundle;
public class Panel2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {

[Code]...

Here is the code for Panel 3:

package net.androidbootcamp.comicapp;
import android.app.Activity;
import android.os.Bundle;
public class Panel3 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {

[Code]...

And here is the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[URL].."
package="net.androidbootcamp.comicapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk

[Code]...

I am sure it is something very simple but I am not sure what it could be.

View Replies View Related

Value Of Variable In Java - Android Studio

Jun 4, 2014

I have an integer variable called 'selectedname' which is declared as shown below.

public class MainActivity extends Activity implements View.onclickListener, AdapterView.OnItemClickListener {
int selectedname;

So when the app starts an Alert Dialog with two buttons asks the user if they want to tell the first or the last name. The two buttons are 'first' and 'last'.

The problem I'm facing is that in the code the value of selectedname is suppose to change depending on the users choice as shown below.

public void displayWelcome() {
//*other code comes here but it works fine*
AlertDialog.Builder choice = new AlertDialog.Builder(this);
choice.setTitle("Yo!");
choice.setMessage("First name or last");
choice.setPositiveButton("First", new DialogInterface.onclickListener() {
public void onclick(DialogInterface dialog, int whichButton) {
selectedname = 1;

[Code] .....

View Replies View Related

Adding App To Launcher Using Android Studio

Feb 5, 2015

I am trying to make my first application on Android. I have never done it before. I am totally new at it. I want my app to show as an icon on the launcher but how to do it.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.graphicport.homeinventory" >
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />

[code]...

View Replies View Related

Android TextView Doesn't Update

Jul 17, 2014

I am trying to present the user with a response of 'correct' or 'incorrect'. I do the following, but mResultTextView never updates.

mResultTextView.setText("Correct");
android.os.SystemClock.sleep(1000);

I think the problem is that my view needs to be re-drawn.

package com.example.quiz;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import android.graphics.Color;

[code]...

View Replies View Related

How To Load Bitmap Image In Android

Apr 23, 2014

I have been trying to draw a bitmap image onto the canvas from Android and all it displays is a blank white screen. Whenever my app starts up, I am calling this in my game - view class which extends View and overrides the onDraw method:

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

[Code] ....

View Replies View Related

Make A Unique News App For Android

Jan 25, 2015

I'm planning to make a unique news app for android (maybe iOS later) and I am fairly experienced in Java. Im thinking to most likely use RSS feeds, but am unaware how to implement them into JAVA.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved