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.
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));
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
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.
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.
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);
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;
I have a class that retrieves an image, and a class that is a game. I want to put my image onto the game to use it as the main figure. As of right now in eclipse, the game class runs, so the game works, but the image doesn't do anything. Need to put the image into the game? Here is my image class:
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.
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.
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.
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.
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.
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;
Write a class named FileDisplay with the following methods:
1.) constructor: the class's constructor should take the name of a fil as an arugment. 2.) displayHead: This method should display only the first five lines of the file's contents
Here is the following code I have made so far
import java.io.*; public class FileDisplay { private String filename; public FileDisplay(String Filename) throws IOException
[Code] ....
First, in my constructor I have taken in an argument and used that argument to open up an output file. Meanwhile, I'm trying to work n the displayhead method to print out information and to read data to. I haven't opened up my input file yet, but I'm not understand how can I read a print data to an output file. in
public void displayHead() {FileWriter file=new FileWriter(Filename)}
do I make create another instance of the filewriter class to output data?
In simple words, suppose to I want to display some messages on my output file in the displayhead function. Since I already have opened up the file in the constructor, how do I combine that in this method...
I tried this program, its guessing game. Where program decide 1 number and user will guess number. I am getting 1 problem. When user want to play game again.the random number remain same. So where i can put reset random in code..? And 1 more question if I want to write driver code for this. What should i transfer to driver code.
import java.util.Random; import java.util.Scanner; public class GuessGame { public static void main(String args[]) { String choice="y";
I am developing a product where the client needs to display the content of XML in a JSP page. This XML will be extracted from database and will be temporarily sotred in a String object and will then be flushed to JSP page for display. This was working fine unitl now. But now the customer wants display each tag with one color. attribute in another color and data in another color.
For ex: <?xml version="1.0" encoding="UTF-8"?>
this should be displayed in one color. Then
<ichicsrmessageheader>Data</ichicsrmessageheader>
In the above one the tag should be displayed in one color and "Data" should be displayed in another color
In the above sample tag should be in one color and attribute should be in one color ex: red and value of the attribute should be in another color ex: blue and "Data" should be in one color ex: green.
Here is the sample screen shot of how xml should is currently being displayed.
Im creating a program that has about 20 different input forms. Fairly standard forms but what i need to know whats the easiest way of creating forms. Is there some way of using templates or some plugin to quickly generate forms.
I am having trouble developing a 4x4 grid that has the letters A-Z and a-z and the corresponding ASCII numbers for each letter. I have created the code to retrieve these letters and their corresponding ASCII numbers, I only am having trouble with creating the grid and displaying these numbers and letters in their separate 4x4 grids: one grid for (a-z), one grid for (A-Z), one grid for (ASCII# a-z), one grid for (ASCII# A-Z).
Empty the following csv table to a map, where the key is a calendar, and the value is arraylist. The table represents the sock values of Google fro a period of time.
"Date,Open,High,Low,Close,Volume,Adj Close 12/8/2014,527.13,531,523.79,526.98,2323000,526.98 12/5/2014,531,532.89,524.28,525.26,2552700,525.26 12/4/2014,531.16,537.34,528.59,537.31,1388300,537.31 12/3/2014,531.44,536,529.26,531.32,1274500,531.32 12/2/2014,533.51,535.5,529.8,533.75,1521600,533.75
[Code] ....
----------------------------------------------- import java.util.*; public class Mymap { public static void main(String[] args) { Map<String,List<String>> map= new HashMap<String, List<String>>(); map.put());
I'm new to Web Services and I've been finding trouble when creating my first one. Before talking about the problem, I'd like to show you the process I followed to see if it's ok. Note that I'm using Eclipse Kepler, Tomcat 5.5 and Axis2.
1- I created a new Dynamic Web Project.
2- I created the Java class that implements the service with just one method, a simple one: you pass it a name and it returns "Hi, <name>"
3- Right click over that class and then: Web Services -> Create Web Service
4- I go through the next steps. On the last one, I select "Launch the Web Services Explorer to publish this Web service to a UDDI Registry". Click on "Finish".
5- The Web Services Explorer is launched, but I just get a "HTTP ERROR: 500" message.
I understand that my Web Service wasn't published and therefore it's useless to create a client as it wouldn't connect.
1) Instead of showing 0K 5K 10K, I would like to show the country names (A - D), with no number or tick. I figured out this one by just commenting out all the codes relating to ticks.
2) Place the country names in the center of the arch. I don't know how to do this one.