hazemsalameh

Tap Games

Dec 11th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. import java.applet.Applet;
  2. import java.awt.Rectangle;
  3. import java.awt.event.KeyEvent;
  4. import java.awt.event.KeyListener;
  5. import java.util.ArrayList;
  6. import java.awt.Graphics;
  7. import java.awt.Graphics2D;
  8. import java.awt.Color;
  9. import java.awt.FlowLayout;
  10. import java.awt.Font;
  11. import java.awt.*;
  12.  
  13.  
  14. import javax.swing.ImageIcon;
  15. import javax.swing.JFrame;
  16. import javax.swing.JLabel;
  17.  
  18. import org.w3c.dom.css.Rect;
  19. public class Game extends Applet implements KeyListener
  20. {
  21.  
  22.     public static int playerA = 0;
  23.    
  24.     public Rectangle rect = new Rectangle(-680, -1000, 1360,1700);public static int playerB = 0;
  25.     public void init()
  26.     {
  27.         this.addKeyListener(this);
  28.        
  29.         this.setFocusable(true);
  30.         this.requestFocusInWindow();
  31.        
  32.     }
  33.     public void paint(Graphics g)
  34.     {
  35.        
  36.         setSize(1360,700);
  37.        
  38.         setBackground(java.awt.Color.BLUE);
  39.         Graphics2D g2 = (Graphics2D)g;
  40.         g2.setColor(Color.RED);
  41.        
  42.         g2.fill(rect);
  43.         if(playerA == 5)
  44.         {
  45.             Font stringFont = new Font( "SansSerif", Font.PLAIN, 180 );
  46.             g2.setColor(Color.WHITE);
  47.             g.drawString("Red Wins", 100, 100);
  48.         }
  49.         if(playerB == 5)
  50.         {
  51.             Font stringFont = new Font( "SansSerif", Font.PLAIN, 180 );
  52.             g2.setColor(Color.WHITE);
  53.             g.drawString("Blue Wins", 100, 100);
  54.         }
  55.        
  56.        
  57.        
  58.     }
  59. private void setFont(int i) {
  60.         // TODO Auto-generated method stub
  61.        
  62.     }
  63. @Override
  64.     public void keyPressed(KeyEvent e) {       
  65.    
  66.     if (e.getKeyCode() == KeyEvent.VK_K)
  67.         {
  68.                
  69.             playerA++;
  70.             playerB--;
  71.             rect.setLocation(rect.x +136 , rect.y );
  72.            
  73.            
  74.         }
  75.         else if (e.getKeyCode() == KeyEvent.VK_A)
  76.         {
  77.            
  78.             playerA--;
  79.             playerB++;
  80.             rect.setLocation(rect.x - 136, rect.y);
  81.            
  82.            
  83.         }
  84.             repaint();
  85.            
  86.     }
  87.    
  88.    
  89.  
  90.     @Override
  91.     public void keyReleased(KeyEvent e) {
  92.         // TODO Auto-generated method stub
  93.        
  94.     }
  95.  
  96.     @Override
  97.     public void keyTyped(KeyEvent e) {
  98.         // TODO Auto-generated method stub
  99.        
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment