This commit is contained in:
Chris Sexton 2019-10-05 12:08:08 -04:00
parent 028ee0bf10
commit 149812b669
3 changed files with 91 additions and 26 deletions

View File

@ -3,12 +3,17 @@
type direction = type direction =
| NS | NS
| EW | EW
| NE
| NW
| SE
| SW
| Corner | Corner
type env = type env =
| Wall of direction | Wall of direction
| Floor | Floor
| Trap | Trap
| Player
let envToString e = let envToString e =
@ -17,10 +22,19 @@ let envToString e =
match d with match d with
| NS -> "|" | NS -> "|"
| EW -> "-" | EW -> "-"
| NE -> "\\"
| NW -> "/"
| SE -> "/"
| SW -> "\\"
| Corner -> "+" | Corner -> "+"
| Floor -> "#" | Floor -> "."
| Trap -> "!" | Trap -> "!"
| Player -> "@"
let rowToString = List.fold (fun r e -> r + envToString e) "" let rowToString = List.fold (fun r e -> r + envToString e) ""
let floorToString = List.fold (fun f r -> f + rowToString r + "\n") "" let floorToString = List.fold (fun f r -> f + rowToString r + "\n") ""
let rowToStringList = List.map (fun e -> envToString e)
let floorToStringLists = List.map rowToStringList

View File

@ -6,6 +6,8 @@ open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Cors.Infrastructure open Microsoft.AspNetCore.Cors.Infrastructure
open Microsoft.AspNetCore.Hosting open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Logging open Microsoft.Extensions.Logging
open Microsoft.AspNetCore.Http
open FSharp.Control.Tasks.V2.ContextInsensitive
open Microsoft.Extensions.DependencyInjection open Microsoft.Extensions.DependencyInjection
open Giraffe open Giraffe
@ -34,17 +36,24 @@ module Views =
link [ _rel "stylesheet" link [ _rel "stylesheet"
_type "text/css" _type "text/css"
_href "/main.css" ] _href "/main.css" ]
script [ _src "//cdnjs.cloudflare.com/ajax/libs/rot.js/0.6.0/rot.js" ] []
script [ _src "//unpkg.com/vue" ] []
script [ _src "//unpkg.com/axios/dist/axios.min.js" ] []
script [ _src "/main.js"; _async ] []
] ]
body [] content body [] content
] ]
let partial() = let partial() =
h1 [] [ encodedText "Server" ] h1 [] [ encodedText "Dis my dumb game" ]
let index (model : Message) = let display() =
div [ _id "game" ] []
let index () =
[ [
partial() partial()
pre [] [ encodedText model.Text ] display()
] |> layout ] |> layout
// --------------------------------- // ---------------------------------
@ -52,21 +61,31 @@ module Views =
// --------------------------------- // ---------------------------------
let indexHandler (name: string) = let indexHandler (name: string) =
let floor = [ let view = Views.index ()
[ Wall Corner; Wall EW; Wall Corner ];
[ Wall NS; Floor; Wall NS ];
[ Wall Corner; Wall EW; Wall Corner ]
]
let model = { Text = floorToString floor }
let view = Views.index model
htmlView view htmlView view
type mapResponse =
{
view: string
}
let mapHandler() =
let floor = [
[ Wall Corner; Wall EW; Wall EW; Wall EW; Wall Corner ];
[ Wall NS; Floor; Floor; Floor; Wall NS ];
[ Wall NS; Floor; Player; Floor; Wall NS ];
[ Wall NS; Floor; Floor; Floor; Wall NS ];
[ Wall Corner; Wall EW; Wall EW; Wall EW; Wall Corner ]
]
json (floorToString floor)
let webApp = let webApp =
choose [ choose [
GET >=> GET >=>
choose [ choose [
route "/" >=> indexHandler "world" route "/" >=> indexHandler "world"
routef "/hello/%s" indexHandler routef "/hello/%s" indexHandler
route "/map" >=> mapHandler()
] ]
setStatusCode 404 >=> text "Not Found" ] setStatusCode 404 >=> text "Not Found" ]

View File

@ -0,0 +1,32 @@
let app = new Vue({
el: "#game" ,
data: {
display: null,
board: [],
err: ""
},
mounted() {
let options = {
forceSquareRatio:true
};
this.display = new ROT.Display(options);
document.getElementById("game").appendChild(this.display.getContainer());
this.getData();
},
methods: {
draw: function(board) {
console.log("drawing board:\n", this.board);
// let str = "Using a regular grid\n@....%b{blue}#%b{}##.%b{red}.%b{}.$$$";
this.display.drawText(0, 0, this.board);
},
getData: function() {
axios.get("/map")
.then(resp => {
console.log("Got data:\n", resp);
this.board = resp.data;
this.draw();
})
.catch(err => this.err = err);
}
}
});