-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgameobjects.cs
91 lines (76 loc) · 2.56 KB
/
gameobjects.cs
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
using System;
namespace asciiadventure {
public abstract class GameObject {
public int Row {
get;
protected set;
}
public int Col {
get;
protected set;
}
public String Token {
get;
protected internal set;
}
public Screen Screen {
get;
protected set;
}
public GameObject(int row, int col, String token, Screen screen){
Row = row;
Col = col;
Token = token;
Screen = screen;
Screen[row, col] = this;
}
public virtual Boolean IsPassable() {
return false;
}
public override String ToString() {
return this.Token;
}
public void Delete() {
Screen[Row, Col] = null;
}
}
public abstract class MovingGameObject : GameObject {
public MovingGameObject(int row, int col, String token, Screen screen) : base(row, col, token, screen) {}
public string Move(int deltaRow, int deltaCol) {
int newRow = deltaRow + Row;
int newCol = deltaCol + Col;
if (!Screen.IsInBounds(newRow, newCol)) {
return "";
}
GameObject gameObject = Screen[newRow, newCol];
if (gameObject != null && !gameObject.IsPassable()) {
// TODO: How to handle other objects?
// walls just stop you
// objects can be picked up
// people can be interactd with
// also, when you move, some things may also move
// maybe i,j,k,l can attack in different directions?
// can have a "shout" command, so some objects require shouting
return "TODO: Handle interaction";
}
// Now just make the move
int originalRow = Row;
int originalCol = Col;
// now change the location of the object, if the move was legal
Row = newRow;
Col = newCol;
Screen[originalRow, originalCol] = null;
Screen[Row, Col] = this;
return "";
}
}
class Wall : GameObject {
public Wall(int row, int col, Screen screen) : base(row, col, "=", screen) {}
}
class Treasure : GameObject {
public Treasure(int row, int col, Screen screen) : base(row, col, "T", screen) {}
public override Boolean IsPassable() {
return true;
}
}
}