Giter Club home page Giter Club logo

cs56-games-rock-paper-scissors's Introduction

cs56-games-rock-paper-scissors

project history

 W14 | bkiefer13 4pm | lesleykhuu | (jcneally) rock paper scissors game using Pokemon
 W15 | mliou (mentor) | brandonwicka & jordannguyen 4pm | (jcneally) rock paper scissors game using Pokemon

Overview

This program allows a choice between two games. The first game is a two player tic tac toe. The players get to choose which Pokemon (Squirtle, Bulbasaur, and Charmander) they want to be as their "X" and "O" pieces. The second game is rock-paper-scissors which also uses Squirtle, Bulbasaur, and Charmander as rock, paper, and scissors, respectively, to play against the computer.

Documentation

public class RunGame extends JFrame {

    private ButtonGroup group;

    public RunGame() {
        ...

        group = new ButtonGroup();
        JRadioButton ttt = new JRadioButton( "Tic Tac Toe", true );
        JRadioButton rps = new JRadioButton( "Rock Paper Scissors" );
        ttt.setActionCommand( "Tic Tac Toe" );
        rps.setActionCommand( "Rock Paper Scissors" );

        ...
    }

    public static void main( String[] arg ) {
        new RunGame();
    }
}

This is a snippet of code from the RunGame.java file, which is the class that starts up the program. It uses a group of JRadioButtons for the game selection options. The main function runs the constructor, which loads up the Home Screen.

public TicTacToe(ImageIcon first, ImageIcon second, String firstName, String secondName){
            this.image1 = first;
            this.image2 = second;
            this.name1 = firstName;
            this.name2 = secondName;
            panel = new JPanel ();
            panel.setLayout (new GridLayout(3,3));
            this.add(panel);
            button = new JButton[9];
            for (int i = 0; i <=8; i++){
				button [i] = new JButton();
				panel.add(button[i]);
				button[i].setEnabled(true);
				button[i].addActionListener( new TicTacListener() );
			}
	    ...

	}

This is part of the TicTacToe constructor, which is located in the TicTacToe.java file. The SecondPlayer class is the one that calls the TicTacToe constructor with the correct parameters after both players have selected their Pokemon. The tic tac toe game board is made up of 9 JButtons placed on a 3x3 GridLayout.

gc.insets = new Insets(5,75,5,5);
        ...

        gc.gridx=0;
        gc.gridy=4;
        rock.addActionListener(new RockListener());
        frame.add(rock, gc);
        gc.gridy=5;
        paper.addActionListener(new PaperListener());
        frame.add(paper, gc);
        gc.gridy=6;
        scissors.addActionListener(new ScissorsListener());
        frame.add(scissors, gc);

        ...  


    }

The layout for rock-paper-scissors is set up on the GameGUI.java class. This snippet of code shows that the rock-paper-scissors interface uses a GridBagLayout, which easily sets the (x,y) coordinates of JButtons and other JComponents.

How to run

To start the game, use ant run.

More info

Brief paths: Choose to play Tic-Tac-Toe or Rock-Paper-Scissors

Tic-Tac-toe game looks like this:

A player wins when he or she successfully places three pieces in a row. If the game board fills up before either player gets three in a row, a tie is declared.

Rock-Paper-Scissors game looks like this:

The user can select their Pokemon (Bulbasaur, Squirtle, or Charmander) from the bottom left to act as their rock, paper, or scissors. The computer simultaneously selects their own Pokemon randomly to play.

For a more in-depth look at this program, please visit the wiki.

W16 Final Remarks

The RunGame.java class is the intial game screen, where the player is promted to pick one of the games. The ActionListener of each selection sets up the starting screen for that game. There is currently a Run.java class that is supposed to set up the game screen for the rock paper scissors game, but it currently serves no purpose because the RunGame.java class takes on that responsibility more effectively. The RunGame.java class creates an instance of the GameGUI.java class (which contains all of the code for rock paper scissors and is difficult to modify or extend) to start the rock paper scissors game if the player selects that game option, or creates an instance of the ChooseOpponent class which brings up a separate window where the player can choose to either play against a computer or second player if tic tac toe is selected as the game. Since the previous editors/creators did not separate the rock paper scissors code into separate classes, it is very difficult to add features without introducing bugs into the rest of the code. So refactoring the code into a more object oriented design would be a good addition, but not an easy task. However, tic tac toe on the other hand, is nicely separated into classes and easier to modify. If tic tac toe is the game chosen, an instance of the PlayerName class is created and brings up a window where the user can enter his/her name to be displayed during the game(if there are two players, then two separate windows will appear successively for entering player names). If the player chooses computer as the opponent, the player is immediately redirected to pick their character and then to the tic tac toe game board; if a second player is playing, the second player will choose their character directly after the first player has chosen his/hers. Once both players have set up their game options, an instance of the actual tic tac toe class is created to bring up the game grid and calculates the winner of the game based on the player moves. The tic tac toe game is broken down into separate classes, while the rock paper scissors class is all implemented together in one class with several inner classes. One helpful addition to the code would be comments for each or most methods describing their function to the overall game. In TicTacToe.java, the firstPlayerWins() and secondPlayerWins() are almost identical and could be refactored into one function that takes the string name (the only variable that is different). In TicTacToe.java, the checkWinner() function duplicates code and could be refactored into a function that takes the player number as a paramater. In TicTacToe.java, some of the variable names (firstName, secondName, etc.) could be renamed for clarity.

M16 Final Remarks

Still, RunGame.java is the initial game screen where we can choose either tic tac toe or rock paper scissors. We done alot of refactoring to the program, getting rid of 4 classes that would create new JFrame's, which was completely inefficient. RunGame.java will be the starting base for whoever decides to work on this next. I would reccomend still refactoring before anything, because this code leaves little room for expansion. Here are some issues you might want to tackle first:

Get these issues done before anything. I wo

F17 final remarks

GameGUI.java, RunGame.java, and TicTacToe.java are where we mainly need to focus on. ย 

  1. GameGUI.java is responsible for the Rock-Paper-Scissor User Interface. We fixed a few bugs in this file, and there are still a lot of improvements can be made. For example, you can clarify characters in rock paper scissors (issue #32). My suggestion is to put rock paper scissor icons next to the three Pokemon buttons, so that it is more visible. Also, other features such as animations can be added here to make the program look better.
  2. RunGame.java is responsible for leading users to pick between these two games. One modification I made was using GridBagConstraints to align the buttons for tic-tac-toe to look nicer. I suggest you make the same modification for rock-paper-scissor and main menu UI as well. Also, because of lack of abstraction(put your tasks in your functions!), the code has many repeated parts. If possible, I suggest refactor the code to increase efficiency(issue #11).
  3. TicTacToe.java serves as an AI for TicTacToe game. It allows player vs computer and player vs player. The computer AI has three different difficulty levels to choose. Currently, the simple AI uses all random, and the medium and hard level has the same algorithm(yea, it is not that smart). You can discover a better TicTacToe AI algorithm to challenge players. In addition, the sound affects can be annoying for some users. You can create a option to disable/enable sound during the games(issue 16).

cs56-games-rock-paper-scissors's People

Contributors

athielk avatar brandonwicka avatar christiannewkirk avatar delinsun avatar giovannidominguez avatar hannavigil avatar hding1 avatar issacholguin avatar issacjames avatar jcneally avatar jordannguyen avatar kjorg50 avatar lanthony159 avatar lesleykhuu avatar mastergberry avatar mliou avatar omeedrabani avatar xosherry avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

cs56-games-rock-paper-scissors's Issues

Theme Options on Main Menu

On original game screen, add in an option to change the theme (current is Pokemon). This would require a lot of work to change code in different files, and would require new images for each theme.

Estimated ~350 pts.

Add more Pokemon choices to use as pieces for TicTacToe

Let the user select more than the current 3 Pokemon available to play with for TicTacToe (ie adding another Pokemon such as Pikachu to choose from). This also entails changing the GUI to display more choices efficiently if there gets to be too many Pokemon.

~Estimated 200

Add another game

Add another game using the pokemon images, such as a Tic-Tac-Toe game allowing the player to choose between the three pokemon instead of X and O.
Also should allow the user to switch between the new game and the current rock-paper-scissors game.

~estimated 500 points.

Help Button

Create a help button on the main game selection screen that brings up a page explaining how to play each game.

~Estimated 150

Unaccepatable Image Loading from Hardcoded Student Github Repo

NO INTERNETS.

java.net.URL path1 = new URL("https://raw.githubusercontent.com/giovannidominguez/cs56-games-rock-paper-scissors/master/src/edu/ucsb/cs56/projects/games/rock_paper_scissors/images/Charmander.jpg");
java.net.URL path2 = new URL("https://raw.githubusercontent.com/giovannidominguez/cs56-games-rock-paper-scissors/master/src/edu/ucsb/cs56/projects/games/rock_paper_scissors/images/Squirtle.jpg");
java.net.URL path3 = new URL("https://raw.githubusercontent.com/giovannidominguez/cs56-games-rock-paper-scissors/master/src/edu/ucsb/cs56/projects/games/rock_paper_scissors/images/Bulbasaur.jpg");

Jump from game to game

Allow the user the option to directly jump from one game to another rather then having the user return to game selection every time.
~250pts

Update javadoc to gh-pages

Have the javadoc be hosted by github.
outline to do this:
remove the javadoc folder from .gitignore
create new branch gh-pages
push javadoc to gh-pages
clean up build.xml

Name of Player does not match character after first game

Steps to reproduce:

  1. Choose to play tic tac toe against a player.
  2. Player 1 enters name and chooses character.
  3. Player 2 enters name and chooses character.
  4. Play so that Player 1 wins.
  5. It shows Player 2's turn, but it is really Player 1's turn. We know it is Player 1's turn because when move is made Player 1's character shows; and the JLabel for the turn system does not update appropriately.

~200 pts M16

Tests

create tests for things. This is going to be one of those things that gets more points the more you do.

clarify characters in rock paper scissors

Right now, initially, is it unclear which image is for the computer and which is the one you picked (especially if the computer and the player pick the same character).

100 pts.

Add a jar task to the build.xml file

There is currently no option to create a jar file from the project. Add a jar task along with a proper target description to the build.xml file.

~estimated 100

Improve Tic-Tac-Toa AI Difficulty

Add an option for an easy and difficult mode in tic tac toe. The user can win almost easily every time against the AI. Improve the current algorithm.
300pts.

Jlabel Titles

The titles of the jlabels are a bit off when choosing pokemon. Edit to correctly display appropriate titles.
~100pts

Refactor the user dialog for TicTacToe to not create so many objects and JFrames

The current TicTacToe games setup dialog is a mess---it creates a sequence of brand new JFrames, and brand new objects, with signifcant overlap in the instance variables.

As a first step towards refactoring the whole project, refactor this sequence of code so that asking for the two player names and selecting the two characters, uses just ONE JFrame that is repainted every time, and just ONE object that has setter methods to store the two player names, and the two characters selected. Pass that SINGLE object into the constructor for the class that creates the JFrame for the TicTacToe game.

The refactoring shouldn't stop there... there is plenty more to do. But for a single issue, its a good start. It should reduce the number of classes, as well as the amount of duplication in the code, and it should mean that if you move the JFrame for the game, it won't jump back to the upper left hand corner of the screen after you click to go to the next step.

300 points.

Adding a Computer TicTacToe #3

Adding in a Computer to play against a Human. The Computer randomly places their Pokemon on the board.

~requested: 200

Correct audio corresponding to pokemon.

In the game TicTacToe, there is supposed to be a corresponding audio file played when making a move. However, when the move is made, the audio file for charmander is played for any pokemon selected. Edit to correct play the right sound.
~100-150 pts.

bug in tic tac toe

during the process of selecting pokemon, "i choose you" botton can be clicked without choosing any pokemon, which results in bugs during game time.

Refactor the code

There are instances of duplicated code within TicTacToe.java, RunGame.java and GameGUI.java. For example, the classes RockListener, PaperListener, and ScissorsListener within GameGUI.java have duplicate code within each actionPerformed method. Refactor the code to remove duplicated lines of code.

~estimated 200 (but more points may be earned for large amounts of refactoring)

Refactor the code for better abstraction - part 1

Currently there are three files which share a tremendous amount of repeated code: NoBulbasaur.java, NoCharmander.java, NoSquirtle.java. These are used in the selection of a pokemon for the tic tac to game. Find a way to remove repetitive code to perform this action of picking a pokemon. This may also involve changing other files.

Additionally, there is a file First.java which should be removed from the project. This functionality now exists in FirstPlayer.java

~Estimated 250

Buttons not on the right window

When the game is chosen, the window says "choose a Pokemon to start!" in the middle of the screen when the buttons for the choices are in the left corner, which is the wrong window.

Add mouse listener to text field

In tic tac toe playerName class, add functionality so that when the user clicks in the text field, the already present "Enter Name" text clears.

150 pts

Add a Difficult TicTacToe AI

Currently, the difficult and medium level for tic-tac-toe computer AI has the same algorithm and they are easy to beat. Add a difficult TicTacToe AI to challenge players.

Add sound effects to TicTacToe

Add sound effects when you place your pieces on the TicTacToe grid so that your Pokemon piece makes their respective "noise".

~Estimated 200

Add networking capabilities to the program

Add networking capabilities to the program to allow two player action over different computers. One machine would host the server, and other clients can connect to it to play together. Maybe only implement one game at first. See this project for help with setting up a server and client connection, and for ideas such as chat clients.

~Estimated 500

Make the README more concise

While the README.md file contains lots of great information, it has a little more than what is usually needed in a typical README.md file. For example, the code examples under "Documentation" contain full classes, where instead it might be more useful if only certain portions of these classes were displayed, with descriptions of why these specific sections are important.

Additionally, the current screenshots show the entire gameplay sequence of the games. It might be preferable to simply display an example of what each different game looks like.

When choosing what to update in the README, don't simply throw existing documentation and/or images. Consider adding them to the wiki:

https://github.com/UCSB-CS56-Projects/cs56-games-rock-paper-scissors/wiki

because this is the appropriate place to put more detailed documentation. Then, just put a note in the README saying that more info can be found in the wiki

~estimated 200

Fix rock-paper-scissor game functionality

Currently, the rock-paper-scissors game does not display the number of games played or the records for wins, losses, and ties. There is code in GameGUI.java that attempts to do so, but a there are bugs preventing it from working properly. Fix this problem, so that the number of games and the scores are displayed.

~estimated 250

Refactor the code for better abstraction - part 2

~depends #10

Once you have cleaned up some of the repetitive code, think about how the overall structure could be improved. Games like Tic Tac Toe are often better suited for a Model-View-Controller architecture. Take a look at the code here to see if you could use any of it, or at least model new code in a similar patter. The goal is to abstract the game logic into different classes than the ones that handle the GUI interactions

http://www.cs.ucsb.edu/~pconrad/cs56/12S/labs/lab06/code/

~Estimated 500

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.