HOLY CROSS OF DAVAO COLLEGE Sta. Ana Avenue cor. C. De Guzman St., Davao City COLLEGE OF ENGINEERING AND TECHNOLOGY BINARY GAME Submitted as a Learning Outcome in CC 103 – Computer Programming 1 by Jeo Carlo M. Lubao Rico F. Ontolan Reden G. Lamosa March 2020 BINARY GAME Figure 1.1: Our group ’ s Binary Game Application Description: Binary (or base-2) a numeric system that only uses two digits — 0 and 1. Computers operate in binary, meaning they store data and perform calculations using only zeros and ones. A single binary digit can only represent True (1) or False (0) in boolean logic. This application tests students on how well can they convert short numbers into binary. This game shall be based on a game created by Jerry Wolski as shown in the figure below. Figure 1.2: Jerry Wolski ’ s “ Binary Fun ” Binary numbers are important because using them instead of the decimal system simplifies the design of computers and related technologies. The simplest definition of the binary number system is a system of numbering that uses only two digits — 0 and 1 — to represent numbers, instead of using the digits 1 through 9 plus 0 to represent numbers. There is an interesting question raised in cseducators.stackexchange.com regarding “ How important is learning Binary for first-year college students? ” asked by Alfred Thompson. One answer by from a person under the username “ Wildcard ” said: “ Binary is fundamental to programming, but this has a lot more to do with logic than just with data storage. Computers work on "yes greater than no" or "no greater than yes." There are only two choices. Boolean logic has only two truth values, "true" or "false." Boolean logic is fundamental to computers. ” Sources: Binary Numbers and Binary Math - Engineering and Technology History Wiki. (2018). Retrieved 12 March 2020, from https://ethw.org/Binary_Numbers_and_Binary_Math Thompson, A. (2017). How important is learning Binary for first-year college students?. Retrieved 15 March 2020, from https://cseducators.stackexchange.com/questions/973/how-important-is-learning- binary-for-first-year-college-students USER MANUAL (USER INTERFACE COMPONENTS) Fig. 2.0: The User Interface and Components of Binary Game TITLE SCREEN SCORE LEVEL/STAGE DIFFICULTY ROUND NUMBER TIME REMAINING CHECK BUTTON START BUTTON BINARY AND THE CORRESPONDI NG EXPONENT DECIMAL AND VALUE Fig. 2.1: The Components and their uses a. The “ Level ” displays the round ’ s respective difficulty Level - The game is divided by 3 difficulty levels: (1) Easy, (2) Medium, and; (3) Hard. - Each difficulty level has 5 questions each. a. b. c. d. e. b. The “ Round ” indicates the question number. In Fig. 2.1, it indicates that it is the first question of the “ Easy ” difficulty level c. The “ Time ” indicates the time remaining to solve the question. All questions shall be given 20 seconds to answer. If the time reaches 0, it automatically displays whether the answer is correct and displays “ Correct ” , otherwise, it displays “ Wrong ” d. It indicates the randomly generated number, which depends on the difficulty level and you need to identify its corresponding binary value. Fig. 2.2: The Binary Game Number system e. These are the corresponding exponents of 2. Since the digits of binary are expressed as: In getting the value in binary of a certain number, one must get the summation of the exponents which are toggled on by one. In the case of Fig. 2.1 n 2 ,..., 2 , 2 , 2 2 1 0 and 2.2, to get the binary value of 7, the numbers 4,2,1 must be clicked by the player to toggle on and turn those zeros(0) into ones(1). Therefore, if adding those values: 4+2+1 = 7 (with a binary value of 00000111), then the player ’ s answer is correct. Fig. 2.3: The Binary Game “ Pregame ” UI In the Pregame screen, the player must click the start button to begin the game. Everything is set to zero (0), and the timer is set at 20, indicating that there are 20 seconds to answer the question. Fig. 2.4a: The Binary Game “ Game phase ” UI. In the Game Phase screen, the text in the start button is changed into “ Continue ” To play the game, the player must: 1. Press “ Start ” 2. Answer the question 3. Click “ Check ” to submit the answer 4. Click “ Continue ” to proceed 5. Repeat steps 1-4 until you reach the last question to see your score. Fig. 2.4b: The Binary Game “ Game phase ” UI. Please do note that the decimal and the number inside the jLabel box is the same. The decimal part in the left side of the screen can be used by the user to compare the given Decimal to the actual value that he/she answers. For every correct answer of the player, the score is incremented. Fig. 2.4c: The Decimal is the random number given, whereas the Value indicates the number that the player answered, if it is a mismatch, the program displays “ Wrong ” inside the box. Fig 2.5: In the lower right corner of the screen, it displays the number of mistakes that the user has commited over the course of the game. For every wrong answer, the number of mistakes is incremented by 1. Fig. 2.6a: The Medium difficulty level Fig.2.6b: The Hard difficulty level Fig. 2.7: After the game, the Score is then displayed inside of the box. Binary Game Source Code: (filename: BinaryGameFrame.java) --- START--- package binarygame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; // used for generating random numbers import javax.swing.JLabel; import javax.swing.Timer; // for the timer public class BinaryGameFrame extends javax.swing.JFrame { public BinaryGameFrame() { initComponents(); } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabelTitle = new javax.swing.JLabel(); jButton128 = new javax.swing.JButton(); jLabel128 = new javax.swing.JLabel(); jButton64 = new javax.swing.JButton(); jLabel64 = new javax.swing.JLabel(); jButton32 = new javax.swing.JButton(); jLabel32 = new javax.swing.JLabel(); jButton16 = new javax.swing.JButton(); jLabel16 = new javax.swing.JLabel(); jButton8 = new javax.swing.JButton(); jLabel8 = new javax.swing.JLabel(); jButton4 = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel(); jButton2 = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jButtonStart = new javax.swing.JButton(); jLabelDecimal = new javax.swing.JLabel(); jLabelRand = new javax.swing.JLabel(); jButtonCheck = new javax.swing.JButton(); jLabelCheck = new javax.swing.JLabel(); jLabelCheckBox = new javax.swing.JLabel(); jLabelScore = new javax.swing.JLabel(); jLabelScoreNum = new javax.swing.JLabel(); jLabelRoundNumber = new javax.swing.JLabel(); jLabelMistakes = new javax.swing.JLabel(); jLabelRound = new javax.swing.JLabel(); jLabelLevel = new javax.swing.JLabel(); jLabelGameLevel = new javax.swing.JLabel(); jLabelDecimalLabel = new javax.swing.JLabel(); jLabelTime = new javax.swing.JLabel(); jLabelTimerCount = new javax.swing.JLabel(); jLabelRound1 = new javax.swing.JLabel(); jLabelMist = new javax.swing.JLabel(); jLabelBG = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Binary Game"); setMinimumSize(new java.awt.Dimension(716, 620)); setResizable(false); setSize(new java.awt.Dimension(716, 620)); getContentPane().setLayout(null); jLabelTitle.setFont(new java.awt.Font("Tahoma", 1, 80)); // NOI18N jLabelTitle.setForeground(new java.awt.Color(51, 255, 0)); jLabelTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabelTitle.setText("BINARY GAME"); getContentPane().add(jLabelTitle); jLabelTitle.setBounds(12, 0, 697, 79); jButton128.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton128.setText("128"); jButton128.setAutoscrolls(true); jButton128.setMaximumSize(new java.awt.Dimension(80, 40)); jButton128.setMinimumSize(new java.awt.Dimension(80, 40)); jButton128.setPreferredSize(new java.awt.Dimension(80, 40)); jButton128.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton128ActionPerformed(evt); } }); getContentPane().add(jButton128); jButton128.setBounds(12, 97, 80, 40); jLabel128.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N jLabel128.setForeground(new java.awt.Color(51, 255, 0)); jLabel128.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel128.setText("0"); getContentPane().add(jLabel128); jLabel128.setBounds(12, 141, 77, 80); jButton64.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton64.setText("64"); jButton64.setMaximumSize(new java.awt.Dimension(80, 40)); jButton64.setMinimumSize(new java.awt.Dimension(80, 40)); jButton64.setPreferredSize(new java.awt.Dimension(80, 40)); jButton64.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton64ActionPerformed(evt); } }); getContentPane().add(jButton64); jButton64.setBounds(96, 97, 80, 40); jLabel64.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N jLabel64.setForeground(new java.awt.Color(51, 255, 0)); jLabel64.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel64.setText("0"); getContentPane().add(jLabel64); jLabel64.setBounds(96, 141, 77, 80); jButton32.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton32.setText("32"); jButton32.setMaximumSize(new java.awt.Dimension(80, 40)); jButton32.setMinimumSize(new java.awt.Dimension(80, 40)); jButton32.setPreferredSize(new java.awt.Dimension(80, 40)); jButton32.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton32ActionPerformed(evt); } }); getContentPane().add(jButton32); jButton32.setBounds(180, 97, 80, 40); jLabel32.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N jLabel32.setForeground(new java.awt.Color(51, 255, 0)); jLabel32.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel32.setText("0"); getContentPane().add(jLabel32); jLabel32.setBounds(180, 141, 77, 80); jButton16.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton16.setText("16"); jButton16.setMaximumSize(new java.awt.Dimension(80, 40)); jButton16.setMinimumSize(new java.awt.Dimension(80, 40)); jButton16.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton16ActionPerformed(evt); } }); getContentPane().add(jButton16); jButton16.setBounds(264, 97, 80, 40); jLabel16.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N jLabel16.setForeground(new java.awt.Color(51, 255, 0)); jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel16.setText("0"); getContentPane().add(jLabel16); jLabel16.setBounds(264, 141, 77, 80); jButton8.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton8.setText("8"); jButton8.setMaximumSize(new java.awt.Dimension(80, 40)); jButton8.setMinimumSize(new java.awt.Dimension(80, 40)); jButton8.setPreferredSize(new java.awt.Dimension(80, 40)); jButton8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton8ActionPerformed(evt); } }); getContentPane().add(jButton8); jButton8.setBounds(348, 97, 80, 40); jLabel8.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N jLabel8.setForeground(new java.awt.Color(51, 255, 0)); jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel8.setText("0"); getContentPane().add(jLabel8); jLabel8.setBounds(348, 141, 77, 80); jButton4.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton4.setText("4"); jButton4.setMaximumSize(new java.awt.Dimension(80, 40)); jButton4.setMinimumSize(new java.awt.Dimension(80, 40)); jButton4.setPreferredSize(new java.awt.Dimension(80, 40)); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); getContentPane().add(jButton4); jButton4.setBounds(432, 97, 80, 40); jLabel4.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N jLabel4.setForeground(new java.awt.Color(51, 255, 0)); jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel4.setText("0"); getContentPane().add(jLabel4); jLabel4.setBounds(432, 141, 77, 80); jButton2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton2.setText("2"); jButton2.setMaximumSize(new java.awt.Dimension(80, 40)); jButton2.setMinimumSize(new java.awt.Dimension(80, 40)); jButton2.setPreferredSize(new java.awt.Dimension(80, 40)); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); getContentPane().add(jButton2); jButton2.setBounds(516, 97, 80, 40); jLabel2.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N jLabel2.setForeground(new java.awt.Color(51, 255, 0)); jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel2.setText("0"); getContentPane().add(jLabel2); jLabel2.setBounds(516, 141, 77, 80); jButton1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton1.setText("1"); jButton1.setMaximumSize(new java.awt.Dimension(80, 40)); jButton1.setMinimumSize(new java.awt.Dimension(80, 40));