From f757f66b991d6bd81fc803521d8a928c736e1b15 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 27 May 2023 06:36:32 -0700 Subject: [PATCH] Add alt code for 2001/kev - arrow key support Since arrow keys can be more natural than other keys like the program's ',' and '.' for movement I added a version which lets you use arrow keys instead. One player could use the ',' and the other '.' or both can play with the same, whichever they pick. I also slowed down the speed of the ball as it moved very fast considering the slow speed the paddle moves. The README.md shows how to reset it or change the value via make. Updated .gitignore. --- 2001/kev/.gitignore | 1 + 2001/kev/Makefile | 9 ++-- 2001/kev/README.md | 70 +++++++++++++++++-------- 2001/kev/kev.alt.c | 122 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 179 insertions(+), 23 deletions(-) create mode 100644 2001/kev/kev.alt.c diff --git a/2001/kev/.gitignore b/2001/kev/.gitignore index 961ec1d0c..1fa9f0a7b 100644 --- a/2001/kev/.gitignore +++ b/2001/kev/.gitignore @@ -1 +1,2 @@ kev +kev.alt diff --git a/2001/kev/Makefile b/2001/kev/Makefile index 9ef43bc04..c1d5aac15 100644 --- a/2001/kev/Makefile +++ b/2001/kev/Makefile @@ -59,7 +59,7 @@ ARCH= # Defines that are needed to compile # -CDEFINE= -DPORT=5455 -DSPEED=50 -Dl_="socket(il.sin_family=AF_INET,SOCK_STREAM,0)" +CDEFINE= -DPORT=5455 -DSPEED=100 -Dl_="socket(il.sin_family=AF_INET,SOCK_STREAM,0)" # Include files that are needed to compile # @@ -115,8 +115,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt ################# @@ -138,6 +138,9 @@ ${PROG}: ${PROG}.c alt: data ${ALT_TARGET} @${TRUE} +${PROG}.alt: ${PROG}.alt.c + ${CC} ${CFLAGS} $< -o $@ ${LIBS} + # data files # data: ${DATA} diff --git a/2001/kev/README.md b/2001/kev/README.md index 3e95bab9c..6ebb48f2d 100644 --- a/2001/kev/README.md +++ b/2001/kev/README.md @@ -1,11 +1,8 @@ # Best Curses Game -Kevin Pulo -School of Information Technologies -Madsen Building F09 -University of Sydney, NSW, 2006 -Australia - +Kevin Pulo
+Australia
+
Mastodon: ## To build: @@ -17,15 +14,49 @@ make ## To run: ```sh -./kev hostname +./kev # in one terminal + +./kev hostname # in another terminal ``` +NOTE: each player's paddle is at the bottom and the opponent at the top. + +[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) slowed down the ball +just a tad as it went too fast for the speed at which the paddles move even when +holding down the movement keys. If you need to change the speed you can +reconfigure it like (say for over a network and not the same host): + +```sh +make clobber SPEED=50 all # default value which is very fast +``` + +There is an alternate version which lets you use the arrow keys to control your +paddle. See below Alternate code. + ## Try: ```sh +./kev ./kev localhost ``` +### Alternate code: + +[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) provided an alternate +version which lets you use the arrow keys on your keyboard instead of the more +awkward ',' and '.'. To use: + +```sh +make alt +``` + +Use `kev.alt` as you would `kev`. + +What happens if you use both, one in one terminal and the other in another +terminal? + +Thank you Cody! + ## Judges' remarks: Continuing with this year's "retro game" theme, this is another old game; @@ -45,7 +76,7 @@ box. * TCP sockets * curses -* usleep +* `usleep()` ### DESCRIPTION @@ -117,18 +148,17 @@ terminal size). ### BUILDING -Just run `make`to use the Makefile as above. The `SPEED` variable in the Makefile -controls the speed of the game (defaults to `50`). This speed is -the delay between frames in milliseconds. Thus a value of 0 will -make the game go as fast as your network can handle, and values -less than 50 are useful for larger terminals or more exciting -games. The program needs bandwidth equal to 1/s bytes per second -(where `s` is the speed value). Any latency on the network will -be added to `s` - so you should probably subtract any latency from -the value of `s` you want to have. Given that `loopback` and fast -Ethernet LANs are both much less than 1ms of latency, you should -only need to worry about this if you plan on playing over a slower -link like a cable modem, DSL, or (God-forbid) dial-up. +Just run `make`to use the Makefile as above. The `SPEED` variable in the +Makefile controls the speed of the game (defaults to `50`). This speed is the +delay between frames in milliseconds. Thus a value of 0 will make the game go +as fast as your network can handle, and values less than 50 are useful for +larger terminals or more exciting games. The program needs bandwidth equal to +1/s bytes per second (where `s` is the speed value). Any latency on the network +will be added to `s` - so you should probably subtract any latency from the +value of `s` you want to have. Given that `loopback` and fast Ethernet LANs are +both much less than 1ms of latency, you should only need to worry about this if +you plan on playing over a slower link like a cable modem, DSL, or (God-forbid) +dial-up. The TCP port to use for network communications is specified by the `PORT` variable in the Makefile. If the default of `5455` is diff --git a/2001/kev/kev.alt.c b/2001/kev/kev.alt.c new file mode 100644 index 000000000..fc2ce1300 --- /dev/null +++ b/2001/kev/kev.alt.c @@ -0,0 +1,122 @@ +#include +#include +#include +#include +#include +#include + +#define o0(M,W) mvprintw(W,M?M-1:M,"%s%s ",M?" ":"",_) +#define O0(M,W) M##M=(M+=W##M)-W##M +#define l1(M,W) M.tv_##W##sec +#define L1(m,M,l,L,o,O) for(L=l;L--;)((char*)(m))[o]=((char*)(M))[O] +#define I1 lL,(struct sockaddr*)&il +#define i1 COLS +#define j LINES +#define L_ ((j%2)?j:j-1) + +fd_set I;struct socka\ +ddr_in il;struct host\ +ent*LI; struct timeval +IL,l;char L[9],_[1<<9] + ;void ___(int __ + ){_[__--]=+0;if( + ++__)___(--__);_ + [__]='=';}double + o,oo=+0,Oo=+0.2; + long O,OO=0,oO=1 + ,ii,iI,Ii,Ll,lL, + II=sizeof(il),Il + ,ll,LL=0,i=0,li, + lI;int main(int\ + iL,char *Li[]){\ + initscr();keypad + (stdscr,1);cbreak + ();noecho();nonl + ();___(lI=i1/4); + _[0]='[';_[lI-1] + =']';L1(&il,&_,\ + II,O,+O,+lI);il. + sin_port=htons(( + unsigned long)(\ + PORT&0xffff));lL + =l_;if(iL=!--iL) + {il. sin_addr .\ + s_addr=0;bind(I1 + ,II);listen(lL,5 + );lL=accept(I1,& + II);}else{oO-=2; + LI=gethostbyname + (Li[1]);L1(&(il. + sin_addr),(*LI). + h_addr_list[0],\ + LI->h_length,iI, + iI,iI);(*(&il)). + sin_family=(&(*\ + LI))->h_addrtype + ;connect(I1,II); + }ii=Ii=(o=i1*0.5 + )-lI/2;iI=L_-1;O + =li=L_*0.5;while + (_){mvaddch(+OO, + oo,' ');o0(ii,iI + );o0(Ii,Il-=Il); + mvprintw(li-1,Il + ,"%d\n\n%d",i,LL + );mvhline(li,+0, + '-',i1);mvaddch( + O,o,'*');move(li + ,Il);refresh();\ + timeout(+SPEED); + gettimeofday(&IL + ,+0);Ll=getch(); + timeout(0);while + (getch()!=ERR);\ + if(Ll=='q'&&iL)\ + write(lL,_+1,1); + if(ii>(ll=0)&&Ll + ==KEY_LEFT){write(lL, + _,-(--Il));}else + if(Ll==KEY_RIGHT&&ii+\ + lIi1){o=i1+i1-o + ;Oo*=-1;}if(o>=( + Ii+=ll)&&O<1&&oO + <0&&o= + (ii+=Il)&&O>iI-1 +&&oO>0&&o+iI){O-=O;i++; +}}endwin();return(0);} +