Commits

Pedro Ferreira  committed 1a8b978

- show a message when a move is invalid etc

  • Participants
  • Parent commits 16e18ef

Comments (0)

Files changed (7)

 
     <script type="text/javascript" src="scripts/utilities.js"></script>
     <script type="text/javascript" src="scripts/move_animation.js"></script>
+    <script type="text/javascript" src="scripts/message.js"></script>
     <script type="text/javascript" src="scripts/cards.js"></script>
     <script type="text/javascript" src="scripts/player.js"></script>
     <script type="text/javascript" src="scripts/bot.js"></script>
 
     <div id="RoundEnded" title="Round ended"></div>
 
+    <div id="Message"></div>
 </body>
 </html>

File scripts/cards.ts

 
     clicked( event )
         {
+        Message.close();
+
             // left click
         if ( event.nativeEvent.button == 0 )
             {

File scripts/game.ts

 /// <reference path='round.ts' />
 /// <reference path='game_menu.ts' />
 /// <reference path='move_animation.ts' />
+/// <reference path='message.ts' />
 
 module Game
 {
 {
 Cards.init();
 MoveAnimation.init();
+Message.init();
 
 PASS_CARDS_ELEMENT = new createjs.Bitmap( G.PRELOAD.getResult( 'pass_left' ) );
 PASS_CARDS_ELEMENT.visible = false;
      return false;
     };
 
-
 drawCards();
 }
 
 
 export function passCards()
 {
+Message.close();
+
 for (var a = 0 ; a < PLAYERS_POSITION.length ; a++)
     {
     var player = PLAYERS[ PLAYERS_POSITION[ a ] ];
 
     if ( player.selectedCards.length < 3 )
         {
-        console.log( "Need to select 3 cards to pass." );
+        Message.open( 'Select 3 cards.', 'Need to select 3 cards to pass to another player.' );
         return;
         }
     }
 
 if ( player !== ACTIVE_PLAYER )
     {
-    console.log( 'Its ' + Position[ ACTIVE_PLAYER.position ] + ' turn' );
+    Message.open( "Other player's turn.", 'Its ' + Position[ ACTIVE_PLAYER.position ] + ' turn' );
     return false;
     }
 

File scripts/main.ts

             - when giving out the hands
             - for bot players
         - save highscores (the winrate - games played, games won, win percentage)
-        - show the messages, instead of printing to the console
-
  */
 
 var G = {

File scripts/message.ts

+/// <reference path='../typings/tsd.d.ts' />
+
+module Message
+{
+var MESSAGE = null;
+
+export function init()
+{
+var message = document.querySelector( '#Message' );
+
+$( message ).dialog({
+        position: { my: 'left bottom', at: 'left bottom', of: window },
+        dialogClass: 'no-close',
+        draggable: false,
+        autoOpen: false
+    });
+
+MESSAGE = message;
+}
+
+export function open( title, text )
+{
+$( MESSAGE ).text( text );
+$( MESSAGE ).dialog( 'option', 'title', title );
+$( MESSAGE ).dialog( 'open' );
+}
+
+
+export function close()
+{
+$( MESSAGE ).dialog( 'close' );
+}
+
+}

File scripts/player.ts

             {
             if ( this.selectedCards.length >= 3 )
                 {
-                console.log( "Can't select more than 3 cards,." );
+                Message.open( 'Only 3 cards.', "Can't select more than 3 cards." );
                 return;
                 }
 

File scripts/round.ts

 
         else
             {
-            console.log( 'Need to play the 2 of clubs' );
+            Message.open( 'Invalid move.', 'The first turn has to start with the 2 of clubs.' );
             return false;
             }
         }
 
                 else
                     {
+                    Message.open( 'Invalid move.', "Hearts haven't been broken yet." );
                     return false;
                     }
                 }
                 {
                 if ( card.suit == Cards.Suit.spades && card.suitSymbol == Cards.SuitSymbol.queen )
                     {
-                    console.log( "Can't play the queen of spades on first turn." );
+                    Message.open( 'Invalid move.', "Can't play the queen of spades on first turn." );
                     return false;
                     }
 
                 else if ( card.suit == Cards.Suit.hearts && player.cards[ 'hearts' ].length < 13 )
                     {
-                    console.log( "Can't play hearts on the first turn (unless you happen to have all 13 hearts cards." );
+                    Message.open( 'Invalid move.', "Can't play hearts on the first turn (unless you happen to have all 13 hearts cards." );
                     return false;
                     }
 
 
         else
             {
+            Message.open( 'Invalid move.', 'Need to play a card of the ' + Cards.Suit[ leadSuit ] + ' suit.' );
             return false;
             }
         }