Categorias: Todos - planning - methods - classes - implementation

por Isabella Arsenault 2 anos atrás

141

ICS4U Summative Planning (Mancala Part 1)

The document outlines the initial planning stages for a project involving the implementation of a game called Mancala. It discusses the preliminary ideas for class structures and methods that will be used in the project.

ICS4U Summative Planning     (Mancala Part 1)

NOTE!!!! When we got more time for this I went back and added a much more in depth plan on the bottom right of this mind map - on the left are pretty rough ideas - on the right most aspects of my project are broken down in a good amount of detail - I'm so sorry that this is a bit all over the place

Legend:

Explanations of various things My thought process will be in these boxes the right of this mind map I left for putting project requirements that have been provided to us the left of the mind map is where I am putting all my ideas and my planning process

Class ideas - very rough draft before thinking about how to better implement them for this assignment

Ideas of classes that I would need and methods that they would implement

Ideas of what abstract parent classes would look like
Sub classes will be shown like this For most of my classes there will also be an arrow pointing to explanation of the use of the parent class - I couldn't figure out how to have only one arrow pointing to different subclasses

Main Topic

ICS4U Summative Planning (Mancala Part 1)

Formatting ideas

Graphic components needed for the high score displaying
labels for name, score and for the menu high scores: the game that the name/score are associated with
Graphics components needed 2048
buttons or drop down menu for navigation
sensors for when actual key board keys are being pressed
would need a design - maybe painting different colour squares in 2d array for rows and columns
Graphic components needed mancala
Panels for holding everything
Labels for game title
paint different stone amounts that would change as slots in the game are filling up or emptying
invisible buttons for when user is choosing where they want to play
Buttons or drop down menu for navigation
paint the mancala board png

using this image taken from google

pop up prompt for user to enter their username
Graphics components needed: menu
Possibly a drop down menu?
Buttons for navigation
Labels for title
See slideshow for visual representation of this plan - in present mode the names of things are linked as if they were actual buttons so it can be used as actual navigation

2048 Rough Ideas

Technically if time could add a section where the high score is displayed along with the current user score because that is more similar to the actual 2048 game
possibly have the option to win the game when 2048 is reached - have continue playing method? where win label would just be set back to invisible and it would be like nothing happened
Tiles should change colour based on how large the number is
I need some sort of tile or square that is not a button that I can use to manipulate the board to show the correct visuals to the user
Label for showing highscore that would change/update as game is being played
would need to check when board is full and none of the tiles can merge which would be game over
would need to check to make sure board can move - sometimes when there is nothing to merge or almost full than even if the user is pressing a direction key, they will not be able to go in that direction
key sensors that tell when the user is pressing up/down or right/left
Planning for this not as in depth - am only going to code this section if I have the time but mancala is the priority

Classes and their methods/ variables that could be useful

AI - class where ai would be choosing its next move
Second option would be to have the ai evaluate each of its moves - checking in a way its neural moves its offensive moves and the defensive moves for neutral it would be checking if there are enough stones in any of its slots to land exactly in the end zone and get an extra turn for offensive it would be checking if there are any empty slots on its side and then if they had any slots with enough stones to land exactly in it and steal the opponents stones the defensive would just be the reverse of the offensive - checking if the actual player has any options to steal any of the stones on the ai's side finally, would probably need an algorithm to way in which type of move is the best move - like if there is an offensive move that will gain the ai 2 stones but if the computer will then lose 5 stones because it didn't check for its defensive moves than there would need to be a way to see which will either gain the most/and lose less than the ai is losing or finding moves where the ai will lose the bare minimum but maybe is gaining stones somewhat slowly
Could have a randomizer where the ai will choose one of the available slots to play and there would be no strategy in choose
Highscores class
Am going to try and use inheritance here at some point - will outline the main methods and variables that all the high scores need and then each high score would just be displaying slightly different things depending on the game highscores that it is displaying or if it is the highscores that are displayed through the menu it should display both
2048 High Scores
Mancala highscore Class how many stones the player ends their turn with

When each entry is added into the .txt file it would be read back into the program and turned into a doubly linked list so that the high scores can be displayed and that the program can traverse through to sort the scores highest to lowest - I think that linked lists would be the most efficient way of storing this information, especially with

Would need class for adding scores and names to a .txt file

Top 5 high scores for both games

will be able to access both of the separate game .txt files and add them to one cumulative file that has all the names and scores on them - would need to find a way to also assign a variable saying which game each high score is related to - will then go through and take the top five - back into another doubly linked list - and would have method to display the top five on another panel

would keep track of names and high scores - figure out how high scores in 2048 are calculated - in the 2048 displaying of high scores it would display all the high scores

If two player game, will have both names of player and then will add an entry for each player and the associated number of stones that ended in their zone would be treated as their high score if it was a player playing with the ai, then it would only be the player that has the score recorded when displaying - would display all the names on the file

Each of the following would have the same methods that have been discussed - the ways that they are slightly altered will be discussed under their tabs

Could maybe inherit? think about this some more would need variables - name and score would need file writer + writeFileMethod: would go through until the next pointer is null and add each line to the file at some point - possibly not in this class would then need a buffered reader to read back the file info - should probably try and keep all the file related methods in the same class would be the parent class to all the other separate game methods that would need to create the .txt file and add entries to it

For my project I want to create files with all the high scores so that all the user high scores are not lost when the user closes the window

And would need a class for the linked list operations

inherits the same but might need a different maxSize than the other two not entirely sure yet

subclass inherits same methods and variables from parent class

Subclass inherits same methods and variables from the parent class

Has variables: int maxSize, int size gameClass head, gameClass tail

Would have the following methods: void add(EntryGame newEG) void remove(String name) boolean hasNext() String toString

Would then need a node class of highscore entries

Menu Screen High Scores

2048

Mancala

node that inherits from parent class, would. need same methods - only difference would be being called in different places

Has variables: string name, int score className next, className prev

Would have the following methods: Constructor for initializing game entry that is passed in probably won't have an exception for if the user enters their info in the wrong order - instead having pop-ups that would prompt the user to enter everything in the right order but could still make an exception for in the weird case that it did happen and surround everything with a try/catch statement getters : getName, getScore, getNext, getPrev setters: setNext and setPrev toString (would pass back getName and get Score)

THIS WOULD BE THE OUTLINE OF AN ABSTRACT CLASS THAT WOULD BE THE PARENT OF ALL THE OTHER CLASSES FOR EACH GAME THAT NEEDS TO USE A HIGH SCORE each game will have a different .txt file that holds the scores, and there will be one .txt with the combined top five scores

going to be adding all the high scores to a separate .txt file where when viewing the files, the user could choose to delete a high score that is present. for deleting - ask the user if they want to delete the highest score or lowest score associated with their name - would determine which way to go through the list to find the right thing to delete

Game board (RULES)
Would be used for keeping track of stone movements if a stone lands in the players end then they would get a bonus turn if their stone lands on an empty slot on their side than they will get to steal all of the stones on the opposite slot if there any in the slot the game will end when either player no longer has any stones left on their side the remaining stones on the board go the the opposite player for right now - might just implement the ending as the stones that are in each end zone will be the amount that both players end with
Window for displaying the menu
Board class (HOW THE PLAYER CAN PLAY) (Separate class but called in the menu window displaying class)

Should be keeping track of how many stones are in each slot would call on another graphics class for properly displaying the amount of stones are in each slot I would like to implement a mouse listener where if the user hovers over a slot they can see how many stones are in it

Probably going to have separate classes when implementing the ai - human turns for two player and the human part of the one player will go in one class while the ai strategy will be in a separate class - This is outlined in a class to the right

Methods for if it is 1 player Mancala and then AI would play as the other player choosing whether to make the AI just randomly choose a turn or choosing the more complex way where it would try and see if it can steal stones or if it has enough stones to get bonus turns - if I have time would be something good to consider - if not, make the ai just choose a random place to go on their own side that has stones in the slot

Methods for two player mancala needs to check when the player is choosing where is going to go and checking to make sure that the slot isn't empty and that the side that they are playing on is the side that corresponds to the right person the slots will be kept in an array of ints - the integer number representing the amount of stones that are in the slot at a time

Constructor for setting the card layout (can card layout work for two separate classes? might just need one big class with action listeners figure out different panes and possibly using a drop down menu to change different games and find the high score instead of just using a ton of buttons to navigate through the program) find way for window to expand to full screen instead of just staying super small and tiny - see example gui code that has been provided
Stone Graphics
Not entirely sure yet how I am going to implement the stone graphics but underneath I'll highlight a few different ideas about possible ways

In regards to deciding how to tell which amount of stones I need to display I'm in between two ideas currently one - use a super class of stone and have the sub classes of all the different images of the stone or create a case statement within the program

For actually creating the stones I would either paint them from scratch - take an image and edit it from online or take a picture myself of mancala stones that I have at home and get it so that there is no background behind them

Because it is possible to have so many stones in each slot I would only have animations for up to five stones in a slot then depending on the number it would display the correct number and the user could hover over to see the precise number of stones that they have

Classes (ideas)

Game Board Layout Class
If I HAVE TIME
Add menu that lets user choose whether they want to play mancala or 2048 if mancala is chosen to be played then they will be asked if they want to play the one player game with AI or play the two player version - create really good ai add music into the game - good music if they choose 2048 it would take them to the 2048 game Each panel would be laid out in a cardLayout and could be accessed through buttons within the program - See attached slideshow to see game design
Mancala Rules Class
Class/Classes for Exceptions
Exception for slot being empty player trying to play on the wrong side
Inherits from Exception
Window for displaying
Menu panel for selecting which game to play - 2 player or play with computer ai

Concepts learned in class that will be used in this assignment - BRAINSTORMING - might not use all of these ideas but possibilities when going into implementing my code

Could use more items on the graphics side of things to create a better board than just creating a panel filled with 12 buttons that would represent each "slot" figure out a way to draw the entire board as well as the stones that are in each slot Using action listers to exception handle and let the user play their turn - for implementing 2048 could use key listeners with the associated numbers that refer to the right keys to move the board properly when the user uses the up/down right/left keys
A way to use inheritance would be to create a player parent class that allows the basic functions of the user being able to assign themselves a name/username - once they finish playing the game it for each game would keep username and score to all of the users that can be accessed within the game in a linked list so it can display the top five - linked list seems more efficient than using a sorting algorithm with an array - queue and stack doesn't really fit the purpose of displaying the high scores in this case for all of the high scores they should also associate which game they are associated with so that in the main menu, the user can access the high scores of the current window - maybe see if theres a way to add it to a txt file so that the scores can be remembered or just have it display the top five scores of each game while the window hasn't been closed

Main ideas reformatted for classes

2048 rough ideas are on another branch and won't be discussed in a lot of detail because that is more an extra part for the sake of my own amusement
AI class
Would access the information about how many stones are in each slot - would access the information from the mancala rules (the controller)
2. the second way would be to set up the ai to evaluate three conditions - there would be the defensive case, the neutral case and the offensive case that the ai would need to choose from and then weigh it's options to choose the best play

Neutral: checking if there is an option to get a bonus turn could probably check at the end if there is a way to get a bonus turn and then also perform an offensive or defensive move

Offensive: the offensive check would basically be the opposite of the defensive - the ai would check if there are any empty slots on their side and if there are in would take into account how many stones it would be stealing from it's opponent

would do the same as the defensive but could also be able to check if there are a lot of stones in the slot that the ai is assessing than it could see if it has enough stones to go around the board once and then land in the newly empty pile or another previously empty pile

Defensive: needs to check and see if the opponent has any open slots and the correct number of stones to land in the empty slot and steal the ai's stones - would take into account how many stones would be stolen

would need to loop through the array that holds the amount of stones on the opponents side, takes account of slots with 0 stones, would then have to loop through the array again - only on the opponents side and see if there are any amounts of stones on their slots that would land in the empty slot

Would implement the ai one of two ways 1. have the program search for all the slots on the correct sides, put the numbers that would correspond to each of the playable slots into an array and randomly choose an int which would determine which of the slots the ai would choose to play out of
Model class would take input from the rules class and change how things are being displayed in the view
I am not entirely sure what I want this class to do, but I would like to use it to try and make my code more straightforward to read in general - I'll come back to the purpose of this class and how it turned out in my reflection
should also send updates to the visual frame to update labels on whos turn it is
This would be the class that is controlling the things like updating the amount of stones that should be displayed on screen when a user plays their turn

Would be connected to the controller class - receives info from the rules/controller class about how the user is playing and would update the way that the view class is displaying its information

High scores class
Abstract parent class that creates the blueprint of the basics that the other high score classes should have trying to incorporate inheritance into the program this would only make sense if I get 2048 working as well other wise I would just have one high scores class I talk about using the variables in the high scores class - have changed my mind where they would be used in an entries class because I am using my own linked list instead of the java libraries linked list I am also just a tiny bit lazy here so they won't be deleted in the top classes underneath here but they will be talked about in the game entry class

In the sub classes there would be a .txt file that is made for each game and the menu high scores will the top five game high scores for both available games to play in this summative

Could probably either have 3 .txt files or just have one big .txt file and then the program would need to check which game the score belonged to while it is reading through each line and adding entries to the linked list

Each subclasses of the high scores will have a read and write method for the file that contains all the high scores the file is created so that the high scores are not lost when the user quits the program

the mancala and 2048 high scores classes will display all the high scores whereas the menu high scores will only display the top five scores from both games as well as displaying which game the scores belong to

The subclasses will then read through the file and add each line (the name, score) the game variable for mancala high scores and 2048 scores would not be displayed - possibly set to null - when each entry is read in they will be added to a linked list that is sorted with the best score being at the start and the worst score being at the end

And possibly have a game entries class this class would be shared by both games

would have the following getters and setters getName getScore getNext getPrev setNext setPrev

would have a constructor

would contain variables for name, score, game, next and previous

because I am using a linked list I will create my own so I will need a doubly linked list class

have a hasnext function and then a getnumentries that could be displayed at the top/bottom of the high scores display (maybe?)

have addlast and addfirst method that would be private

Would have variables of the game entry type for the head and the tail

If i manage to add the delete button for the high scores than it would need a remove method

the linked list class would have an add method

Would probably just be using the code from the linked list assignment and change it slightly because they basically have the same purpose of the basic functions being used

Would start off with a blank .txt file for all of the high score subclasses

The parent class would have the protected variables of username. score and game

Game would be set to null for the mancala and 2048 high scores

Mancala rules - would act as the controller class as the user uses the program the rules class will update the amount of stones in each slot (not the display just the back end info), would deal with checking for a winning case and seeing if user gets a bonus turn or can steal the opponents stones if they landed in an empty slot
after each turn the player should be switched

have a getplayer and setplayer method

when user hovers over a box, should return the amount of stones to the model class so that it can be displayed on screen
Exceptions that would need to be handled

have pop-up messages that either disappear after a certain amount of time or have the user be able to x out of the pop-up

user chooses a slot to play that doesnt have any stones than they need to choose another slot user tries to play on the opposite players side user tries to play from one of the end zones

method for user playing a turn

would take into account which slot is chosen and will add one stone to each of the next array values for the amount of stones that were in the original pile if the very last slot turns into a one - then the method for checking for stealing should occur

Would need a constructor and getters and setters
Method for checking for bonus turn

if last stone ends in the users end zone than they will get to play again

Method for checking for stealing

if last stone lands exactly on an empty slot on the users side and their opponent has stones in the opposite slot than the stones in the opponents slot gets

have some method that will be able to tell if the value of the slot from the array value is 0

Would have separate methods for checking for winning cases

The game is over is there are no more stones left on one of the sides

the player with the remaining stones on their sides gets to keep those stones

Class would contain the 1d/2d array that would represent the game slots (should be 14, 12 normal and the two end slots)

would be an array of ints, where the int value of each would represent the amount of stones that are in each slot

need some way of differentiating the end piles - maybe having them in a separate array but would still need way of adding stones to the end zones

Class for displaying this is the view of MCV it is what the user is shown - like the front end design of the project displaying through different panels in a cardlayout to be able to switch back and forth the different panels in this class will be - 1 - menu panel, 2 - menu high scores panel, 3 - mancala panel, 4 - mancala high scores panel, 5 - 2048 panel, 6 - 2048 high scores panel
mancala high scores panel

possibly add a button that would prompt the user if pressed to ask if they want to delete an entry - this would be something to add if there is extra time

would need labels or a space on screen where the high scores are displayed

user name and amount of stones captured in end zone would be displayed

Would need buttons for navigation to menu or back to the game screen

Menu high scores panel

like the mancala high scores, if time would add a delete entry button to delete a high score - based on username that the user would enter into the pop-up and then would go thru linked list of high scores until the match was found if not having a pop-up exception of username not being found come up on screen for a little bit

labels for which game the high score is related to, the user name and the actual score

Would need a button for navigation back to the menu

2048 panel briefly described over to the right
THIS IS SPECIFICALLY FOR THE MANCALA JPANEL for this display under currently the plan for the mancala layout is described - at the same level of this branch will be a couple of other panels that would be in a cardlayout Will need to have different images for the background need to find out whether making a panel with an image background will only fit the dimensions of the image or whether more space can be added if more space cant be added than import the png to google drawings, add space and then add the buttons in front afterwards

If I had time at the end could probably also have a pop-up appear right before the user is quitting the actual program to ask them if they are sure

Would also need popup that would appear for the user to enter their username this info would later be passed into the high scores class so that the right score is displayed with the right person

On the highest layer I will have buttons that have their visibility set to true, but they will have a transparent background and no edge it needs to be at the front so that when the user is trying to choose where to make their move then they will be able to click on the buttons instead of clicking on an image and having nothing happen

Another similar implementation of the buttons would be putting if statements for when the mouse is clicked in a certain area - in a way forming a square with x/y coords where certain intervals would correspond to a slot and the associated slot would be modified when the user's mouse is clicked in the box

For the buttons I will have a 2d array of buttons for the 12 buttons in the two rows

The end zone buttons will be in a separate 1d array

using pop-ups for the exceptions so that the console does not need to be used. either set the pop up so that the user can click to exit or so that it disappears after a certain amount of time

The end zones need buttons not so that the user would choose to move their stones if they pressed on that button, instead for the program to exception handle

One image with the stones this would be in front of the image of the game board either have a hierarchy of different stone images that would be displayed or repaint for the correct amount of stones when necessary

Would also need a label for which player's turn and a label for the winner

could also have a case statement with the different amounts of stones that should be displayed and then would just repaint accordingly

The images would all already be loading using a buffered image and then ImageIO.read(new File()) method

If using a hierarchy for the stones than there would be the abstract parent class with the main characteristics of the stone - maybe the conditions for when a different type of stone is displayed

Would have five subclasses - one for each of the different types of stones that would be displayed depending on the number of stones in each slot - see google slides for ideas of what stones will look like

I don't want to have text that is displaying the amount of stones in each slot the entire time because in a real game you wouldn't be able to count the number of stones

On the same level there would be labels next to each box that would be set to invisible and when the user would hover over each of the slots than the label would become visible and display the amount of stones that are in the slot

The labels could also probably be created in a 2d array

As the amount of stones in each slot is changed the label that displays the amount should be changed accordingly

Would need to use a mouse listener that could probably use the buttons as what the mouse listener is set to and when the mouse is hovered over the visibility will change

One image with the game board the game board would be in front of the background

At the bottom there would be three buttons on the same lvl one for resetting the game one for viewing high scores and the last would be to quit and go back to the main menu

Buttons would have action listeners for when clicked to either reset game, change to the menu panel or change to the high score panel

On the same level as this I would have a title label at the top of the panel to display which game is being played

I guess the easiest way as I am thinking about this is to have a three layers of images - one layer which will be the background and it will be at the very back of the panel

Am having a background image so I can have the panel be bigger than just the size of the board - I am ok if it is the same width as the board png but want it to be a bigger height

Menu Jpanel

potentially add image or something as an icon for summative

Buttons for: going to mancala going to menu high scores - page that would hold the high scores of both games going to to play 2048 quitting the program

Clicking on these buttons would switch which panel is being displayed with the card layout

Possibly create a pop-up that when the quit button is pressed it makes sure that that was an intential choice by the user

Label for title

label for subtitle

Am trying to use the Model, View, Controller method of setting up my code to try and make it more efficient - using info based of of this website (see link to the side of this box, it should be a very small c to the right)

Part 3 Requirements

Finally rate yourself by copying the evaluation below and add it to the document you hand in.
Write a Personal Critique of what you have accomplished Reflect on your overall design. Include a description of the implementation of your Game Include Name and rules – particularly if you decided to implement “different” rules and why Are you satisfied with its outcome? State the limitations (what does not work that well)… be specific State the strengths of the program…. be specific State ways you could improve (make it better, add additional features or make it more user friendly)… be specific

Part 2 Requirements

6. Remember to include your headers and decent comments in your code (a quick description at the beginning of a method should be sufficient in most cases)
5. You must present an option to play again.
4. You must have some form of message stating the end of the game.
3. You must check for invalid moves.
2. Implement the rules and details as you see most beneficial. To start make the program two player, you can implement “player vs the computer” if you have time.
1. Implement the game with at least 2 classes. The first is a window class. This sets up your frame for your game (similar to what you did for TicTacToe). The second class should probably be the game board and any of its relevant characteristics. Sometimes it is easier to have a class that executes the rules holds the values that are later shown on the board, I leave this up to you. If you would like to implement this as a console application you may do so.

Part 1 Requirements

Create a document (you can include a visual with some explanation) on how you will create the program. The more new (and appropriate) features/concepts that we have learned, the better. If it helps to explain what is happening you may be want to use a diagram similar to the image to the right. Please note, all of your field and method names need not be on the chart, but those that you can think of to start off would be helpful. Having a good idea of the relationship of your classes is more important at this stage. (inheritance is shown with the arrow to the superclass)