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

ufwoom.c

Go to the documentation of this file.
00001 // ********************************************************************
00002 // * AUTHOR: Steven W               *
00003 // * TITLE: UFWOOM.C                                                  *
00004 // * DATE: April 29, 1993                                             *
00005 // * PURPOSE: User-Friendly Windows Oriented Options Menu             *
00006 // ********************************************************************
00007 
00008 #include "ui.h"
00009 #include "ufwoom.h"
00010 #include "group.h"
00011 #include "button.h"
00012 #include "window.h"
00013 #include <conio.h>
00014 #include <stdio.h>
00015 #include <alloc.h>
00016 #include <assert.h>
00017 
00018 
00019 
00020 int* UserInterface::UFWOOM()
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 }
00148 
00149 

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