The project is to design and write a C++17/FLTK computer game program with a gra
ID: 3816998 • Letter: T
Question
The project is to design and write a C++17/FLTK computer game program with a graphical user interface. The object of the game is to keep the computer from guessing the player’s next choice of two possible values. We will call the choices “heads” and “tails” below, but you are free to use maroon/white, on/off, up/down, 0/1, etc. instead.
The player starts by making a certain number of choices, attempting to be as random as possible, which the computer observes. Then for each of the following choices the computer guesses in advance, and then compares its guess to the next choice. For difficulty level 1 (see below) there are 32 choices in the observation phase and 32 choices in the guessing phase. The player earns 10 points for each choice the computer guessed wrong, so for difficulty level 1 the maximum score is 320.
my parts are :
Ask for the player's initials and display them with a blank score below the top 5 scores.
Instruct the player to make that many choices, attempting to be as random as possible, and show how many choices remain. For example, for difficulty level 1 the setup screen might say “You have 32 choices to go; click Heads or Tails.”
Explanation / Answer
bundle com.zetcode;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Ellipse2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
class Surface broadens JPanel {
private void doDrawing(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(new Color(150, 150, 150));
RenderingHints rh = new RenderingHints(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
rh.put(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHints(rh);
g2d.fillRect(30, 20, 50, 50);
g2d.fillRect(120, 20, 90, 60);
g2d.fillRoundRect(250, 20, 70, 60, 25, 25);
g2d.fill(new Ellipse2D.Double(10, 100, 80, 100));
g2d.fillArc(120, 130, 110, 100, 5, 150);
g2d.fillOval(270, 130, 50, 50);
}
@Override
open void paintComponent(Graphics g) {
super.paintComponent(g);
doDrawing(g);
}
}
open class BasicShapesEx broadens JFrame {
open BasicShapesEx() {
initUI();
}
private void initUI() {
add(new Surface());
setTitle("Basic shapes");
setSize(350, 250);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
open static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
open void run() {
BasicShapesEx ex = new BasicShapesEx();
ex.setVisible(true);
}
});
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.