Removed offset for player position calculation as server does this for now
[clanbomber-xamarin-client.git] / src / communication / ConnectionTest / TcpJsonConnectionTest / Program.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Net;
5 using System.Net.Sockets;
6 using System.Text;
7 using System.Threading.Tasks;
8
9 namespace Bomberman
10 {
11     class Program
12     {
13         static void Main(string[] args)
14         {
15             TcpJsonConnection con = new TcpJsonConnection(DisplayServerInformation);
16
17             con.Connect(Dns.GetHostEntry(Dns.GetHostName()).AddressList[1]);    //localhost
18             // con.Connect(IPAddress.Parse("fe80::c0a:44f1:63e7:bfb8%4"));
19              //con.Connect(IPAddress.Parse("10.29.17.60"));
20
21             while (true)
22             {
23                 con.SendEvent(TcpJsonConnection.InputState.Right);
24                 System.Threading.Thread.Sleep(100);
25                 con.SendEvent(TcpJsonConnection.InputState.Down);
26                 System.Threading.Thread.Sleep(100);
27                 con.SendEvent(TcpJsonConnection.InputState.Left);
28                 System.Threading.Thread.Sleep(100);
29                 con.SendEvent(TcpJsonConnection.InputState.Up);
30                 System.Threading.Thread.Sleep(100);
31
32                 con.SendEvent(TcpJsonConnection.InputState.Idle);
33                 con.SendEvent(TcpJsonConnection.InputBomb.PlaceBomb);
34                 System.Threading.Thread.Sleep(100);
35                 con.SendEvent(TcpJsonConnection.InputBomb.Idle);
36                 System.Threading.Thread.Sleep(100);
37
38                 if(Console.KeyAvailable)
39                 {
40                     break;
41                 }
42             }
43
44
45             con.Close();
46
47         }
48
49
50
51         static void DisplayServerInformation(TcpJsonConnection.ServerPackage pkg)
52         {
53             char[,] playground = new char[pkg.Field.Count,pkg.Field.Count];
54
55
56             for (int i = 0; i < pkg.Field.Count; i++)
57             {
58                 for (int j = 0; j < pkg.Field[i].Count; j++)
59                 {
60                     playground[i,j]= FieldTypeToChar(pkg.Field[i][j]);
61                 }
62             }
63
64             foreach(var player in pkg.Players)
65             {
66                 playground[(int)player.Y, (int)player.X] = System.Convert.ToChar(player.Id + '0');
67             }
68
69             foreach (var bomb in pkg.Bombs)
70             {
71                 playground[(int)bomb.Y, (int)bomb.X] = 'o';
72             }
73
74             foreach (var flame in pkg.Flames)
75             {
76                 playground[(int)flame.Y, (int)flame.X] = '/';
77             }
78
79
80
81             for (int i = 0; i < pkg.Field.Count; i++)
82             {
83                 for (int j = 0; j < pkg.Field[i].Count; j++)
84                 {
85                     Console.Write(playground[i, j]);
86                 }
87                 Console.WriteLine();
88             }
89
90         }
91
92
93         static char FieldTypeToChar(TcpJsonConnection.ServerPackage.FieldTypes field)
94         {
95             switch(field)
96             {
97                 case TcpJsonConnection.ServerPackage.FieldTypes.DynamicOrDestroyableBlock:
98                     return '%';
99                 case TcpJsonConnection.ServerPackage.FieldTypes.StaticOrUndestroyableBlock:
100                     return '#';
101                 case TcpJsonConnection.ServerPackage.FieldTypes.ItemOrMoreBombs:
102                     return 'O';
103             }
104
105             return ' ';
106         }
107
108
109
110
111     }
112 }