GithubHelp home page GithubHelp logo

zavieryang / nimgame_project2 Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 76 KB

This is a Nim Game project from a programming course and this is the second part of this project.

Java 100.00%
nimgame java java-concepts

nimgame_project2's Introduction

Importance

This is a project from a programming course (subject). If you come to watch because of your course (subject) assignment, DO NOT just copy and paste this code or just modify the variables name otherwise your score is possible to be penalised. Moreover, this project is divided into three parts and is completed with the progress of the course (subject). Therefore, different JAVA concepts will not be implemented in the same part, and the difficulty will be different.

NimGame_project2

This project (Project 2), and the next one (Project 3), will continue with the same theme introduced in Project 1 - namely, an implementation of the game of Nim. Please refer to the Project A specification for a description of the game and its rules.

Go to Project 1

Go to Project 3

Key Knowledge Points Covered in Project 2:

  1. Design of the class structure for the project requires the knowledge of UML diagrams.
  2. Implementation requires understanding of Classes and Arrays (Cannot use Arraylist)

Requirements

In this project, we introduce a third class NimGame. The game playing process is delegated from Nimsys to NimGame. Since only one game will be active at any given time, only a single NimGame instance is required at any time by Nimsys. Nimsys should also maintain a collection of players. Initially, this collection will be empty - players will need to be added in order to play a game.

  • NimGame need to havse some information (more information can added in order to finish project):

    1. The current stone count
    2. An upper bound on stone removal
    3. Two players
  • NimPlayer need to havse some information (more information can added in order to finish project):

    1. A username
    2. A given name
    3. A family name
    4. Number of games played
    5. Number of games won

The system should allow players to be added. It should also allow for players to be deleted, or for their details to be edited. Players should not be able to directly edit their game statistics, although they should be able to reset them.

The system is a text based interactive program that reads and executes commands from standard input (the keyboard) until an ‘exit’ command is issued, which will terminate the program. If a command produces output, it should be printed to standard output (the terminal).

  • Input syntax descriptions

    1. addplayer - Allows new players to be added to the game. If a player with the given username already exists, the system should indicate this.

      Syntax:

       addplayer username,family_name,given_name
      
    2. removeplayer - Allows players to be removed from the game. The username of the player to be removed is given as an argument to the command. If no username is given, the command should remove all players, but in this case, it should display a confirmation question first (ask whether user wants to delete all or not and then user need to input y or n). If a username for a non-existent player is given, the system should indicate that the player does not exist.

    • remove one player

      Syntax:

      removeplayer username
      
    • remove all player: enter removeplayer then display the second sentence.

      Syntax:

       removeplayer
       Are you sure you want to remove all players? (y/n)
      
    1. editplayer - Allows player details to be edited. Note that the player’s username cannot be changed after the player is created. If a username for a non-existent player is given, the system should indicate that the player does not exist.

      Syntax:

       editplayer username,new_family_name,new_given_name
      
    2. resetstats - Allows player statistics to be reset. The username of the player whose statistics are to be reset is given as an argument to the command. If no username is given, the command should reset all player statistics, but as with the ‘removeplayer’ command, a confirmation question should be displayed in this case. If a username for a non-existent player is given, the system should indicate that the player does not exist.

      Syntax:

      resetstats username

    3. displayplayer - Displays player information. The username of the player whose information is to be displayed is given as an argument to the command. If no username is given, the command should display information for all players, ordered by username alphabetically. If a username for a non-existent player is given, the system should indicate that the player does not exist, as illustrated in the example execution. Please note when displaying player, the sequence of syntax is username,givenname,familyname,number of games played,number of games won.

      Syntax:

       displayplayer username
      
    4. rankings - Outputs a list of player rankings. There are three columns displayed. The first column displays percentage wins or winning ratio, the second column displays the number of games played, and the final column shows the player’s full name, that is, first name followed by last name. This command takes the sort order as an argument. The sort order is desc or descending by default. That is, if no argument or desc is provided, the program should rank the players by the percentage of games they have won in descending order, i.e., players with highest percentage wins should be displayed first. If the user provides asc as an argument, the players should be ranked by the percentage of games they have won in ascending order. Round the percentages to the nearest integer value. However, you should use the exact values of winning ratios when comparing and sorting two users’ winning ratios. Ties should be resolved by sorting on usernames alphabetically. Only the first 10 players should be displayed, if there are more than 10. The output should be formatted according to the example below. For the purposes of formatting the output, you may assume that no player has played more than 99 games. Note that the vertical lines need to be aligned, with a single space appearing on either side. This means that in the first column you must have 5 characters consisting of a number, ’%’, and spaces. The first column must be left-justified.

      Syntax:

       rankings [asc|desc]
      

      Example Execution:

       100% | 03 games | XXXX XXXXXX
       75%  | 04 games | ZZZ ZZZZZ
       14%  | 07 games | YYY YYYYYY
      
    5. startgame - Creates and commences a game of Nim. The game’s rules, and the usernames of the two players, are provided as arguments. You may assume that the initial stones and upperbound arguments are valid and correct. However, if at least one (i.e. one or two) of the usernames doesn’t correspond to an actual player, the system should indicate this by the output “One of the players does not exist.”, and the game should not commence. Otherwise, the ‘startgame’ command will commence a game, i.e., after executing it, the system is in the game state. When a game is in progress, the system should proceed according to the game play mechanics discussed in Project A, i.e., players should, in an alternating fashion, be asked to enter the number of stones they would like to remove, with the game state being updated accordingly. In this project, bounds on stone removal should be enforced. That is, players should only be allowed to remove between 1 and N stones inclusive, where N is the upper bound or the number of stones remaining, whichever is smaller. Once all the stones are gone, a winner should be announced, and the statistics for the two players should be updated accordingly. The system should then return to the idle state, and a command prompt should be displayed again.

      Syntax:

       startgame initialstones,upperbound,username1,username2
      

      Example of the game

       $startgame 10,3,X,Y
       
       Initial stone count: 10
       Maximum stone removal: 3
       Player 1: XXX XXXXXX
       Player 2: YYY YYYYYY
       
       10 stones left: * * * * * * * * * *
       XXX’s turn - remove how many?
       $3
       
       7 stones left: * * * * * * *
       YYY’s turn - remove how many?
       $4
       
       Invalid move. You must remove between 1 and 3 stones.
       7 stones left: * * * * * * *
       YYY’s turn - remove how many?
       $3
       
       4 stones left: * * * *
       XXX’s turn - remove how many?
       $3
       
       1 stones left: *
       YYY’s turn - remove how many?
       $0
       
       Invalid move. You must remove between 1 and 1 stones.
       1 stones left: *
       YYY’s turn - remove how many?
       $1
       
       Game Over
       XXX XXXXXX wins!
      

Source

University of Melbourne COMP90041 Subject

Received marks of this project: 19 / 20

nimgame_project2's People

Contributors

zavieryang avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.