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


ADVERTISEMENT

Keeping Track Of Team Standings In A League

Apr 18, 2014

Here are my conditions: You are developing a program to keep track of team standings in a league. When a game is played, the winning team (the team with the higher score) gets 2 points and the losing team gets no points. If there is a tie, both teams get 1 point. The order of the standings must be adjusted whenever the results of a game between two teams are reported. The following class records the results of one game.

public class GameResult
{
public String homeTeam() // name of home team
{ /* code not shown */ }

public String awayTeam() // name of away team

[Code] ....

The class TeamStandings stores information on the team standings. A partial declaration is shown below.

public class TeamStandings
{
TeamInfo[] standings; // maintained in decreasing order by points,
// teams with equal points can be in any order
public void recordGameResult(GameResult result)

[Code] ....

And here is the actual question:

Write the method adjust. The method adjust should increment the team points for the team found at the index position in standings by the amount given by the parameter points. In addition, the position of the team found at index in standings should be changed to maintain standings in decreasing order by points; teams for which points are equal can appear in any order.

And here is what I have so far:

private void adjust(int index, int points)
{
int Score[] = new int[standings.length]
for ( int i=0; i <= standings.length; i++)
{
Score[i] = index, points;
}
}

View Replies View Related

Keeping Track Of Inventory For A Company - How To Update Variables

Feb 11, 2015

My program is supposed to be used to keep track of inventory for a company. The user is prompted with a menu that asks them which item they want to update and then gives them another menu that allows them to buy, sell, or change the price of the items. For this, I need to have the variable values to change (based on the input of the user), because they are initially set to specific numbers. How would I do this?

Here's the part of my code that is relevant to this question:

balance = 4000.00;
lampQuantity = 400;
lampPrice = 10;
chairQuantity = 250;
chairPrice = 20.00;
deskQuantity = 300;
deskPrice = 100.00;
  
System.out.println("Current Balance: $" + balance);
System.out.print("1. Lamps " + lampQuantity);
System.out.println(" at $" + lampPrice);
System.out.print("2. Chairs " + chairQuantity);
System.out.println(" at $" + chairPrice);

[Code] .....

View Replies View Related

JavaFX 2.0 :: TableView - Keeping Track Of Topmost Visible Row

Apr 1, 2015

I have a TableView and it is scrolled to have some rows visible. Lets call the top visible row T, and the bottom one B.

I now replace the items in the TableView with a whole new list of items (so new data to view), but I want to scroll back to either T or B.

It seems to me that I have to somehow keep track of the topmost visible row, or the bottom-most visible row, but I can't figure out how to do that.

View Replies View Related

How To Track Player Positioning

Nov 25, 2014

So I have a player an enemy and enemy bounds the enemy can go. I need to have the enemy track my position and when I go into the position (I am using a collision method for this) the enemy comes over at a speed of 1. My problem is the enemy jumps to me and then follows at speed of 2 (2 is the player speed). The code is wrong this is why it is jumping and I have my other problems. so my question is what is a good solution for this? I am trying to make a method to track playerposition() so what I am thinking I could do is find x, y of player then store those into an array and return the array to Enemy so he tracks.

player.java
public class Player{
int x = 100; // Location of player
int y = 200; // location of player
int xa = 0; // Representation of where the player goes
int ya = 0; // Representation of where the player goes
private int speed = 2;

[Code] .....

Please note this is not the entire code I have cut some things out that did not need to be there. Also, the code is just to get an idea of what I was thinking of doing. The ideas that are came up with are not meant to be a reflection of what I already have but, what I could add or replace.

View Replies View Related

Swing/AWT/SWT :: Keeping Track Of Strings Drawn On JPanel Using Paint

Nov 1, 2014

So, I have this simple program that paints a string on JPanel using g2.drawString("Hello world", 40, 120). Basically, I want to be able to keep track of many strings on the JPanel at once. I'm not sure how to do this. For example, I would want to have an ArrayList of objects that keep track of these strings.

I want to be able to click-and-drag these strings so I will need to know there locations, etc.

Right now, using g2.drawString, it only draws the string. I want something like gw.draw(myStringObject).

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JFrame;
import javax.swing.JPanel;

[Code] .....

View Replies View Related

Keeping Track Of Product With Highest Price - Loop Condition

Sep 22, 2014

The Program prompts the user to enter the number of products in the product catalog. The program should then prompt the user for the name and the price of each product in the product catalog. Once all of the products have been entered, the program should output the product information (name and price) of the most expensive product in the catalog. Your solution to keep track of the product with the highest price.

import java.util.Scanner;
public class ProductTester {
private static final String price = null;
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.print("Enter the number of Products: ");
int count = console.nextInt();

[Code] ....

View Replies View Related

Priority Queue In Java Which Keeps Track Of Each Node Position

May 4, 2014

I'm working on a lab for my class. I need to create a Priority Queue in Java using an array list. The kicker is that each node has to have a "handle" which is just an object which contains the index of of the node that it's associated with. I know that sounds weird but we have to implement it this way. Anyway, my priority queue seem to work fine except the handle values apparently aren't updating correctly because I fail the handle test. Also, I run into problems with handles only after extractMin() is called, so I figured the problem would be somewhere in that method but I've been through it a million times and it looks good to me.

Here is my Priority Queue Class:

package lab3;
 import java.util.ArrayList;
 /**
* A priority queue class supporting operations needed for
* Dijkstra's algorithm.
*/
class PriorityQueue<T> {
final static int INF = 1000000000;
ArrayList<PQNode<T>> queue;
 
[Code] ....

I can post the tests too but I don't know if that would do much good. Just know that the queue works as is should, but the handles don't point to the right nodes after extractMin() is utilized.

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

Java Program - Track Position Of Imaginary Ball As It Bounces Around Imaginary Box

Oct 3, 2014

I am working on a program that asks me to track the position of an imaginary ball as it bounces around an imaginary box. The user gives me input for the starting position of the ball (x,y), the bottom-left boundaries of the box (xl, yl), the top right boundaries (xr, yr) and the angle. The program then needs to find where the ball will hit the box, and then print that location and find the new angle for the next point. My program currently works in most cases if the angle is less than pi.

Here is my code

public class BouncyBall {
public static void main(String args[]){
if (args.length != 8) {
System.out.println("Error: usage is X, Y, Angle, Xl, Yl, Xr, Yr,N");
System.exit(1);
}
double x,y,xl,yl,xr,yr,angle;
int n;
x=Double.parseDouble(args[0]);
y=Double.parseDouble(args[1]);

[Code] .....

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

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

Turning Single Player Blackjack Game Into Multiplayer

Mar 19, 2014

I wrote a single player blackjack code and i want to play this game with multiplayers, which steps should i take to do this

package blackjack;
import java.util.Random;
import java.util.Scanner;
public class Blackjack {
public static void main(String[] args) {
Random kagit=new Random ();

[Code] .....

View Replies View Related

Hangman 2 Player Game - User Cannot Guess More Than 6 Times

May 27, 2014

I am creating a hangman code. So the game i am creating is 2 player, first player enters the word and second player guesses. i made the code but i don't know how to restrict the first player from adding random characters into the secret word because for my project the word can only contain letters. so i need making the code so the player 1 can only enter letters.

My code is below:

/**
* Auto Generated Java Class.
*/
import java.util.Scanner;
public class Hangman {
public static void main(String[] args) {
Scanner input= new Scanner(System.in);
String player1,player2;
int wrongguessamount = 0; //keeps the count of the amount of wrong guesses
int correctguessamount = 0; //keeps count of the amount of correct guesses
int maxincorrect=6;//makes sure the user cant guess more than 6 times

[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

Multi-Player Game With Multiple Worlds - Unhandled Packets

Sep 16, 2014

So I am trying to create a Multi-Player game in java, and I have a Game server and a Client. They normally connect with either but I would like to add a login server so that there can be an option to go to a different world then just the main one. It will have the same map and data but will be separate from the Players that are on world one per say. Now if you are on world two I would like it to have the option for you to be able to Private message players that are on World one. That is where the login server comes in to play.

I am still new at Java and would like to be able to understand Packets and how to handle them more clearly. So far I have gotten the basis of the login server connected to the server and the client connects to the server via the login server. But I am getting a bunch of "unhandled packets" and I would like to know how to handle them. Here are some bits of the code.

package com.ls.net;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;

[Code] ....

So when I run my client this pops up in the console:

[Tue Sep 16 16:50:56 EDT 2014][LoginServer]: Finished initializing login server.
[Tue Sep 16 16:50:56 EDT 2014][SignalMultiplexer]: Unhandled packet: 15
[Tue Sep 16 16:50:56 EDT 2014][SignalMultiplexer]: Unhandled packet: 41
[Tue Sep 16 16:50:56 EDT 2014][SignalMultiplexer]: Unhandled packet: 74

[Code] ....

And here are the class's for Accounts:

package com.ls.net.codec.decoder.packets;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.ChannelHandlerContext;
import com.ls.bufutils.BufferUtils;
import com.ls.net.codec.decoder.PacketDecoder;
import com.ls.net.codec.decoder.handlers.AccountHandler;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: 2D Spaceship Game - Image Rotation And Position

Aug 29, 2014

I'm attempting to create a 2D spaceship game from scratch. My problem is that I feel like the way Im rotating images is awkward and just wrong. I believe what I'm doing in the following code is loading an image into a JPanel and rotating the image and moving the JPanel.

The code is unrefined and only partial, but it show how I am manipulating images.

import java.util.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.geom.AffineTransform;
import javax.swing.*;
import java.lang.Math.*;
import java.io.*;
import javax.imageio.*;

[Code] .....

What seems so awkward is that I have to create a new JPanel for every image, I would think there is a better way but I don't know. I have tried to get one image on top of an other with the JPanels to no avail. That said I haven't put much time into trying to get that to work. I want to know if I should continue my attempt with JPanels or to pursue a different method.

View Replies View Related

Complicated ArrayList Function - Moving Between Fields Which A Player Can Perform Based On Game Rules

May 27, 2014

I have been working on this function and i can't get it to work. It's a little bit complicated so let me first explain what this is about:

1. As a little exam in my studies i have to program a halma console game with KI an stuff.

2. Everything is finished and works except for the Move-Calculation.

3. A Move is a Move from Field a to Field b which a player can perform in one round based on the game rules (Careful: We are not using the standard halma rules, we use different ones).

4. Class Move consists of the Starting Cell where the Figure before the Move stands and a target Cell where the figure will stay on at the Move end. It may include an Array of serveral Cells, the stop cells which the figure passes from start -> target since several jumps can be performed in one Move.

Valid Examples for Moves:

a -> b (From Field a to Field b)
d -> f through g,h,i (From Field d to Field f through the Field g,h,i

My Move Calculation where all possible Moves are calculated for a given figure consists of 2 parts. An expand() function which will generate all possible moves (works perfectly) and a jumpFix() function which isn't working properly.

Example:

After expand() I'm getting something like that:

a -> b
b -> c
c -> d
s -> t

This is however not finished, because the first 3 Moves are actually 1 Move. Because the player can Move from a -> d in one turn because those 3 are consecutive Move. The fixed Move would look like that:

a -> d through b,c

jumpFix() is also perfectly working for that situation, however there is one specific situation when it doesn't work. Let's say we have this situation.

a -> b
b -> c
c -> d
b -> e
e -> f
f -> g
s -> t

Then the only valid jumpFix() output would be:

a -> d through b,c
a -> g through b,e,f
s -> t

However i can not get it to work yet. Note: It definitely needs to be iterative, not rekursive else i would get an StackoverflowError.

This is my current Code of jumpFix():

Java Code:

/**
* Takes a look into all calculated moves and finds those which should be seen as one move, but are still considered to be more than one move (several jumps in one move)
*/

public static List<Move> jumpFix(List<Move> moves) {
Set<Move> result = new HashSet<Move>();
Set<Move> remove = new HashSet<Move>();
int lastSize = -1;
// repeat action until no moves could be merged
while (lastSize != remove.size()) {

[Code] ....

How to implement the special case where a Move splits into 2 or more branches and jumpFix() able to handle this case.

View Replies View Related

Player One Type A Number And Player Two Suppose To Guess - Infinite Looping

Apr 2, 2014

Its a basic program that is played by 2 people. Player one is suppose to type a number and the second player is suppose to guess the number. However after I test it out, and if I guess too low or too high I get stuck in "Your guess is too low, try again." infinite loop, what is wrong.

import java.io.*;
class GuessingGame
{
public static void main (String[] args) throws IOException
{
BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
String firstPlayer, secondPlayer;
int firstInput, secondInput;
int guessCount = 0;

[Code] .....

View Replies View Related

How To Resize Array With Keeping Previous Value

Jan 29, 2014

Suppose i have a book class and bookArray class.in book class contains four fields name,id ,publisher and author. in bookArray class: book bookArray=new book[20]; i have to save those four fields in the array but after completed the array i should have re-size the array with contains the previous data. How?? I have pass those values from the main class..

View Replies View Related

Splitting A String While Keeping Some Spaces

Jan 21, 2014

I am trying to split a string into a String[] tokens array to declare variables for an object; however, I'm having an issue getting the string to tokenize correctly. Here's an example of the input:

a : 100 : John Smith : 20 Main St.
a : 101 : Mary Jones : 32 Brook Rd.

Here is the basic code I have now, to properly sort each line of text, etc. (without the split() method):

Java Code:

while (scanner.hasNextLine()) {
currentLine = scanner.nextLine();
lineScan = new Scanner(currentLine);
if (currentLine.startsWith("/") || currentLine.trim().isEmpty())
continue;

[Code] ....

I was able to eliminate the comments and identifiers from the text by trimming the first two characters of the string. For the split, I tried String[] tempArray = currentLine.split("s+"); however, that also took the spaces out of the addresses and names...so the results looked like this:

100
John
Smith
20
Main
St.

As you can see, it splits via space regardless, including where I replaced all the :'s with spaces. Is there any way to do this?

View Replies View Related

Calculate And Store Value Into String The User Selected And Keeping It Going

Oct 28, 2014

This is the first time we are using 2 different classes. This is the code I have so far. What I am having trouble is doing the calculations and storing the value into the planet the user selected and keeping it going. I will attach the instructions ....

public class FakeGravity{
// Instance variables
private String planet;
private int VelocityDecay;
private double BouncinessFactor;
// default constructor
public FakeGravity(){

[Code] ....

View Replies View Related

Iterating Through Months While Keeping In Mind Different Length Of Month

May 20, 2015

I have to create a method to find the current month with the input being a number of milliseconds using System.currentTimeMillis(). Now I was able to solve the problem with the following extremely cumbersome method:

public static int monthLeap(long ms) {
int result = 0;
int jan = 31, mar = 31, may = 31, jul = 31, aug = 31, oct = 31, dec = 31;
int apr = 30, jun = 30, sep = 30, nov = 30;
int feb = 28;
int febLeap = 29;

[Code] ....

I first go through a loop that goes through all the years and subtracting the number of days of a normal year or a leap year in milliseconds from the total milliseconds. At the end I should have a rest value of milliseconds that represents the amount of milliseconds that have passed already this year. Out of this number I then find the month we are currently in.

My problem is that the above method is way to large and I get a checkstyle warning: "NPath Complexity is 12,288 (max allowed is 80)".

I know that this can somehow be solved with a for loop iterating through the time and counting up months until there is no more month left. My problem though is the different lengths of the months. If each month was the same I could just subtract the amount of days in each month from the rest value.

(Since I already got it down to <= 12 months, I shouldnt bother with the extra days to find the month. Yet if I want to find the month when the date is the first or last day of the month it is important to be very precise) ....

View Replies View Related

JDBC :: Connection Pool Keeping More Than Necessary Inactive Connections

Jun 19, 2015

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production0PL/SQL Release 12.1.0.2.0 - Production0CORE12.1.0.2.0Production0TNS for Linux: Version 12.1.0.2.0 - Production0NLSRTL Version 12.1.0.2.0 - Production0 

Using JavaSE-1.7
Using ucp.jar,ons.jar and OJDBC7.jar

I set up the datasource as follows :
 
pds = PoolDataSourceFactory.getPoolDataSource();
  pds.setConnectionFactoryClassName(factoryClassName);
  pds.setMaxPoolSize(maxPoolSize);                                                       maxPoolSize  10
  pds.setMinPoolSize(minPoolLimit);                                                        minPoolLimit 1

[Code] ....
 
In the class that actually uses it I create a method variable for the connection object.

Closing the connection as well as pds.getConnection().close();e

I am thinking that at the most I should have only one inactive connection showing up when I monitor the session. How do I configure the pool as to only show on inactive connection? I am running the test queries once every five minutes. But I am opening three connections each time.

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







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