Java Snake

A fairly simple Rock — Paper — Scissors game which will allow two players to play with each other. Follows the basic rules of the game where:.

2 player game java code

When both users have entered their choice it will then decided based on the rules above who is the winner or if it is a tie. At the end of the game the users have the option where they would like to play again or quit. If they choose to quit they will be given an overview of the results which are carried on in every game played. You are commenting using your WordPress.

You are commenting using your Google account. You are commenting using your Twitter account. You are commenting using your Facebook account. Notify me of new comments via email. Notify me of new posts via email.

Ratu jp hongkong

What it does: A fairly simple Rock — Paper — Scissors game which will allow two players to play with each other. Follows the basic rules of the game where: Rock defeats breaks Scissors. Scissors defeats cuts Paper. Paper defeats covers Rock. Like this: Like Loading Leave a Reply Cancel reply Enter your comment here Fill in your details below or click an icon to log in:. Email required Address never made public.

Name required.

2 player game java code

Post was not sent - check your email addresses! Sorry, your blog cannot share posts by email. By continuing to use this website, you agree to their use. To find out more, including how to control cookies, see here: Cookie Policy.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It only takes a minute to sign up.

I've made a player class, but have run into a code efficiency issue. In the method setAttributesit determines the baseline stats for the newly created player. I use multiple if statements to achieve this. First, I would not use Strings here to represent class types. Say you accidentally typo a class name:. Now setAttributes silently "fails" and doesn't set anything. You could manually handle bad cases like this, but now you're handling bad data at runtime that could have been caught at compile time.

The immediate benefits are IDEs can help auto-complete enum names so typos are difficult to cause, andif you do typo a name, it will fail with an error at compile time instead of having code-dependent effects at runtime.

This doesn't answer your main question, but it's an important point. Don't use Strings to mark "members of a set", like you're using in this case to mark members of the player class set.

Holmes 750

I'd refactor your class a bit to make dealing with class stats easier. I think Player is too big, with too many fields. I would create a Stats class:. There's going to be bulk somewhere that decides what stats each class have. You just need to find how you can organize the bulk so it's readable and easier to deal with. The main issue with this design choice is hp and mp are now a part of Statswhich feels a little odd since these are "fluid" values that can change often.

Now to damage the player, you need to alter player. It may be better to change hp and mp in Stats to maxHp and maxMP since you'd likely need to track those values anywaysthen give Player back hp and mp fields that you alter as needed. First of all, mine is an addition to Carcigenicate's answer. This is taking some of the concepts one step further and refining them using design patterns.

I agree with the comment - this does suck. The problem here is remembering what is what, when we do new Stats 1, 2, 3, 4, 5, 6, 7, 8, 9 it's very hard to remember what 6 is or if that's even the correct number of arguments. I even had to check three times to make sure it was correct and even then I found I had miscounted. To solve this problem, we can use the Builder pattern :. Note: a lot of IDEs have support to generate this for you via refactoring tools. They can even replace any direct calls to the constructor with using the Builder.

Since it a fluent interface we can chain the calls, so. We now know exactly what you're setting to what without needing to look up the values. We can even set these in any order you want. The Builder can also make copies of the stats for you if you just define a method Stats buildFrom Stats otherStats that takes a Stats object and creates a new one copying each property.Jump to content.

You currently have javascript disabled. Several functions may not work. Please re-enable javascript to access full functionality. Siten - Jun 20 PM. PJohnson - Apr 18 AM. Barnsite's Blog 17 Jun. Barnsite's Blog 01 Oct. Barnsite's Blog 12 Jun. Barnsite's Blog 01 Jun. Posted 06 October - PM. Here is the Tic-Tac-Toe Game i have made! I am actually very impressed with the layout I have done and it looks pretty cool if i do say so myself lol. I will be working further on this to add like a High Score thing and like asking the user for the names and the CPU and more when i think of some good ideas to add on to this.

So thank you for that John Here is the code and no. Besides this tic-tac-toe tutorial from Johndefinitely check out his Java tutorial series! Posted 11 October - PM. Here is another Version of Tic-Tac-Toe.

I still haven't done the computer AI yet but that will come in next version! Hope you like what I have done so far. Posted 13 October - PM.

Posted 24 November - PM. Posted 03 December - PM. Posted 08 December - PM. Posted 10 December - PM. Posted 29 December - AM. Posted 12 January - PM. Posted 17 January - PM. Posted 24 January - AM. Community Forum Software by IP. Why Join Codecall?

TwoPersonZeroSumGame.java

Register with Facebook Register with Twitter. Javascript Disabled Detected You currently have javascript disabled. Check out our Community Blogs. Register and join over 40, other developers! Learn algorithms and programming concepts johnnylo - Apr 23 AM.

How to make code run differently depending on the platform it is running on? How do I set a breakpoint in an attached process in visual studio xarzu - Apr 04 AM.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It only takes a minute to sign up. I'm a first year uni student. We were asked to come up with code that can represent a simple two players dice throwing game specifications are given below. I know as a matter of fact that there are many areas upon which my code could be improved.

However, rather than asking other people to correct my code, I would much prefer to be given hints or general principles as to how my code could be improved. I think I could get more out of this exercise this way. So could someone please provide me with some comments or suggestions?

Critics of any level and kind are welcomed! Feel free to pick apart my code! For this assignment you will write a program that simulates a rather simplistic Dice Throwing Game. This section specifies the required functionality of the program. The aim of the Dice Throwing Game is to simulate a simple game for 2 players, where they take turn to each roll a dice twice, and score points according to the results of the dice rolls.

The winner is the one who accumulates a pre-defined maximum score first. Your program will display a menu which allows the user of the program to select various options to simulate the various operations. Results of all the operations will be printed on the screen as plain text only eg. The program will update each player's current score accordingly. For this assignment, the program will only handle TWO players. It will keep track of the current score of the players until one, or both, reaches the pre-defined maximum score, agreed upon at the start of the game.

The Dice Throwing Game begins with a welcome message followed by a menu with the following options :. Option 1 asks the 2 players to enter their names. If this option is chosen again after the players have already been set up, 2 "new" players are set up ie.

Note that the new players replace the previous players — there are only ever two players at any one time. After the names are set up, the game asks for a maximum score. The default maximum score should be set to points.

Teamsters history

When this option is chosen, the computer generates 4 random numbers between ie. It then updates both players' scores accordingly. The scoring rules for each "round" are as follows :. The menu must be displayed repeatedly after each operation, until the user chooses Option 5. Inputs other than should be rejected, with appropriate error messages printed. The displayGameMenu method prints a list of options.In this part of the Java 2D games tutorial, we create a Java Snake game clone.

Source code and images can be found at the author's Github Java-Snake-Game repository.

Coding with Notch (from Minecraft: The Story of Mojang)

Snake is an older classic video game. It was first created in late 70s. Later it was brought to PCs. In this game the player controls a snake. The objective is to eat as many apples as possible. Each time the snake eats an apple its body grows. The snake must avoid the walls and its own body. This game is sometimes called Nibbles.

The size of each of the joints of a snake is 10 px. The snake is controlled with the cursor keys. Initially, the snake has three joints. If the game is finished, the "Game Over" message is displayed in the middle of the board. In the loadImages method we get the images for the game.

In the initGame method we create the snake, randomly locate an apple on the board, and start the timer. If the apple collides with the head, we increase the number of joints of the snake.

We call the locateApple method which randomly positions a new apple object. In the move method we have the key algorithm of the game. To understand it, look at how the snake is moving.

Java Source Code: Tic-Tac-Toe Game

We control the head of the snake. We can change its direction with the cursor keys. The rest of the joints move one position up the chain. The second joint moves where the first was, the third joint where the second was etc. In the checkCollision method, we determine if the snake has hit itself or one of the walls. The setResizable method affects the insets of the JFrame container on some platforms.

Therefore, it is important to call it before the pack method. Otherwise, the collision of the snake's head with the right and bottom borders might not work correctly.GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. If nothing happens, download GitHub Desktop and try again. If nothing happens, download Xcode and try again. If nothing happens, download the GitHub extension for Visual Studio and try again.

War is a card game for two players. A standard deck of 52 cards is dealt so that both players have 26 cards. During each round of play or "battle"both players play a card from the top of their hand face up.

The player who plays the card of the higher rank wins both cards and places them at the bottom of his stack of cards.

If both cards played are of the same rank, then both players play three additional cards face down and then one more card face up this is called a "war". The player who wins the war by playing the higher card wins all ten cards. If the ranks are still the same, additional wars are played until one player wins the turn.

If either player runs out of cards to play, he loses the game. You will use only ArrayLists to store the cards in this program.

This means cards cannot be stored in arrays.

Subscribe to RSS

Skip to content. Dismiss Join GitHub today GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Sign up. WAR is a simple game — 2 people play. One card is dealt to each player, face up. The highest value card wins. Java Branch: master.

Find file. Sign in Sign up. Go back.

2 player game java code

Launching Xcode If nothing happens, download Xcode and try again. Latest commit Fetching latest commit…. Sample output might look like this: player 1 plays Card is 9 of Clubs player 2 plays Card is Ace of Diamonds player 2 wins the round player 1 plays Card is 10 of Diamonds player 2 plays Card is Ace of Hearts player 2 wins the round player 1 plays Card is 7 of Clubs player 2 plays Card is 6 of Hearts player 1 wins the round player 1 plays Card is 9 of Hearts player 2 plays Card is 9 of Clubs war war card for player1 Card is xx war card for player2 Card is xx war card for player1 Card is xx war card for player2 Card is xx war card for player1 Card is xx war card for player2 Card is xx war card for player1 Card is 7 of Clubs war card for player2 Card is 10 of Diamonds player 2 wins the war round player 1 plays Card is 6 of Hearts player 2 plays Card is Ace of Hearts player 2 wins the round game over player 2 wins the game.

You signed in with another tab or window.In this programming challenge you will create a simple trivia game for two players. The program will work like this:. In this program you will design a Question class to hold the data for a trivia question. The Question class should have member variables for the following data:. The program should create an array of 10 Question objects, one for each trivia question. Make up your own trivia questions on the subject or subject of your choice for the objects.

The problem In this programming challenge you will create a simple trivia game for two players. The program will work like this: Starting with player 1, each player gets a turn at answering five trivia questions. There are a total of 10 questions.

React navigation dismiss modal

When a question is displayed, four possible answers are also displayed. Only one of the answers is correct, and if the player selects the correct answer he or she earns a point. After answers have been selected for all of the questions, the program displays the number of points earned by each player and declares the player with the highest number of points the winner.

The Question class should have member variables for the following data: A trivia question Possible answer 1, 2, 3, and 4 The number of the correct answer 1, 2, 3, or 4 The Question class should have appropriate constructor saccessor, and mutator functions.

Old Fashioned 3. Manhattan 4. Bloody Mary Enter the number of the correct answer: 1 Correct! Question for player 1 Consecrated inwhere is the Cathedral Church of St Michael? Church of Hope 3. Sagrada Familia 4. Notre Dame de Paris Enter the number of the correct answer: 1 Correct!

Question for player 1 How many tentacles does a squid have? TEN 2. Eight 3. Nine 4. Five 5. Four Enter the number of the correct answer: 1 Correct!


Replies to “2 player game java code

Leave a Reply

Your email address will not be published. Required fields are marked *