added getting words
This commit is contained in:
		| @@ -4,10 +4,11 @@ import ( | |||||||
| 	"net/http" | 	"net/http" | ||||||
|  |  | ||||||
| 	"gitea.elara.ws/Hazel/hangman/internal/game" | 	"gitea.elara.ws/Hazel/hangman/internal/game" | ||||||
|  | 	"gitea.elara.ws/Hazel/hangman/internal/words" | ||||||
| 	"github.com/labstack/echo/v4" | 	"github.com/labstack/echo/v4" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func CreateSession(c echo.Context) error { | func CreateSession(c echo.Context) error { | ||||||
| 	s := game.NewSession() | 	s := game.NewSession(words.GetRandomWord()) | ||||||
| 	return c.JSON(http.StatusOK, s) | 	return c.JSON(http.StatusOK, s) | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										104338
									
								
								internal/words/dictionary.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										104338
									
								
								internal/words/dictionary.go
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										10
									
								
								internal/words/get_words.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								internal/words/get_words.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | |||||||
|  | package words | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"math/rand/v2" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | func GetRandomWord() string { | ||||||
|  | 	// https://stackoverflow.com/a/22876612/16804841 | ||||||
|  | 	return Words[rand.IntN(len(Words))] | ||||||
|  | } | ||||||
							
								
								
									
										4
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								main.go
									
									
									
									
									
								
							| @@ -8,6 +8,7 @@ import ( | |||||||
|  |  | ||||||
| 	"gitea.elara.ws/Hazel/hangman/internal/rest_handler" | 	"gitea.elara.ws/Hazel/hangman/internal/rest_handler" | ||||||
| 	"gitea.elara.ws/Hazel/hangman/internal/view_handler" | 	"gitea.elara.ws/Hazel/hangman/internal/view_handler" | ||||||
|  | 	"gitea.elara.ws/Hazel/hangman/internal/words" | ||||||
| 	"github.com/labstack/echo/v4" | 	"github.com/labstack/echo/v4" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| @@ -26,6 +27,9 @@ func (t *TemplateRegistry) Render(w io.Writer, name string, data interface{}, c | |||||||
| } | } | ||||||
|  |  | ||||||
| func main() { | func main() { | ||||||
|  | 	fmt.Println(words.GetRandomWord()) | ||||||
|  | 	return | ||||||
|  |  | ||||||
| 	fmt.Println("wanna play hangman? Well ya cant since it isn't implemented yet..") | 	fmt.Println("wanna play hangman? Well ya cant since it isn't implemented yet..") | ||||||
|  |  | ||||||
| 	e := echo.New() | 	e := echo.New() | ||||||
|   | |||||||
| @@ -66,7 +66,29 @@ class Session: | |||||||
|         return u |         return u | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def build_word_dict(): | ||||||
|  |     lines = [ | ||||||
|  |         """package words | ||||||
|  |  | ||||||
|  | var Words []string = []string{""" | ||||||
|  |     ] | ||||||
|  |  | ||||||
|  |     with open("/usr/share/dict/words", "r") as f: | ||||||
|  |         for l in f.readlines(): | ||||||
|  |             lines.append(f'\t"{l.strip()}",') | ||||||
|  |      | ||||||
|  |     lines.append("}") | ||||||
|  |  | ||||||
|  |     with open("internal/words/dictionary.go", "w") as f: | ||||||
|  |         f.write("\n".join(lines)) | ||||||
|  |  | ||||||
|  |     exit() | ||||||
|  |      | ||||||
|  |  | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
|  |  | ||||||
|  |     build_word_dict() | ||||||
|  |  | ||||||
|     s = Session() |     s = Session() | ||||||
|     print(s) |     print(s) | ||||||
|     s.add_user(name="Hazel") |     s.add_user(name="Hazel") | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user