Creating Memory Game

Jul 9, 2014

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
public class memgame extends JFrame
{
Timer myTimer;

[Code] ....

View Replies


ADVERTISEMENT

Memory Game 2D Array

Oct 3, 2014

So I have that traditional memory game homework assignment and for some reason I can't figure out how to put the codes in order. I can't figure out the arrangement to make it work. So far I have

import java.util.Random;
import java.util.Scanner;
public class MemoryGame {

[Code].....

View Replies View Related

Memory Game GUI Images Not Displaying

Nov 14, 2014

package memorygame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.Random;
import java.awt.*;
public class MemoryGame extends JFrame{

[Code]...

View Replies View Related

GUI Memory Game - Matching Images

Jun 30, 2014

Making a memory game where you click a square it turns over an image and you match the two pretty simple. My issue is my images are not displaying and I am not sure why everything looks correct to me.

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.Random;
public class MemoryApp extends JFrame {
static String Pics[] = {"beaver.JPG", "dawgs.jfif",

[Code] ....

View Replies View Related

Java Memory Matching Game

Feb 13, 2015

"A common memory matching game played by young children is to start with a deck of cards that contain identical pairs. For example, given six cards in the deck, two might be labeled

1, two might be labeled
2 and two might be labeled
3. The cards are shuffled and placed face down on the table.

The player then selects two cards that are face down, turns them face up, and if they match they are left face up. If the two cards do not match they are returned to their original position face down. The game continues in this fashion until all cards are face up.Write a program that plays the memory matching game. Use sixteen cards that are laid out in a 4x4 square and are labeled with pairs of numbers from 1 to 8. Your program should allow the player to specify the cards that she would like to select through a coordinate system.For example in the following layout:

1 2 3 4
--------------------
1 | 8 * * *
2 | * * * *
3 | * 8 * *
4 | * * * *

All of the cards are face down except for the pair 8 which has been located at coordinates (1,1) and (2,3). To hide the cards that have been temporarily placed face up, output a large number of newlines to force the old board off the screen.Use 2D array for the arrangement of cards and another 2D array that indicates if a card is face up or face down.Or, a more elegant solution is to create a single 2D array where each element is an object that stores both the cards value and face.Write a function that shuffles the cards in the array by repeatedly selecting two cards at random and swapping them.

Note:To generate a random number x, where 0<= x <1, use x=Math.random();.For example, multiplying y six and converting to an integer results in an integer that is from 0 to 5."I have been thinking about the algorithm and design of the question for a few hours.

View Replies View Related

Creating GUI For Game Of Life?

Dec 31, 2014

Here is my Code for the Game Of Life that I am programming to teach my self java. I am trying to create a GUI and I have done so and a window displays however i don't understand how i can get the Game of Life to display within that GUI?

import java.io.*;
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.FlowLayout; //Provides default layout managing
import javax.swing.JLabel;
public class LifeMain extends JFrame

[Code] ......

View Replies View Related

CheckerBoard Won't Appear - Creating A Game In Java

Mar 8, 2015

Anyway I am creating a game for my A2 coursework, most commonly known as Checkers. I have completed my code and everything works as I had planned except that the CheckerBoard itself as well as the checkerpieces do not appear to be showing.

The section of were my board should be present is just a black space. Although my board does not appear to be displaying, all of the actions I perform on it such as clicking certain section produces the planned response, and although I've checked through my code I cannot work out what I've done wrong.

CheckerBoard content = new CheckerBoard(); // Sets the CheckerBoard values into the content to be used in the next line
application.setContentPane(content); // Container holds the values together, Content pane of the CheckerBoard
application.pack(); // Use preferred size of content to set size of application.
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
application.setLocation( (screensize.width - application.getWidth())/2,
(screensize.height - application.getHeight())/2 );

[Code] ....

I have noticed is that within the BoardComplete(), if you change the setBackground(Color.BLACK) to WHITE, it will change the colour of the section to white, but the checkboard is still unshown.

View Replies View Related

Creating A Guessing Game In Java

Nov 30, 2014

I am creating a Guessing game program in java code. I am having an issue with the guess class and main/tester class running. The instructions for the game are The computer generates a random # and the user must guess that number in 7 or fewer guesses. If the guesses exceed 7, then the game is over and the user is asked if they want to 'play again?'These are things I need to incorporate into my code:

If Statement

A Loop of some kind
At least three imported methods
At least two methods you create
Obtains input from the user
At least two instance variables
At least two local variables
Some form of concatenation
At least two calculations

import java.util.Random;
public class Guess
{
int computersNumber; // A random number picked by the computer.
int usersGuess = 0; // A number entered by user as a guess.
int guessCount = 0; // Number of guesses the user has made.

[code]...

View Replies View Related

Creating Tiled Based Map Game In Java?

May 10, 2014

I'm trying to create a tile based map JPanel but all I get is a white screen. I'm fairly new to the Java Swing and AWT package so I've been watching tutorials on YouTube so learn as much as I can. I don't know where I'm going wrong.

I've got three classes: Window.java which includes the Main method, Panel.java which is the JPanel and Tile.java to draw all the images into an array.

Window.java:

import javax.swing.JFrame;
public class Window extends JFrame {
public Window() {
setTitle("Project");
setSize(500, 400);
setLocationRelativeTo(null);

[Code] ....

Panel.java:

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JPanel;
public class Panel extends JPanel implements Runnable {
private Image dbImage;

[code]....

I've checked through everything and still cannot find what I'm doing wrong. I did try different codes but I just got errors instead.

View Replies View Related

Creating Leaderboard For Game - Display Top 5 Players

Feb 26, 2014

I'm in the process of building an algorithm for a leaderboard for my game, but now I'm stuck.

- It is a two-player game.
- The leaderboard is supposed to display the top 5 players.
- Scores will be saved to an external .txt file as a reference.

Also, may I add that I still cannot decide if I should only consider the winner's score for the leaderboard, or also the loser's.

For example:

Player 1 is Juliet.
Player 2 is Romeo.

At the end of the match, Juliet's score is greater than Romeo's.

Should I only evaluate Juliet's score for the leaderboard, or both of their scores? As of now my algorithm considers only the winner's score.

As of the moment I'm also only thinking of using JLabel to display the scores, but I'm not sure if this is the most efficient way to do it. I'm considering JTable.

So here's my current algorithm:

1) When the user starts a new match/returns to menu/exits game: (I provided 4 options: new game (scores remain but the board is reset), new match (everything is reset), menu, and exit.)

public class Game
{
//This class also holds the code for the operation of the game
if (event.getSource() == newmatch)//or menu or exit {
if (p1score != 0 || p2score != 0) {
Leaderboard x;

[Code] .....

3) The next step which is I'm highly unsure of is to create an ArrayList for the scores (I'm missing the part about the player's name because well I'm not sure as well how I will approach it) and then sort it, but the problem after that would be how to make the score agree with the player's name, if you get what I mean.

Like for example the scores are:

Anna = 1
Pamela = 5
Gabby = 3
Sorted: 5, 3, 1

Pamela has the highest score, but how will I be able to display her name together with her score?

4) I have a checker which determines if the ArrayList of scores is empty, and if it is, it will automatically display the player's name and score (this is for the first pair of players).

It's something like this:

if (board.isEmpty()){
label1.setText(winnername);
scorelabel1.setText(winnerscore);
} else {
//
}

There's a whole lot of buzz going on and now I don't know how I should proceed.

View Replies View Related

Creating Conway Game Of Life - Index Out Of Bounds?

Mar 3, 2015

The question pretty much says it all. My problem seems to be when adding the neighbours, I am always getting a Index out of Bounds problem. I know this is because the code is reaching for the edge of the table, for example if the column, i = 0 and the statement says to perform i - 1 and return it, then we are going to have a problem.

Similarly with anything like j = 20, j + 1 (as the grid only has 20 spaces). I understand the problem, but I am unsure of how to solve it. I have tried messing around with the if statements, but I continue to get the 'out of bounds' problem...

import javax.swing.*;
public class GameOfLife {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int cellChoice = 0;
int newCells = 1;
int generation = 1;
int neighbours = 0;

[Code] .....

View Replies View Related

Deck Card Game - Creating Classes For Code

May 17, 2014

I created the below code and it works fine. It is a deck card game. I just want to divide my code into classes so that it seems more organized.

Java Code:

package getimage;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.*;

[code]....

View Replies View Related

Creating Cursor For A Game That Moves Square By Square - Removing Trailing Images

Aug 31, 2014

I'm trying to create a cursor for a game that moves square by square. While it will move to the next square, though, it leaves the image of the previous cursor on the last square it was on.

As a visual explanation, this is what the program looks like on launch:

This is what it's suppose to look like after you press the right arrow key once (made by forcibly changing launch coordinates):

And this is what it actually looks like after you press the right arrow key once:

Here is the code for the program:

package cursortest;
import javax.swing.*;
import java.awt.*;
import javax.imageio.*;
import java.io.*;
import java.awt.event.*;
public class CursorTest extends JPanel implements KeyListener{

[Code] ......

I'm fully aware that I could just use g.clearRect on the area and remove it for sure, but I know for a fact I shouldn't have to as I have another program I made a long time ago that tried to do something similar without needing to resort to that.

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

Displaying Memory Location Instead Of Name?

Jan 28, 2014

Aatrox
Champions@3622e177
Champions@4805e9f1
Champions@57e40274
Champions@354124d6
Champions@262f4813
Champions@64f01d52
Frozen Heart
Randuin's Omen

As you can see instead of displaying the champion name it is displaying the memory location and I do not know how to fix it.

class Champions
{
String name;
Champions [] weak = new Champions [3];
Champions [] strong = new Champions [3];
String [] items = new String [3];
public static void main (String [] args)
{

[Code]...

View Replies View Related

SOP Returning Memory Location?

Jul 15, 2014

For some reason my code returns the memory address of the array when its a print statement with a string, but it works fine when its in a separate print statement all by itself. Why? Do I need to create a toString method that converts a char array to a String to something? The reason why I ask that is becuase on Eclipse line 10 has a warning stating "Must explicitly convert char[] to a String".

public class Ex {
private String word;
public Ex(String word) {
this.word = word;
}
public char[] Display(){
char[] wordChars = this.word.toCharArray();
return wordChars;

[Code] .....

Result:

Hello world
The word is: [C@1db9742

I also tried this, knowing that it's a long shot, but that didnt do anything...

public String toString(){
Ex ex = new Ex(this.word);
char[] word = ex.Display();
String updated = word.toString();//counter intuitive?
return updated;
}

View Replies View Related

How Do All Nodes Continue To Occupy Memory

Dec 30, 2014

I had a question about data structures. For the insert method of a linked list, the 'node' object is declared in the insert method. So doesn't the 'node' get destroyed as soon as the closing brace of the insert method is encountered? How do all the nodes continue to occupy memory?

View Replies View Related

When Final Variable Occupy Memory

Sep 23, 2014

when final variable occupy memory in java?

View Replies View Related

Eclipse Takes Lot Of System Memory?

Jan 11, 2014

when running Eclipse, roughly 250k memory is used by it?In my Task Manager, it says: javaw.exe00265,000 KJava(TM) Platform SE binary.The value of 265,000 K is of course fluctuating, but around this value. Btw, this is when Eclipse is just running in the background, without even any java programs running in it. Is this normal memory usage by Eclipse?

View Replies View Related

Trying To Build A Simple Cache Memory

Mar 29, 2015

Started ok i guess? But when it comes to the save and get methods im totaly lost.. (See the code)

import java.util.HashMap;
public class Model {
HashMap<Integer,Long> m = new HashMap<Integer,Long>();
Integer value;
Long result = 2 * computePower(value-1);
public long computePower(int value){
if(value <= 0 )

[Code] .....

View Replies View Related

Add Hook To JVM So It Would Print Log When Reaches 70% Of Memory

Apr 28, 2014

Is there any hook i can attach to a JVM process so it can log when it reaches 70% of total memory,

I can use code like below to get memory information, but this is kind of on demand, is there a way i can get memory information by event or some thing

Java Code:

Runtime runtime = Runtime.getRunTime();
runtime.totalMemory(); mh_sh_highlight_all('java');

View Replies View Related

Memory Calculator - How To Keep Track Of Current Value

Nov 10, 2014

Basically we have to create a calculator that it will have to keep track of the current value, and do the functions that the calculator uses.

But I have it working for the most part, but the current value does not keep...

The double " currentValue " Must stay private.

import java.util.*;
 public class MemoryCaluclator {
 private double currentValue;
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int answer = 0;

[Code] ......

View Replies View Related

JVM Not Execute The Code Without Storing In Memory?

Jun 5, 2014

Any article where it mentions about when the class is loaded into memory?Does it happen before the server starts?

Also does the class needed to be loaded into memory? Can the JVM not just execute the code without storing in memory?

I searched in google. Could not get anything concrete.

View Replies View Related

Ratio Of Memory (RAM) To Heap Space?

Nov 10, 2013

What is the ratio of Memory(RAM) to heap space ? ie: When JVM will throw OutOfMemoryError based on heap available to JVM ?

OutofMemoryError - Memory:RAM size

View Replies View Related

Construction Of Child Object In Memory

Apr 19, 2015

I understand how to write a child object. I know what can access what and the order of execution of each statement, including fields, initialization blocks, and constructors. I know what will be inherited by the child and how private fields and methods are not inherited. I also know that private fields and methods in Parent are still accessible indirectly through constructors, and non-private methods. I know how to use super() and this() with or without parameters. I know when super() will be automatically inserted by the compiler and how the Object class will always be the ultimate parent class. However, I have not been able to find an explanation of exactly (or even approximately) how all this is actually put together into an actual object in memory.

For instance, if Parent.field is private and Parent.fieldGetter() is public then Child inherits fieldGetter() and can call it directly as if it is a member of Child. In fact other classes can call Child.fieldGetter() with no clue that it is not an actual member of Child. But, if fieldGetter() is now part of Child and Parent was never actually instantiated, then how is Parent.field available for Child.fieldGetter() to read? In fact, how does Parent.field exist at all? Where is it stored? (OK, I know, "on the heap.") But I want to know what it is associated with in memory. Is it treated like part of Child? Is there really a Parent object on the heap and Child simply contains references to the parts of Parent that it inherited? What?

View Replies View Related







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