The final project of Computer Network in 2020A, written in Python.
Progress To-do List:
Meeting Summary:
urllib
or requests
Function Demand: Gamerule, which is listed in docs.
Demo implementation:
Protocol implementation: Please refer to its introduction page
Function Demand: Player's identity
All players in the game are summarized in a abstract class Person
which provides the following attributes and methods.
client
, a socket.socket
object, which is the sending socket to send packets.id
, the sequential identification number of the player, or the seat the player has taken.vote()
, joinElection()
, voteForPolice()
and speak()
method.police
, whether the player is the police officer. Notice that there is at most one police officer in a game.Villager
is the subclass of Person
, corresponds to the villager identity in the game. This subclass does not have any more attributes or methods.
Wolf
is the subclass of Person
, corresponds to all the evil identities in the game, including werewolves, King of Werewolves, and the White Werewolf. The latter two is the subclass of Wolf
. The Wolf
class include the following attributes and methods:
kill()
, werewolves need to kill a person at night. destruct()
, a werewolf reveals its identity and it turns night immediately.SkilledPerson
is the abstract subclass of Person
, corresponds to the skilled villager identity in the game, including Predictor
, Witch
, Hunter
, Guard
and Idiot
. The specific identity should be implemented in the subclass
skill()
, method for a player to use his skill.It should be noticed that the all the method mentioned above are based on the protocol and sends a packet to the client when the method is called. These methods return the action status of the play. For werewolves, for example, kill()
method should return a number indicating the person to be killed and destruct()
method should return a boolean value indicating whether the werewolf want to reveal its identity.
This layer is implemented on 2020/10/24, in abstraction.py
Function Demand: Server interface
The server should control the game progress, and inform each player's action.
Task: GUI design
PyQt5 is used to design and implement the GUI. A prototype will be needed.
Code Review Result of abstraction.py
The original file is modified to meet the function demand. Refer to the annotation in the file to get more information about the structure of the classes. UML graph is shown below:
Implementation of server side
Implementation of client side
Implementation of server side
The server plays a role as the God in the werewolf game, most game rules are carried out by the server and it follows the implementation logic like the following:
Implementation of client side
Implementation of server side
The code is committed to server.py and logic.py
Currently pending for further implementation and code review!
Implementation of client side
Discussed implementation of the special ability of wolves (狼人自爆). The consensus was that this ability is triggered by Ctrl-C. Python will raise an KeyboardInterrupt
exception to break out from the ongoing thread. The client use try-except
to catch this input and start processing.
The current code is committed to client_subthread.py. This file is not designed to be a standalone Python script file. It is to be checked and modulized.
Currently pending for further implementation and code review!
Implementation of server side
The code is committed to server.py and logic.py. For code review please refer to the following commits:
Issues during the development:
Currently pending for code review, static syntax check and joint debug with the client.
Implementation of client side
Progressed the implementation of the client side. Existing code is merged into client.py, and pending for code review. Please refer to history commits for more information.
Issues during the development: