File: xtron.c

package info (click to toggle)
xtron 1.1a-17
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 416 kB
  • sloc: ansic: 914; makefile: 17
file content (119 lines) | stat: -rw-r--r-- 2,737 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* tron.c - xtron v1.1 player routines
 *
 *   Copyright (C) 1995 Rhett D. Jacobs <rhett@hotel.canberra.edu.au>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 1, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Last Modified: 16/4/95
 */

#include "xtron.h"

struct Player p[2];
struct Board b;

void plr_setup(void)
{
  int i;

  /* set starting directions and player types, plus scores */
  p[0].plr_dir = left;
  p[1].plr_dir = right;
  
  for (i=0; i < 2; i++) {
    p[i].plr_type = computer;
    p[i].alive = 1;
    p[i].score = 0;
    p[i].co_ords[1] = MAXVERT/2;
  }
  p[0].co_ords[0] = (MAXHORZ/2)-3;
  p[1].co_ords[0] = (MAXHORZ/2)+3;
}


int plr_checkmove(int p_num, int new_val, int axis_type, enum directions dir)
{
  enum directions temp = left;

  switch (p[p_num].plr_dir) {
  case left:
    temp = right; break;
  case right:
    temp = left; break;
  case up:
    temp = down; break;
  case down:
    temp = up; break;
  }
  
  /* if move is in the opposite direction - invalid */
  if (dir == temp)
    return(0);
  return(1);
}


void plr_turn(int p_num, enum directions dir)
{
  switch(dir) {
  case left:
    if (plr_checkmove(p_num, (p[p_num].co_ords[0])-1, 0, dir))
      p[p_num].plr_dir = left;
    break;
  case right:
    if (plr_checkmove(p_num, (p[p_num].co_ords[0])+1, 0, dir))
      p[p_num].plr_dir = right;
    break;
  case up:
    if (plr_checkmove(p_num, (p[p_num].co_ords[1])-1, 1, dir))
      p[p_num].plr_dir = up;
    break;
  case down:
    if (plr_checkmove(p_num, (p[p_num].co_ords[1])+1, 1, dir))
      p[p_num].plr_dir = down;
    break;
   }
}


void brd_setup(void)
{
  int i,j;

  /* clear board */
  for(i=0; i< DIMS; i++)
    for(j=0;j< DIMS;j++)
      b.contents[i][j] = 0;
  
  /* inital player pieces */
  brd_newcontents((MAXHORZ/2)-3, MAXVERT/2, 1);
  brd_newcontents((MAXHORZ/2)+3, MAXVERT/2, 2);
}


int brd_newcontents(int x, int y, int what)
{
  /* 0 - Empty, 1 - Player 1, 2 - Player 2 */ 
  if (x > DIMS || x < 0)
    return(0);
  if (y > DIMS || y < 0)
    return(0);
  if (b.contents[x][y] != 0)
    return(0);
  else {
    b.contents[x][y] = what;
    return(1);
  }
}