home *** CD-ROM | disk | FTP | other *** search
- /* GAME.C
- * Main program, with main() function. Must still #include externs.h for
- * function prototypes.
- */
-
- #include <proto/all.h>
- #include <stdlib.h>
- #include <intuition/intuition.h>
- #include <stdio.h>
- #include <math.h>
- #include <time.h>
- #include <libraries/dos.h>
- #include "defns.h"
- #include "externs.h"
- int CXBRK(VOID) { return 0;}
-
- VOID titles(VOID);
- VOID main(VOID);
-
- VOID main()
- {
- struct IntuiMessage *msg;
- ULONG class,mnum,inum,snum;
- USHORT code,game;
- unsigned int clock[2];
- fclose(stdin); fclose(stdout); /*get rid of window opened automatically
- on the WorkBench screen*/
- timer(clock);
- srand(clock[1]); /*seed random number generator*/
- openall();
- initialisepack();
- DrawImage(wind->RPort,packim[0][0],FUPX,FUPY);
- DrawImage(wind->RPort,packim[0][0],FDPX,FDPY);
- AddGList(wind,&stdgad[3],-1,5,NULL);
- RefreshGList(&stdgad[3],wind,NULL,5);
- RemoveGList(wind,&stdgad[3],5); /*display standard gadgets*/
- titles();
- ScreenToFront(scr);
-
- while(!quit)
- {
- Wait(1l << mp->mp_SigBit);
- game=0;
- while(msg=(struct IntuiMessage *)GetMsg(mp))
- {
- class = msg->Class;
- code = msg->Code;
- gaddr = (struct Gadget *)msg->IAddress;
- ReplyMsg((struct Message *)msg);
- switch(class)
- {
- case GADGETUP:
- break;
- case MENUPICK:
- while(code!=MENUNULL)
- {
- mnum=MENUNUM(code);
- inum=ITEMNUM(code);
- snum=SUBNUM(code);
- switch(mnum)
- {
- case PROJMENU:
- switch(inum)
- {
- case 0:/* play */
- game = snum+1; /*process other messages first*/
- break;
- case 2:/* about */
- about();
- }
- }
- code=((struct MenuItem *)ItemAddress(menu,(LONG)code))->NextSelect;
- }
- }
- }
- switch(game)
- {
- case 1:
- REMHAND(plr[1]);
- REMHAND(plr[2]);
- REMHAND(plr[3]);
- DrawImage(wind->RPort,&setrem,0,0);
- OnMenu(wind,0x0020); OffMenu(wind,0x0000); OffMenu(wind,0x1000);
- OnMenu(wind,0xf862); OnMenu(wind,0x1800);
- playgame(3);
- OffMenu(wind,0x0020); OnMenu(wind,0x0000); OnMenu(wind,0x1000);
- OffMenu(wind,0xf862); OffMenu(wind,0x1800);
- DrawImage(wind->RPort,packim[0][0],FUPX,FUPY);
- DrawImage(wind->RPort,packim[0][0],FDPX,FDPY);
- TXTOUT(MESX,MESY,1,0,"Use Menus To Play....")
- titles();
- break;
- case 3:
- REMHAND(plr[1]);
- REMHAND(plr[2]);
- REMHAND(plr[3]);
- DrawImage(wind->RPort,&setrem,0,0);
- OnMenu(wind,0x0020); OffMenu(wind,0x0000); OffMenu(wind,0x1000);
- OnMenu(wind,0xf862); OnMenu(wind,0x1800); OffMenu(wind,0x1062);
- OffMenu(wind,0xf841); OffMenu(wind,0x1002); OffMenu(wind,0x1042);
- playgame(2);
- OffMenu(wind,0x0020); OnMenu(wind,0x0000); OnMenu(wind,0x1000);
- OffMenu(wind,0xf862); OffMenu(wind,0x1800); OnMenu(wind,0x1062);
- OnMenu(wind,0xf841); OnMenu(wind,0x1002); OnMenu(wind,0x1042);
- DrawImage(wind->RPort,packim[0][0],FUPX,FUPY);
- DrawImage(wind->RPort,packim[0][0],FDPX,FDPY);
- TXTOUT(MESX,MESY,1,0,"Use Menus To Play....")
- titles();
- break;
- }
- }
- closeall();
- }
-
- VOID openall()
- {
- if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",33l)))
- {
- closeall();
- exit(1);
- }
- if(!(scr=OpenScreen(&scrspec)))
- {
- closeall();
- exit(1);
- }
- winspec.Screen = scr;
- if(!(wind=OpenWindow(&winspec)))
- {
- closeall();
- exit(1);
- }
- if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0l)))
- {
- closeall();
- exit(1);
- }
- instexcp();
- SetMenuStrip(wind,menu); /*attach debug menu*/
- SetRGB4(&scr->ViewPort,0,3,9,3);
- SetRGB4(&scr->ViewPort,1,13,13,13);
- SetRGB4(&scr->ViewPort,2,12,4,4);
- SetRGB4(&scr->ViewPort,3,0,0,0);
- SetRGB4(&scr->ViewPort,4,4,5,11);
- SetRGB4(&scr->ViewPort,5,12,11,1);
- SetRGB4(&scr->ViewPort,6,9,9,9);
- SetRGB4(&scr->ViewPort,7,15,15,15);
- SetRGB4(&scr->ViewPort,16,4,5,11);
- SetRGB4(&scr->ViewPort,17,1,3,10);
- SetRGB4(&scr->ViewPort,18,6,9,9);
- SetRGB4(&scr->ViewPort,19,0,0,0);
- initdisp();
- SETPTR(ptrs[0])
- }
-
- VOID initdisp()
- {
- PrintIText(wind->RPort,inittxt,0,0);
- DrawImage(wind->RPort,plrids,0,0);
- }
-
- VOID instexcp()
- { /*install exception handler*/
- if(!(mp=CreatePort(NULL,0)))
- {
- closeall();
- exit(2);
- }
- if(!(tc=FindTask(NULL)))
- {
- closeall();
- exit(1);
- }
- tc->tc_ExceptCode = (APTR) excp;
- SetExcept(0xffffffff,1l << wind->UserPort->mp_SigBit);
- }
-
- VOID titles()
- {
- USHORT i;
- static struct TextAttr tp60it =
- { (STRPTR) "topaz.font", TOPAZ_SIXTY,FSF_ITALIC,FPF_ROMFONT };
- static struct IntuiText titletxt[] =
- {
- { 7,0,JAM1,445,70,&tp60it,"Rummy V1.00",&titletxt[1]},
- { 7,0,JAM1,427,100,&tp60it,"By Simon Preene",&titletxt[2]},
- { 7,0,JAM1,477,110,&tp60it,"1990",&titletxt[3]},
- { 4,0,JAM1,382,140,&tp60it,"Copyright Amiga Computing",&titletxt[4]},
- { 3,0,JAM1,378,170,&tp60it,"Use Project Menu To Start,",&titletxt[5]},
- { 3,0,JAM1,387,180,&tp60it,"Special And Intelligence",&titletxt[6]},
- { 3,0,JAM1,414,190,&tp60it,"To Select Options",NULL}
- };
- PrintIText(wind->RPort,titletxt,0,0);
- for(i=JACK;i<=KING;i++)
- {
- DrawImage(wind->RPort,packim[0][CARD(i,1)],30,plr[i-JACK+1]->yc+2);
- DrawImage(wind->RPort,packim[0][CARD(i,3)],100,plr[i-JACK+1]->yc+2);
- }
- }
-
- VOID closeall()
- {
- remexcp();
- if(GfxBase) CloseLibrary(GfxBase);
- if(wind)
- {
- if(wind->MenuStrip) ClearMenuStrip(wind);
- CloseWindow(wind);
- }
- if(scr) CloseScreen(scr);
- if(IntuitionBase) CloseLibrary(IntuitionBase);
-
- }
-
- VOID remexcp()
- { /*remove exception handler*/
- struct IntuiMessage *m2;
- if(tc) tc->tc_ExceptCode = NULL;
- if(mp)
- {
- while(m2=(struct IntuiMessage *)GetMsg(mp)) ReplyMsg((struct Message *)m2);
- DeletePort(mp);
- }
- }
-
- ULONG __asm excp(register __d0 ULONG signals,register __a1 ULONG exceptData)
- {
- static exgmverf=1,quitverf=1; /*flags used to decide if verify menus
- should be enabled or disabled*/
- ULONG class,mnum,inum,snum,gid,pos;
- USHORT code,pass; /*pass message to main program?*/
- struct IntuiMessage *m1;
- struct MenuItem *item;
- while(m1=(struct IntuiMessage *)GetMsg(wind->UserPort))
- {
- pass=0;
- class=m1->Class;
- code=m1->Code;
- switch(class)
- {
- case GADGETUP:
- gid=((struct Gadget *)(m1->IAddress))->GadgetID;
- switch(gid)
- {
- case CONTG:
- cont=1;
- pass=1;
- break;
- case NHANDG: /* Num hand gadget */
- numhand = ((struct StringInfo *)(stdgad[7].SpecialInfo))->LongInt;
- break;
- case FUPG:
- if(stdgad[5].Flags&SELECTED)
- {
- pos=RemoveGList(wind,&stdgad[6],1);
- RefreshGList(&stdgad[6],wind,NULL,1);
- stdgad[6].Flags &= ~SELECTED;
- AddGList(wind,&stdgad[6],pos,1,NULL);
- pass=1;
- }
- break;
- case FDPG:
- if(stdgad[6].Flags&SELECTED)
- {
- pos=RemoveGList(wind,&stdgad[5],1);
- RefreshGList(&stdgad[5],wind,NULL,1);
- stdgad[5].Flags &= ~SELECTED;
- AddGList(wind,&stdgad[5],pos,1,NULL);
- pass=1;
- }
- break;
-
- default:
- pass=1;
- }
- break;
- case MENUPICK:
- while(code!=MENUNULL)
- {
- item=ItemAddress(menu,code);
- mnum=MENUNUM(code);
- inum=ITEMNUM(code);
- snum=SUBNUM(code);
- switch(mnum)
- {
- case PROJMENU:
- switch(inum)
- {
- case 0:
- if(snum==3)
- { /*exit game*/
- exgmverf = !exgmverf;
- if(!exgmverf)
- {
- OnMenu(wind,0xf803);
- SetWindowTitles(wind,NULL,"Rummy <END GAME>: Use Verify Menu To Confirm");
- }
- else
- { /*reselect to cancel*/
- OffMenu(wind,0xf803);
- if(quitverf) SetWindowTitles(wind,NULL,"Rummy by Simon Preene, Copyright Amiga Computing 1990");
- else SetWindowTitles(wind,NULL,"Rummy <QUIT>: Use Verify Menu To Confirm");
- }
- }
- case 1:
- case 2:
- pass=1;
- break;
- case 3:
- /*quit=1;*/
- quitverf = !quitverf;
- if(!quitverf)
- {
- OnMenu(wind,0xf823);
- SetWindowTitles(wind,NULL,"Rummy <QUIT>: Use Verify Menu To Confirm");
- }
- else
- { /*reselect to cancel*/
- OffMenu(wind,0xf823);
- if(exgmverf) SetWindowTitles(wind,NULL,"Rummy by Simon Preene, Copyright Amiga Computing 1990");
- else SetWindowTitles(wind,NULL,"Rummy <END GAME>: Use Verify Menu To Confirm");
- }
- pass=1; /*must still awaken main program*/
- break;
- }
- break;
- case INTELLMENU:
- plr[inum+1]->level = snum+1;
- break;
- case DEBUGMENU:
- switch(inum)
- {
- case 0:/*view cards*/
- plr[snum+1]->viewcard = item->Flags & CHECKED;
- break;
- case 1:/*manual deal*/
- mandeal=item->Flags & CHECKED;
- break;
- case 2:/*manual control*/
- plr[snum+1]->manctrl = item->Flags & CHECKED;
- break;
- case 3:/*modify memory*/
- pass=1;
- break;
- case 4:/*initialise pack*/
- initpack[snum] = item->Flags & CHECKED;
- break;
- case 5:/*shuffle pack*/
- shufpack[snum] = item->Flags & CHECKED;
- break;
- case 6:/*continuous play*/
- contplay = item->Flags&CHECKED;
- break;
- }
- break;
- case VERIFYMENU:
- if(inum==0)
- {
- exgm=1;
- exgmverf = !exgmverf;
- OffMenu(wind,0xf803);
- if(quitverf) SetWindowTitles(wind,NULL,"Rummy by Simon Preene, Copyright Amiga Computing 1990");
- else SetWindowTitles(wind,NULL,"Rummy <QUIT>: Use Verify Menu To Confirm");
- }
- else quit=inum==1;
- pass = quit || exgm;
- }
- code=item->NextSelect;
- }
- }
- if(pass) PutMsg(mp,(struct Message *)m1); /*pass message to main program*/
- else ReplyMsg((struct Message *)m1);
- }
- return signals;
- }
-
- VOID prgenmsg(ULONG class,USHORT code,APTR iaddr,struct playerinfo *cp)
- { /* in this function switches are used in places where they are not
- needed to simplify future changes*/
- ULONG mnum,inum,snum;
- switch(class)
- {
- case GADGETUP:
- break; /*gadget processing handled in main program*/
- case MENUPICK:
- while(code!=MENUNULL)
- {
- mnum=MENUNUM(code);inum=ITEMNUM(code);snum=SUBNUM(code);
- switch(mnum)
- {
- case PROJMENU:
- switch(inum)
- {
- case 1: /*reorder*/
- reorder(cp);
- break;
- case 2:/*about*/
- about();
- break;
- }
- break;
- case DEBUGMENU:
- switch(inum)
- {
- case 3: /*modify memory*/
- modmem(plr[snum+1]);
- break;
- }
- }
- code=((struct MenuItem *)ItemAddress(menu,(LONG)code))->NextSelect;
- }
- }
- }
-
- VOID about()
- {
- struct IntuiMessage *msg;
- USHORT fin=0;
- Request(&aboutr,wind);
- while(!fin)
- {
- Wait(1<<mp->mp_SigBit);
- while(msg=(struct IntuiMessage *)GetMsg(mp))
- {
- if(msg->Class == GADGETUP && ((struct Gadget *)(msg->IAddress))->GadgetID==PROCG) fin=1;
- ReplyMsg((struct Message *)msg);
- }
- }
- }
-
-