Changeset 5454:2ab8612a9401 in roaraudio


Ignore:
Timestamp:
03/25/12 20:24:36 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

use numblock encoding as requested

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/universal/tic-tac-toe.c

    r5450 r5454  
    3737"\n" \ 
    3838"Game board:     IDs:\n"        \ 
    39 " %c | %c | %c      0 | 1 | 2\n"   \ 
     39" %c | %c | %c      7 | 8 | 9\n"   \ 
    4040"---+---+---     ---+---+---\n" \ 
    41 " %c | %c | %c      3 | 4 | 5\n"   \ 
     41" %c | %c | %c      4 | 5 | 7\n"   \ 
    4242"---+---+---     ---+---+---\n" \ 
    43 " %c | %c | %c      6 | 7 | 8\n"   \ 
     43" %c | %c | %c      1 | 2 | 3\n"   \ 
    4444"\n" \ 
    4545"%s\n" 
     
    231231} 
    232232 
     233static char input2id(char c) { 
     234 if ( c > '9' ) 
     235  return c; 
     236 if ( c >= '7' ) 
     237  return c - 7; 
     238 if ( c >= '4' ) 
     239  return c - 1; 
     240 if ( c >= '1' ) 
     241  return c + 5; 
     242 return c; 
     243} 
     244 
    233245static int check_client(int client, struct roar_vio_calls * vio) { 
    234246 struct roar_client_server * cs; 
     
    239251 char won; 
    240252 int player_move = -1; 
     253 char c; 
    241254 
    242255 ROAR_DBG("check_client(client=%i, vio=%p) = ?", client, vio); 
     
    266279 
    267280 for (i = 0; i < len; i++) { 
    268   switch (buf[i]) { 
     281  c = input2id(buf[i]); 
     282  switch (c) { 
    269283   case 'q': 
    270284     clients_delete(client); 
     
    273287   case '0': case '1': case '2': case '3': case '4': 
    274288   case '5': case '6': case '7': case '8': 
    275      if ( try_put(cs->protoinst, buf[i] - '0', _PLAYER) == -1 ) { 
     289     if ( try_put(cs->protoinst, c - '0', _PLAYER) == -1 ) { 
    276290      msg = MSG__CANNOT_PUT_HERE; 
    277291      draw_game(client, cs->protoinst, msg); 
     
    280294      msg = MSG__YOUR_TURN; 
    281295      i = len; // end the loop. 
    282       player_move = buf[i] - '0'; 
     296      player_move = c - '0'; 
    283297     } 
    284298    break; 
Note: See TracChangeset for help on using the changeset viewer.