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

UserInterface Class Reference

#include <ui.h>

List of all members.

Public Methods

void FlashNodes (Player &p, MoveList &ml)
void ShowAllPlayers (void)
Move GetPlayerMove (Player &, MoveList &)
void BeginTurn (Player &)
void EndTurn (Player &, Move)
void RevealSpy (Player &p, Move m)
void SpyTurn (Move &, int)
Move NoLegalMoves (Player &p)
int TransPop (byte bv, int color)
void InitScreen (void)
void DrawScreen (void)
void EraseScreen (void)
void Refresh (void)
void DrawTitleScreen ()
int * UFWOOM (void)
void Intro ()
void AboutButton (Display &)
void AnnounceWin (Player &, int)

Private Methods

void ShowSpyMoves (MoveList &moves)
int ComputePossTokens (MoveList &, int dest)

Private Attributes

MapWindowmapwin
KeyWindowkeywin
CPanelWindowcpanel
PlayerWindowplaywin
InfoWindowinfowin


Member Function Documentation

void UserInterface::AboutButton Display  
 

Definition at line 17 of file intro.c.

References Display::Add(), Window::Client(), Display::Draw(), Viewport::GetMaxX(), Viewport::GetMaxY(), Viewport::OutTextXY(), Pause, Viewport::SetTextJustify(), and Viewport::SetTextStyle().

Referenced by Intro().

00018 {
00019   Window *wf1 = new Window (200, 80, GREEN, LIGHTGRAY);
00020   assert (wf1 != NULL);
00021   IntroDisplay.Add (wf1, 175, 20);
00022   IntroDisplay.Draw();
00023   wf1->Client().SetTextStyle (GOTHIC_FONT, 0, 3);
00024   wf1->Client().SetTextJustify (CENTER_TEXT, CENTER_TEXT);
00025   wf1->Client().OutTextXY (wf1->Client().GetMaxX()/2, wf1->Client().GetMaxY()/2, "PREGO");
00026   delay(Pause);
00027   Window *wf2 = new Window (200, 80, GREEN, LIGHTGRAY);
00028   assert (wf2 != NULL);
00029   IntroDisplay.Add (wf2, 5, 250);
00030   IntroDisplay.Draw();
00031   wf2->Client().SetTextStyle (GOTHIC_FONT, 0, 3);
00032   wf2->Client().SetTextJustify (CENTER_TEXT, CENTER_TEXT);
00033   wf2->Client().OutTextXY (wf2->Client().GetMaxX()/2, wf2->Client().GetMaxY()/2, "SOMBRERO");
00034   delay(Pause);
00035   Window *wf3 = new Window (200, 80, GREEN, LIGHTGRAY);
00036   assert (wf3 != NULL);
00037   IntroDisplay.Add (wf3, 350, 223);
00038   IntroDisplay.Draw();
00039   wf3->Client().SetTextStyle (GOTHIC_FONT, 0, 3);
00040   wf3->Client().SetTextJustify (CENTER_TEXT, CENTER_TEXT);
00041   wf3->Client().OutTextXY (wf3->Client().GetMaxX()/2, wf3->Client().GetMaxY()/2, "KNEE CAPS");
00042   delay (Pause);
00043   Window *wf4 = new Window (300, 50, BLUE, LIGHTGRAY);
00044   assert (wf4 != NULL);
00045   IntroDisplay.Add (wf4, 5, 400);
00046   IntroDisplay.Draw();
00047   wf4->Client().SetTextStyle (GOTHIC_FONT, 0, 2);
00048   wf4->Client().SetTextJustify (CENTER_TEXT, CENTER_TEXT);
00049   wf4->Client().OutTextXY (wf4->Client().GetMaxX()/2, wf4->Client().GetMaxY()/2, "Click anywhere to play game");
00050   delay (Pause/2);
00051 }

void UserInterface::AnnounceWin Player  ,
int   
 

Definition at line 217 of file ui.c.

References FlashNodes(), Player::GetName(), Player::IsSpy(), MessageWin(), and NLines.

Referenced by main().

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 }

void UserInterface::BeginTurn Player  
 

Definition at line 140 of file ui.c.

References mapwin, playwin, Player::Position(), MapWindow::UnHilightNode(), and PlayerWindow::Update().

00141 {
00142   playwin->Update (p, theRules.CurrentTurn());
00143   mapwin->UnHilightNode (p.Position());
00144 }

int UserInterface::ComputePossTokens MoveList  ,
int    dest
[private]
 

Definition at line 126 of file ui.c.

References MoveList::GetCurrent(), MoveList::Next(), Move::Node, MoveList::Reset(), and Move::Trans.

Referenced by GetPlayerMove().

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 }

void UserInterface::DrawScreen void    [inline]
 

Definition at line 56 of file ui.h.

Referenced by InitScreen(), and Refresh().

00056 { theDisplay.Draw (); }

void UserInterface::DrawTitleScreen  
 

Definition at line 249 of file ui.c.

Referenced by UFWOOM().

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 }

void UserInterface::EndTurn Player  ,
Move   
 

Definition at line 147 of file ui.c.

References Player::GetColor(), MapWindow::HilightNode(), mapwin, Move::Node, Player::Position(), and MapWindow::UnHilightNode().

00148 {
00149   mapwin->UnHilightNode (p.Position());
00150   mapwin->HilightNode (m.Node, p.GetColor ());
00151 }

void UserInterface::EraseScreen void    [inline]
 

Definition at line 57 of file ui.h.

Referenced by InitScreen(), and Refresh().

00057 { theDisplay.Erase (); theDisplay.Clear (); }

void UserInterface::FlashNodes Player   p,
MoveList   ml
 

Definition at line 107 of file ui.c.

References MapWindow::DisableNodes(), MapWindow::EnableNodes(), Player::GetColor(), MapWindow::HilightNode(), mapwin, Player::Position(), and MapWindow::UnHilightNode().

Referenced by AnnounceWin(), GetPlayerMove(), and RevealSpy().

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 }

Move UserInterface::GetPlayerMove Player  ,
MoveList  
 

Definition at line 56 of file ui.c.

References AwayNow, ButtonMsg, ButtonPress, byte, Message::code, ComputePossTokens(), Message::d1, MapWindow::DisableNodes(), False, FlashNodes(), Player::GetColor(), ID_LEGAL, ID_QUIT, ID_REFRESH, ID_SPY, Player::IsSpy(), mapwin, MessageWin(), On, Message::origin, Player::Position(), Refresh(), ShowSpyMoves(), SpyMove, Status, TransPop(), True, and MapWindow::UnHilightNode().

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 }

void UserInterface::InitScreen void   
 

Definition at line 21 of file ui.c.

References cpanel, DrawScreen(), EraseScreen(), infowin, keywin, mapwin, and playwin.

Referenced by main().

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 }

void UserInterface::Intro  
 

Definition at line 55 of file intro.c.

References AboutButton(), Display::Add(), ButtonMsg, ButtonPress, Viewport::Clear(), Window::Client(), Display::Dispatch(), Display::Draw(), Viewport::GetMaxX(), Viewport::GetMaxY(), PushButton::GetXDim(), PushButton::GetYDim(), Viewport::OutTextXY(), Pause, Viewport::SetBkColor(), Viewport::SetColor(), Viewport::SetTextJustify(), and Viewport::SetTextStyle().

Referenced by main().

00056 {
00057   Display IntroDisplay;
00058 
00059   IntroDisplay.SetBkColor (BLACK);
00060   IntroDisplay.Clear();
00061 
00062   IntroDisplay.SetTextStyle (TRIPLEX_FONT, 0, 12);
00063   IntroDisplay.SetColor (LIGHTGRAY);
00064   IntroDisplay.SetTextJustify (CENTER_TEXT, CENTER_TEXT);
00065   IntroDisplay.OutTextXY (IntroDisplay.GetMaxX()/2, 90, "Scotland");
00066   IntroDisplay.SetColor (WHITE);
00067   IntroDisplay.OutTextXY (IntroDisplay.GetMaxX()/2 - 4, 86, "Scotland");
00068   IntroDisplay.SetTextStyle (TRIPLEX_FONT, 0, 14);
00069   IntroDisplay.SetColor (LIGHTGRAY);
00070   IntroDisplay.OutTextXY (IntroDisplay.GetMaxX()/2, 300, "Yard");
00071   IntroDisplay.SetColor (WHITE);
00072   IntroDisplay.OutTextXY (IntroDisplay.GetMaxX()/2 - 4, 296, "Yard");
00073 
00074 //  delay(1500);
00075 
00076   Window *w2 = new Window (100, 80, BLUE, LIGHTGRAY);
00077   assert (w2 != NULL);
00078   IntroDisplay.Add (w2, 160, 180);
00079   IntroDisplay.Draw();
00080   w2->Client().SetTextStyle (GOTHIC_FONT, 0, 3);
00081   w2->Client().SetColor (BLUE);
00082   w2->Client().OutTextXY(18, 10, "Chris");
00083   w2->Client().OutTextXY(15, 30, "L");
00084   delay(Pause);
00085 
00086   Window *w4 = new Window (100, 80, BLUE, LIGHTGRAY);
00087   assert (w4 != NULL);
00088   IntroDisplay.Add (w4, 370, 180);
00089   IntroDisplay.Draw();
00090   w4->Client().SetTextStyle (GOTHIC_FONT, 0, 3);
00091   w4->Client().SetColor (BLUE);
00092   w4->Client().OutTextXY(20, 10, "Evan");
00093   w4->Client().OutTextXY(14, 30, "O");
00094   delay(Pause);
00095 
00096   Window *w3 = new Window (100, 80, BLUE, LIGHTGRAY);
00097   assert (w3 != NULL);
00098   IntroDisplay.Add (w3, 265, 180);
00099   IntroDisplay.Draw();
00100   w3->Client().SetTextStyle (GOTHIC_FONT, 0, 3);
00101   w3->Client().SetColor (BLUE);
00102   w3->Client().OutTextXY(15, 10, "Wilson");
00103   w3->Client().OutTextXY(20, 30, "T");
00104   delay(Pause);
00105 
00106   Window *w = new Window (100, 80, BLUE, LIGHTGRAY);
00107   assert (w != NULL);
00108   IntroDisplay.Add (w, 55, 180);
00109   IntroDisplay.Draw();
00110   w->Client().SetTextStyle (GOTHIC_FONT, 0, 3);
00111   w->Client().SetColor (BLUE);
00112   w->Client().OutTextXY(18, 10, "Steve");
00113   w->Client().OutTextXY(18, 30, "W");
00114   delay(Pause);
00115 
00116   Window *w5 = new Window (100, 80, BLUE, LIGHTGRAY);
00117   assert (w5 != NULL);
00118   IntroDisplay.Add (w5, 475, 180);
00119   IntroDisplay.Draw();
00120   w5->Client().SetTextStyle (GOTHIC_FONT, 0, 3);
00121   w5->Client().SetColor (BLUE);
00122   w5->Client().OutTextXY(20, 10, "Evan");
00123   w5->Client().OutTextXY(14, 30, "B");
00124 
00125   PushButton *pb = new PushButton ("Play Game", BLUE, 0xFB);
00126   assert (pb != NULL);
00127   PushButton *pb2 = new PushButton ("About...", BLUE, 0xFA);
00128   assert (pb2 != NULL);
00129 //  PushButton *pb3 = new PushButton ("Huh???", BLUE, 0xF0);
00130 //  assert (pb3 != NULL);
00131 
00132   IntroDisplay.Add (pb, 500, IntroDisplay.GetMaxY() - pb->GetYDim() - 5);
00133   IntroDisplay.Add (pb2, 500 - pb->GetXDim() - 5, IntroDisplay.GetMaxY() - pb2->GetYDim() - 5);
00134 //  IntroDisplay.Add (pb3, 500 - pb->GetXDim() - pb2->GetXDim() - 20, IntroDisplay.GetMaxY() - pb3->GetYDim() - 5);
00135   IntroDisplay.Draw();
00136 
00137   Message DoneMsg (ButtonMsg, ButtonPress, 0xFB),
00138     AboutMsg (ButtonMsg, ButtonPress, 0xFA),
00139 //    Bounce (ButtonMsg, ButtonPress, 0xF0),
00140     m;
00141 
00142   do {
00143     m = IntroDisplay.Dispatch (Mouse.Event());
00144     if (m == AboutMsg)
00145     { AboutButton(IntroDisplay);
00146       m = IntroDisplay.Dispatch (Mouse.WaitForAnyEvent());
00147       m = DoneMsg;
00148     }
00149 //    if (m == Bounce)
00150 //    {
00151 //      for (int i = 0; i < 10; i++)
00152 //      {
00153 //
00154 //
00155 //      }
00156 //    }
00157   } while (m != DoneMsg);
00158 }

Move UserInterface::NoLegalMoves Player   p
 

Definition at line 198 of file ui.c.

References Player::GetName(), MessageWin(), and NullMove.

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 }

void UserInterface::Refresh void    [inline]
 

Definition at line 58 of file ui.h.

References DrawScreen(), and EraseScreen().

Referenced by GetPlayerMove().

00058 { EraseScreen(); DrawScreen (); }

void UserInterface::RevealSpy Player   p,
Move    m
 

Definition at line 154 of file ui.c.

References BusMask, FlashNodes(), Player::GetName(), MessageWin(), SubwayMask, and Move::Trans.

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 }

void UserInterface::ShowAllPlayers void   
 

Definition at line 42 of file ui.c.

References Player::GetColor(), MapWindow::HilightNode(), mapwin, and Player::Position().

Referenced by main().

00043 {
00044   for (int i=1; i<NumPlayers; i++)
00045   {
00046     Player* p = thePlayers [i];
00047     mapwin->HilightNode (p->Position(), p->GetColor());
00048   }
00049 }

void UserInterface::ShowSpyMoves MoveList   moves [private]
 

Definition at line 21 of file spywin.c.

References Display::Add(), BusMask, ButtonPress, Window::Client(), Message::code, Display::Dispatch(), Window::Draw(), MoveList::GetCurrent(), Viewport::GetMaxX(), Viewport::GetMaxY(), PushButton::GetXDim(), PushButton::GetYDim(), Window::Init(), MoveList::Next(), Viewport::OutTextXY(), MoveList::Reset(), Viewport::SetColor(), SubwayMask, TaxiMask, and Move::Trans.

Referenced by GetPlayerMove().

00022 {
00023   PopUpWin *SMWindow = new PopUpWin(200, 170, BLUE, WHITE, "Spy Moves", WHITE);
00024   assert (SMWindow != NULL);
00025   SMWindow->Init(&theDisplay, 100, 100);
00026   PushButton *pb = new PushButton (" OK ", BLUE, 0xF0);
00027   assert (pb != NULL);
00028   SMWindow->Client().Add (pb, (SMWindow->Client().GetMaxX()/2) - (pb->GetXDim()/2), SMWindow->Client().GetMaxY() - pb->GetYDim() - 5);
00029   SMWindow->Draw();
00030   SMWindow->Client().SetColor (BLACK);
00031 
00032   Move *current;
00033   char info[20];
00034   moves.Reset();
00035   int i = 1,AddlX = 0, y = 0;
00036   if (moves.Reset())
00037   {
00038     do {
00039       current = moves.GetCurrent();
00040       if (current->Trans==SubwayMask)
00041    {sprintf (info, "%2d: Subway", i);}
00042       else
00043       if (current->Trans==TaxiMask)
00044    {sprintf (info, "%2d: Taxi", i);}
00045       else
00046       if (current->Trans==BusMask)
00047    {sprintf (info, "%2d: Bus", i);}
00048       if (i == 13)
00049   {AddlX = 100; // puts text in second column
00050    y = 0;}      // puts text in first row
00051       SMWindow->Client().OutTextXY(5 + AddlX, 5 + (8*y), info);
00052       i++;
00053       y++;
00054     } while (moves.Next());
00055   }
00056   Message m;
00057   do
00058   {
00059     m = SMWindow->Client().Dispatch (Mouse.Event());
00060   } while (m.code != ButtonPress);
00061   delete SMWindow;
00062 }

void UserInterface::SpyTurn Move  ,
int   
 

Definition at line 175 of file ui.c.

References BusMask, MessageWin(), NLines, SubwayMask, and Move::Trans.

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 }

int UserInterface::TransPop byte    bv,
int    color
 

Definition at line 24 of file transpop.c.

References Group::Add(), Display::Add(), BusMask, ButtonMsg, ButtonPress, byte, Window::Client(), Message::code, Message::d1, Message::d2, Group::DisableBox(), Window::Dispatch(), Window::Draw(), Viewport::GetMaxX(), Viewport::GetMaxY(), PushButton::GetYDim(), Window::Init(), Message::origin, Square, Status, SubwayMask, TaxiMask, TWinXDim, and TWinYDim.

Referenced by GetPlayerMove().

00025 {
00026   int Mode=0, i=0;
00027 
00028   // CREATE WINDOW
00029   PopUpWin *w = new PopUpWin(TWinXDim, TWinYDim, RED, WHITE,
00030     "Mode of Transportation", WHITE);
00031   assert(w !=NULL);
00032   w->Init(&theDisplay, 640/2-TWinXDim/2, 480/2-TWinYDim/2);
00033 
00034   // CREATE CHECKBOXES
00035   CheckBox *ch[3];
00036   ch[0] = new CheckBox("Taxi", BLACK, color, 1000, Square);
00037   ch[1] = new CheckBox("Bus", BLACK, color, 1001, Square);
00038   ch[2] = new CheckBox("Subway", BLACK, color, 1002, Square);
00039   for(i=0; i<3; i++)
00040     assert(ch[i] !=NULL);
00041 
00042   // CREATE PUSHBUTTONS
00043   PushButton *pb[2];
00044   pb[1] = new PushButton ("Cancel", BLUE, 901);
00045   pb[0] = new PushButton ("Done", BLUE, 900, pb[1]->GetXDim(), pb[1]->GetYDim());
00046   for(i=0; i<2; i++)
00047     assert(pb[i] !=NULL);
00048 
00049   //CREATE GROUP AND ADD CHECKBOXES
00050   Group *modes = new Group(3, 1000);
00051     assert(modes !=NULL);
00052   w->Client().Add(modes, 0, 0);
00053   for(i=0; i<3; i++)
00054     modes->Add(ch[i], 20, 20+(i*20));
00055 
00056   //ADD PUSHBUTTONS AND GROUP TO POP-UP WINDOW
00057   w->Client().Add(pb[0], w->Client().GetMaxX()/2-65, w->Client().GetMaxY()-pb[0]->GetYDim()-5);
00058   w->Client().Add(pb[1], w->Client().GetMaxX()/2+5, w->Client().GetMaxY()-pb[1]->GetYDim()-5);
00059 
00060   //DRAW POP-UP WINDOW
00061   w->Draw();
00062 
00063   int def = 0;
00064   if(!(bv & TaxiMask))
00065     modes->DisableBox(1000);
00066   else
00067     def = 1000;
00068   if(!(bv & BusMask))
00069     modes->DisableBox(1001);
00070   else if (!def) def = 1001;
00071   if(!(bv & SubwayMask))
00072     modes->DisableBox(1002);
00073   else if (!def) def = 1002;
00074 
00075   Mode=def-1000;
00076   Message DoneMsg(ButtonMsg, ButtonPress, 900), m;
00077   Message CancelMsg(ButtonMsg, ButtonPress, 901);
00078   do {
00079     m=w->Dispatch(Mouse.Event());
00080     if((m.origin==ButtonMsg)&&(m.code==Status)&&(m.d2)) //Checkbox on
00081       Mode=m.d1-1000;
00082   } while((m != DoneMsg) && (m != CancelMsg));
00083 
00084   delete w;
00085 
00086   if(m==CancelMsg)
00087     return (-1);
00088   else
00089     return Mode;
00090 }

int * UserInterface::UFWOOM void   
 

Definition at line 20 of file ufwoom.c.

References Group::Add(), Display::Add(), ButtonMsg, ButtonPress, Circle, Viewport::Clear(), Window::Client(), Message::code, ComputerP, Message::d1, Message::d2, Disable, Display::Dispatch(), Display::Draw(), DrawTitleScreen(), Enable, Viewport::GetMaxX(), Viewport::GetMaxY(), PushButton::GetXDim(), PushButton::GetYDim(), GodMsg, HumanP, Inactive, Initial_Button_ID, Initial_Circle_CheckBox_ID, Initial_Group_ID, Initial_Square_CheckBox_ID, MaxPlayers, Off, On, Message::origin, Viewport::OutTextXY(), PColor, RequestStatus, Viewport::SetBkColor(), Viewport::SetColor(), Viewport::SetTextStyle(), Square, and Status.

Referenced by PlayerSetup().

00021 {
00022   Display UFWOOMDisplay;
00023   int* info; // used to return info to user
00024 
00025   int Num_Buttons = 0;
00026   int Num_Square_CheckBoxes = 0;
00027   int Num_Circle_CheckBoxes = 0;
00028   int Num_Groups = 0;
00029 
00030   char buf[40];
00031 
00032   int i;
00033   info = new int[6]; // new space to store info
00034 
00035   UFWOOMDisplay.SetBkColor (BLACK);
00036   UFWOOMDisplay.Clear ();
00037 
00038   CheckBox *box [MaxPlayers*3]; // each player requires three checkboxes
00039   for (int plyr = 0; plyr < MaxPlayers; plyr++)
00040   { // new control checkboxes for each player
00041     box[plyr*2] = new CheckBox ("Computer", BLACK, PColor[plyr], Initial_Square_CheckBox_ID + Num_Square_CheckBoxes, Square);
00042     Num_Square_CheckBoxes++; // increment square check box count
00043     box[(plyr*2)+1] = new CheckBox ("Human", BLACK, PColor[plyr], Initial_Square_CheckBox_ID + Num_Square_CheckBoxes, Square);
00044     Num_Square_CheckBoxes++;
00045   }
00046 
00047   box[Num_Square_CheckBoxes + Num_Circle_CheckBoxes] = new CheckBox ("Mr. X", BLACK, PColor[0], Initial_Circle_CheckBox_ID + Num_Circle_CheckBoxes, Circle);
00048   Num_Circle_CheckBoxes++;
00049 
00050   for (i = 0; i < MaxPlayers; i++) {
00051     sprintf (buf, "Detective %d", i+1);
00052     box[Num_Square_CheckBoxes + Num_Circle_CheckBoxes] = new CheckBox (buf, BLACK, PColor[i+1], Initial_Circle_CheckBox_ID + Num_Circle_CheckBoxes, Circle);
00053     Num_Circle_CheckBoxes++;
00054     }
00055 
00056   PushButton *pb = new PushButton ("Play Game", BLUE, Initial_Button_ID);
00057   Num_Buttons++;
00058 
00059   // assert gracefully aborts if failure
00060   for (i=0; i < (Num_Square_CheckBoxes + Num_Circle_CheckBoxes); i++)
00061     assert (box[i] != NULL);
00062   assert (pb != NULL);
00063 
00064   Group *g[6];
00065 
00066   for (i=0; i < MaxPlayers; i++)
00067   {
00068     g[i] = new Group (2, Initial_Group_ID + Num_Groups);
00069     Num_Groups++;
00070   }
00071 
00072   Window *w = new Window (376, 235, RED, LIGHTGRAY, "Player Information", WHITE);
00073   assert (w != NULL);
00074   // add window to display
00075   UFWOOMDisplay.Add (w, UFWOOMDisplay.GetMaxX()/2-(376/2), UFWOOMDisplay.GetMaxY()/2-(235/2));
00076   for(i=0; i<MaxPlayers; i++)
00077     w->Client().Add (g[i], 0, 0); // add groups to the window
00078 
00079   for (i=0; i<12; i+=2) {
00080     g[i/2]->Add(box[i], 167, 40+(20*(i/2))); // add boxes to the groups
00081     g[i/2]->Add(box[i+1], 267, 40+(20*(i/2)));
00082   }
00083 
00084   for (i=0; i < MaxPlayers; i++) // add boxes to windows
00085     w->Client().Add (box[i+12], 10, 40+(20*i));
00086   // add push button to window
00087   w->Client().Add (pb, (w->Client().GetMaxX()/2)-(pb->GetXDim()/2), w->Client().GetMaxY() - pb->GetYDim() - 5);
00088 
00089   DrawTitleScreen(); // this probably shouldn't be in func UFWOOM, but for now
00090 
00091   UFWOOMDisplay.Draw ();
00092 
00093   w->Client().SetTextStyle(DEFAULT_FONT, 0, 1);
00094   w->Client().SetColor(WHITE);
00095   w->Client().OutTextXY(15, 20, "Players");
00096   w->Client().OutTextXY(170, 20, "Control");
00097 
00098   for(i=102; i<107; i++) // disable circle buttons for all but spy and player 1
00099     UFWOOMDisplay.Dispatch (Message (GodMsg, Disable, i-100+200));
00100 
00101 // the circle button for the spy and detective 1 are ALWAYS on
00102   box[12] -> ChangeStatus (On); // A game consists of a spy
00103   box[12] -> SetPseudo (Off);
00104   box[13] -> ChangeStatus (On); // and at least 1 detective
00105   box[13] -> SetPseudo (Off);
00106 
00107   Message DoneMsg (ButtonMsg, ButtonPress, 0xFF), m;
00108 
00109   do {
00110     m = UFWOOMDisplay.Dispatch (Mouse.Event ());
00111 
00112     if ((m.origin==ButtonMsg)&&(m.code==Status)&&(m.d2)) {
00113       for(i=102; i<107; i++) {
00114   if(m.d1==i)
00115     UFWOOMDisplay.Dispatch (Message (GodMsg, Enable, i-100+200));
00116    }
00117     }
00118     else
00119     if ((m.origin == ButtonMsg) && (m.code == Status)&&(!m.d2)) {
00120       for(i=102; i<107; i++) {
00121   if(m.d1==i)
00122     UFWOOMDisplay.Dispatch (Message (GodMsg, Disable, i-100+200));
00123    }
00124     }
00125   } while (m != DoneMsg); // when they click Play Game button, end loop
00126 
00127   // loop through the circle buttons and request their status
00128  for (i = Initial_Circle_CheckBox_ID; i < Initial_Circle_CheckBox_ID + Num_Circle_CheckBoxes; i++) {
00129    m = UFWOOMDisplay.Dispatch (Message (GodMsg, RequestStatus, i));
00130    info[i - Initial_Circle_CheckBox_ID] = Inactive; // initialize players to inactive
00131    if ((m.origin == ButtonMsg) && (m.code == Status) && (m.d1 == i))
00132    {
00133     if (m.d2) // button is pressed
00134     { // are they controlled by a human or the computer
00135       m = UFWOOMDisplay.Dispatch (Message (GodMsg, RequestStatus, (Initial_Square_CheckBox_ID + ((i - Initial_Circle_CheckBox_ID) *2))));
00136       if ((m.origin == ButtonMsg) && (m.code == Status) && (m.d1 == Initial_Square_CheckBox_ID + ((i - Initial_Circle_CheckBox_ID) *2)))
00137       { // note: control buttons are mutually exclusive
00138   if (m.d2) // they are controlled by the computer
00139     {info[i - Initial_Circle_CheckBox_ID] = ComputerP;}
00140   else if (!m.d2) // they are controlled by a human
00141     {info[i - Initial_Circle_CheckBox_ID] = HumanP;}
00142       }
00143     }
00144    }
00145  }
00146  return (info);
00147 }


Member Data Documentation

CPanelWindow* UserInterface::cpanel [private]
 

Definition at line 35 of file ui.h.

Referenced by InitScreen().

InfoWindow* UserInterface::infowin [private]
 

Definition at line 37 of file ui.h.

Referenced by InitScreen().

KeyWindow* UserInterface::keywin [private]
 

Definition at line 34 of file ui.h.

Referenced by InitScreen().

MapWindow* UserInterface::mapwin [private]
 

Definition at line 33 of file ui.h.

Referenced by BeginTurn(), EndTurn(), FlashNodes(), GetPlayerMove(), InitScreen(), and ShowAllPlayers().

PlayerWindow* UserInterface::playwin [private]
 

Definition at line 36 of file ui.h.

Referenced by BeginTurn(), and InitScreen().


The documentation for this class was generated from the following files:
Generated on Sun Jul 6 23:07:18 2003 for Scotland Yard by doxygen1.2.15