[ADDED] a start for reading the random word from a file
This commit is contained in:
@@ -178,6 +178,7 @@ namespace Server.Models
|
||||
ServerCommunication.INSTANCE.JoinLobby(this.User,id);
|
||||
sendMessage(JSONConvert.ConstructLobbyJoinSuccessMessage());
|
||||
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
|
||||
Debug.WriteLine("Random chosen word: {0}", JSONConvert.GetRandomWord(@"..\resources\WordsForGame.json"));
|
||||
break;
|
||||
case LobbyIdentifier.LEAVE:
|
||||
id = JSONConvert.GetLobbyID(payload);
|
||||
|
||||
@@ -6,6 +6,16 @@
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="resources\WordsForGame.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="resources\WordsForGame.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AsyncAwaitBestPractices" Version="4.3.0" />
|
||||
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.0.1" />
|
||||
|
||||
31
Server/resources/WordsForGame.json
Normal file
31
Server/resources/WordsForGame.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"filename": "wordsForGame",
|
||||
"words": [
|
||||
"teacher",
|
||||
"love",
|
||||
"engineer",
|
||||
"supermarket",
|
||||
"disaster",
|
||||
"studio",
|
||||
"restaurant",
|
||||
"music",
|
||||
"chocolate",
|
||||
"dirt",
|
||||
"thought",
|
||||
"virus",
|
||||
"lieutenant",
|
||||
"painter",
|
||||
"kiwi",
|
||||
"power ranger",
|
||||
"computer",
|
||||
"people",
|
||||
"candidate",
|
||||
"security guard",
|
||||
"Canada",
|
||||
"teeth",
|
||||
"army",
|
||||
"airport",
|
||||
"president",
|
||||
"bedroom"
|
||||
]
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@@ -159,7 +160,22 @@ namespace SharedClientServer
|
||||
Array.Copy(BitConverter.GetBytes(payloadBytes.Length+5),0,res,0,4);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static string GetRandomWord(string filename)
|
||||
{
|
||||
string[] words = new string[25];
|
||||
using(StreamReader reader = new StreamReader(@"../../json1.jsonWordsForGame.json"))
|
||||
{
|
||||
string json = reader.ReadToEnd();
|
||||
words = JsonConvert.DeserializeObject<List<string>>(json).ToArray();
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
int index = random.Next(0, 24);
|
||||
|
||||
return words[index];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user