gridworld snake game all over the internet, but all of those are the "snakebug extends Bug" version, mine is different. im behind everyone else in apcs so i rarely have any idea what im doing(gridworld especially). our teacher gave us most of the code, which i coped down (hopefully correctly) and he told us that we still needed to fill in the "removeTail" method which i did. basically the snake moves by placing a segment in front then removing the last segment.
When i click run the snakerunner file, i can make the snake segment rotate by pressing the arrow keys, but it doesn't move. when i click the "run" on the gridworld window, the single snake segment just disappears. so the move method is triggering the "removetail" method but it isn't placing the next segment. im starting to think that i copied something wrong from the board, because he showed us the entire move method. i have attached my gridworld files, what is wrong with my snake.java that makes the move method delete a segment but not add one
I tried to make a runnable snake game. When i try to run my code i get this:
Exception in thread "main" java.lang.NullPointerException at Game.Move(Game.java:85) at Game.run(Game.java:244) at Game.main(Game.java:38)
The game runs, but the snake doesn't move, and apples are spawned everywhere.
Here are Move, run and main code:
public static void main(String[] args) { JFrame frame = new JFrame("Snake"); Game game = new Game(); frame.add(game); frame.setSize(406, 430); frame.setVisible(true); frame.setResizable(false);
I am busy programming a clone of the popular phone game they had on Nokia cellphones a long time ago called Snake II but since I know very little about programming I will be using ASCII graphics instead of a 2D graphics engine.
My idea for implementation is having a main class called game which should refresh a grid of ascii characters every, say 0.2 seconds. Then I have another class called Dot. Each Dot object has x and y coordinates, and a direction in the x and y planes (dirx = -1 means left, dirx = 1 means right, diry = 1 means up, diry = -1 means down, and obviously the snake cant move the diagonals)
The Game class prints a "*" symbol where the Dot is, and what I'm trying to do is get the screen to refresh (I think I need to use the sleep() function for this to slow the game down to a reasonable pace), and go in the direction it is supposed to go.
(I haven't programmed this in yet but the snake will be an array of Dot, and at each refresh Dot at position 0 will pass it's coordinates and direction to Dot at position 1, Dot1 to Dot2, Dot2 to Dot3, etc.
Here's my code so far:
A first class called Game.
Java Code: //Not done yet but this is the start to my game of Snake. Basically the class Game generates a Grid of ASCII characters
import java.util.Scanner; public class Game { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); final int WIDTH = 79;
[Code] .....
My problem now is that I am taking input from the Scanner class. What it does is wait for my input, then it goes on to executing the rest of the code in other words refresh the ASCII grid. This is a problem because I need the snake to keep moving at constant pace while listening to the keyboard.
How can I get my while loop to keep going (i will add a sleep() function later) while listening to the keyboard without stopping?
I've been using grid world with my school. It's a part of the eimacs textbook. the following code that I wrote for gridworld. It's a very small tad bit of code:
Actor actor = new Actor(); actor.putSelfInGrid( grid, new Location( 5, 3 ) ); public void setColor (Color RED);
I am making a chess game in Gridworld. My pawn method is not working. For example, when I use getMoveLocations() on a pawn the first time, it brings up both valid moves. Once I move it two spaces and use getMoveLocations() again, it brings up the space behind the pawn. When I move it there, and then I use getMoveLocations(), it just brings up an empty ArrayList.
I have a question about updating a grid during runtime in GridWorld. I'm making a game called Flood-It (basically, you click on squares to change their color and attempt to get all of the squares the same color in the grid) and I'm having trouble with changing the grid size. I made my own world class, called CellWorld.
Whenever a user wants to change the grid size after playing the game, this is supposed to set the grid to the new updated size, but it never changes in the actual game, i.e. the user just won a 2x2 game, attempts to change the size to 10x10, but the grid stays 2x2. By debug testing, I can say for certain that everything else works, such as the maxStepCalc and loading the grid. The only issue is the new grid not showing up.
I am having a problem with my java program. My goal is to request the user to enter how many times they want to roll a pair of dices. Each dice have numbers 1-6. When rolling the dices, I randomly pick a number from each dice and total the number. My goal is to calculate the number of times snake-eyes was rolled which is a total of 2 and total number of times a total of 7 was rolled. Here is my code. I am calling the rollDice method to perform the random pick and calculations. The error I am getting is at the bottom of the code.
package dice; import java.util.Scanner; import java.util.Random; public class Dice { public static void main(String[] args) { int numRolls; // number of rolls
[code]...
How many times would you like to roll the two dice? 1000 Exception in thread "main" java.lang.NullPointerException at dice.Dice.main(Dice.java:40) Java Result: 1 BUILD SUCCESSFUL (total time: 4 seconds)
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;
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've been at this for a while and I would like to make the Camera in my game follow the player and I know the way to do this would be to move the map and not the player. How would I do this if my map is rendered from a text file using for loops. Here is my code for the map.
package Game; import java.awt.Graphics; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Map {
I am creating a simple AirHockey game in Eclipse Java Jframe. I was just wondering how it is i add a score keeper to my game. for example if player 1 scores a goal 1 is added onto there score at the top.
import java.util.Scanner; public class TicTacToe { public static void main(String[] args) { //Create scanner Scanner in = new Scanner(System.in); //Declare variables to hold the board
[Code] ....
I need to create a while statement for random computer moves.
I'm making a game which lets the player move around with arrow keys, but my KeyListeners are working less-than-satisfactorily. I googled this and I found that I should use KeyBindings.
1) Right now I have booleans for each key used in the game. When a key is pressed, the boolean is set to true, and set to false when it is released. In the ActionListener for the Timer I have, I then check if each is pressed or not, and do the corresponding action. I do this so that movement is smooth.If I was to use KeyBindings, would I use the same technique, or would I just do the action in their Action?
2) How do I do it? From the example I thought was most useful, this is my guess: (this code would be in a JPanel)
Java Code:
this.getInputMap().put( KeyStroke.getKeyStroke( "ENTER" ) , "doEnterAction" ); this.getActionMap().put( "doEnterAction" , EnterAction ); static class EnterAction extends AbstractAction { public void actionPerformed( ActionEvent tf ) { enterKeyIsPressed=true; //If using this method, I would also have a separate InputMapping, ActionMapping,
I know a lot of people taking beginning java courses have posted questions about creating a tic tac toe game, but here is another one. Below is my code. I can't seem to get the X's and O's to show up on the board or to determine a winner.
import java.util.*; public class Trial3 { public static char turn; public static int count; public static void main(String[]args) { Scanner input=new Scanner(System.in); char[][]b=new char[3][3]; boolean flag=false; count=0;
Create another class called Race with a main method. Make some Car objects, and use them in a race.The first race will have 2 cars. The main method only needs 2 local variables, i.e. the 2 Car objects.
-The length of the race is 1000.
-Both cars will start out with a speed of 30.
The race will be implemented as a loop. Each time through the loop:
-Your cars will move to a next location by adding their current speed to their location. (If the speed is 50, and they are at location 200, then change the location to 250.)
-Call out the race (SOPLs) like a NASCAR announcer: Andretti is in the lead at position 365. He is flying at 30 mph!
-Or It's neck and neck with both cars at position 45 or something more creative that you can come up with.
-Each car will increase or decrease their speed randomly each time through the main loop.
-The car that is behind will increase its speed by 2 mph, and the car that is in the lead will decrease its speed by 2 mph. (Tighten the race to make it more exciting.)
-The loop will continue until one of the cars is declared to be the winner.
This is my code so far.
public class RaceCarsMain { public static void main(String[] args) {
int length = 0;
Cars c = new Cars("Andretti", 30); Cars c2 = new Cars("Fiviotini", 30); while (c.getLocation() < 1000){ length++; c.randomSpeedChange(); c.accelerate(2); c.deaccelerate(2); c.locationchange();
[code]....
I have been able to print out the first car "Andretti" until its location reaches 1000, but the 2nd car I have not being able to print out the change of speed and change of location.how to proceed and making the 2nd car do the same, do I have to create another class? or how can i use the Cars class to do it for both.
When the tile loads it loads at the side where i wanted it to be and when my character falls down the image/tile stretches to the collision and stops. looks like this stretches.jpg
Our assignment is to make a version of the classic 'Connect Four' game, where we need to construct a GUI that shows the current state of the game and instead of having a winner once a player has four chips in a row, the game needs to continue until no chips can be placed anymore.We currently get stuck in the GUI part. Running it right now results in a board with empty spaces only. Also after choosing a column to place, the board remains empty.
Our question: How do we get the board filled with the right color of chips at the right place?We know the 'ArcsPanel'-class (almost at the bottom of the code) is wrong, but we don't know what to do to make it right.
how to make a simple game. I am having trouble when it comes to adding sound though. It tells me to do this:
package net.game.Game;
import java.applet.Applet; import java.applet.AudioClip; public class Sound { public static final AudioClip BALL = Applet.newAudioClip(Sound.class.getResource("ball.wav")); public static final AudioClip GAMEOVER = Applet.newAudioClip(Sound.class.getResource("gameover.wav")); public static final AudioClip BACK = Applet.newAudioClip(Sound.class.getResource("back.wav")); }
What this does is it gets the sound file then gives it a name(BALL=ball.wav GAMEOVER=gameover.wav ect..) and then there is other code in other classes that call the sound so it will run but it keeps giving me an error and I don't know what to do. How can I get it to import the sound? Here is the error.
PHP Code:
Exception in thread "main" java.lang.ExceptionInInitializerError at net.game.Game.stuff.<init>(stuff.java:35) at net.game.Game.stuff.main(stuff.java:62) Caused by: java.lang.NullPointerException at sun.applet.AppletAudioClip.<init>(Unknown Source) at java.applet.Applet.newAudioClip(Unknown Source) at net.game.Game.Sound.<clinit>(Sound.java:7) ... 2 more
I am new to java, i can develop basic java programs but am not really good at it. How should i pursue and how should i start. I know the game rules.Do i need to learn swings for the same?
This code is for a tic tac toe game. I have a action listener set up and if the user entered a move that would win the game of tic tac toe it would call on a restart() method to clear the board, but every time some one wins the GUI freezes.
class ListenerCA implements ActionListener { public void actionPerformed(ActionEvent event) { Board.clear(); if (turn == 0) { start.answer = "CA";
[Code] .....
The code below this is the normal execution flow.
static void start_game(String board[][]){ final int one = 1; final int two = 2; int x = 0; play game = new play();
[Code] .....
In the above code gui == true always, I just kept an option if i ever wanted to run the program in console. The code below is the restart method.