Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Project: Create a brief version of the solitaire card game called Aces Up.

ID: 3702634 • Letter: J

Question

Java Project:

Create a brief version of the solitaire card game called Aces Up. use a Gui to function. A website with a version of the game and the rules for playing the game

Rules

https://www.wikihow.com/Play-Aces-Up

Online version of the game

http://webofsolitaire.com/Solitaire-Aces-Up/

// below is an example of getting a card,should be able to get 52 cards

/**
Private inner class that handles the event when
the user clicks the button.
*/

private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
// Read the image file into an ImageIcon object.
ImageIcon cardImage = new ImageIcon("3_clubs.jpg");

// Display the image in the label.
imageLabel.setIcon(cardImage);

// Remove the text from the label.
imageLabel.setText(null);

// Pack the frame again to accomodate the
// new size of the label.
pack();
}
}

/**
The main method creates an instance of the
MyCatImage class which causes it to display
its window.
*/
public static void main(String[] args)
{
new MyCardImage();
}
}

//Below is the Aces Up Game playingCardsGui.java layout manager, need a start buttom to start the game, need 5 buttons for the card holers include a backface and 4 frontface button. and one more button for waste cards. last need a score counter so that can show how many cards have been wasted. the more cards be wasted the higher score is.

//********************************************************************
// GridPanel.java Java Foundations
//
// Represents the panel in the LayoutDemo program that demonstrates
// the grid layout manager.
//********************************************************************

import java.awt.*;
import javax.swing.*;

public class GridPanel extends JPanel
{
//-----------------------------------------------------------------
// Sets up this panel with some buttons to show how grid
// layout affects their position, shape, and size.
//-----------------------------------------------------------------
public GridPanel()
{
setLayout(new GridLayout(2, 3));

setBackground(Color.green);

JButton b1 = new JButton("BUTTON 1");
JButton b2 = new JButton("BUTTON 2");
JButton b3 = new JButton("BUTTON 3");
JButton b4 = new JButton("BUTTON 4");
JButton b5 = new JButton("BUTTON 5");

add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
}
}

Explanation / Answer

import java.awt.*; import java.awt.event.*; import java.applet.*; class Link { private Object valueField; private Link nextLink; public Link (Object newValue, Link next) { valueField = newValue; nextLink = next; } // get Object part of link public Object value() { return valueField; } // get Link part of link public Link next() { return nextLink; } } ////////////////////////////// // Defines a LinkedList class // // used by CardPile ////////////////////////////// class LinkedList { private Link firstLink; public LinkedList() { firstLink = null; } // true if empty, false otherwise public boolean empty() { return firstLink == null; } // add an Object to our list public void add (Object newValue) { firstLink = new Link(newValue, firstLink); } // inspect front of list public Object front() { if (firstLink == null) return null; return firstLink.value(); } // pop front of list public Object pop() { if (firstLink == null) return null; Object result = firstLink.value(); firstLink = firstLink.next(); return result; } // return an iterator for the list public ListIterator iterator() { return new ListIterator(firstLink); } } //////////////////////////////// // Defines a ListIterator class // // used by LinkedList //////////////////////////////// class ListIterator { private Link currentLink; public ListIterator (Link firstLink) { currentLink = firstLink; } // true if we reached end of list, false otherwise public boolean atEnd() { return currentLink == null; } // move to next link public void next() { if (currentLink != null) currentLink = currentLink.next(); } // return value of current link public Object current() { if (currentLink == null) return null; return currentLink.value(); } } //////////////////////// // Defines a Card class // // used by CardPile //////////////////////// class Card { // data fields for colors and suits final static int width = 50; final static int height = 70; final static int red = 0; final static int black = 1; final static int heart = 0; final static int spade = 1; final static int diamond = 2; final static int club = 3; final static int ace = 0; final static int king = 12; private static String names[] = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}; // data fields private boolean faceup; private int rank; private int suit; // constructor Card (int s, int r) { suit = s; rank = r; faceup = false; } // get rank of card as an int in the interval [0, 12] public int rank() { return rank; } // get suit of card as an int in the interval [0, 3] public int suit() { return suit; } // true if card is face up, false otherwise public boolean faceUp() { return faceup; } // change value of faceup public void flip() { faceup = ! faceup; } // true if card is ace, false otherwise public boolean isAce() { return rank == ace; } // true if card is king, false otherwise public boolean isKing() { return rank == king; } // return color of card as an int in the range [0,1] public int color() { if (suit() == heart || suit() == diamond) return red; return black; } // draw the card public void draw (Graphics g, int x, int y) { // clear rectangle, draw border g.clearRect(x, y, width, height); g.setColor(Color.black); g.drawRect(x, y, width, height); // draw body of card if (faceUp()) { if (color() == red) g.setColor(Color.red); else g.setColor(Color.black); g.drawString(names[rank()], x+3, y+15); if (suit() == heart) { g.drawLine(x+25, y+30, x+35, y+20); g.drawLine(x+35, y+20, x+45, y+30); g.drawLine(x+45, y+30, x+25, y+60); g.drawLine(x+25, y+60, x+5, y+30); g.drawLine(x+5, y+30, x+15, y+20); g.drawLine(x+15, y+20, x+25, y+30); } else if (suit() == spade) { g.drawLine(x+25, y+20, x+40, y+50); g.drawLine(x+40, y+50, x+10, y+50); g.drawLine(x+10, y+50, x+25, y+20); g.drawLine(x+23, y+45, x+20, y+60); g.drawLine(x+20, y+60, x+30, y+60); g.drawLine(x+30, y+60, x+27, y+45); } else if (suit() == diamond) { g.drawLine(x+25, y+20, x+40, y+40); g.drawLine(x+40, y+40, x+25, y+60); g.drawLine(x+25, y+60, x+10, y+40); g.drawLine(x+10, y+40, x+25, y+20); } else if (suit() == club) { g.drawOval(x+20, y+25, 10, 10); g.drawOval(x+25, y+35, 10, 10); g.drawOval(x+15, y+35, 10, 10); g.drawLine(x+23, y+45, x+20, y+55); g.drawLine(x+20, y+55, x+30, y+55); g.drawLine(x+30, y+55, x+27, y+45); } } else // face down { g.setColor(Color.yellow); g.drawLine(x+15, y+5, x+15, y+65); g.drawLine(x+35, y+5, x+35, y+65); g.drawLine(x+5, y+20, x+45, y+20); g.drawLine(x+5, y+35, x+45, y+35); g.drawLine(x+5, y+50, x+45, y+50); } } } ////////////////////////////////////// // Defines a CardPile class // // used as a base to build card piles ////////////////////////////////////// class CardPile { // coordinates of the card pile protected int x; protected int y; // linked list of cards protected LinkedList cardList; CardPile (int xl, int yl) { x = xl; y = yl; cardList = new LinkedList(); } ///////////////////////////////////// // access to cards are not overridden // true if pile is empty, false otherwise public final boolean empty() { return cardList.empty(); } // inspect card at the top of pile public final Card top() { return (Card)cardList.front(); } // pop card at the top of pile public final Card pop() { return (Card)cardList.pop(); } ///////////////////////////////////////// // the following are sometimes overridden // true if point falls inside pile, false otherwise public boolean includes (int tx, int ty) { return x
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote