-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtanks
40 lines (36 loc) · 1010 Bytes
/
tanks
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
using System;
class Program
{
static int playerPosition = 5;
static int enemyPosition = 10;
static void Main(string[] args)
{
while (true)
{
Draw();
string command = Console.ReadLine();
ProcessCommand(command);
if (playerPosition == enemyPosition)
{
Console.WriteLine("You hit the enemy!");
break;
}
}
}
static void Draw()
{
for (int i = 0; i < 15; i++)
{
if (i == playerPosition) Console.Write('T');
else if (i == enemyPosition) Console.Write('E');
else Console.Write('_');
}
Console.WriteLine();
}
static void ProcessCommand(string command)
{
if (command == "left" && playerPosition > 0) playerPosition--;
else if (command == "right" && playerPosition < 14) playerPosition++;
else if (command == "fire") playerPosition = enemyPosition;
}
}