Applets :: Game Character At The Bottom Of Screen Dodging Falling Rocks

Jun 4, 2014

This is code for a game I am making where you are a character at the bottom of the screen dodging falling rocks. I was wondering how to add in the falling rocks. I think I need to use Timer and an ArrayList but I am not sure if that would work and not truly sure how to go about doing it.

import java.applet.Applet;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseListener;
import javax.imageio.ImageIO;

[Code] .....

View Replies


ADVERTISEMENT

Cardlayout Format - Change Main Menu Screen Into Game Screen On Button Click

Mar 16, 2015

I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so

Here is the code from my CardLayout:

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;

[Code] ....

I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.

Here is the main important GUI from my CheckerBoard class:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
  public class CheckerBoard extends JPanel implements ActionListener, MouseListener {
// Main routine that opens an Applet that shows a CheckerBoard
public static void main(String[] args) {
new CLayout();
 
[Code] ....

Once again kept to a minimal.

View Replies View Related

Applets :: Program A Game Of Rock Paper Scissors?

Jun 23, 2014

I am trying to program a game of RPS.

View Replies View Related

2D Slide Scrolling Game - Character Cannot Jump

Mar 31, 2014

There is a problem in my 2D slide scrolling game where the character can't jump until he reaches the enemy.

The Boards class-

package OurGame;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
public class Board extends JPanel implements ActionListener, Runnable {

[Code] .....

View Replies View Related

Bullets Are Not Showing Up Across Network Client Screen In Game

Apr 11, 2014

Tank war game thats ran over a network and is multiplayer, however whenever I fire a bullet it shows on my screen but not the other player's screen. Here's the code:

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.util.*;
import java.net.*;
import java.io.*;
 
[Code] ....

View Replies View Related

5 Card Stud Game - Constantly Repainting Screen

Apr 11, 2014

I am currently making a 5 card stud game for my Java Programming class at my highschool. I am deciding to go a little above expectations and make my poker game a little more fun than just comparing a few cards. However I want there to be text that is changing on my screen, but the repaint() is not the most reliable way to make the screen update, I am wanting a way for have the program constantly update the screen so that if I do something like someLabel.setText("Text"); then the text will update automatically whenever it is changed.

Here is my declarations and main/constructor method

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class FiveCard extends JFrame implements ActionListener {

[Code] .....

Here is the method addMainPage, which is called in the constructor. Whenever the enterButton is pressed, the actionListener directs it to loadBoard();

I use GridBag Layout, so to skip through all of the constraints

public void addMainPage() {
for (int i = 0; i < 4; i++) {
players[i] = new Player();
}
Icon cardBackImage = new ImageIcon("back.gif");

[Code] .....

Game intro is a method that changes the text of a label every second using .setText(), however it does not work because the enterButton is pressed, then after loadBoard() and gameIntro() is ran, it repaints the frame with the board objects and the gameIntro's final .setText() command.The action listener is simple...

public void actionPerformed(ActionEvent e) {
if (e.getSource() == enterButton) {
players[0].setName(playerNameField.getText());
loadBoard();
}
p.repaint();
}

View Replies View Related

Bullets Are Not Showing Up Across Network Client Screen In Game

Apr 13, 2014

Tank war game thats ran over a network and is multiplayer, however whenever I fire a bullet it shows on my screen but not the other player's screen. Here's a snippet of code form where i think the problem is coming from:

class Tank implements Ball {
double locX, locY, radius, angle;
int self; // index of this tank in WarPanel.tanks
public boolean turnL, turnR, forth, back, fire;
boolean prevtL, prevtR, prevfo;
Color color;

[Code] ....

View Replies View Related

Sound Won't Play When Player Dies And A Game Over Screen Pops Up

Jan 14, 2014

I am making a game with java in a program called greenfoot.My problem is that a sound won't play when the player dies and a Game Over screen pops up..

- I have saved the audio file in my sound map of the scenario
- Applied the good name of the file
- tested the sound effect and it's working

this is my code:

public GameOver()
{
setImage(new GreenfootImage("GAME OVER", 100, Color.BLACK, null));
Greenfoot.playSound("fail-trombone-03.wav");
Greenfoot.stop();
}

View Replies View Related

Swing/AWT/SWT :: JLabel That Robotically Type Words Character By Character

Feb 2, 2015

i want to have a JLabel that could "robotically" type words character by character.

View Replies View Related

Carriage Return Character Working Like New Line Character On MacBook

Nov 21, 2013

I use Eclipse (kepler version, with JDK 7) on MacBook Pro (Lion).I want to overwrite a line printed on my console. I used "" for that. I was expecting the cursor to go to the beginning of the line. Instead, it is going to the next line.

Code:

System.out.print("Superman
Sober");

Expected Output:
Soberman

Actual Output:
----------------
Superman
Sober

View Replies View Related

How To Find XOR Value Of Character Of Character Array In Java

Mar 3, 2015

What I am trying is find the XOR value between charcters of a String here is my code

public static void main(String[] args) {
System.out.println(grayCode("100"));
}
public static String grayCode(String input){
StringBuilder temp=new StringBuilder();
temp.append(input.charAt(0));
for(int j=1;j<input.length();j++){
char previous=input.charAt(j-1);
char current=input.charAt(j);
char xorVal=(char)(previous^current);
temp.append(xorVal);
}
return temp.toString();
}

but I am not getting actual XOR value of two charcters that I am trying to get.

View Replies View Related

Build Up Alphabet Character By Character

Mar 9, 2014

I am trying to build up the alphabet character by character. Like:

a
ab
abc
abcd

Well as of now I can only print out the alphabet with my loop like abcdefg...z.. So here is the code I am trying to use:

public void loop4() {
char alph = 'a';
while(alph <= 'z') {
System.out.println(alph);
alph++; 
}
}

View Replies View Related

Input More Than One Character But Output Is Only One Character

Feb 28, 2015

I have entered more than one character but output is only one character .....

class InputUser
{
public static void main(String arg[])
throws java.io.IOException
{
char ch;
ch=(char) System.in.read();
System.out.println(ch);
}
}

View Replies View Related

Applets :: SecurityException When Using Applets

Dec 26, 2013

I am new to applets, and my manifest file is:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Permissions: all-permissions
Created-By: 1.6.0-internal (Sun Microsystems Inc.)

Name: com/myPackage/test/client/TaskApplet.class
SHA1-Digest: pLmraui35IkgfAq+v3WGj1LwCYQ=

The error I get is as follows...When the page is loaded I get the following error: java.lang.SecurityException: class "com.myPackage. test.client. TaskApplet" does not match trust level of other classes in the same package

View Replies View Related

JButton Positioning On Bottom

May 20, 2014

import java.awt.GridLayout;
import javax.swing.*;
 public class Screen
{
JButton start;
JButton reset;
JButton box[][] = new JButton[20][20];
Screen()

[Code] ....

I am trying to place the buttons on the bottom. I tried a few different things but the grid layout keeps grabbing it and making them a part of the grid at the button.

View Replies View Related

Draw From Bottom Of Bounds?

May 26, 2014

I 'm trying to draw a button by resizing a simple button background image to fit the size of the text. Everything works well except for the actual drawing of the string. The y value that I give the Graphics object designates the baseline, however I would like to draw the the string above the y. So that the image below doesn't happen.

I gave the graphics object the y of the bottom of the "P" and would instead like to give it the value of the bottom of the "y". Is there a way to do that by reading the String's bounds or something, or is there a way to get the Graphics object to use the passed y value as the definite bottom of the String?

View Replies View Related

Finding Path Through 2D Array From Top To Bottom?

Apr 20, 2015

I have a 2D array that is of type int[][]. it is populated with 1's and 0's. I need to create a method that allows me to search from the top row finding a possible path to the bottom--the path is a path of connecting cells containing 1. I need to create an array that stores the cells that are needed to be searched. When the search carries out, for each cell stored it needs to check the cells to the left, right, below and above the current cell.

I also need to create a variable to store the current cell. I thought initially it would be an int but it can't be because it needs to hold the the index of the current cell. and any of the cells searched that are an immediate neighbour of the current cell are added to the storage array.

I have these instructions but I am having trouble converting into code

Finding a path through vegetation from the top row to the bottom row: The idea is we will start from a cell in the top row and advance below for as long as we can. Since we are still not done exploring a cell until we have explored ALL it’s vegetation neighbors, we will add the cell to an array of cellsToExplore and only come back to it if the current cell we are examining is fully explored. Here is pseudo-code of the algorithm !

• Create array cellsToExplore (what size should this array be?)!

• Create an integer count that stores the number of cells in cellsToExplore!

• Go through the top row and add ALL vegetation cells to cellsToExplore!

• Create a variable to store currentCell we are exploring and set it to null.!

• while count > 0 do!

- set currentCell to the last cell in cellsToExplore (last cell added to the array).!

- label currentCell as burning vegetation!

- If the currentCell is on the bottom row then we return true (we found the path).!

- if the cell below currentCell is vegetation then add the cell below to the cellsToExplore array.!

- else if cell to the right of currentCell is vegetation then add the cell to the right to cellsToExplore!

- else if cell to the left of currentCell is vegetation then add the cell to the left to cellsToExplore!

- else if cell above the currentCell is vegetation then add the cell above to cellsToExplore.!

- else remove the currentCell from the cellsToExplore (we are done with this cell). !

• Return false!

View Replies View Related

Drawing Shapes Bottom Right To Top Left

Mar 17, 2014

I am having issues with drawing shapes from bottom right to top left.

Issue:

- g.drawRect() will show like I am calling g.fillRect()
- other shapes will not even show the shape in that area

Needs:

- g.drawSHAPE needs to show and not be filled unless I have my fill checkbox selected

The Program:

- Create a JFrame with a draw panel and a component panel
- have a combobox with shapes that, when selected, will draw that shape in the draw panel
- have a button that, when clicked, will launch JColorChooser to change the color of the drawn shape (draw panel is set to black)
- have a checkbox that, when checked, fills the shape
- have mouse listeners to adjust X and Y and will instantly update the shapes size to where you drag/click/press/release

Code for my drawRect():

Java Code:

// if statement to check if mouse drag X is less than starting X
if(x2 <= x){
if(emptyORfill.isSelected()) // emptyORfill is my JCheckBox
g.fillRect(x2, y, x-x2, y2-y); // x-x2 is the same as Math.abs(x2-x)
else
g.drawRect(x2, y, x-x2, y2-y);

[Code] .....

This is just for my Rectangle. This will show a filled rectangle when both mouse drag X and Y are less then the starting X and Y. If I take this fully functional code and adapt it to drawRoundRect(), the round rectangle wont even show the shape when mouse drag X and Y are less than the starting X and Y but will be fine if one or the other is less than the starting X or Y. NOTE: This same exact code worked on my classmates laptop in her program, but in my program on her laptop it did not. She took out the "else" in the else if's and just made them if statements all the way down and it worked on her laptop in my program, but the same "fix" did not work on my pc.

My mouse listener just sets X and Y values in my Shape class that updates my shape methods. I have an item listener for my comboBox that sets default values when a new selection is made and enables/disables editable on my fill checkbox for certain shapes. My action listener looks for the button click and the checkBox click.

View Replies View Related

Random Color Ball And Move Bottom Bar Vector?

Feb 20, 2014

I created this simple vector java program where ball falling and when collide with the bar below, the ball stops.

I need to make the ball falling randomly from different direction and also need to make the bar move left right using keyboard arrow.

Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
 //using timer to increase the counter

[code].....

View Replies View Related

Return Height Of Heap Of Sand In Bottom Of Hourglass

Nov 18, 2014

I am working on program and have been struggling to get around step 5 and 6 given below.

I have got on with the first couple of points. Where to begin with steps 5 and 6.

Java Code:

class Hourglass {
int height;
int bottomHalf;
public Hourglass (int h) {
height =h;
}
public Hourglass (){
height=3;
}

/*Write a method dropGrain that simulates one grain of sand falling into the bottom half of the Hourglass. If all the sand is already at the bottom before a grain is dropped, this method should cause the hourglass to be flipped, meaning that all the sand will be in the top again. Then, one grain of sand should fall. */

//Hint: this method can be quite short. All you need to do is update one attribute.

public void dropGrain(){
}

/*Write a method getHeapHeight() which returns the height of the heap of sand in the bottom of the hourglass.

Hint: a triangle of height h contains h*h grains (=1+3+5+...+h).

So determining the height when the amount of sand in the bottom half is a square (1,4,9,16,...) is easy. Think about what happens if the amount of sand is not exactly a square.*/

public int getHeapHeight() {
} mh_sh_highlight_all('java');

View Replies View Related

Paint Window Moving Picture From Bottom To Top Diagonally

Sep 30, 2014

PaintWindow pw = new PaintWindow();
Random rand = new Random();
ImageIcon image = new ImageIcon("C:/Users/Ghostkilla/Desktop/gubbe.jpg");
setWidth(pw.getBackgroundWidth());
int height = pw.getBackgroundHeight();

[Code] ....

If you run this code it will move a picture from right to left and hit the left wall and then go to right again leaving the window (It stops there). I want to make so it hits left and then right wall continuously till someones close the window. So basically I am using a for loop to make it go left right all the time.

How to make so the picture moves from bottomleftcorner to toprightcorner diagonally without leaving the window.

View Replies View Related

Swing/AWT/SWT :: Append Always Visible JTable Footer At The Bottom Of Table

Nov 27, 2014

I am building a little application for personal use where I can track my finance. Now, what I would like to get is an always visible JTable "footer" OR horizontal space field attached to the bottom of the window. The idea is that scrolling down/up wouldn't affect it's visibility(like JTable header). Might a picture tell a thousand words: see attachment.

I am wondering, maybe JTable OR TableModel class has a property to solve this problem(I haven't found any)? Or shall I make another ScrollPane/JPanel? Which path of search shall I pursue?

View Replies View Related

Flip Bottom Half And Copy It To Produce Upper Half Of Shape

Jun 15, 2014

So my goal is to use the graphics class to draw this shape: [URL] ....

so far I've managed to draw the bottom half, but now I want to utilize the copyArea() method to flip the bottom half and copy it to produce the upper half of the shape: [URL] ....

and this is what I wrote to produce the bottom half:

import java.awt.Graphics;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

public class MyFrame extends javax.swing.JFrame {

/**
* Creates new form MyFrame
*/
public MyFrame() {
initComponents();

[Code] .....

View Replies View Related

Swing/AWT/SWT :: When Click On Button From Bottom Panel Top Panel Need To Be Redrawn

Apr 1, 2014

When i click on the button from bottom panel, top panel need to be redrawn. But redrawing is not happening. It happens only when resizing the applet.

public class Graphics_Chart(){
public init(){
JScrollPane topPane = new JScrollPane(new ImagePanel2());
topPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
topPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);

[code]...

View Replies View Related

Opoly Game - Goal Of The Game Is To Reach Or Exceed Reward Value 1000

Mar 12, 2015

Opoly works this way: The board is a circular track of variable length (the user determines the length when the game app runs). There is only one player, who begins the game at position 0.

Thus, if the board length is 20, then the board locations start at position 0 and end at position 19. The player starts with a reward of 100, and the goal of the game is to reach or exceed reward value 1000. When this reward value is reached or exceeded, the game is over. When the game ends, your program should report the number of turns the player has taken, and the final reward amount attained.

In Opoly the game piece advances via a spinner - a device that takes on one of the values 1, 2, 3, 4, 5 at random, with each of the five spin values equally likely.

Although the board is circular, you should draw the state of the board as a single "line", using an 'o' to represent the current player position, and * represent all other positions. Thus if the board size is 10, then this board drawing:

**o******

means that the player is at location 2 on the board.

Here are the other Opoly game rules:

If your board piece lands on a board cell that is evenly divisible by 7, your reward doubles.

If you land on the final board cell, you must go back 3 spaces. Thus if the board size is 20, the last position is position 19, and if you land there, you should go back to position 16. (If the position of the last cell is evenly divisible by 7, no extra points are added, but if the new piece location, 3 places back, IS evenly divisible by 7, then extra points ARE added).

If you make it all the way around the board, you get 100 points. Note that if you land exactly on location 0, you first receive 100 extra points (for making it all the around), and then your score is doubled, since 0 is evenly divisible by 7,

Every tenth move (that is, every tenth spin of the spinner, move numbers 10,20,30,... etc.), reduces the reward by 50 points. This penalty is applied up front, as soon as the 10th or 20th or 30th move is made, even if other actions at that instant also apply. Notice that with this rule it's possible for the reward amount to become negative.

Here is the driver class for the game:

import java.util.*;
public class OpolyDriver{
public static void main(String[] args){
System.out.println("Enter an int > 3 - the size of the board");
Scanner s = new Scanner(System.in);
int boardSize = s.nextInt();

[Code] ....

heres the methods:

REQUIRED CODE STRUCTURE: Your Opoly class must include the following methods (in addition to the Opoly constructor) and must implement the method calls as specified:

playGame - The top-level method that controls the game. No return value, no parameters. Must call drawBoard, displayReport, spinAndMove, isGameOver.

spinAndMove - spins the spinner and then advances the piece according to the rules of the game. No return value, no parameters. Must call spin and move.

spin - generates an integer value from 1 to 5 at random- all equally likely. Returns an integer, no parameters.

move - advances the piece according to the rules of the game. No return value, takes an integer parameter that is a value from 1 to 5.

isGameOver - checks if game termination condition has been met. Returns true if game is over, false otherwise. No parameters.

drawBoard - draws the board using *'s and an o to mark the current board position. Following each board display you should also report the current reward. No return value, no parameters.

displayReport - reports the end of the game, and gives the number of rounds of play, and the final reward. No return value, no parameters.

View Replies View Related

Tic Tac Toe Game - Random Number Generator And Two Dimensional Arrays For Game Board

May 9, 2015

Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.

import java.util.Random;
import java.util.Scanner;
 public class TicTacToe {
 private static Scanner keyboard = new Scanner(System.in);
private static char[][] board = new char[3][3];
public static int row, col;
 
[Code] ....

View Replies View Related







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