-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
96 lines (52 loc) · 1.47 KB
/
README
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
This is my attempt at Snake in javascript, meant mainly to use javascript in a "meaningful" way.
This README alsocontains all my design notes,
snake design:
Initialise variables
At every tick:
update input vector
try to move:
if touches snake then
gameover
if touches nugget then
eat nugget
add new nugget
add 1 length to snake
else
move snake accordingly
Representation of snake:
list of points
functions:
move
set direction
lengthen
existence at point
Representation of world:
snake
tick function
nugget position
html inclusion:
just making it a div? <div class="snake"> ... ?
I'm fine with this.
snake representation details
the pointlist that holds the "parts" of the snake...... hiow do they work?
If I have three parts, for example, in order
0--1--2
when I move I could just move 0:
1--2--0
in which case 1 would be the new last.
so point list works like a circular buffer: there's a "current tail", as well as a "current head". We increment each every time.
This might seem like enough, but there's a slight problem.... adding requires a lot of shifting.
So I'll use a linked list. (or rather, just a cobbled together node list. I can't write linked list functionality correctly otherwise!)
The design remains similar.
When adding a thing, we'll just duplicate the tail....
before add:
0--1--2
hd: 2 -> 0
tl: 0 -> 1
adding an el't:
0/3--1--2
hd: 2->3
tl: 3->0
after "step":
0--1--2--3
BAM!