home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xpool-10.zip / Xpool / main.c < prev    next >
C/C++ Source or Header  |  1992-05-26  |  5KB  |  191 lines

  1.  
  2.  
  3. /* I. ARIT 1992 Hidirbeyli,AYDIN,TR.  09400
  4.                 Golden,    CO,   USA. 80401
  5.  
  6.  
  7.   Copyright (C) 1992 Ismail ARIT
  8.  
  9.   This file  is distributed in the hope that it will be useful,
  10.   but without any warranty.  No author or distributor accepts
  11.   responsibility to anyone for the consequences of using it or for
  12.   whether it serves any particular purpose or works at all.
  13.  
  14.  
  15.   Everyone is granted permission to copy, modify and redistribute
  16.   this file under the following conditions:
  17.  
  18.      Permission is granted to anyone to make or distribute copies
  19.      of the source code, either as received or modified, in any
  20.      medium, provided that all copyright notices, permission and
  21.      nonwarranty notices are preserved, and that the distributor
  22.      grants the recipient permission for further redistribution as
  23.      permitted by this document.
  24.      No part of this program can be used in any commercial product.
  25.  
  26.  
  27. */
  28.  
  29.  
  30.  
  31. #include <string.h>
  32. #include <X11/Xlib.h>
  33. #include "definition.h" 
  34.  
  35.  
  36. extern char *progname;
  37. extern  Display disp;
  38. extern  Window Pane;
  39. extern  GC gc;
  40. extern int  file_type;
  41. extern  Ball * new__Ball (double Mass, double radious, float initX, float initY, double initVx, double initVy, double initVr);
  42.  
  43. extern  Coordinator * new__Coordinator (int HowManyObjects);
  44. extern  Stick * new__Stick (int type);
  45.  
  46.  
  47. /* at the beginning */
  48. int     WhiteBallOut = NO;
  49. int     BlackBallOut = NO;
  50.  
  51. int     YourScore = 0,
  52.         MyScore = 0;
  53. /* these are for stick position */
  54. int     StartX,
  55.         StartY,
  56.         NewX,
  57.         NewY;
  58.  
  59.  
  60.  
  61.  
  62. Space PlayGround;
  63. Timing PlayTime;
  64.  
  65.  
  66.  
  67. void usage () {
  68.     printf ("pool [/h] [3] [16] \n /h -->> prints this \n 3 -->> for three ball \n");
  69.     printf (" 16 -->> 16 ball play \n");
  70.     exit (0);
  71. }
  72.  
  73.  
  74.  
  75.  
  76. /* this is the big guy, controlling everything*/
  77. Coordinator * Dept_Head;
  78.  
  79. Stick * PoolStick;
  80. Stick * Trajectory;
  81.  
  82.     Ball * WhiteBall, *BlackBall;
  83.     Ball * DottedWhiteBall;     /* we'll use it for 3-ball pool */
  84.     Ball * MyBalls[7];
  85.     Ball * YourBalls[7];
  86.  
  87.  
  88. main (argc, argv)
  89. int     argc;
  90. char  **argv;
  91. {
  92.     int     i;
  93.     int     gameType,
  94.             HowManyBalls;
  95.  
  96.  
  97.     PlayGround.xmin = 1.000000;
  98.     PlayGround.ymin = 1.000000;
  99.     PlayGround.xmax = 745.000000;
  100.     PlayGround.ymax = 460.000000;
  101.     PlayTime.currenttime = 0.000;
  102.     PlayTime.totaltime = 100000.0000;/* you can play max 100000 sec. */
  103.     /* seconds */
  104.     PlayTime.dt = 0.040000; /* don't change this value without adjusting
  105.                                others */
  106.  
  107.     initgraph (argc, argv);
  108.     init_colors ();
  109.  
  110. /* here are the defaults */
  111.     gameType = SIXTEENBALL;
  112.     HowManyBalls = SIXTEENBALL;
  113.  
  114.     if (argc > 1) {
  115.     if (strcmp (argv[1], "/h") == 0)
  116.         usage ();
  117.     else
  118.         HowManyBalls = atoi (argv[1]);
  119.     printf ("%d   %s\n", HowManyBalls, argv[1]);
  120.  
  121.  
  122.     if (!((HowManyBalls != THREEBALL) || (HowManyBalls != SIXTEENBALL)))
  123.         usage ();
  124.     if (HowManyBalls == THREEBALL)
  125.         gameType = THREEBALL;
  126.     else
  127.         gameType = SIXTEENBALL;
  128.     }
  129.  
  130.     PoolStick = new__Stick (STICK);
  131.     Trajectory = new__Stick (TRAJECTORY);
  132.  
  133.     PoolStick -> GetColor (PoolStick, get_color (STICK_COLOR));
  134.     Trajectory-> GetColor (Trajectory, get_color (STICK_COLOR));
  135.  
  136.  
  137.  
  138.     Dept_Head = new__Coordinator (HowManyBalls);
  139.  
  140. /* we need these balls anyway */
  141.     WhiteBall = new__Ball (20, 12.5, 600, 230, 50, 0, 0);
  142.     BlackBall = new__Ball (20, 12.5, 200, 230, 0.1, 0, 0);
  143.  
  144.     WhiteBall -> MyColor_is (WhiteBall, WHITE_BALL);
  145.     BlackBall -> MyColor_is (BlackBall, BLACK_BALL);
  146.  
  147.     WhiteBall -> MyIDis (WhiteBall, Dept_Head -> RegisterThisObject (Dept_Head, WhiteBall));
  148.     BlackBall -> MyIDis (BlackBall, Dept_Head -> RegisterThisObject (Dept_Head, BlackBall));
  149.  
  150.  
  151.  
  152.  
  153. /* now let's see what user wants to play */
  154.     if (gameType == SIXTEENBALL) {
  155.     for (i = 0; i < 7; i++) {
  156.         MyBalls[i] = new__Ball (20, 12.5, 100 + i * 42, 400, 0.1, 0, 0);
  157.         MyBalls[i] -> MyColor_is (MyBalls[i], MY_BALLS_COLOR);
  158.         MyBalls[i] -> MyIDis (MyBalls[i], Dept_Head -> RegisterThisObject (Dept_Head, MyBalls[i]));
  159.     }
  160.     for (i = 0; i < 7; i++) {
  161.         YourBalls[i] = new__Ball (20, 12.5, 100 + i * 42, 300, 0.1, 0, 0);
  162.         YourBalls[i] -> MyColor_is (YourBalls[i], YOUR_BALLS_COLOR);
  163.         YourBalls[i] -> MyIDis (YourBalls[i], Dept_Head -> RegisterThisObject (Dept_Head, YourBalls[i]));
  164.  
  165.     }
  166.     }
  167.     else {
  168.     DottedWhiteBall = new__Ball (20, 15, 100, 250, 0.1, 0, 0);
  169.     DottedWhiteBall -> MyColor_is (DottedWhiteBall, YOUR_BALLS_COLOR);
  170.     DottedWhiteBall -> MyIDis (DottedWhiteBall, Dept_Head -> RegisterThisObject (Dept_Head, DottedWhiteBall));
  171.     }
  172.  
  173.  
  174.  
  175.     Dept_Head -> GetGameType (Dept_Head, gameType);
  176.  
  177.     Dept_Head -> GetBoundary (Dept_Head, PlayGround);
  178.  
  179.     Dept_Head -> GetTime (Dept_Head, PlayTime);
  180.  
  181. /*  Dept_Head -> AllowableBump (Dept_Head, 4.000000); */
  182.  
  183.     Dept_Head -> CheckSpeedsAndCalculateK (Dept_Head);
  184.  
  185.  
  186.     while (1) {
  187.     take_event ();
  188.     }
  189.  
  190. }
  191.