Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

ui.c

Go to the documentation of this file.
00001 /**********************************************************************
00002 * FILE: ui.c
00003 * AUTHOR: CAL
00004 * DATE: 30 April 1993
00005 * PURPOSE:
00006 *   Houses the user interface
00007 ***********************************************************************/
00008 
00009 #include "ui.h"
00010 
00011 #include <stdio.h>
00012 #include <dos.h>
00013 #include <assert.h>
00014 #include "errwin.h"
00015 #include "msgwin.h"
00016 #include "rules.h"
00017 
00018 const int NLines = 5;   // Max lines of text in UI message windows
00019 
00020 
00021 void UserInterface::InitScreen (void)
00022 {
00023   EraseScreen ();
00024 
00025   mapwin  = new MapWindow;
00026   keywin  = new KeyWindow;
00027   cpanel  = new CPanelWindow;
00028   playwin = new PlayerWindow;
00029   infowin = new InfoWindow;
00030 
00031   theDisplay.Add (mapwin, 0,   0);
00032   theDisplay.Add (keywin,  223, 403);
00033   theDisplay.Add (cpanel, 300, 403);
00034   theDisplay.Add (playwin, 0,   403);
00035   theDisplay.Add (infowin, 502, 403);
00036   theDisplay.SetLineStyle (SOLID_LINE, HORIZ_DIR, 2);
00037   theDisplay.SetColor (BLUE);
00038   theDisplay.Line (0, 401, 639, 401);
00039   DrawScreen ();
00040 }
00041 
00042 void UserInterface::ShowAllPlayers (void)
00043 {
00044   for (int i=1; i<NumPlayers; i++)
00045   {
00046     Player* p = thePlayers [i];
00047     mapwin->HilightNode (p->Position(), p->GetColor());
00048   }
00049 }
00050 
00051 
00052 char* AwayNow [] = {"We go away now.", ""};
00053 char* SpyMove [] = {"Spy is about to move.",
00054         "Promise not to look at my Bum!?", "" };
00055 
00056 Move UserInterface::GetPlayerMove (Player& p, MoveList& ml)
00057 {
00058   if (p.IsSpy())
00059   {
00060     char buf [40];
00061     sprintf (buf, "Round %d", theRules.CurrentTurn());
00062     MessageWin (BLUE, WHITE, buf, WHITE, SpyMove, BLACK);
00063   }
00064   FlashNodes (p, ml);
00065 
00066   Message m;
00067   bool Done = False;
00068   int token;
00069 
00070   Mouse.Flush ();
00071   do {
00072     m = theDisplay.Dispatch (Mouse.Event ());
00073     if ((m.origin == ButtonMsg) && (m.code == ButtonPress))
00074       switch (m.d1)
00075       {
00076   case ID_REFRESH:
00077     Refresh ();
00078   case ID_LEGAL:
00079     FlashNodes (p, ml);
00080     break;
00081   case ID_SPY:
00082     ShowSpyMoves (thePlayers[0]->GetHistory());
00083     break;
00084   case ID_QUIT:
00085     MessageWin (RED, WHITE, "Quit Game", WHITE, AwayNow, BLACK);
00086     exit (1);
00087     break;
00088       }
00089     if ((m.origin == ButtonMsg) && (m.code == Status))
00090     {
00091       byte bv = ComputePossTokens (ml, m.d1);
00092       token = TransPop (bv, p.GetColor());
00093       if (token == -1)    // if they cancel
00094   mapwin->UnHilightNode (m.d1);
00095       else
00096   Done = True;
00097     }
00098   } while (! Done);
00099 
00100   mapwin->UnHilightNode (p.Position());
00101   mapwin->UnHilightNode (m.d1);
00102   mapwin->DisableNodes (ml);
00103   return Move (p.Position(), m.d1, On<<token);
00104 }
00105 
00106 
00107 void UserInterface::FlashNodes (Player& p, MoveList& ml)
00108 {
00109   const int delaytime = 250;
00110   const int iterations = 2;
00111 
00112   for (int i=0; i<iterations; i++)
00113   {
00114     mapwin->EnableNodes (ml, p.GetColor());
00115     mapwin->HilightNode (p.Position(), p.GetColor());
00116     delay (delaytime);
00117     mapwin->DisableNodes (ml);
00118     mapwin->UnHilightNode (p.Position());
00119     delay (delaytime);
00120   }
00121   mapwin->EnableNodes (ml, p.GetColor());
00122   mapwin->HilightNode (p.Position(), p.GetColor());
00123 }
00124 
00125 
00126 int UserInterface::ComputePossTokens (MoveList& ml, int dest)
00127 {
00128   int transtypes = 0;
00129 
00130   if (ml.Reset ())
00131     do {
00132       if (ml.GetCurrent()->Node == dest)
00133   transtypes = ml.GetCurrent()->Trans;
00134     } while (ml.Next ());
00135 
00136   return transtypes;
00137 }
00138 
00139 
00140 void UserInterface::BeginTurn (Player& p)
00141 {
00142   playwin->Update (p, theRules.CurrentTurn());
00143   mapwin->UnHilightNode (p.Position());
00144 }
00145 
00146 
00147 void UserInterface::EndTurn (Player& p, Move m)
00148 {
00149   mapwin->UnHilightNode (p.Position());
00150   mapwin->HilightNode (m.Node, p.GetColor ());
00151 }
00152 
00153 
00154 void UserInterface::RevealSpy (Player& p, Move m)
00155 {
00156   const int nlines = 3;
00157   char *Text [nlines];
00158 
00159   for (int i=0; i<nlines; i++)
00160     Text [i] = new char [40];
00161 
00162   sprintf (Text[0], "%s was seen taking %s",
00163      p.GetName(), (m.Trans==SubwayMask)? "the Subway" :
00164       ((m.Trans==BusMask)? "the Bus" : "a Taxi"));
00165   sprintf (Text[1], "He will now be revealed!");
00166   sprintf (Text[2], "");
00167 
00168   MessageWin (BLUE, WHITE, "Tip", WHITE, Text, BLACK);
00169 
00170   MoveList ml;
00171   FlashNodes (p, ml);
00172 }
00173 
00174 
00175 void UserInterface::SpyTurn (Move& mv, int RoundN)
00176 {
00177   char* Text [NLines];
00178   char t [40];
00179 
00180   for (int i=0; i<NLines; i++)
00181     Text [i] = new char [40];
00182 
00183   sprintf (t, "Tip: Round %d", RoundN+1);
00184   sprintf (Text [0], "Sources tell you the");
00185   sprintf (Text [1], "Spy was seen taking");
00186   if (mv.Trans & SubwayMask)
00187     sprintf (Text [2], "the Subway");
00188   else if (mv.Trans & BusMask)
00189     sprintf (Text [2], "the Bus");
00190   else
00191     sprintf (Text [2], "a Taxi");
00192   sprintf (Text [3], "");
00193 
00194   MessageWin (BLUE, WHITE, t, WHITE, Text, BLACK);
00195 }
00196 
00197 
00198 Move UserInterface::NoLegalMoves (Player& p)
00199 {
00200   char* Text [5];
00201   for (int i=0; i<5; i++)
00202   {
00203     Text [i] = new char [40];
00204     assert (Text [i] != NULL);
00205   }
00206   sprintf (Text[0], "%s has", p.GetName());
00207   sprintf (Text[1], "no legal moves");
00208   sprintf (Text[2], "this turn.");
00209   sprintf (Text[3], "");
00210   MessageWin (BLUE, WHITE, "Sorry", WHITE, Text, BLACK);
00211   for (i=0; i<5; i++)
00212     delete Text [i];
00213   return NullMove;
00214 }
00215 
00216 
00217 void UserInterface::AnnounceWin (Player& P, int RoundN)
00218 {
00219   char* Text [NLines];
00220 
00221   for (int i=0; i<NLines; i++)
00222     Text [i] = new char [40];
00223 
00224   if (P.IsSpy ())
00225   {
00226     sprintf (Text [0], "** Congratulations **");
00227     sprintf (Text [1], "The elusive %s", P.GetName ());
00228     sprintf (Text [2], "escaped from the Detectives...");
00229     sprintf (Text [3], "");
00230     MoveList m;
00231     FlashNodes (P, m);
00232     FlashNodes (P, m);
00233   }
00234   else
00235   {
00236     sprintf (Text [0], "** Congratulations **");
00237     sprintf (Text [1], "%s", P.GetName ());
00238     sprintf (Text [2], "caught the spy");
00239     sprintf (Text [3], "in round %d.", RoundN+1);
00240     sprintf (Text [4], "");
00241   }
00242   MessageWin (RED, WHITE, "Game Over...", WHITE, Text, BLACK);
00243 
00244   for (i=0; i<NLines; i++)
00245     delete Text [i];
00246 }
00247 
00248 
00249 void UserInterface::DrawTitleScreen()
00250 {
00251   theDisplay.SetTextJustify (CENTER_TEXT, CENTER_TEXT);
00252   theDisplay.SetTextStyle (TRIPLEX_FONT, 0, 8);
00253   theDisplay.OutTextXY (theDisplay.GetMaxX()/2, 35, "Scotland Yard");
00254 }
00255 

Generated on Sun Jul 6 23:07:16 2003 for Scotland Yard by doxygen1.2.15