Results 1 to 5 of 5
  1. #1
    tabchas's Avatar
    tabchas is offline Member
    Join Date
    Mar 2011
    Location
    Austin
    Posts
    60
    Rep Power
    0

    Default What to do next?

    Hey Guys,

    I upped my skill in Java most likely to an intermediate programmer. But I am still confused on what to program. I want to do something cool like maybe developing a game or something along the lines of that. I have went through several Java programming books including Deitel and Head First learning all the way up until networking and multithreaded programming. What should I do? I feel a little bored in a sense I don't know what to program?

    Thanks!
    Tabish Chasmawala

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Text editor
    Spreadsheet
    File manager
    Web browser
    CD/DVD library manager

    Choose something related to a hobby.

    - If you are into trainspotting then write an app to hold pictures, data about the loco, where and when you saw it etc
    - Scuba diver? An electronic log book for all your dives.

    Sport related.

    - Fantasy football manager.

    To be honest if you don't have the imagination to think of something then I have to worry about your ability to write the program.

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Address book of some sort to use some form of io(serialization, or create your own way to store and retrieve objects), a lot of nice stuff can be learned with this.

    Try writing a simple terminal based blackjack game, or a game of some sort. Plus everything junky suggested is good.

    A simple notepad, GUI calculator, etc.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    I was just digging through some old files and found this TicTacToe variant I wrote in Javascript. Try adapting it for Java.
    Java Code:
    <html>
    <head>
    <script>
    player = 0;
    token = "X";
    var opp;
    win = false;
    started = false;
    
    function chooseMove(dir, spot){
      if(started){
        if(opp != null){
          opp.disabled = false;
          nextto.disabled = false;
        }
        if(dir == 1){
          makeMove(spot, -6);
          downMove(spot);
        } else if(dir== 2){
          makeMove(spot, -1);
          rightMove(spot);
        } else if(dir == 3){
          makeMove(spot, 1);
          leftMove(spot);
        } else if(dir == 4){
          makeMove(spot, 6);
          upMove(spot);
        }
        opp.disabled = true;
        nextto.disabled = true;
        checkWin();
        changePlayers();
      } else {
        if(win){
          document.qq.message.value = "The game has already been won. Click the 'New Game' button.";
        } else {
          document.qq.message.value = "The game has not begun yet. Click the 'Start Game' button.";
        }
      }
    }
    
    function makeMove(cells, step) {
      for(i = 0; i < 3; i++) {
        document.qq.elements[cells].value = document.qq.elements[cells + step].value;
        cells += step;
      }
      document.qq.elements[cells].value = token;
    }
    
    function leftMove(cells){
      if(cells == 5){
        opp = document.qq.l1;
        nextto = document.qq.b4;
      } else if(cells == 11){
        opp = document.qq.l2;
        nextto = opp;
      } else if(cells == 17){
        opp = document.qq.l3;
        nextto = opp;
      } else {
        opp = document.qq.l4;
        nextto = document.qq.t4;
      }
    }
    
    function rightMove(cells){
      if(cells == 8){
        opp = document.qq.r1;
        nextto = document.qq.b1;
      } else if(cells == 14){
        opp = document.qq.r2;
        nextto = opp;
      } else if(cells == 20) {
        opp = document.qq.r3;
        nextto = opp;
      } else {
        opp = document.qq.r4;
        nextto = document.qq.t1;
      }
    }
    
    function upMove(cells){
      if(cells == 5) {
        opp = document.qq.t1;
        nextto = document.qq.r4;
      } else if(cells == 6) {
        opp = document.qq.t2;
        nextto = opp;
      } else if(cells == 7) {
        opp = document.qq.t3;
        nextto = opp;
      } else {
        opp = document.qq.t4;
        nextto = document.qq.l4;
      }
    }
    
    function downMove(cells){
      if(cells == 23) {
        opp = document.qq.b1;
        nextto = document.qq.r1;
      } else if(cells == 24) {
        opp = document.qq.b2;
        nextto = opp;
      } else if(cells == 25) {
        opp = document.qq.b3;
        nextto = opp;
      } else {
        opp = document.qq.b4;
        nextto = document.qq.l1;
      }
    }
    
    function checkWin(){
      naughtWin = winDiag(5, 7, "O") || winDiag(7, 5, "O") || winHorVer(1, 4, "O") || winHorVer(6, -11, "O");
      crossWin = winDiag(5, 7, "X") || winDiag(7, 5, "X") || winHorVer(1, 4, "X") || winHorVer(6, -11, "X");
      if(naughtWin && crossWin){
        document.qq.message.value = "The game was a draw!";
        win = true;
      } else if(naughtWin){
        document.qq.message.value = "Well done player 2, you have won.";
        win = true;
      } else if(crossWin){
        document.qq.message.value = "Well done player 1, you have won!";
        win = true;
      }
      if(win){
        started = false;
        document.qq.newGame.value = "New Game";
        document.qq.newGame.disabled = false;
      }
    }
    
    function winHorVer(inVal, outVal, c){
      field = 5;
      for(outer = 0; outer < 4; outer++){
        for(inner = 0; inner < 2; inner++){
          if(document.qq.elements[field].value == c && document.qq.elements[field].value == document.qq.elements[field + inVal].value && document.qq.elements[field].value == document.qq.elements[field + (2 * inVal)].value){
            return true;
          }
          field += inVal;
        }
        field += outVal;
      }
      return false;
    }
    
    function winDiag(field, gap, c) {
      for(outer = 1; outer < 5; outer++) {
        if(document.qq.elements[field].value == c && document.qq.elements[field].value == document.qq.elements[field + gap].value && document.qq.elements[field].value == document.qq.elements[field + (2 * gap)].value){
            return true;
        }
        if(outer % 2 == 1) {
          field ++;
        } else {
          field += 5;
        }
      }
    }
    
    function changePlayers(){
      if(!win){
        if(player == 0){
          player = 1;
          token = "O";
          document.qq.message.value = "Player 2, it is your turn";
        } else {
          player = 0;
          token = "X";
          document.qq.message.value = "Player 1, it is your turn";
        }
      }
    }
    
    function startGame(){
      document.qq.newGame.disabled = true;
      for(i = 5; i < 27; i++) {
        if(i != 9 && i != 10 && i != 15 && i != 16 && i != 21 && i != 22) {
          document.qq.elements[i].value = "";
        }
      }
      if(win)
        opp.disabled = false;
      started = true;
      document.qq.message.value = "Player 1, it is your turn";
      win = false;
    }
    </script>
    </head>
    <body>
    <form name=qq>
    <table>
    <tr>
    <td></td>
    <td><input type=button name="t1" value="V" onclick="chooseMove(1, 23)"></td>
    <td><input type=button name="t2" value="V" onclick="chooseMove(1, 24)"></td>
    <td><input type=button name="t3" value="V" onclick="chooseMove(1, 25)"></td>
    <td><input type=button name="t4" value="V" onclick="chooseMove(1, 26)"></td>
    <td></td>
    </tr>
    <tr>
    <td><input type=button name="l1" value=">" onclick="chooseMove(2, 8)"></td>
    <td><input type=text name=one size=1 readonly></td>
    <td><input type=text name=two size=1 readonly></td>
    <td><input type=text name=three size=1 readonly></td>
    <td><input type=text name=four size=1 readonly></td>
    <td><input type=button name="r1" value="<" onclick="chooseMove(3, 5)"></td>
    </tr>
    <tr>
    <td><input type=button name="l2" value=">" onclick="chooseMove(2, 14)"></td>
    <td><input type=text name=five size=1 readonly></td>
    <td><input type=text name=six size=1 readonly></td>
    <td><input type=text name=seven size=1 readonly></td>
    <td><input type=text name=eight size=1 readonly></td>
    <td><input type=button name="r2" value="<" onclick="chooseMove(3, 11)"></td>
    </tr>
    <tr>
    <td><input type=button name="l3" value=">" onclick="chooseMove(2, 20)"></td>
    <td><input type=text name=nine size=1 readonly></td>
    <td><input type=text name=ten size=1 readonly></td>
    <td><input type=text name=eleven size=1 readonly></td>
    <td><input type=text name=twelve size=1 readonly></td>
    <td><input type=button name="r3" value="<" onclick="chooseMove(3, 17)"></td>
    </tr>
    <tr>
    <td><input type=button name="l4" value=">" onclick="chooseMove(2, 26)"></td>
    <td><input type=text name=thirteen size=1 readonly></td>
    <td><input type=text name=fourteen size=1 readonly></td>
    <td><input type=text name=fifteen size=1 readonly></td>
    <td><input type=text name=sixteen size=1 readonly></td>
    <td><input type=button name="r4" value="<" onclick="chooseMove(3, 23)"></td>
    </tr>
    <tr>
    <td></td>
    <td><input type=button name="b1" value="^" onclick="chooseMove(4, 5)"></td>
    <td><input type=button name="b2" value="^" onclick="chooseMove(4, 6)"></td>
    <td><input type=button name="b3" value="^" onclick="chooseMove(4, 7)"></td>
    <td><input type=button name="b4" value="^" onclick="chooseMove(4, 8)"></td>
    <td></td>
    </tr>
    </table>
    <br>
    <input type=text name="message" value="Click 'Start Game' to begin." size=60 readonly>
    <br>
    <br>
    <input type=button name="newGame" value="Start Game" onclick="startGame()">
    </form>
    </body>
    </html>
    How it works is you don't select the cell you want to place your naught/cross. Instead you click one of the buttons around the edge and your naught/cross slides onto the board and pushes all other values across the board. So if X goes first and clicks the top button on th left hand side:
    X _ _ _
    _ _ _ _
    _ _ _ _
    _ _ _ _
    then O makes the same move it pushes the X to the right
    O X _ _
    _ _ _ _
    _ _ _ _
    _ _ _ _
    then X clicks the left button on the top pushing the O down
    X X _ _
    O _ _ _
    _ _ _ _
    _ _ _ _

    The objective is still to get three in a row. Also to avoid a stalemate of the players cancelling each others moves out, I disallow pushing the move just made off the board by the next player. If X goes first by clicking the top button on the left, O cannot click the top button on the right (or the left button on the bottom) to immediately push the X back off the board.

  5. #5
    tabchas's Avatar
    tabchas is offline Member
    Join Date
    Mar 2011
    Location
    Austin
    Posts
    60
    Rep Power
    0

    Default

    Awesome. Thanks guys. I am for sure going to try to code the Tic-Tac-Toe variant that you posted Junky.
    Tabish Chasmawala

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •