The document discusses an online Java compiler and IDE that can be integrated with websites and learning management systems. It provides code for a game board class in Java that controls the size of the board, number of coins, and includes a player and coins on the board. It uses a timer to call an actionPerformed method every set delay.
The document discusses an online Java compiler and IDE that can be integrated with websites and learning management systems. It provides code for a game board class in Java that controls the size of the board, number of coins, and includes a player and coins on the board. It uses a timer to call an actionPerformed method every set delay.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
Integrating Compiler & IDE with your Website and LMS, Join the Free Webinar |
22nd February at 2:30 pm (AEDT) Book Your Seat
Online Java Compiler IDE Font Size: 12px https://www.jdoodle.com/online-java-compiler 1 import java.awt.*; 2 import java.awt.event.*; 3 import java.util.ArrayList; 4 import java.util.Random; 5 import javax.swing.*; 6 7 public class Board extends JPanel implements ActionListener, KeyListener { 8 9 // controls the delay between each tick in ms 10 private final int DELAY = 25; 11 // controls the size of the board 12 public static final int TILE_SIZE = 50; 13 public static final int ROWS = 12; 14 public static final int COLUMNS = 18; 15 // controls how many coins appear on the board 16 public static final int NUM_COINS = 5; 17 // suppress serialization warning 18 private static final long serialVersionUID = 490905409104883233L; 19 20 // keep a reference to the timer object that triggers actionPerformed() in 21 // case we need access to it in another method 22 private Timer timer; 23 // objects that appear on the game board 24 private Player player; 25 private ArrayList<Coin> coins; 26 27 public Board() { 28 // set the game board size 29 setPreferredSize(new Dimension(TILE_SIZE * COLUMNS, TILE_SIZE * ROWS)); 30 // set the game board background color 31 setBackground(new Color(232, 232, 232)); 32 33 // initialize the game state 34 player = new Player(); 35 coins = populateCoins(); 36 37 // this timer will call the actionPerformed() method every DELAY ms 38 timer = new Timer(DELAY, this); 39 timer.start(); 40 41 // add key listener to the board
Add code to ask user about the number of players (from 1 to 3) - use game.askForInt. Store the input in a variable numPlayers. QUESTION 2 Modify the code below to ask for players' names and add them to the game in a