aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-08-24 21:07:15 +0000
committerrodri <rgl@antares-labs.eu>2023-08-24 21:07:15 +0000
commit25e1b9489b9090b5d3372dd0dac09c1e7b3f10b3 (patch)
tree0145aaa99e65aee163d1ab69368ec3ef264f43b8
parent034cb6685100baa4452c9f2d3e445f6f1f7d5bf4 (diff)
downloadbattleship-25e1b9489b9090b5d3372dd0dac09c1e7b3f10b3.tar.gz
battleship-25e1b9489b9090b5d3372dd0dac09c1e7b3f10b3.tar.bz2
battleship-25e1b9489b9090b5d3372dd0dac09c1e7b3f10b3.zip
minor ship placement clean up.
-rw-r--r--bts.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/bts.c b/bts.c
index 05fb80d..bda3be9 100644
--- a/bts.c
+++ b/bts.c
@@ -20,7 +20,6 @@ Image *tiletab[NTILES];
Board alienboard;
Board localboard;
Ship armada[NSHIPS];
-Ship *curship;
struct {
int state;
@@ -250,7 +249,6 @@ initarmada(void)
Ship *s;
int i;
- s = nil;
for(i = 0; i < nelem(armada); i++){
s = &armada[i];
switch(i){
@@ -266,16 +264,14 @@ initarmada(void)
memset(s->hit, 0, s->ncells*sizeof(int));
s->sunk = 0;
}
- curship = s;
}
-/* XXX now placeships */
void
placeship(Mousectl *mc, Ship *s)
{
Rectangle newbbox;
- while(s >= armada){
+ for(;;){
if(readmouse(mc) < 0)
break;
@@ -287,12 +283,21 @@ placeship(Mousectl *mc, Ship *s)
s->bbox = newbbox;
}
if(mc->buttons == 1 && ptinrect(mc->xy, localboard.bbox))
- s--;
+ break;
send(drawchan, nil);
}
}
void
+placeships(Mousectl *mc)
+{
+ int i;
+
+ for(i = 0; i < nelem(armada); i++)
+ placeship(mc, &armada[i]);
+}
+
+void
lmb(Mousectl *mc)
{
Board *b;
@@ -333,7 +338,7 @@ rmb(Mousectl *mc)
switch(menuhit(3, mc, &menu, _screen)){
case PLACESHIP:
- placeship(mc, curship);
+ placeships(mc);
break;
}
}