home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume6 / xplumb / part01 / init.C < prev    next >
C/C++ Source or Header  |  1990-04-11  |  3KB  |  83 lines

  1. /*
  2.  * Copyright 1990 Digital Equipment Corporation
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and its
  5.  * documentation for any purpose and without fee is hereby granted,
  6.  * provided that the above copyright notice appear in all copies and that
  7.  * both that copyright notice and this permission notice appear in
  8.  * supporting documentation, and that the name of Digital Equipment
  9.  * Corporation not be used in advertising or publicity pertaining to
  10.  * distribution of the software without specific, written prior
  11.  * permission.  Digital Equipment Corporation makes no representations
  12.  * about the suitability of this software for any purpose.  It is
  13.  * provided "as is" without express or implied warranty.
  14.  *
  15.  * DIGITAL EQUIPMENT CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16.  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17.  * FITNESS, IN NO EVENT SHALL DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
  18.  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20.  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  21.  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Terry Weissman
  24.  *          weissman@wsl.dec.com
  25.  */
  26.  
  27. #include "plumbing.h"
  28.  
  29.  
  30. void InitLevel() {
  31.     int x, y;
  32.     fastflow = False;
  33.     numtoget = LevelNumToGet();
  34.     for (x=0 ; x<HSQUARES ; x++) {
  35.     for (y=0 ; y<VSQUARES ; y++) {
  36.         board[x][y].Clear();
  37.     }
  38.     }
  39.     startx = Random(HSQUARES - 2) + 1;
  40.     starty = Random(VSQUARES - 2) + 1;
  41.     startdir = Random(4);
  42.     board[startx][starty].SetPiece(PieceStart[startdir]);
  43.     board[startx][starty].ClearRemovable();
  44.     score->SetCountDown(LevelCountDown());
  45. }
  46.  
  47.  
  48. void InitializeGame() {
  49.     level = 1;
  50.     score->ClearScore();
  51.     InitLevel();
  52. }
  53.  
  54.  
  55. void GameOver() {
  56.     int i, x, y;
  57.     Display *dpy;
  58.     XEvent event;
  59.     TimerClearAll();
  60.     for (y=0 ; y<VSQUARES ; y++) {
  61.     for (x=0 ; x<HSQUARES ; x++) {
  62.         if (board[x][y].GetPiece() != PieceNone &&
  63.           board[x][y].GetRemovable()) {
  64.         board[x][y].SetPiece(PieceNone);
  65.         score->AddScore(LevelExtraScore());
  66.         for (i=0 ; i<numscreens ; i++)
  67.             XFlush(screen[i]->GetDpy());
  68.         TimerSleep(200);
  69.         }
  70.     }
  71.     }
  72.     mode = (numtoget > 0) ? ModeGameOver : ModeEndOfLevel;
  73.     if (mode == ModeGameOver) {
  74.     prevscore = score->GetScore();
  75.     score->RecordScore();
  76.     }
  77.     for (i=0 ; i<numscreens ; i++) {
  78.     dpy = screen[i]->GetDpy();
  79.     XClearArea(dpy, screen[i]->GetWindow(), 0, 0, 1, 1, True);
  80.     while (XCheckMaskEvent(dpy, ButtonPressMask, &event)) ;
  81.     }
  82. }
  83.