Java landlords game project source code, java landlords source code

Source: Internet
Author: User

Java landlords game project source code, java landlords source code

Some code is as follows:
Main. java

Package com; import java. awt. color; import java. awt. container; import java. awt. point; import java. awt. event. actionEvent; import java. awt. event. actionListener; import java. util. arrayList; import java. util. list; import java. util. random; import javax. swing. imageIcon; import javax. swing. JButton; import javax. swing. JFrame; import javax. swing. JLabel; import javax. swing. JMenu; import javax. swing. JMenuBar; import javax. s Wing. JMenuItem; import javax. swing. JOptionPane; import javax. swing. JTextField; import javax. swing. swingUtilities; public class Main extends JFrame implements ActionListener {public Container container = null; // defines the Container JMenuItem start, exit, about; // define the menu button JButton landlord [] = new JButton [2]; // grab the landlord button JButton publishCard [] = new JButton [2]; // issue button int dizhuFlag; // int turn; JLabel dizhu; // List of landlord icons <Card> CurrentList [] = new ArrayList [3]; // The current issue List <Card> playerList [] = new ArrayList [3]; // define the List of Three player tables <Card> lordList; // The landlord Card card [] = new Card [56]; // define 54 cards JTextField time [] = new JTextField [3]; // timer Time t; // timer (thread) boolean nextPlayer = false; // convert the role public Main () {Init (); // initialize SetMenu (); // create the menu button (grab the landlord, license, timer) this. setVisible (true); CardInit (); // licensed getLord (); // start to grab the landlord after the card is issued [1]. setVisible (tr Ue); // thread security. Put the UI control of non-main threads into SwingUtilities. invokeLater (new NewTimer (this, 10);} // grab the landlord public void getLord () {// System. out. println (CardType. c0.toString (); for (int I = 0; I <2; I ++) landlord [I]. setVisible (true);} // initialize the card // the card to be shuffled public void CardInit () {int count = 1; // initialize the card for (int I = 1; I <= 5; I ++) {for (int j = 1; j <= 13; j ++) {if (I = 5) & (j> 2) break; else {card [count] = new Card (thi S, I + "-" + j, false); card [count]. setLocation (350, 50); container. add (card [count]); count ++ ;}}// disrupt the order for (int I = 0; I <100; I ++) {Random random = new Random (); int a = random. nextInt (54) + 1; int B = random. nextInt (54) + 1; Card k = card [a]; card [a] = card [B]; card [B] = k ;} // start licensing for (int I = 0; I <3; I ++) playerList [I] = new ArrayList <Card> (); // lordList = new ArrayList <Card> (); // three int t = 0 for the primary Card (int I = 1; I <= 54; I ++) {If (I> = 52) // host card {Common. move (card [I], card [I]. getLocation (), new Point (300 + (i-52) * 80, 10); lordList. add (card [I]); continue;} switch (t ++) % 3) {case 0: // left-side player Common. move (card [I], card [I]. getLocation (), new Point (50, 60 + I * 5); playerList [0]. add (card [I]); break; case 1: // my Common. move (card [I], card [I]. getLocation (), new Point (180 + I * 7,450); playerList [1]. add (card [I]); card [I]. turnFront (); // display positive Break; case 2: // The Player Common on the right. move (card [I], card [I]. getLocation (), new Point (+ I * 5); playerList [2]. add (card [I]); break;} // card [I]. turnFront (); // display front iner. setComponentZOrder (card [I], 0) ;}// the order of the cards, from large to small for (int I = 0; I <3; I ++) {Common. order (playerList [I]); Common. rePosition (this, playerList [I], I); // rePosition} dizhu = new JLabel (new ImageIcon ("images/dizhu.gif"); dizhu. setVisible (false); dizhu. SetSize (40, 40); container. add (dizhu);} // initialize the form public void Init () {this. setTitle ("java standalone landlords"); this. setSize (830,620); setResizable (false); setLocationRelativeTo (getOwner (); // The screen center container = this. getContentPane (); container. setLayout (null); this. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); container. setBackground (new Color (0,112, 26); // The background is green} // create the menu function button public void SetMenu () {JM EnuBar jMenuBar = new JMenuBar (); JMenu game = new JMenu ("game"); JMenu help = new JMenu ("help "); start = new JMenuItem ("new Game"); exit = new JMenuItem ("quit"); about = new JMenuItem ("about"); start. addActionListener (this); exit. addActionListener (this); about. addActionListener (this); game. add (start); game. add (exit); help. add (about); jMenuBar. add (game); jMenuBar. add (help); this. setJMenuBar (jMenuBar); landlord [0] = new JButton (""); landlord [1] = new JButton (""); publishCard [0] = new JButton (" "); publishCard [1] = new JButton ("don't"); for (int I = 0; I <2; I ++) {publishCard [I]. setBounds (320 + I * 100,400, 60, 20); landlord [I]. setBounds (320 + I * 100,400, 75, 20); container. add (landlord [I]); landlord [I]. addActionListener (this); landlord [I]. setVisible (false); container. add (publishCard [I]); publishCard [I]. setVisible (fals E); publishCard [I]. addActionListener (this) ;}for (int I = 0; I <3; I ++) {time [I] = new JTextField ("Countdown :"); time [I]. setVisible (false); container. add (time [I]);} time [0]. setBounds (140,230, 60, 20); time [1]. setBounds (374,360, 60, 20); time [2]. setBounds (620,230, 60, 20); for (int I = 0; I <3; I ++) {currentList [I] = new ArrayList <Card> ();}} @ Override public void actionreceivmed (ActionEvent e) {// TODO Auto-gen Erated method stub if (e. getSource () = exit) {this. dispose ();} if (e. getSource () = about) {JOptionPane. showMessageDialog (this, "Haha");} if (e. getSource () = start) {// this. restart ();} if (e. getSource () = landlord [0]) {time [1]. setText ("grab the landlord"); t. isRun = false; // clock termination} if (e. getSource () = landlord [1]) {time [1]. setText ("don't grab"); t. isRun = false; // clock termination} // if it is not if (e. getSource () = publishCard [1]) {thi S. nextPlayer = true; currentList [1]. clear (); time [1]. setText ("don't");} // if it is a card button if (e. getSource () = publishCard [0]) {List <Card> c = new ArrayList <Card> (); // click the Card for (int I = 0; I <playerList [1]. size (); I ++) {Card card = playerList [1]. get (I); if (card. clicked) {c. add (card) ;}} int flag = 0; // if I take the initiative to issue a card if (time [0]. getText (). equals ("don't") & time [2]. getText (). equals ("don't") {if (Common. jugdeType (c )! = CardType. c0) flag = 1; // indicates that a card can be played} // if I am playing with else {flag = Common. checkCards (c, currentList);} // determines whether the card meets the requirement. if (flag = 1) {currentList [1] = c; playerList [1]. removeAll (currentList [1]); // remove the selected card. // locate the card. Point = new point (); Point. x = (770/2)-(currentList [1]. size () + 1) * 15/2; point. y = 300; for (int I = 0, len = currentList [1]. size (); I <len; I ++) {Card card = currentList [1]. get (I); Common. move (card, card. getLocation (), point); point. x + = 15;} // sort the cards again after the cards are drawn. rePosition (this, playerList [1], 1); time [1]. setVisible (false); this. nextPlayer = true ;}} public static void main (String args []) {new Main () ;}} class NewTimer implements Runnable {Main main; int I; public NewTimer (Main m, int I) {this. main = m; this. I = I ;}@ Override public void run () {// TODO Auto-generated method stub main. t = new Time (main, 10); // countdown from 10 to main. t. start ();}}

 


<Ignore_js_op>


<Ignore_js_op>

<Ignore_js_op>


<Ignore_js_op>


Http://java.662p.com/thread-1542-1-1.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.