Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Commit

Permalink
Rearrange directories
Browse files Browse the repository at this point in the history
  • Loading branch information
jak103 committed May 29, 2020
1 parent 1416025 commit f4f6bd8
Show file tree
Hide file tree
Showing 33 changed files with 9,885 additions and 27 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions client/dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="favicon.ico">
<title>frontend</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">
<link href="/js/about.js" rel="prefetch"><link href="/js/app.js" rel="preload" as="script"><link href="/js/chunk-vendors.js" rel="preload" as="script"></head>
<body>
<noscript>
<strong>We're sorry but frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
<script type="text/javascript" src="/js/chunk-vendors.js"></script><script type="text/javascript" src="/js/app.js"></script></body>
</html>
157 changes: 157 additions & 0 deletions client/dist/js/about.js

Large diffs are not rendered by default.

454 changes: 454 additions & 0 deletions client/dist/js/app.js

Large diffs are not rendered by default.

9,224 changes: 9,224 additions & 0 deletions client/dist/js/chunk-vendors.js

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
Binary file added client/public/favicon.ico
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 13 additions & 3 deletions server/docker-compose.yml → docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
version: '3.6'

services:
dev:
client:
image: node:12-slim
working_dir: /client
volumes:
- ./client:/client
command:
npm run-script build-watch
environment:
NODE_ENV: development

server:
image: golang:1.14.2
container_name: golang
working_dir: /code
working_dir: /server
volumes:
- .:/code
- ./server:/server
command: bash -c "sleep infinity"

db:
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ import (
func main() {
fmt.Println("USU - UNO v0.0.0")


// New Echo server
e := echo.New()

// Setup middleware
e.File("/", "web/dist/index.html")
e.File("/", "/client/dist/index.html")

e.Use(middleware.Gzip())
e.Use(middleware.Recover())

e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
Root: "web/dist",
Root: "/client/dist",
HTML5: true,
}))
}))

// Setup routes
setupRoutes(e)
Expand Down
35 changes: 15 additions & 20 deletions server/uno.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
package main

import (
"github.com/labstack/echo"
"math/rand"
)

"github.com/labstack/echo"
)

////////////////////////////////////////////////////////////
// Structs used for the talking with frontend
////////////////////////////////////////////////////////////
type Response struct {
ValidGame bool `json:"valid"` // Valid game id
Payload map[string]interface{} `json:"payload"`
ValidGame bool `json:"valid"` // Valid game id
Payload map[string]interface{} `json:"payload"`
}

type Card struct {
Number int `json:"number"`
Color string `json:"color"`
Number int `json:"number"`
Color string `json:"color"`
}


////////////////////////////////////////////////////////////
// Utility functions used in place of firebase
////////////////////////////////////////////////////////////
func randColor(i int) string {
switch (i) {
switch i {
case 0:
return "red"
case 1:
Expand All @@ -37,39 +36,36 @@ func randColor(i int) string {
return ""
}


////////////////////////////////////////////////////////////
// All the data needed for a simulation of the game
// eventually, this will be replaced with firebase
////////////////////////////////////////////////////////////
var gameID string = ""
var currCard []Card = nil // The cards are much easier to render as a list
var currCard []Card = nil // The cards are much easier to render as a list
var players []string = []string{}
var playerIndex = 0 // Used to iterate through the players
var playerIndex = 0 // Used to iterate through the players
var currPlayer string = ""
var allCards map[string][]Card = make(map[string][]Card) // k: username, v: list of cards
var gameStarted bool = false


////////////////////////////////////////////////////////////
// Utility functions
////////////////////////////////////////////////////////////
func newRandomCard() []Card {
return []Card{Card{rand.Intn(9), randColor(rand.Intn(3))}}
return []Card{Card{rand.Intn(10), randColor(rand.Intn(4))}}
}

func newPayload(user string) map[string]interface{} { // User will default to "" if not passed
payload := make(map[string]interface{})

// Update known variables
// Update known variables
payload["current_card"] = currCard
payload["current_player"] = currPlayer
payload["all_players"] = players
payload["deck"] = allCards[user] // returns nil if currPlayer = "" or user not in allCards
payload["game_id"] = gameID
payload["game_over"] = checkForWinner()


return payload
}

Expand All @@ -86,7 +82,6 @@ func contains(arr []string, val string) (int, bool) {
return -1, false
}


////////////////////////////////////////////////////////////
// These are all of the functions for the game -> essentially public functions
////////////////////////////////////////////////////////////
Expand All @@ -112,12 +107,12 @@ func joinGame(c echo.Context) *Response {
}
return &Response{true, newPayload(c.Param("username"))}
}
return &Response{false, nil} // bad game_id
return &Response{false, nil} // bad game_id
}

func playCard(c echo.Context, card Card) *Response {
if checkID(c.Param("game")) && currPlayer == c.Param("username") {
if card.Color == currCard[0].Color || card.Number == currCard[0].Number {
if card.Color == currCard[0].Color || card.Number == currCard[0].Number {
// Valid card can be played
playerIndex = (playerIndex + 1) % len(players)
currPlayer = players[playerIndex]
Expand Down Expand Up @@ -157,12 +152,12 @@ func dealCards() {
for k := range players {
cards := []Card{}
for i := 0; i < 7; i++ {
cards = append(cards, Card{rand.Intn(9), randColor(rand.Intn(3))})
cards = append(cards, Card{rand.Intn(10), randColor(rand.Intn(4))})
}
allCards[players[k]] = cards
}

currCard = newRandomCard()
currCard = newRandomCard()
}

// TODO: make sure this reflects on the front end
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit f4f6bd8

Please sign in to comment.