فهرست منبع

First steps for adding a new game

Pjotir 10 ماه پیش
والد
کامیت
9e7f614079
5فایلهای تغییر یافته به همراه63 افزوده شده و 9 حذف شده
  1. 2 0
      .gitignore
  2. 25 1
      flaskapp.py
  3. 2 2
      game.py
  4. 2 1
      static/css/custom.css
  5. 32 5
      templates/home.html

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+/venv
+/__pycache__

+ 25 - 1
flaskapp.py

@@ -1,7 +1,10 @@
-from flask import Flask, render_template
+from flask import Flask, abort, render_template, request, session
+
+from game import Game
 
 app = Flask(__name__)
 app.secret_key = "somebullshit"
+app.games = []
 
 
 @app.route("/")
@@ -9,5 +12,26 @@ def home():
     return render_template("home.html")
 
 
[email protected]("/newgame")
+def new_game(name):
+    try:
+        name = request.args["playerName"]
+        hand_size = request.args["handSize"]
+        match_count = request.args["matchCount"]
+        turn_count = request.args["turnCount"]
+    except KeyError as e:
+        return abort(400)
+
+    game = Game(name, hand_size, match_count, turn_count)
+    app.games.append(game)
+    session["game_id"] = game.id
+    session["player_id"] = game.player1.id
+
+
[email protected]("/game/<game_id>")
+def game(game_id):
+    return render_template("game.html", game_id=game_id)
+
+
 if __name__ == "__main__":
     app.run(debug=True)

+ 2 - 2
game.py

@@ -23,7 +23,7 @@ class Player:
 
 
 class Game:
-    def __init__(self, name, hand_size, match_amount):
+    def __init__(self, name, hand_size, match_amount, turns):
         self.id = randomword(5)
         self.player1 = Player(name)
         self.tile_pile = []
@@ -135,7 +135,7 @@ class Game:
 
 
 if __name__ == "__main__":
-    game = Game("testplayer", 7, 2)
+    game = Game("testplayer", 7, 2, 10)
     game.player_join("testplayer2")
     game.start_game()
     while True:

+ 2 - 1
static/css/custom.css

@@ -20,6 +20,7 @@ body {
     width: 100%;
 }
 
-input[type="text"] {
+input[type="text"],
+input[type="number"] {
     color: black;
 }

+ 32 - 5
templates/home.html

@@ -1,16 +1,43 @@
 {% extends "base.html" %}
 {% block content %}
 <div class="container">
-    <form action="/game">
+    <form action="/newgame">
         <div class="row">
-            <div class="one-half column">
+            <div class="six columns">
+                <label for="playerNameNewInput">Player Name</label>
                 <input type="text"
                     class="u-full-width"
-                    placeholder="Player Name"
+                    placeholder="Cool Guy"
                     id="playerNameNewInput"
                     name="playerName">
             </div>
-            <div class="one-half column">
+            <div class="two columns">
+                <label for="handSizeInput">Hand Size</label>
+                <input type="number"
+                    name="handSize"
+                    id="handSizeInput"
+                    class="u-full-width"
+                    value="7">
+            </div>
+            <div class="two columns">
+                <label for="matchCountInput">Match Count</label>
+                <input type="number"
+                    name="matchCount"
+                    id="matchCountInput"
+                    class="u-full-width"
+                    value="2">
+            </div>
+            <div class="two columns">
+                <label for="turnCountInput">Turn Count</label>
+                <input type="number"
+                    name="turnCount"
+                    id="turnCountInput"
+                    class="u-full-width"
+                    value="10">
+            </div>
+        </div>
+        <div class="row">
+            <div class="twelve column">
                 <button type="submit"
                     class="button-primary button-full">
                     New Game
@@ -19,7 +46,7 @@
         </div>
     </form>
     <hr>
-    <form action="/game">
+    <form action="/joingame">
         <div class="row">
             <div class="one-third column">
                 <input type="text"