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


ADVERTISEMENT

How To Display Players Score In Panel

Jun 19, 2014

So I'm working on this game for a school project and I have 2 problems

1.I do not know how to display the players score in the panel
2.Every single time the console reads the second button I click on as a 0 instead of the number underlining it

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.*;
public class Matchgame extends JPanel implements ActionListener { 
private final JPanel Brd = new JPanel(new BorderLayout(3, 3));

[Code]...

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

Football Manager - Find Out Optimal First Eleven Amongst 25 Or 30 Players

Nov 26, 2014

I am looking into making a program, that will find out the optimal first eleven (in football or soccer for americans) amongst 25 or 30 players. This is going to apply for a computer game: "Football manager 2015"

I was thinking one class would be the player class that is going to have the variables:

player_number (unique) integer
name string
position (there are eleven positions)
position_rating for each position capable of playing

constructor would be add_player(int number, string name)

and a method would be add_position(position, position_rating)

one player can have more than one positions

another class would be the position

position name (unique) string

that's all I can think of now.

the main class would do a loop

starting with a random or defined position it would do all combinations of every single player into each position.

For example it could start with center forward position. There are 5 available players for that position. Lets say the program picks the first player that is also capable of playing in wide position. If the player is picked for center forward he is not avaialable for wide position.

Then the program would move to the wide position and lets say there are 4 players available. It would pick one.

Once 11 players are selected it would add the 11 ratings.

and start over for a different player in center forward position.

at the end of all loops it would print out the 11 players into their respective positions that got the best score.

View Replies View Related

JOptionPane - Display Total Number Of Goals Scored By All Players

May 22, 2014

JOptionPane.showMessageDialog(null,myRoster.totalGoalsScored + " is the total number of goals scored by all the players on the roster");

HOW CAN I CALL THE METHOD totalGoalsScored and display it using JOptionPane

ERROR: CAN NOT FIND SYMBOL

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

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 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

Colors In Java

Aug 4, 2014

So i was thinking about colors in java and was wondering what kinda colors are regonised by java..found this java.awt.color.. which goes very indepth with transparancy(alpha) and other formats of colors..

Question:

I wanne make a programm in java that breaks up a picture(pixels) and put it together again..Storing values of the colors and so forth..Which format of colors would be easy to start with if taking about java programming? RGB?

View Replies View Related

Store A Number Of Different Value Cards For A Number Of Players?

Feb 18, 2014

i am trying to store a number of different value cards for a number of players. E.g there can be 2 , 4 or more players and each player can have any number of cards.

I have decided to use an arraylist for cards and tried using an array for players. But after coding and reading some information online, i realised that it is not possible to have an array of arraylist.

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

IndexColorModel 255 Colors To BufferedImage

Apr 4, 2014

I need to write an image to a .png with a 255-color indexed color model. I know usually do it like this: Java Code: BufferedImage img=new BufferedImage(width,height,BufferedImage.TYPE_BYTE_INDEXED,model); mh_sh_highlight_all('java'); but that doesn't work with models with 255 colors (as opposed to 256 colors). I'm fairly sure it is the BufferedImage creation that is the problem, as when I call model.getMapSize(), it returns the correct size.

The extra color added to the image's index is 15,15,15.

Should I be something other than a BufferedImage to write the image, or should I be using a different constructor for BufferedImage, or am I doing something else wrong?

View Replies View Related

Swing/AWT/SWT :: Button Colors Different In XP And Win 8

Jan 26, 2015

I have a program I wrote long ago. I change colors of buttons at times. Here is the code:

for(int Player=0; Player < 8; Player++){
//make them all background
dealerLabels[Player].setBackground(new java.awt.Color(212,208,200));
}
//Now make the new dealer green
dealerLabels[dl].setBackground(new java.awt.Color(51, 255, 0));

The color of the buttons has always changed under XP but when I run the program on Windows 8 only the edges of the buttons change.

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

Multiple Colors For A Text Field

May 25, 2014

I have a question about JTextArea colors. When i set the color to blue and then write something on the JTextArea (JTextArea.append) and then set it back to black everything will be black. How can i solve that? Like in Notepad++ or Eclipse when you write keywords in a JTextArea (where you write your code) only some words change color.

This is my code:

// All the imports
public class whatever extends JFrame {
JTextArea a = new JTextArea();
public whatever() {
super("Title");
add(a);

[code]...

View Replies View Related

How To Keep Colors / Layout And Formatting After Generating JAR

May 10, 2014

After generating a. JAR with Netbeans Java, when I play I see the colors of the components, the design and formatting is lost and the form gets a very basic formatting, for example, if I set a button with the color [0, 40.255] and build the. JAR after this, when I run the. JAR this button turns gray, and it happens with all the layout of the form.

settings:
Netbeans 8.0
Windows 7

View Replies View Related

Adding Borders And BG Colors To JTable

Jul 28, 2014

I have a 30 X 10 JTable which i would like to put a border around some cells and change Background colors on others.For example i would like to put a border around cells 1,1 to 15,1 I would like to change background colours on several individual total cells.What the shortest way to color individual cells and add a border?

View Replies View Related

How To Keep Colors / Layout And Formatting After Generating JAR

May 11, 2014

After generating a. JAR with Netbeans Java, when I play I see the colors of the components, the design and formatting is lost and the form gets a very basic formatting, for example, if I set a button with the color [0, 40.255] and build the. JAR after this, when I run the. JAR this button turns gray, and it happens with all the layout of the form.

settings:
Netbeans 8.0
Windows 7

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







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