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

control.c

Go to the documentation of this file.
00001 /**********************************************************************
00002 *       FILE:   control.c
00003 *       AUTHOR: Evan H. B
00004 *       DATE:   1 May, 1993
00005 *       PURPOSE: To play the game!
00006 **********************************************************************/
00007 
00008 #include "keybd.h"
00009 #include "ui.h"
00010 #include "players.h"
00011 #include "map.h"
00012 #include "rules.h"
00013 #include "ufwoom.h"
00014 #include <assert.h>
00015 #include <stdio.h>
00016 #include <conio.h>
00017 
00018 
00019 Video   Screen (VGAHi);
00020 MSMouse Mouse (Graphics);
00021 Keybd   Keys;
00022 
00023 Player *thePlayers [MAXPLAYERS];
00024 int     NumPlayers;
00025 
00026 Display   theDisplay;
00027 Map     theMap;
00028 UserInterface   UI;
00029 Rules     theRules;
00030 
00031 
00032 void PlayerSetup (void)
00033   {
00034    int *info, counter, nextPlayer;
00035 
00036    info = UI.UFWOOM ();
00037    if ((*info) == ComputerP)
00038      *thePlayers = new ComputerSpy ("Mr. X", PColor [0]);
00039    else
00040      *thePlayers = new HumanSpy ("Mr. X", PColor [0]);
00041 
00042    nextPlayer = NumPlayers = 1;   // Need a spy; first detective = player #1
00043    for (counter = 1; counter < MAXPLAYERS; counter++)
00044    {
00045      char buf [40];
00046      sprintf (buf, "Detective %d", counter);
00047      switch (info [counter])
00048        {
00049   case ComputerP :
00050     thePlayers [nextPlayer++] = new ComputerDetective (buf, PColor [counter]);
00051     NumPlayers++;
00052     break;
00053   case HumanP :
00054     thePlayers [nextPlayer++] = new HumanDetective (buf, PColor [counter]);
00055     NumPlayers++;
00056     break;
00057        }
00058    }
00059    delete info;         // Big Brother is gonna f--- you up real bad
00060   }
00061 
00062 void HosePlayers (void)
00063   {
00064     for (int i=0; i<NumPlayers; i++)
00065       delete thePlayers [i];
00066   }
00067 
00068 
00069 
00070 main ()
00071   {
00072    assert (Mouse.SetupOK ());
00073    assert (theMap.load_map ("NODELIST"));    // Get filename from cmdline
00074    bool busted;         // Has the spy been caught?
00075    int counter;
00076 
00077    UI.Intro();
00078 
00079    PlayerSetup ();      // You figure it out, ya dumb f---
00080 
00081    UI.InitScreen ();
00082    UI.ShowAllPlayers ();
00083 
00084    // Main game loop
00085    while (! (busted = (bool) theRules.GameOver ()))
00086      {
00087       // Move the Spy
00088       (*thePlayers) -> TakeTurn ();
00089 
00090       // Move the detectives
00091       for (counter = 1; (counter < NumPlayers) && (!busted); counter++)
00092   {
00093    thePlayers [counter] -> TakeTurn ();
00094    busted = (bool) theRules.SpyCaught ();
00095   }
00096       theRules.NewTurn ();
00097      }
00098    if (busted == -1)
00099      UI.AnnounceWin (*thePlayers[0], theRules.CurrentTurn());
00100    else
00101      UI.AnnounceWin (*thePlayers[busted], theRules.CurrentTurn());
00102 
00103 //   HosePlayers ();      // Nuke the players; we don't need them anymore
00104 
00105    return 0;
00106   }

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