Basic card game
Results 1 to 2 of 2

Thread: Basic card game

  1. #1
    Senior Member cluelessPHP's Avatar
    Join Date
    Apr 2015
    Location
    Scotland
    Posts
    490

    Basic card game

    So as the title says, and given what I've being doing recently surprise surprise a card game

    It's not perfect you could inspect the element and change how many tokens you have I guess

    PHP Code:
    <div class="contain">
            <
    div class="top"><h1>My card game</h1></div>
            <
    div class="win"></div>
            <
    div class="tokens">500</div>
            <
    ul class="list">
             <
    li><div class="one"><img src='images/ace.jpg'></div></li>
            <
    li><div class="two"><img src='images/ace.jpg'></div></li>
            <
    li><div class="three"><img src='images/ace.jpg'></div></li>
            </
    ul>
            <
    button id="click">button</button>
        </
    div
    PHP Code:
    $(document).ready(function() { 

      
    setInterval(function(){ 
         var 
    bet parseFloat($('.tokens').text()) || 0;
         var 
    qty 2;
         var 
    total bet qty;
        $(
    '.tokens').text(total);
      }, 
    2000);

        $(
    "#click").click(function() { 
          
          var 
    tokens parseFloat($('.tokens').text()) || 0,
           
    qty 10,
           
    lose tokens qty,
           
    ace 100,
           
    king 70,
           
    queen 60,
           
    aceWin tokens ace,
           
    kingWin tokens king,
           
    queenWin tokens queen,
           
    image1 = [ "<img src='images/ace.png'>""<img src='images/king.png'>""<img src='images/queen.png'>"],
           
    number1 Math.floor(Math.random(image1) * 3),
           
    image2 = [ "<img src='images/ace.png'>""<img src='images/king.png'>""<img src='images/queen.png'>"],
           
    number2 =  Math.floor(Math.random(image2) * 3), 
           
    image3 = [ "<img src='images/ace.png'>""<img src='images/king.png'>""<img src='images/queen.png'>"], 
           
    number3 Math.floor(Math.random(image3) * 3),
           
    image1Pos image1.indexOf("<img src='images/ace.png'>"),
           
    image2Pos image1.indexOf("<img src='images/king.png'>"),  
           
    image3Pos image1.indexOf("<img src='images/queen.png'>"); 

        if(
    tokens 10){
          $(
    '.win').html("<h1>Not enough tokens</h1>"); 
          return 
    false;
       }
        else{
          $(
    '.one').html(image1[number1]); 
          $(
    '.two').html(image2[number2]); 
          $(
    '.three').html(image3[number3]); 
          
              if((
    number1 === number2) && (number2 === number3)){  
                 if(
    number1 === image1Pos){
                   $(
    '.win').html("<h1>You win!!</h1>");     
                   $(
    '.tokens').text(aceWin);
                 }
                else if(
    number1 === image2Pos){
                   $(
    '.win').html("<h1>You win!!</h1>");     
                   $(
    '.tokens').text(kingWin);
                 }
                else if(
    number1 === image3Pos){
                 $(
    '.win').html("<h1>You win!!</h1>");     
                 $(
    '.tokens').text(queenWin);
                 }
          }
          else{ 
              if( 
    lose >= ) {
                    $(
    '.tokens').text(lose);
              } 
                $(
    '.win').html("<h1>Try again!!</h1>"); 
                
    console.log("You lose"); 
          } 
        }    
      }); 
        

      
    }); 
    I haven't bothered with much CSS yet, but a live version

    Card game
    Once you had a good excuse, you opened the door to bad excuses ― Terry Pratchett, Thud
    Fresh start
    Github version
    Current date 14/10/17
    Finish date "should be" 14/04/18

    Vote on your preferred indentation method

  2. #2
    phpMaster
    Join Date
    Jun 2005
    Location
    Europe
    Posts
    3,009
    I tried your game: https://www.gotsocial.co.uk/math/

    I think you have done a great job with that game!
    Apache-2.4.28 (Win64) / PHP-7.1.10 / MySQL-5.7.19 / phpMyAdmin-4.7.4

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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