Jump to content

davej

Moderator
  • Posts

    3,988
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by davej

  1. static int winOrTie() {
       if ( ( ) ) {
          return CROSS;
    } else if ( ( ) ) {
          return NOUGHT;
    } else if ( ( ) ) {
         return
    } else {
         return
    }
     
    }

    This approach can only be used if the board is a fixed size. If you know it is always a 3 x 3 board then it is easy to formulate an if structure. Something simple like this could work...

    if(gameboard[0][0] + gameboard[0][1] + gameboard[0][2] == 3*NOUGHT){return NOUGHT;}
    if(gameboard[1][0] + gameboard[1][1] + gameboard[1][2] == 3*NOUGHT){return NOUGHT;}
    if(gameboard[2][0] + gameboard[2][1] + gameboard[2][2] == 3*NOUGHT){return NOUGHT;}
    
    if(gameboard[0][0] + gameboard[1][0] + gameboard[2][0] == 3*NOUGHT){return NOUGHT;}
    if(gameboard[0][1] + gameboard[1][1] + gameboard[2][1] == 3*NOUGHT){return NOUGHT;}
    if(gameboard[0][2] + gameboard[1][2] + gameboard[2][2] == 3*NOUGHT){return NOUGHT;}
    
    if(gameboard[0][0] + gameboard[1][1] + gameboard[2][2] == 3*NOUGHT){return NOUGHT;}
    if(gameboard[0][2] + gameboard[1][1] + gameboard[2][0] == 3*NOUGHT){return NOUGHT;}
    
    if(gameboard[0][0] + gameboard[0][1] + gameboard[0][2] == 3*CROSS){return CROSS;}
    if(gameboard[1][0] + gameboard[1][1] + gameboard[1][2] == 3*CROSS){return CROSS;}
    if(gameboard[2][0] + gameboard[2][1] + gameboard[2][2] == 3*CROSS){return CROSS;}
    
    if(gameboard[0][0] + gameboard[1][0] + gameboard[2][0] == 3*CROSS){return CROSS;}
    if(gameboard[0][1] + gameboard[1][1] + gameboard[2][1] == 3*CROSS){return CROSS;}
    if(gameboard[0][2] + gameboard[1][2] + gameboard[2][2] == 3*CROSS){return CROSS;}
    
    if(gameboard[0][0] + gameboard[1][1] + gameboard[2][2] == 3*CROSS){return CROSS;}
    if(gameboard[0][2] + gameboard[1][1] + gameboard[2][0] == 3*CROSS){return CROSS;}
    
    if(turn < 9){
        return INCOMPLETE;
    }else{
        return TIE;
    }
    
    
    
  2.  

    This is a small assignment I have been given. They have given me most of the code and I have to figure out the rest.

     

     

    Given by who? This is terrible code. Don't learn to code like this. There are many books and tutorials available.

     

    Begin with a main() something like this...

    public static void main(String[] args)  {
    
            gameboard = new int[SIZE][SIZE]; // board must be square
            int outcome;
             
            do {
                displayBoard();
                promptUser();
                outcome = winOrTie();
                
            } while ( outcome == INCOMPLETE );
            
            displayResults(outcome);
            
        }// end of main
    
  3. Main should be simple and provide an outline of what you are doing. In my version of your program it looks like this...

    public static void main(String[] args)  {
    
            gameboard = new int[SIZE][SIZE]; // board must be square
            int turn = 0;
            int outcome;
            displayBoard();
             
            do {
                turn = promptUser(turn);
                displayBoard();
                outcome = winOrTie();
                
            } while ( outcome == -2 );
            
            displayResults(outcome);
            
        }// end of main
    
  4. The easy fix seems to be just to use float rather than inline-block...

     .summaryBox { 
     float:left;
     width: 20%; 
     height: 250px; 
     margin: 1em 1em 1em 2em; 
     padding: 0; 
     border: 1px solid black; 
     }   
     footer{clear:both;}
    
  5. You should paste that code into a codeblock...

     

    Hmmm... I see what you are saying. Something odd happens when you put a block inside an inline-block.

    <!DOCTYPE HTML>   
     <html lang="en">   
     <head>   
     <title>Blog - Home</title>   
     <meta name="viewport" content="width=device-width, initial-scale=1.0">   
     <meta charset="utf-8">   
     <link href="_css/pj.css" type="text/css" rel="stylesheet">       
     <style>   
     article { padding: 0; }   
     .summaryBox { 
     display: inline-block; 
     width: 20%; height: 250px; 
     margin: 1em 1em 1em 2em; 
     padding: 0; 
     border: 1px solid black; 
     }   
     .pgBanner { opacity: 0.5; filter: alpha(opacity=50); } /* For IE8 and earlier */   
     .artBanner ( position: relative; )       
     </style>       
     </head>   
      
     <body class="clearfix">   
     
     <header>   
     <img src="_img/atomic_logo.png" width="100" height="125" class="pjLogo" alt="company logo">   
     <h1 class="pj_header">Blog Home</h1>   
     </header>  
     
     <nav id="headNav" class="upperBar headNav ulBars">   
     <ul id="topList">   
     <li><a href="about.html">About</a></li>   
     <li><a href="blog_home.html">Blog</a></li>   
     <li><a href="faq.html">Home</a></li>   
     </ul>   
     </nav>   
     <section class="sumFont">   
     <h2>BLOG Under Construction</h2>   
     <article class="summaryBox"><h3>Heading</h3></article>   
     <article class="summaryBox"></article>   
     <article class="summaryBox"></article>   
     <article class="summaryBox"></article>   
     <article class="summaryBox"></article>   
     <article class="summaryBox"></article>   
     </section>   
     <footer>   
     <nav id="footNav" class="lowerBar footNav ulBars">   
     <ul id="bottomList">   <li><a href="about.html">About</a></li>   
     <li><a href="blog_home.html">Blog</a></li>   <li><a href="faq.html">Home</a></li>   
     </ul>   
     </nav>   
     <div id="footContact">   
     <br>   
     <a style="margin: 20% 0 0 50%" target="_blank" title="Follow me on facebook" href="http://www.facebook.com/bob.kefurtii">
     <img alt="follow me on facebook" src="https://c866088.sslfacebook30x30.png" border="0"></a>       
     <p style="text-align: center">   
     Plutonim Jelly<br>   
     94 Atomic way<br>   
     Sparkling PU, 239239<br>   
     Office: (555) 888-8080<br>   
     Email: <a href="mailto:someone@example.com?Subject=New%20Interest">PuJy@atomicserver.com</a>
     <br><br>   
     <sub>Copyright© 2017 Bob Kefurt</sub>
     </p>   
     </div>   
     </footer>   
     </body>   
     </html>
    
  6. The w3Schools tutorial isn't terrible. I just wish it didn't use document.write() and inline javascript. Just rewrite each example so that document.write() isn't used.

     

    http://www.w3schools.com/js/default.asp

     

    One of the first few lessons explains why document.write() is inferior, so then why do they keep using it throughout the rest of the tutorial? I don't know. Also learn to use addEventListener() as a more flexible alternative to inline javascript which is embedded into the HTML.

     

    For books get...

     

    https://www.amazon.com/JavaScript-Definitive-Guide-Activate-Guides-ebook/dp/B004XQX4K0/ref=sr_1_3?ie=UTF8&qid=1485791079&sr=8-3&keywords=javascript&refinements=p_72%3A2661618011

     

    ...and either this...

     

    https://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742/ref=sr_1_8?ie=UTF8&qid=1485791079&sr=8-8&keywords=javascript&refinements=p_72%3A2661618011

     

    ...or this (they are approximately the same material)...

     

    https://www.amazon.com/JavaScript-Patterns-Better-Applications-Coding/dp/0596806752/ref=sr_1_17?ie=UTF8&qid=1485791342&sr=8-17&keywords=javascript&refinements=p_72%3A2661618011

     

    However please realize that an entirely new and more complex version of Javascript is on the horizon... but you should probably not begin with this book...

     

    https://www.amazon.com/Learning-JavaScript-Essentials-Application-Development/dp/1491914912/ref=sr_1_3?ie=UTF8&qid=1485791459&sr=8-3&keywords=javascript+es6

    • Like 1
  7. You should have zero errors. Your first errors are related to the fact that a meta tag doesn't like a closing slash...

    This is good...
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    This is bad...
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    

    The internet is filled with tutorials, references, and resources, or you could hire a local web-savvy teenager.

     

    http://www.w3schools.com/

  8. Try...

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8"/>
    <title>title</title>
    <style>
    body{
    text-align:center;
    }
    </style>
    <script>
    window.onerror = function(a,b,c,d){
    alert('Javascript Error: '+a+'\nURL: '+b+'\nLine Number: '+c+'  Col Number: '+d);
    return true;
    }
    </script>
    <script>
    'use strict';
    
    // JavaScript Document
    // rot 0 starts on April 5
    //12 nov rocks
    window.onload = getrot;
    
    function getrot() {
    var rotations = new Array();
    rotations[0] = "AGD-KTV";
    rotations[1] = "KAD-GTV";
    rotations[2] = "ATD-KGV";
    rotations[3] = "ADV-KTG";
    rotations[4] = "KAG-TDV";
    rotations[5] = "ATG-KDV";
    rotations[6] = "AGV-KTD";
    rotations[7] = "KAT-GDV";
    rotations[8] = "KAV-DTG";
    rotations[9] = "ATV-KDG";
    rotations[10] = "KDG-ATV";
    rotations[11] = "DTG-KAV";
    rotations[12] = "GDV-KAT";
    rotations[13] = "KTD-AGV";
    rotations[14] = "KDV-ATG";
    rotations[15] = "DTV-KAG";
    rotations[16] = "KTG-ADV";
    rotations[17] = "KGV-ATD";
    rotations[18] = "GTV-KAD";
    rotations[19] = "KTV-AGD";
    
    var araxrotations = new Array();
    araxrotations[0] = "Path 1 & 2";
    araxrotations[1] = "Path 2 & 3";
    araxrotations[2] = "Path 3 & 1";
    
    var ragorotation = new Array();
    ragorotation[0] = "Rocks";
    ragorotation[1] = "Scopulus";
    ragorotation[2] = "Vitalis";
    ragorotation[3] = "Green Bomb";
    ragorotation[4] = "Teamsplit";
    ragorotation[5] = "Purple Bomb";
    
    
    var oneDay = 24*60*60*1000;
    var begin = new Date(2014,3,5,13,0,0);
    var beginrago = new Date(2014,10,12,13,0,0);
    var beginarax = new Date(2014,9,18,13,0,0);
    var d = new Date();
    var utcyear = d.getUTCFullYear();
    var utcmonth = d.getUTCMonth();
    var utcdate = d.getUTCDate();
    var utchours = d.getUTCHours();
    var utcminutes = d.getUTCMinutes();
    var utcseconds = d.getUTCSeconds();
    
    var utctime = new Date(utcyear,utcmonth,utcdate,utchours,utcminutes,utcseconds);
    
    var diffDays = Math.round(Math.abs((begin.getTime() - utctime.getTime())/(oneDay)));
    var diffDaysRago = Math.round(Math.abs((beginrago.getTime() - utctime.getTime())/(oneDay)));
    var diffDaysArax = Math.round(Math.abs((beginarax.getTime() - utctime.getTime())/(oneDay)));
    var diffRotations = Math.floor(diffDaysArax/4);
    var nextaraxrot = 4 - diffDaysArax%4;
    var resetstring = " reset"
    if(nextaraxrot > 1){resetstring = " resets"};
    var currentAraxxorrot = (diffRotations%3);
    var currentrot = (diffDays % 20);
    var diffWeeks = Math.floor(diffDaysRago / 7);
    var currentragorot = (diffWeeks % 6);
    var tomorrowragorot = currentragorot + 1;
    if(tomorrowragorot == 6){tomorrowragorot = 0};
    var tomorrowrot = currentrot + 1;
    if(tomorrowrot == 20){tomorrowrot = 0};
    var tomorrowaraxrot = currentAraxxorrot + 1;
    if(tomorrowaraxrot == 3){tomorrowaraxrot = 0};
    
    document.getElementById('cc1').innerHTML="Today: " + ragorotation[currentragorot] + "<br> Next rotation: " + ragorotation[tomorrowragorot]; 
    
    document.getElementById('cc2').innerHTML="Today: " + araxrotations[currentAraxxorrot] + "<br>" + araxrotations[tomorrowaraxrot] + " open after " + nextaraxrot + resetstring;
    
    document.getElementById('cc3').innerHTML="Today: " + rotations[currentrot] + "<br> Tomorrow: " + rotations[tomorrowrot];
    //alert('done');
    };
    
    </script>
    </head>
    
    <body>
    <!-- Vorago Rotation: Purple Bomb<br> Next rotation: Rocks -->
    <!-- Araxxor Current Path: Path 1 & 2<br>Path 2 & 3 open after 2 resets -->
    <!-- ROTS Rotation: KDV-ATG<br> Tomorrow:DTV-KAG -->
    
    <span class="title" id="cc1"></span>
    <span class="title" id="cc2"></span>
    <span class="title" id="cc3"></span>
    
    </body>    
    </html>
    
  9. Of course they could use e-mail or a chat application to share answers.

     

    Also--

     

    Do you randomize the order of the questions and the order of the multiple-guess answers for each student? That might make attempts at cheating quite a bit more difficult. Just generate the page content dynamically from a randomized array.

×
×
  • Create New...